Choreonoid  1.8
SimpleController.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_BODY_SIMPLE_CONTROLLER_H
6 #define CNOID_BODY_SIMPLE_CONTROLLER_H
7 
8 #include "ControllerIO.h"
9 #include "exportdecl.h"
10 
11 namespace cnoid {
12 
13 class CNOID_EXPORT SimpleControllerIO : public ControllerIO
14 {
15  public:
16  virtual void enableIO(Link* link) = 0;
17  virtual void enableInput(Link* link) = 0;
18  virtual void enableInput(Link* link, int stateFlags) = 0;
19  virtual void enableOutput(Link* link) = 0;
20  virtual void enableOutput(Link* link, int stateFlags) = 0;
21  virtual void enableInput(Device* device) = 0;
22 
23  template<class T> T* getOrCreateSharedObject(const std::string& name) {
24  return body()->getOrCreateCache<T>(name);
25  }
26 
27  template<class T> T* findSharedObject(const std::string& name){
28  return body()->findCache<T>(name);
29  }
30 
31  [[deprecated("Use the controllerName function.")]]
32  std::string name() const;
33  [[deprecated("Use enableInput for all links.")]]
34  virtual void setJointInput(int stateFlags);
35  [[deprecated("Use enableOutput and Link::setActuationMode for all links.")]]
36  virtual void setJointOutput(int stateFlags);
37  [[deprecated("Use enableInput for the link.")]]
38  virtual void setLinkInput(Link* link, int stateFlags);
39  [[deprecated("Use enableOutput and Link::setActuationMode for the link.")]]
40  virtual void setLinkOutput(Link* link, int stateFlags);
41 };
42 
43 
45 {
46 public:
47  [[deprecated("Use ControllerIO::isNoDelayMode().")]]
48  virtual bool isImmediateMode() const = 0;
49  [[deprecated("Use ControllerIO::setNoDelayMode().")]]
50  virtual void setImmediateMode(bool on) = 0;
51 };
52 
53 
54 class CNOID_EXPORT SimpleControllerConfig
55 {
56 public:
58 
59  virtual std::string controllerName() const;
60  virtual Body* body();
61 
69  virtual Referenced* bodyItem();
70 
71  virtual std::string optionString() const;
72  std::vector<std::string> options() const;
73  virtual std::ostream& os() const;
74  SignalProxy<void()> sigChanged();
75 
76 private:
78  Signal<void()> sigChanged_;
79 };
80 
81 
82 class CNOID_EXPORT SimpleController
83 {
84 public:
85  typedef SimpleController* (*Factory)();
86 
87  virtual ~SimpleController();
88 
100  virtual bool configure(SimpleControllerConfig* config);
101 
107  virtual bool initialize(SimpleControllerIO* io);
108 
116  virtual bool start();
117 
125  virtual bool control();
126 
131  virtual void stop();
132 
137  virtual void unconfigure();
138 
139  enum StateType {
140  StateNone = Link::StateNone,
141  JointDisplacement = Link::JointDisplacement,
142  JointAngle = Link::JointAngle,
143  JointVelocity = Link::JointVelocity,
144  JointAcceleration = Link::JointAcceleration,
145  JointEffort = Link::JointEffort,
146  JointForce = Link::JointForce,
147  JointTorque = Link::JointTorque,
148  LinkPosition = Link::LinkPosition,
149  LinkTwist = Link::LinkTwist,
150  LinkExtWrench = Link::LinkExtWrench,
151  LinkContactState = Link::LinkContactState,
152 
153  // deprecated
154  JOINT_DISPLACEMENT = JointDisplacement,
155  JOINT_ANGLE = JointAngle,
156  JOINT_VELOCITY = JointVelocity,
157  JOINT_SURFACE_VELOCITY = Link::DeprecatedJointSurfaceVelocity,
158  JOINT_ACCELERATION = JointAcceleration,
159  JOINT_EFFORT = JointEffort,
160  JOINT_TORQUE = JointTorque,
161  JOINT_FORCE = JointForce,
162  LINK_POSITION = LinkPosition,
163  LINK_FORCE = LinkExtWrench
164  };
165 
166  protected:
168 
169  private:
171 };
172 
173 }
174 
175 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
176 #define CNOID_SIMPLE_CONTROLLER_EXPORT __declspec(dllexport)
177 #elif __GNUC__ >= 4
178 #define CNOID_SIMPLE_CONTROLLER_EXPORT __attribute__ ((visibility("default")))
179 #else
180 #define CNOID_SIMPLE_CONTROLLER_EXPORT
181 #endif
182 
184 
185 #define CNOID_IMPLEMENT_SIMPLE_CONTROLLER_FACTORY(ControllerClassName) \
186  extern "C" CNOID_SIMPLE_CONTROLLER_EXPORT cnoid::SimpleController* createSimpleController() \
187  { \
188  return new ControllerClassName(); \
189  }
190 
191 #endif
cnoid::SimpleControllerIO::getOrCreateSharedObject
T * getOrCreateSharedObject(const std::string &name)
Definition: SimpleController.h:23
ControllerIO.h
createSimpleController
CNOID_SIMPLE_CONTROLLER_EXPORT cnoid::SimpleController * createSimpleController()
CNOID_SIMPLE_CONTROLLER_EXPORT
#define CNOID_SIMPLE_CONTROLLER_EXPORT
Definition: SimpleController.h:180
cnoid::SimpleController
Definition: SimpleController.h:82
cnoid::SimulationSimpleControllerIO
Definition: SimpleController.h:44
cnoid::ControllerIO
Definition: ControllerIO.h:16
cnoid::SimpleControllerIO::findSharedObject
T * findSharedObject(const std::string &name)
Definition: SimpleController.h:27
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::SimpleController::StateType
StateType
Definition: SimpleController.h:139
cnoid::SimpleControllerConfig
Definition: SimpleController.h:54
cnoid::Referenced
Definition: Referenced.h:54
cnoid::SimpleControllerIO
Definition: SimpleController.h:13
cnoid::Body
Definition: Body.h:28
cnoid::Signal
Definition: Signal.h:165
cnoid::Device
Definition: Device.h:53
cnoid::SignalProxy
Definition: Signal.h:470