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