Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
joint.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __JOINT_H
25 #define __JOINT_H
26 
27 #include <assert.h>
28 #include <list>
29 
30 #include "primitive.h"
31 #include "osgforwarddecl.h"
32 #include "axis.h"
33 #include "osghandle.h"
34 #include "odehandle.h"
35 
36 namespace lpzrobots {
37 
38 
39  /***************************************************************************/
40 
41  class Joint {
42  public:
44  : joint(0), part1(part1), part2(part2), anchor(anchor), feedback(0) {
45  assert(part1 && part2);
46  }
47  virtual ~Joint();
48  /** initialises (and creates) the joint. If visual is true then the joints is
49  also drawn. visualSize is the size of the visual representation.
50  If ignoreColl is true then the pair of connected parts is ignored
51  at collision handling.
52  The member variable odeHandle is set to the given handle.
53  (To be overloaded, but this init should be called always from children!)
54  */
55  virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
56  bool withVisual = true, double visualSize = 0.2,
57  bool ignoreColl = true);
58 
59  /// should syncronise the Ode stuff and the OSG notes (if any)
60  virtual void update() = 0;
61  /// sets the ODE joint parameter (see ODE manual)
62  virtual void setParam(int parameter, double value) = 0;
63  /// return the ODE joint parameter (see ODE manual)
64  virtual double getParam(int parameter) const = 0;
65 
66  dJointID getJoint() const { return joint; }
67  const Primitive* getPart1() const { return part1; }
68  Primitive* getPart1() { return part1; }
69  const Primitive* getPart2() const { return part2; }
70  Primitive* getPart2() { return part2; }
71  const osg::Vec3 getAnchor() const { return anchor; }
72 
73  /// returns the number of Axes
74  virtual int getNumberAxes() const = 0;
75  /// returns the n'th axis of the joint (starting with 0)
76  virtual Axis getAxis(int n) const { return Axis();};
77 
78  /// returns the positions of all Axes
79  virtual std::list<double> getPositions() const { return std::list<double>(); }
80  /// returns the position rates of all Axes
81  virtual std::list<double> getPositionRates() const { return std::list<double>(); }
82  /// stores the positions of all Axes into sensorarray and returns the number of written entries
83  virtual int getPositions(double* sensorarray) const { return 0; }
84  /** stores the position rates of all Axes into sensorarray and
85  returns the number of written entries
86  */
87  virtual int getPositionRates(double* sensorarray) const { return 0; }
88 
89  /// enable or disable the feedback mode
90  virtual void setFeedBackMode(bool mode);
91  /// torque applied to body 1 and body 2
92  virtual bool getTorqueFeedback(Pos& t1, Pos& t2) const;
93  /// force applied to body 1 and body 2
94  virtual bool getForceFeedback(Pos& f1, Pos& f2) const;
95 
96  static osg::Matrix anchorAxisPose(const osg::Vec3& anchor, const Axis& axis);
97  protected:
98  dJointID joint;
102 
103  dJointFeedback* feedback;
104  public:
106  };
107 
108  class OneAxisJoint : public Joint {
109  public:
111  : Joint(part1, part2, anchor), axis1(axis1) {}
112  virtual Axis getAxis(int n) const { return axis1;}
113  virtual Axis getAxis1() const { return axis1; };
114 
115  virtual double getPosition1() const = 0;
116  virtual double getPosition1Rate() const = 0;
117  virtual void addForce1(double force) = 0;
118 
119  virtual int getNumberAxes() const { return 1;};
120  virtual std::list<double> getPositions() const;
121  virtual std::list<double> getPositionRates() const;
122  virtual int getPositions(double* sensorarray) const;
123  virtual int getPositionRates(double* sensorarray) const;
124  protected:
126  };
127 
128  class TwoAxisJoint : public OneAxisJoint {
129  public:
131  const Axis axis2 )
132  : OneAxisJoint(part1, part2, anchor, axis1), axis2(axis2) {}
133  virtual Axis getAxis(int n) const { if (n==0) return axis1; else return axis2;}
134  virtual Axis getAxis2() const { return axis2; };
135 
136  virtual double getPosition2() const = 0;
137  virtual double getPosition2Rate() const = 0;
138  virtual void addForce2(double force) = 0;
139  void addForces(double force1,double force2){
140  addForce1(force1); addForce2(force2);
141  }
142 
143  virtual int getNumberAxes() const { return 2;};
144  virtual std::list<double> getPositions() const;
145  virtual std::list<double> getPositionRates() const;
146  virtual int getPositions(double* sensorarray) const;
147  virtual int getPositionRates(double* sensorarray) const;
148 
149  protected:
151  };
152 
153  /***************************************************************************/
154 
155  class FixedJoint : public Joint {
156  public:
157  /** the anchor is only required for drawing.
158  If not provided than part1 position is used
159  */
161  const osg::Vec3& anchor = osg::Vec3(0,0,0));
162 
163  virtual ~FixedJoint();
164 
165  /** initialises (and creates) the joint.
166  */
167  virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
168  bool withVisual = true, double visualSize = 0.2,
169  bool ignoreColl = true);
170 
171  virtual void update();
172  virtual void setParam(int parameter, double value);
173  virtual double getParam(int parameter) const;
174 
175  virtual int getNumberAxes() const { return 0; }
176  protected:
178  };
179 
180 
181  /***************************************************************************/
182 
183  class HingeJoint : public OneAxisJoint {
184  public:
186  const Axis& axis1);
187 
188  virtual ~HingeJoint();
189 
190  /** initialises (and creates) the joint. If visual is true then the axis of the joints is
191  also drawn as a slim cylinder. visualSize is the length of the cylinder.
192  */
193  virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
194  bool withVisual = true, double visualSize = 0.2,
195  bool ignoreColl = true);
196 
197  virtual void update();
198 
199  virtual void addForce1(double t);
200  virtual double getPosition1() const;
201  virtual double getPosition1Rate() const;
202  virtual void setParam(int parameter, double value);
203  virtual double getParam(int parameter) const;
204 
205  protected:
207  };
208 
209  /***************************************************************************/
210 
211  class Hinge2Joint : public TwoAxisJoint {
212  public:
214  const Axis& axis1, const Axis& axis2);
215 
216  virtual ~Hinge2Joint();
217 
218  /** initialises (and creates) the joint. If visual is true then axis2 of the joints is
219  also drawn as a slim cylinder. visualSize is the length of the cylinder.
220  */
221  virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
222  bool withVisual = true, double visualSize = 0.2,
223  bool ignoreColl = true);
224 
225  virtual void update();
226 
227  /// adds torques to axis 1 and 2
228  virtual void addForce1(double t1);
229  virtual void addForce2(double t2);
230  virtual double getPosition1() const;
231  virtual double getPosition2() const; /// This is not supported by the joint!
232  virtual double getPosition1Rate() const;
233  virtual double getPosition2Rate() const;
234  virtual void setParam(int parameter, double value);
235  virtual double getParam(int parameter) const;
236 
237  protected:
239  };
240 
241  /***************************************************************************/
242 
243  class UniversalJoint : public TwoAxisJoint {
244  public:
246  const Axis& axis1, const Axis& axis2);
247 
248  virtual ~UniversalJoint();
249 
250  /** initialises (and creates) the joint. If visual is true then axix1 and axis2 of the joints is
251  also drawn as a slim cylinder. visualSize is the length of the cylinder.
252  */
253  virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
254  bool withVisual = true, double visualSize = 0.2,
255  bool ignoreColl = true);
256 
257  virtual void update();
258 
259  /// adds torques to axis 1 and 2
260  virtual void addForce1(double t1);
261  virtual void addForce2(double t2);
262  virtual double getPosition1() const;
263  virtual double getPosition2() const;
264  virtual double getPosition1Rate() const;
265  virtual double getPosition2Rate() const;
266 
267  virtual void setParam(int parameter, double value);
268  virtual double getParam(int parameter) const;
269 
270  protected:
273  };
274 
275  /***************************************************************************/
276 
277  class BallJoint : public Joint {
278  public:
280 
281  virtual ~BallJoint();
282 
283  /** initialises (and creates) the joint.
284  If visual is true then ball is drawn as a sphere with radius of visualSize.
285  */
286  virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
287  bool withVisual = true, double visualSize = 0.2,
288  bool ignoreColl = true);
289 
290  virtual void update();
291 
292  virtual int getNumberAxes() const { return 0; }
293  // Ball and Socket has no parameter
294  virtual void setParam(int parameter, double value);
295  virtual double getParam(int parameter) const;
296 
297  protected:
299  };
300 
301 
302  /***************************************************************************/
303 
304  class SliderJoint : public OneAxisJoint {
305  public:
307  const Axis& axis1);
308 
309  virtual ~SliderJoint();
310 
311  /** initialises (and creates) the joint. If visual is true then the axis of the joints is
312  also drawn as a slim cylinder. VisualSize is added to the lenght of the slider and is used
313  for the length of the cylinder. The radius is visualSize/10
314  */
315  virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
316  bool withVisual = true, double visualSize = 0.1,
317  bool ignoreColl = true);
318 
319  virtual void update();
320 
321  virtual void addForce1(double t);
322  virtual double getPosition1() const;
323  virtual double getPosition1Rate() const;
324  virtual void setParam(int parameter, double value);
325  virtual double getParam(int parameter) const;
326 
327  protected:
329  double visualSize;
331  };
332 
333 
334  // /***************************************************************************/
335  // // does not work
336  // class LMotorJoint : public TwoAxisJoint {
337  // public:
338  // /// @param relative: how to anchor the axes: 0: global, 1: first 2: second body
339  // LMotorJoint(Primitive* part1, Primitive* part2, int relative, const Axis& axis1, const Axis& axis2);
340 
341  // virtual ~LMotorJoint();
342 
343  // /** initialises (and creates) the joint. If visual is true then the axes of the joints are
344  // also drawn as slim cylinders.
345  // */
346  // virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
347  // bool withVisual = true, double visualSize = 0.1,
348  // bool ignoreColl = true);
349 
350  // virtual void update();
351 
352  // virtual void addForce1(double t);
353  // virtual void addForce2(double t);
354  // virtual double getPosition1() const;
355  // virtual double getPosition2() const;
356  // virtual double getPosition1Rate() const;
357  // virtual double getPosition2Rate() const;
358 
359  // virtual void setParam(int parameter, double value);
360  // virtual double getParam(int parameter) const;
361 
362  // protected:
363  // OSGPrimitive* visual1;
364  // OSGPrimitive* visual2;
365  // int relative;
366  // };
367 
368  /***************************************************************************/
369 
370 
371 
372 }
373 
374 #endif
OSGPrimitive * visual2
Definition: joint.h:272
virtual void addForce2(double force)=0
virtual void setParam(int parameter, double value)
sets the ODE joint parameter (see ODE manual)
Definition: joint.cpp:521
dJointFeedback * feedback
Definition: joint.h:103
virtual int getNumberAxes() const
returns the number of Axes
Definition: joint.h:143
virtual std::list< double > getPositionRates() const
returns the position rates of all Axes
Definition: joint.cpp:97
Definition: joint.h:243
virtual ~Hinge2Joint()
Definition: joint.cpp:255
virtual void addForce1(double force)=0
SliderJoint(Primitive *part1, Primitive *part2, const osg::Vec3 &anchor, const Axis &axis1)
Definition: joint.cpp:456
virtual bool getForceFeedback(Pos &f1, Pos &f2) const
force applied to body 1 and body 2
Definition: joint.cpp:83
Data structure for accessing the ODE.
Definition: odehandle.h:44
virtual bool getTorqueFeedback(Pos &t1, Pos &t2) const
torque applied to body 1 and body 2
Definition: joint.cpp:76
Definition: axis.h:36
virtual void update()
should syncronise the Ode stuff and the OSG notes (if any)
Definition: joint.cpp:171
virtual double getParam(int parameter) const
return the ODE joint parameter (see ODE manual)
Definition: joint.cpp:526
UniversalJoint(Primitive *part1, Primitive *part2, const osg::Vec3 &anchor, const Axis &axis1, const Axis &axis2)
Definition: joint.cpp:330
Definition: joint.h:155
virtual double getParam(int parameter) const
return the ODE joint parameter (see ODE manual)
Definition: joint.cpp:449
Axis axis2
Definition: joint.h:150
virtual void addForce2(double t2)
add torque to axis 1
Definition: joint.cpp:297
Matrixd Matrix
Definition: osgforwarddecl.h:47
virtual ~BallJoint()
Definition: joint.cpp:418
virtual double getPosition1() const =0
Interface class for graphic primitives like spheres, boxes, and meshes, which can be drawn by OSG...
Definition: osgprimitive.h:62
virtual void setParam(int parameter, double value)
sets the ODE joint parameter (see ODE manual)
Definition: joint.cpp:177
virtual void setParam(int parameter, double value)
sets the ODE joint parameter (see ODE manual)
Definition: joint.cpp:447
Definition: joint.h:41
dJointID joint
Definition: joint.h:98
virtual double getPosition1() const
Definition: joint.cpp:387
virtual std::list< double > getPositions() const
returns the positions of all Axes
Definition: joint.cpp:103
Primitive * getPart2()
Definition: joint.h:70
virtual ~FixedJoint()
Definition: joint.cpp:150
Definition: joint.h:108
OdeHandle odeHandle
Definition: joint.h:105
virtual void init(const OdeHandle &odeHandle, const OsgHandle &osgHandle, bool withVisual=true, double visualSize=0.1, bool ignoreColl=true)
initialises (and creates) the joint.
Definition: joint.cpp:465
virtual int getNumberAxes() const
returns the number of Axes
Definition: joint.h:175
Definition: pos.h:36
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
virtual double getParam(int parameter) const
return the ODE joint parameter (see ODE manual)
Definition: joint.cpp:323
virtual void addForce1(double t1)
adds torques to axis 1 and 2
Definition: joint.cpp:293
virtual double getPosition2Rate() const
Definition: joint.cpp:314
OSGPrimitive * visual
Definition: joint.h:328
virtual double getPosition1Rate() const
Definition: joint.cpp:234
virtual void addForce1(double t)
Definition: joint.cpp:226
virtual double getPosition1() const
Definition: joint.cpp:230
TwoAxisJoint(Primitive *part1, Primitive *part2, const osg::Vec3 &anchor, const Axis axis1, const Axis axis2)
Definition: joint.h:130
FixedJoint(Primitive *part1, Primitive *part2, const osg::Vec3 &anchor=osg::Vec3(0, 0, 0))
the anchor is only required for drawing.
Definition: joint.cpp:141
virtual std::list< double > getPositionRates() const
returns the position rates of all Axes
Definition: joint.h:81
virtual double getPosition2Rate() const
Definition: joint.cpp:399
double visualSize
Definition: joint.h:329
virtual ~Joint()
Definition: joint.cpp:44
virtual double getPosition2() const =0
virtual double getParam(int parameter) const
return the ODE joint parameter (see ODE manual)
Definition: joint.cpp:407
Vec3f Vec3
Definition: osgforwarddecl.h:42
virtual double getParam(int parameter) const =0
return the ODE joint parameter (see ODE manual)
virtual ~SliderJoint()
Definition: joint.cpp:461
Hinge2Joint(Primitive *part1, Primitive *part2, const osg::Vec3 &anchor, const Axis &axis1, const Axis &axis2)
Definition: joint.cpp:250
virtual void init(const OdeHandle &odeHandle, const OsgHandle &osgHandle, bool withVisual=true, double visualSize=0.2, bool ignoreColl=true)
initialises (and creates) the joint.
Definition: joint.cpp:422
virtual ~HingeJoint()
Definition: joint.cpp:191
virtual void update()
should syncronise the Ode stuff and the OSG notes (if any)
Definition: joint.cpp:487
virtual void addForce1(double t)
Definition: joint.cpp:509
OSGPrimitive * visual1
Definition: joint.h:271
void addForces(double force1, double force2)
Definition: joint.h:139
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
Definition: joint.h:128
virtual void update()
should syncronise the Ode stuff and the OSG notes (if any)
Definition: joint.cpp:360
virtual ~UniversalJoint()
Definition: joint.cpp:335
Primitive * part2
Definition: joint.h:100
osg::Vec3 anchor
Definition: joint.h:101
virtual double getPosition1Rate() const
Definition: joint.cpp:517
virtual int getNumberAxes() const
returns the number of Axes
Definition: joint.h:292
virtual void update()
should syncronise the Ode stuff and the OSG notes (if any)
Definition: joint.cpp:435
virtual void setParam(int parameter, double value)
sets the ODE joint parameter (see ODE manual)
Definition: joint.cpp:403
const Primitive * getPart2() const
Definition: joint.h:69
virtual void update()=0
should syncronise the Ode stuff and the OSG notes (if any)
Definition: joint.h:277
OSGPrimitive * visual
Definition: joint.h:298
virtual double getPosition1() const
Definition: joint.cpp:513
Definition: joint.h:211
Primitive * part1
Definition: joint.h:99
virtual void init(const OdeHandle &odeHandle, const OsgHandle &osgHandle, bool withVisual=true, double visualSize=0.2, bool ignoreColl=true)
initialises (and creates) the joint.
Definition: joint.cpp:195
virtual double getPosition1Rate() const
This is not supported by the joint!
Definition: joint.cpp:310
virtual void update()
should syncronise the Ode stuff and the OSG notes (if any)
Definition: joint.cpp:211
virtual void init(const OdeHandle &odeHandle, const OsgHandle &osgHandle, bool withVisual=true, double visualSize=0.2, bool ignoreColl=true)
initialises (and creates) the joint.
Definition: joint.cpp:156
OSGPrimitive * visual
Definition: joint.h:177
Primitive * getPart1()
Definition: joint.h:68
virtual std::list< double > getPositions() const
returns the positions of all Axes
Definition: joint.cpp:92
virtual void init(const OdeHandle &odeHandle, const OsgHandle &osgHandle, bool withVisual=true, double visualSize=0.2, bool ignoreColl=true)
initialises (and creates) the joint.
Definition: joint.cpp:52
Definition: joint.h:304
virtual int getPositionRates(double *sensorarray) const
stores the position rates of all Axes into sensorarray and returns the number of written entries ...
Definition: joint.h:87
virtual void init(const OdeHandle &odeHandle, const OsgHandle &osgHandle, bool withVisual=true, double visualSize=0.2, bool ignoreColl=true)
initialises (and creates) the joint.
Definition: joint.cpp:340
virtual double getPosition1Rate() const
Definition: joint.cpp:395
virtual void init(const OdeHandle &odeHandle, const OsgHandle &osgHandle, bool withVisual=true, double visualSize=0.2, bool ignoreColl=true)
initialises (and creates) the joint.
Definition: joint.cpp:259
virtual double getParam(int parameter) const
return the ODE joint parameter (see ODE manual)
Definition: joint.cpp:243
virtual double getPosition2() const
Definition: joint.cpp:391
virtual void update()
should syncronise the Ode stuff and the OSG notes (if any)
Definition: joint.cpp:276
virtual void setParam(int parameter, double value)=0
sets the ODE joint parameter (see ODE manual)
virtual double getPosition1Rate() const =0
const Primitive * getPart1() const
Definition: joint.h:67
Axis axis1
Definition: joint.h:125
BallJoint(Primitive *part1, Primitive *part2, const osg::Vec3 &anchor)
Definition: joint.cpp:413
virtual void addForce1(double t1)
adds torques to axis 1 and 2
Definition: joint.cpp:380
OneAxisJoint(Primitive *part1, Primitive *part2, const osg::Vec3 &anchor, const Axis axis1)
Definition: joint.h:110
int t
Definition: hexapod.cpp:55
const osg::Vec3 getAnchor() const
Definition: joint.h:71
Joint(Primitive *part1, Primitive *part2, const osg::Vec3 &anchor)
Definition: joint.h:43
virtual int getNumberAxes() const
returns the number of Axes
Definition: joint.h:119
virtual int getNumberAxes() const =0
returns the number of Axes
virtual double getParam(int parameter) const
return the ODE joint parameter (see ODE manual)
Definition: joint.cpp:180
OsgHandle osgHandle
Definition: joint.h:330
virtual Axis getAxis(int n) const
returns the n'th axis of the joint (starting with 0)
Definition: joint.h:76
virtual std::list< double > getPositionRates() const
returns the position rates of all Axes
Definition: joint.cpp:109
virtual void setParam(int parameter, double value)
sets the ODE joint parameter (see ODE manual)
Definition: joint.cpp:238
virtual int getPositions(double *sensorarray) const
stores the positions of all Axes into sensorarray and returns the number of written entries ...
Definition: joint.h:83
Definition: joint.h:183
virtual Axis getAxis1() const
Definition: joint.h:113
virtual void addForce2(double t2)
Definition: joint.cpp:383
HingeJoint(Primitive *part1, Primitive *part2, const osg::Vec3 &anchor, const Axis &axis1)
Definition: joint.cpp:186
virtual Axis getAxis(int n) const
returns the n'th axis of the joint (starting with 0)
Definition: joint.h:112
virtual double getPosition1() const
Definition: joint.cpp:301
virtual double getPosition2Rate() const =0
virtual Axis getAxis(int n) const
returns the n'th axis of the joint (starting with 0)
Definition: joint.h:133
virtual void setFeedBackMode(bool mode)
enable or disable the feedback mode
Definition: joint.cpp:62
virtual double getPosition2() const
Definition: joint.cpp:305
virtual std::list< double > getPositions() const
returns the positions of all Axes
Definition: joint.h:79
OSGPrimitive * visual
Definition: joint.h:238
static osg::Matrix anchorAxisPose(const osg::Vec3 &anchor, const Axis &axis)
Definition: joint.cpp:40
virtual Axis getAxis2() const
Definition: joint.h:134
virtual void setParam(int parameter, double value)
sets the ODE joint parameter (see ODE manual)
Definition: joint.cpp:318
OSGPrimitive * visual
Definition: joint.h:206
dJointID getJoint() const
Definition: joint.h:66