NTRT Simulator  v1.1
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgBasicController.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
27 #include "tgBasicController.h"
28 
29 #include "core/tgControllable.h"
30 
31 // The C++ Standard Library
32 #include <cassert>
33 #include <stdexcept>
34 #include <cstddef> // NULL keyword
35 
36 tgBasicController::tgBasicController(tgControllable* controllable, double setPoint) :
37 m_setPoint(setPoint),
38 m_controllable(controllable)
39 {
40  assert(controllable != NULL);
41 }
42 
44 {
45  m_controllable = NULL;
46 }
47 
49 {
50  if (dt <= 0.0)
51  {
52  throw std::runtime_error ("Timestep must be positive.");
53  }
54 
56 }
57 
58 void tgBasicController::control(double dt, double setPoint, double sensorData)
59 {
60  if (dt <= 0.0)
61  {
62  throw std::runtime_error ("Timestep must be positive.");
63  }
64 
65  // Suppress compiler warning for unused variable
66  (void)sensorData;
67 
68  setNewSetPoint(setPoint);
69  control(dt);
70 }
71 
72 void tgBasicController::setNewSetPoint(double newSetPoint)
73 {
74  m_setPoint = newSetPoint;
75 }
76 
77 
tgControllable * m_controllable
virtual void setControlInput(double input)=0
Definition of the tgControllable abstract base class.
virtual void setNewSetPoint(double newSetPoint)
virtual void control(double dt)
virtual void control(double dt, double setPoint, double sensorData=0)
tgBasicController(tgControllable *controllable, double setPoint=0.0)
Definition of the tgBasicController base class.