Robot Simulator of the Robotics Group for Self-Organization of Control: joint.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# joint.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
    00003  *    martius@informatik.uni-leipzig.de                                    *
    00004  *    fhesse@informatik.uni-leipzig.de                                     *
    00005  *    der@informatik.uni-leipzig.de                                        *
    00006  *                                                                         *
    00007  *   This program is free software; you can redistribute it and/or modify  *
    00008  *   it under the terms of the GNU General Public License as published by  *
    00009  *   the Free Software Foundation; either version 2 of the License, or     *
    00010  *   (at your option) any later version.                                   *
    00011  *                                                                         *
    00012  *   This program is distributed in the hope that it will be useful,       *
    00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00015  *   GNU General Public License for more details.                          *
    00016  *                                                                         *
    00017  *   You should have received a copy of the GNU General Public License     *
    00018  *   along with this program; if not, write to the                         *
    00019  *   Free Software Foundation, Inc.,                                       *
    00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00021  ***************************************************************************
    00022  *                                                                         *
    00023  *  Joint wrapper to ba able to draw joints and abstract from ode details  *
    00024  *                                                                         *
    00025  *   $Log: joint.h,v $
    00026  *   Revision 1.7  2007/07/03 13:03:07  martius
    00027  *   assert for parts
    00028  *   getPartX also as non-Const
    00029  *
    00030  *   Revision 1.6  2007/03/16 11:00:41  martius
    00031  *   registration of ignored geoms
    00032  *
    00033  *   Revision 1.5  2007/01/26 12:05:36  martius
    00034  *   joint support forces in uniform manner
    00035  *
    00036  *   Revision 1.4  2006/08/02 10:11:27  martius
    00037  *   getNumberAxes was mistyped
    00038  *
    00039  *   Revision 1.3  2006/07/26 10:36:05  martius
    00040  *   joints support getPositions and getNumberAxes
    00041  *
    00042  *   Revision 1.2  2006/07/14 12:23:35  martius
    00043  *   selforg becomes HEAD
    00044  *
    00045  *   Revision 1.1.2.12  2006/06/29 16:35:56  robot3
    00046  *   includes cleared up
    00047  *
    00048  *   Revision 1.1.2.11  2006/03/29 15:05:57  martius
    00049  *   fixed joint
    00050  *
    00051  *   Revision 1.1.2.10  2006/02/01 18:34:03  martius
    00052  *   use Axis type for Joint axis. very important, since otherwise Vec3 * pose is not the right direction vector anymore
    00053  *
    00054  *   Revision 1.1.2.9  2006/01/12 22:19:08  martius
    00055  *   bugfix in TwoAxisJoint Constructor (axis and anchor swapped)
    00056  *
    00057  *   Revision 1.1.2.8  2006/01/11 14:11:06  fhesse
    00058  *   moved anchor up into Joint and introduced getAnchor()
    00059  *
    00060  *   Revision 1.1.2.7  2005/12/21 15:39:03  martius
    00061  *   OneAxisJoint and TwoAxisJoint as superclasses
    00062  *
    00063  *   Revision 1.1.2.6  2005/12/19 16:34:18  martius
    00064  *   added Ball and Universal joint
    00065  *
    00066  *   Revision 1.1.2.5  2005/12/15 17:03:42  martius
    00067  *   cameramanupulator setPose is working
    00068  *   joints have setter and getter parameters
    00069  *   Primitives are not longer inherited from OSGPrimitive, moreover
    00070  *   they aggregate them
    00071  *
    00072  *   Revision 1.1.2.4  2005/12/14 15:36:45  martius
    00073  *   joints are visible now
    00074  *
    00075  *   Revision 1.1.2.3  2005/12/13 18:11:13  martius
    00076  *   transform primitive added, some joints stuff done, forward declaration
    00077  *
    00078  *   Revision 1.1.2.2  2005/12/12 23:40:22  martius
    00079  *   hinge2joint started
    00080  *
    00081  *   Revision 1.1.2.1  2005/12/12 22:25:16  martius
    00082  *   added joint
    00083  *
    00084  *
    00085  *                                                                 *
    00086  ***************************************************************************/
    00087 #ifndef __JOINT_H
    00088 #define __JOINT_H
    00089
    00090 #include <assert.h>
    00091 #include <list>
    00092
    00093 #include "primitive.h"
    00094 #include "osgforwarddecl.h"
    00095 #include "axis.h"
    00096 #include "osghandle.h"
    00097 #include "odehandle.h"
    00098
    00099 namespace lpzrobots {
    00100
    00101
    00102   /***************************************************************************/
    00103
    00104   class Joint {
    00105   public:
    00106     Joint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor)
    00107       : joint(0), part1(part1), part2(part2), anchor(anchor) {
    00108       assert(part1 && part2);
    00109     }
    00110     virtual ~Joint();
    00111     /** initialises (and creates) the joint. If visual is true then the joints is
    00112         also drawn. visualSize is the size of the visual representation.
    00113         Also member variable odeHandle should be set.
    00114         (To be overloaded, but this init should be called always from children!)
    00115     */
    00116     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00117                       bool withVisual = true, double visualSize = 0.2);
    00118
    00119     /// should syncronise the Ode stuff and the OSG notes (if any)
    00120     virtual void update() = 0;
    00121     /// sets the ODE joint parameter (see ODE manual)
    00122     virtual void setParam(int parameter, double value) = 0;
    00123     /// return the ODE joint parameter (see ODE manual)
    00124     virtual double getParam(int parameter) const = 0;
    00125
    00126     dJointID getJoint() const  { return joint; }
    00127     const Primitive* getPart1() const { return part1; }
    00128     Primitive* getPart1() { return part1; }
    00129     const Primitive* getPart2() const { return part2; }
    00130     Primitive* getPart2() { return part2; }
    00131     const osg::Vec3 getAnchor() const { return anchor; }
    00132
    00133     /// returns the number of Axes
    00134     virtual int getNumberAxes() const = 0;
    00135     /// returns the positions of all Axes
    00136     virtual std::list<double> getPositions() const { return std::list<double>(); }
    00137     /// returns the position rates of all Axes
    00138     virtual std::list<double> getPositionRates() const { return std::list<double>(); }
    00139     /// stores the positions of all Axes into sensorarray and returns the number of written entries
    00140     virtual int getPositions(double* sensorarray) const { return 0; }
    00141     /** stores the position rates of all Axes into sensorarray and
    00142         returns the number of written entries
    00143      */
    00144     virtual int getPositionRates(double* sensorarray) const { return 0; }
    00145
    00146     static osg::Matrix anchorAxisPose(const osg::Vec3& anchor, const Axis& axis);
    00147   protected:
    00148     dJointID joint;
    00149     Primitive* part1;
    00150     Primitive* part2;
    00151     osg::Vec3 anchor;
    00152   public:
    00153     OdeHandle odeHandle;
    00154   };
    00155
    00156   class OneAxisJoint : public Joint {
    00157   public:
    00158     OneAxisJoint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor, const Axis axis1)
    00159       : Joint(part1, part2, anchor), axis1(axis1) {}
    00160     virtual Axis getAxis1() const { return axis1; };
    00161
    00162     virtual double getPosition1() const = 0;
    00163     virtual double getPosition1Rate() const = 0;
    00164     virtual void addForce1(double force) = 0;
    00165
    00166     virtual int getNumberAxes() const { return 1;};
    00167     virtual std::list<double> getPositions() const;
    00168     virtual std::list<double> getPositionRates() const;
    00169     virtual int getPositions(double* sensorarray) const;
    00170     virtual int getPositionRates(double* sensorarray) const;
    00171   protected:
    00172     Axis axis1;
    00173   };
    00174
    00175   class TwoAxisJoint : public OneAxisJoint {
    00176   public:
    00177     TwoAxisJoint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor, const Axis axis1,
    00178                  const Axis axis2 )
    00179       : OneAxisJoint(part1, part2, anchor, axis1), axis2(axis2) {}
    00180     virtual Axis getAxis2() const { return axis2; };
    00181
    00182     virtual double getPosition2() const = 0;
    00183     virtual double getPosition2Rate() const = 0;
    00184     virtual void addForce2(double force) = 0;
    00185     void addForces(double force1,double force2){
    00186       addForce1(force1); addForce2(force2);
    00187     }
    00188
    00189     virtual int getNumberAxes() const { return 2;};
    00190     virtual std::list<double> getPositions() const;
    00191     virtual std::list<double> getPositionRates() const;
    00192     virtual int getPositions(double* sensorarray) const;
    00193     virtual int getPositionRates(double* sensorarray) const;
    00194
    00195   protected:
    00196     Axis  axis2;
    00197   };
    00198
    00199   /***************************************************************************/
    00200
    00201   class FixedJoint : public Joint {
    00202   public:
    00203     FixedJoint(Primitive* part1, Primitive* part2);
    00204
    00205     virtual ~FixedJoint();
    00206
    00207     /** initialises (and creates) the joint.
    00208     */
    00209     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00210                       bool withVisual = true, double visualSize = 0.2);
    00211
    00212     virtual void update();
    00213     virtual void setParam(int parameter, double value);
    00214     virtual double getParam(int parameter) const;
    00215
    00216     virtual int getNumberAxes() const { return 0; }
    00217
    00218   };
    00219
    00220
    00221   /***************************************************************************/
    00222
    00223   class HingeJoint : public OneAxisJoint {
    00224   public:
    00225     HingeJoint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor,
    00226                 const Axis& axis1);
    00227
    00228     virtual ~HingeJoint();
    00229
    00230     /** initialises (and creates) the joint. If visual is true then the axis of the joints is
    00231         also drawn as a slim cylinder. visualSize is the length of the cylinder.
    00232     */
    00233     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00234                       bool withVisual = true, double visualSize = 0.2);
    00235
    00236     virtual void update();
    00237
    00238     virtual void addForce1(double t);
    00239     virtual double getPosition1() const;
    00240     virtual double getPosition1Rate() const;
    00241     virtual void setParam(int parameter, double value);
    00242     virtual double getParam(int parameter) const;
    00243
    00244   protected:
    00245     OSGPrimitive* visual;
    00246   };
    00247
    00248   /***************************************************************************/
    00249
    00250   class Hinge2Joint : public TwoAxisJoint {
    00251   public:
    00252     Hinge2Joint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor,
    00253                 const Axis& axis1, const Axis& axis2);
    00254
    00255     virtual ~Hinge2Joint();
    00256
    00257     /** initialises (and creates) the joint. If visual is true then axis2 of the joints is
    00258         also drawn as a slim cylinder. visualSize is the length of the cylinder.
    00259     */
    00260     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00261                       bool withVisual = true, double visualSize = 0.2);
    00262
    00263     virtual void update();
    00264
    00265     /// adds torques to axis 1 and 2
    00266     virtual void addForce1(double t1);
    00267     virtual void addForce2(double t2);
    00268     virtual double getPosition1() const;
    00269     virtual double getPosition2() const; /// This is not supported by the joint!
    00270     virtual double getPosition1Rate() const;
    00271     virtual double getPosition2Rate() const;
    00272     virtual void setParam(int parameter, double value);
    00273     virtual double getParam(int parameter) const;
    00274
    00275   protected:
    00276     OSGPrimitive* visual;
    00277   };
    00278
    00279   /***************************************************************************/
    00280
    00281   class UniversalJoint : public TwoAxisJoint {
    00282   public:
    00283     UniversalJoint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor,
    00284                 const Axis& axis1, const Axis& axis2);
    00285
    00286     virtual ~UniversalJoint();
    00287
    00288     /** initialises (and creates) the joint. If visual is true then axix1 and axis2 of the joints is
    00289         also drawn as a slim cylinder. visualSize is the length of the cylinder.
    00290     */
    00291     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00292                       bool withVisual = true, double visualSize = 0.2);
    00293
    00294     virtual void update();
    00295
    00296     /// adds torques to axis 1 and 2
    00297     virtual void addForce1(double t1);
    00298     virtual void addForce2(double t2);
    00299     virtual double getPosition1() const;
    00300     virtual double getPosition2() const;
    00301     virtual double getPosition1Rate() const;
    00302     virtual double getPosition2Rate() const;
    00303
    00304     virtual void setParam(int parameter, double value);
    00305     virtual double getParam(int parameter) const;
    00306
    00307   protected:
    00308     OSGPrimitive* visual1;
    00309     OSGPrimitive* visual2;
    00310   };
    00311
    00312   /***************************************************************************/
    00313
    00314   class BallJoint : public Joint {
    00315   public:
    00316     BallJoint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor);
    00317
    00318     virtual ~BallJoint();
    00319
    00320     /** initialises (and creates) the joint.
    00321         If visual is true then ball is drawn as a sphere with radius of visualSize.
    00322     */
    00323     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00324                       bool withVisual = true, double visualSize = 0.2);
    00325
    00326     virtual void update();
    00327
    00328     virtual int getNumberAxes() const { return 0; }
    00329     // Ball and Socket has no parameter
    00330     virtual void setParam(int parameter, double value);
    00331     virtual double getParam(int parameter) const;
    00332
    00333   protected:
    00334     OSGPrimitive* visual;
    00335   };
    00336
    00337   /***************************************************************************/
    00338
    00339   class SliderJoint : public OneAxisJoint {
    00340   public:
    00341     SliderJoint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor,
    00342                 const Axis& axis1);
    00343
    00344     virtual ~SliderJoint();
    00345
    00346     /** initialises (and creates) the joint. If visual is true then the axis of the joints is
    00347         also drawn as a slim cylinder. VisualSize is added to the lenght of the slider and is used
    00348         for the length of the cylinder. The radius is visualSize/10
    00349     */
    00350     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00351                       bool withVisual = true, double visualSize = 0.1);
    00352
    00353     virtual void update();
    00354
    00355     virtual void addForce1(double t);
    00356     virtual double getPosition1() const;
    00357     virtual double getPosition1Rate() const;
    00358     virtual void setParam(int parameter, double value);
    00359     virtual double getParam(int parameter) const;
    00360
    00361   protected:
    00362     OSGPrimitive* visual;
    00363     double visualSize;
    00364     OsgHandle osgHandle;
    00365   };
    00366
    00367   /***************************************************************************/
    00368
    00369
    00370
    00371 }
    00372
    00373 #endif