openrave.org

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
controller.h
Go to the documentation of this file.
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2006-2011 Rosen Diankov <rosen.diankov@gmail.com>
3 //
4 // This file is part of OpenRAVE.
5 // OpenRAVE is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef OPENRAVE_CONTROLLER_H
23 #define OPENRAVE_CONTROLLER_H
24 
25 namespace OpenRAVE {
26 
31 {
32 public:
33  ControllerBase(EnvironmentBasePtr penv) : InterfaceBase(PT_Controller, penv) {
34  }
35  virtual ~ControllerBase() {
36  }
37 
39  static inline InterfaceType GetInterfaceTypeStatic() {
40  return PT_Controller;
41  }
42 
48  virtual bool Init(RobotBasePtr robot, const std::vector<int>& dofindices, int nControlTransformation) = 0;
49 
51  virtual const std::vector<int>& GetControlDOFIndices() const = 0;
52 
56  virtual int IsControlTransformation() const = 0;
57 
58  virtual RobotBasePtr GetRobot() const = 0;
59 
62  virtual void Reset(int options=0) = 0;
63 
68  virtual bool SetDesired(const std::vector<dReal>& values, TransformConstPtr trans=TransformConstPtr()) = 0;
69 
73  virtual bool SetPath(TrajectoryBaseConstPtr ptraj) = 0;
74 
77  virtual void SimulationStep(dReal fTimeElapsed) = 0;
78 
85  virtual bool IsDone() = 0;
86 
88  virtual dReal GetTime() const OPENRAVE_DUMMY_IMPLEMENTATION;
89 
93  virtual void GetVelocity(std::vector<dReal>& vel) const OPENRAVE_DUMMY_IMPLEMENTATION;
94 
98  virtual void GetTorque(std::vector<dReal>& torque) const OPENRAVE_DUMMY_IMPLEMENTATION;
99 
100  // Specifies the controlled degrees of freedom used to control the robot through torque In the
101  // general sense, it is not always the case that there's a one-to-one mapping between a robot's
102  // joints and the motors used to control the robot. A good example of this is a
103  // differential-drive robot. If developers need such a robot, they should derive from RobotBase
104  // and override these methods. The function that maps control torques to actual movements of
105  // the robot should be put in SimulationStep. As default, the control degrees of freedom are
106  // tied directly to the active degrees of freedom; the max torques for affine dofs are 0 in
107  // this case.
108  // virtual void GetControlMaxTorques(std::vector<dReal>& vmaxtorque) const;
109  // virtual void SetControlTorques(const std::vector<dReal>& pTorques);
110 
111 private:
112  virtual const char* GetHash() const {
114  }
115 };
116 
122 {
123 public:
125  virtual ~MultiController();
126 
128  virtual bool Init(RobotBasePtr robot, const std::vector<int>& dofindices, int nControlTransformation);
129  virtual const std::vector<int>& GetControlDOFIndices() const;
130  virtual int IsControlTransformation() const;
131  virtual RobotBasePtr GetRobot() const;
132 
138  virtual bool AttachController(ControllerBasePtr controller, const std::vector<int>& dofindices, int nControlTransformation);
139 
141  virtual void RemoveController(ControllerBasePtr controller);
142 
144  virtual ControllerBasePtr GetController(int dof) const;
145 
146  virtual void Reset(int options=0);
147  virtual bool SetDesired(const std::vector<dReal>& values, TransformConstPtr trans=TransformConstPtr());
148  virtual bool SetPath(TrajectoryBaseConstPtr ptraj);
149  virtual void SimulationStep(dReal fTimeElapsed);
150 
152  virtual bool IsDone();
153 
155  virtual dReal GetTime() const;
156 
157  virtual void GetVelocity(std::vector<dReal>& vel) const;
158 
162  virtual void GetTorque(std::vector<dReal>& torque) const;
163 
164 protected:
166  std::vector<int> _dofindices, _dofreverseindices;
168  std::list<ControllerBasePtr> _listcontrollers;
169  std::vector<ControllerBasePtr> _vcontrollersbydofs;
172  mutable boost::mutex _mutex;
173 };
174 
175 typedef boost::shared_ptr<MultiController> MultiControllerPtr;
176 typedef boost::shared_ptr<MultiController const> MultiControllerConstPtr;
177 
178 } // end namespace OpenRAVE
179 
180 #endif