Klamp't  0.8.1
Controller.h
1 #ifndef CONTROL_CONTROLLER_BASE_H
2 #define CONTROL_CONTROLLER_BASE_H
3 
4 #include <Klampt/Modeling/Robot.h>
5 #include <Klampt/Sensing/Sensor.h>
6 #include "Command.h"
7 #include <KrisLibrary/File.h>
8 #include <map>
9 
28 {
29 public:
30  RobotController(Robot& robot);
31  virtual ~RobotController() {}
32  //subclasses fill these out
33  virtual const char* Type() const { return "RobotController"; }
34  virtual void Update(Real dt) { time+=dt; }
35  virtual void Reset() { time=0; }
36  virtual bool ReadState(File& f);
37  virtual bool WriteState(File& f) const;
38  //settings: can be set by external configuration files / functions
39  virtual map<string,string> Settings() const { return map<string,string>(); }
40  virtual bool GetSetting(const string& name,string& str) const { return false; }
41  virtual bool SetSetting(const string& name,const string& str) { return false; }
42 
43  virtual vector<string> Commands() const { return vector<string>(); }
44  virtual bool SendCommand(const string& name,const string& str) { return false; }
45 
46  //convenience functions
47  void SetPIDCommand(const Config& qdes);
48  void SetPIDCommand(const Config& qdes,const Config& dqdes);
49  void SetFeedforwardPIDCommand(const Config& qdes,const Config& dqdes,const Vector&torques);
50  void SetTorqueCommand(const Vector& torques);
51 
52  bool GetCommandedConfig(Config& q);
53  bool GetCommandedVelocity(Config& dq);
54  bool GetSensedConfig(Config& q);
55  bool GetSensedVelocity(Config& dq);
56 
57  Robot& robot;
58  Real time;
60 
63 };
64 
68 shared_ptr<RobotController> MakeDefaultController(Robot* robot);
69 
79 {
80  public:
81  static void RegisterDefault(Robot& robot);
82  static void Register(RobotController* controller);
83  static void Register(const char* name,RobotController* controller);
84  static shared_ptr<RobotController> CreateByName(const char* name);
85  static shared_ptr<RobotController> CreateByName(const char* name,Robot& robot);
86  static shared_ptr<RobotController> Load(const char* fn,Robot& robot);
87  static bool Save(RobotController* controller,const char* fn);
88  static shared_ptr<RobotController> Load(TiXmlElement* in,Robot& robot);
89  static bool Save(RobotController* controller,TiXmlElement* out);
90 
91  static std::map<std::string,shared_ptr<RobotController> > controllers;
92 };
93 
94 //these macros will help you read in / write out settings
95 #define FILL_CONTROLLER_SETTING(res,membername) \
96  { \
97  stringstream ss; \
98  ss<<membername; \
99  res[#membername] = ss.str(); \
100  }
101 #define READ_CONTROLLER_SETTING(membername) \
102  if(name == #membername) { \
103  stringstream ss; \
104  ss << membername; \
105  str = ss.str(); \
106  return true; \
107  }
108 #define WRITE_CONTROLLER_SETTING(membername) \
109  if(name == #membername) { \
110  stringstream ss(str); \
111  ss >> membername; \
112  return bool(ss); \
113  }
114 
115 
116 #endif
The main robot type used in RobotSim.
Definition: Robot.h:79
A collection of basic motor types.
Definition: Command.h:43
A class to simplify the loading of different controllers at run time.
Definition: Controller.h:78
Real nominalTimeStep
a "desired" time step, by default 0, which acts as a hint to the simulator. Note that it doesn&#39;t have...
Definition: Controller.h:59
A set of sensors for the robot.
Definition: Sensor.h:106
RobotMotorCommand * command
motor command output (output to simulator)
Definition: Controller.h:62
A base class for a robot controller. The base class does nothing.
Definition: Controller.h:27
RobotSensors * sensors
sensor input (filled in by simulator)
Definition: Controller.h:61