Robotsystem from Robot Group Leipzig: joint.h Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- 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.1.2.11  2006/03/29 15:05:57  martius
    00027  *   fixed joint
    00028  *
    00029  *   Revision 1.1.2.10  2006/02/01 18:34:03  martius
    00030  *   use Axis type for Joint axis. very important, since otherwise Vec3 * pose is not the right direction vector anymore
    00031  *
    00032  *   Revision 1.1.2.9  2006/01/12 22:19:08  martius
    00033  *   bugfix in TwoAxisJoint Constructor (axis and anchor swapped)
    00034  *
    00035  *   Revision 1.1.2.8  2006/01/11 14:11:06  fhesse
    00036  *   moved anchor up into Joint and introduced getAnchor()
    00037  *
    00038  *   Revision 1.1.2.7  2005/12/21 15:39:03  martius
    00039  *   OneAxisJoint and TwoAxisJoint as superclasses
    00040  *
    00041  *   Revision 1.1.2.6  2005/12/19 16:34:18  martius
    00042  *   added Ball and Universal joint
    00043  *
    00044  *   Revision 1.1.2.5  2005/12/15 17:03:42  martius
    00045  *   cameramanupulator setPose is working
    00046  *   joints have setter and getter parameters
    00047  *   Primitives are not longer inherited from OSGPrimitive, moreover
    00048  *   they aggregate them
    00049  *
    00050  *   Revision 1.1.2.4  2005/12/14 15:36:45  martius
    00051  *   joints are visible now
    00052  *
    00053  *   Revision 1.1.2.3  2005/12/13 18:11:13  martius
    00054  *   transform primitive added, some joints stuff done, forward declaration
    00055  *
    00056  *   Revision 1.1.2.2  2005/12/12 23:40:22  martius
    00057  *   hinge2joint started
    00058  *
    00059  *   Revision 1.1.2.1  2005/12/12 22:25:16  martius
    00060  *   added joint
    00061  *
    00062  *
    00063  *                                                                 *
    00064  ***************************************************************************/
    00065 #ifndef __JOINT_H
    00066 #define __JOINT_H
    00067
    00068 #include "primitive.h"
    00069 #include "osgforwarddecl.h"
    00070 #include "axis.h"
    00071
    00072 namespace lpzrobots {
    00073
    00074   /***************************************************************************/
    00075
    00076   class Joint {
    00077   public:
    00078     Joint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor)
    00079       : joint(0), part1(part1), part2(part2), anchor(anchor) {}
    00080     virtual ~Joint();
    00081     /** initialises (and creates) the joint. If visual is true then the joints is
    00082         also drawn. visualSize is the size of the visual representation.
    00083         (To be overloaded)
    00084     */
    00085     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00086                       bool withVisual = true, double visualSize = 0.2) = 0;
    00087
    00088     /// should syncronise the Ode stuff and the OSG notes (if any)
    00089     virtual void update() = 0;
    00090     /// sets the ODE joint parameter (see ODE manual)
    00091     virtual void setParam(int parameter, double value) = 0;
    00092     /// return the ODE joint parameter (see ODE manual)
    00093     virtual double getParam(int parameter) = 0;
    00094
    00095     dJointID getJoint() const  { return joint; }
    00096     const Primitive* getPart1() const { return part1; }
    00097     const Primitive* getPart2() const { return part2; }
    00098     const osg::Vec3 getAnchor() const { return anchor; }
    00099
    00100     static osg::Matrix anchorAxisPose(const osg::Vec3& anchor, const Axis& axis);
    00101   protected:
    00102     dJointID joint;
    00103     Primitive* part1;
    00104     Primitive* part2;
    00105     osg::Vec3 anchor;
    00106   };
    00107
    00108   class OneAxisJoint : public Joint {
    00109   public:
    00110     OneAxisJoint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor, const Axis axis1)
    00111       : Joint(part1, part2, anchor), axis1(axis1) {}
    00112     virtual Axis getAxis1() const { return axis1; };
    00113
    00114     virtual double getPosition1() = 0;
    00115     virtual double getPosition1Rate() = 0;
    00116
    00117   protected:
    00118     Axis axis1;
    00119   };
    00120
    00121   class TwoAxisJoint : public OneAxisJoint {
    00122   public:
    00123     TwoAxisJoint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor, const Axis axis1,
    00124                  const Axis axis2 )
    00125       : OneAxisJoint(part1, part2, anchor, axis1), axis2(axis2) {}
    00126     virtual Axis getAxis2() const { return axis2; };
    00127
    00128     virtual double getPosition2() = 0;
    00129     virtual double getPosition2Rate() = 0;
    00130
    00131   protected:
    00132     Axis  axis2;
    00133   };
    00134
    00135   /***************************************************************************/
    00136
    00137   class FixedJoint : public Joint {
    00138   public:
    00139     FixedJoint(Primitive* part1, Primitive* part2);
    00140
    00141     virtual ~FixedJoint();
    00142
    00143     /** initialises (and creates) the joint.
    00144     */
    00145     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00146                       bool withVisual = true, double visualSize = 0.2);
    00147
    00148     virtual void update();
    00149     virtual void setParam(int parameter, double value);
    00150     virtual double getParam(int parameter);
    00151   };
    00152
    00153
    00154   /***************************************************************************/
    00155
    00156   class HingeJoint : public OneAxisJoint {
    00157   public:
    00158     HingeJoint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor,
    00159                 const Axis& axis1);
    00160
    00161     virtual ~HingeJoint();
    00162
    00163     /** initialises (and creates) the joint. If visual is true then the axis of the joints is
    00164         also drawn as a slim cylinder. visualSize is the length of the cylinder.
    00165     */
    00166     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00167                       bool withVisual = true, double visualSize = 0.2);
    00168
    00169     virtual void update();
    00170
    00171     virtual void addTorque(double t);
    00172     virtual double getPosition1();
    00173     virtual double getPosition1Rate();
    00174     virtual void setParam(int parameter, double value);
    00175     virtual double getParam(int parameter);
    00176
    00177   protected:
    00178     OSGPrimitive* visual;
    00179   };
    00180
    00181   /***************************************************************************/
    00182
    00183   class Hinge2Joint : public TwoAxisJoint {
    00184   public:
    00185     Hinge2Joint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor,
    00186                 const Axis& axis1, const Axis& axis2);
    00187
    00188     virtual ~Hinge2Joint();
    00189
    00190     /** initialises (and creates) the joint. If visual is true then axis2 of the joints is
    00191         also drawn as a slim cylinder. visualSize is the length of the cylinder.
    00192     */
    00193     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00194                       bool withVisual = true, double visualSize = 0.2);
    00195
    00196     virtual void update();
    00197
    00198     /// adds torques to axis 1 and 2
    00199     virtual void addTorques(double t1, double t2);
    00200     virtual double getPosition1();
    00201     virtual double getPosition2(); /// This is not supported by the joint!
    00202     virtual double getPosition1Rate();
    00203     virtual double getPosition2Rate();
    00204     virtual void setParam(int parameter, double value);
    00205     virtual double getParam(int parameter);
    00206
    00207   protected:
    00208     OSGPrimitive* visual;
    00209   };
    00210
    00211   /***************************************************************************/
    00212
    00213   class UniversalJoint : public TwoAxisJoint {
    00214   public:
    00215     UniversalJoint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor,
    00216                 const Axis& axis1, const Axis& axis2);
    00217
    00218     virtual ~UniversalJoint();
    00219
    00220     /** initialises (and creates) the joint. If visual is true then axix1 and axis2 of the joints is
    00221         also drawn as a slim cylinder. visualSize is the length of the cylinder.
    00222     */
    00223     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00224                       bool withVisual = true, double visualSize = 0.2);
    00225
    00226     virtual void update();
    00227
    00228     /// adds torques to axis 1 and 2
    00229     virtual void addTorques(double t1, double t2);
    00230     virtual double getPosition1();
    00231     virtual double getPosition2();
    00232     virtual double getPosition1Rate();
    00233     virtual double getPosition2Rate();
    00234
    00235     virtual void setParam(int parameter, double value);
    00236     virtual double getParam(int parameter);
    00237
    00238   protected:
    00239     OSGPrimitive* visual1;
    00240     OSGPrimitive* visual2;
    00241   };
    00242
    00243   /***************************************************************************/
    00244
    00245   class BallJoint : public Joint {
    00246   public:
    00247     BallJoint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor);
    00248
    00249     virtual ~BallJoint();
    00250
    00251     /** initialises (and creates) the joint.
    00252         If visual is true then ball is drawn as a sphere with radius of visualSize.
    00253     */
    00254     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00255                       bool withVisual = true, double visualSize = 0.2);
    00256
    00257     virtual void update();
    00258
    00259     // Ball and Socket has no parameter
    00260     virtual void setParam(int parameter, double value);
    00261     virtual double getParam(int parameter);
    00262
    00263   protected:
    00264     OSGPrimitive* visual;
    00265   };
    00266
    00267   /***************************************************************************/
    00268
    00269   class SliderJoint : public OneAxisJoint {
    00270   public:
    00271     SliderJoint(Primitive* part1, Primitive* part2, const osg::Vec3& anchor,
    00272                 const Axis& axis1);
    00273
    00274     virtual ~SliderJoint();
    00275
    00276     /** initialises (and creates) the joint. If visual is true then the axis of the joints is
    00277         also drawn as a slim cylinder. VisualSize is added to the lenght of the slider and is used
    00278         for the length of the cylinder. The radius is visualSize/10
    00279     */
    00280     virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00281                       bool withVisual = true, double visualSize = 0.1);
    00282
    00283     virtual void update();
    00284
    00285     virtual void addForce(double t);
    00286     virtual double getPosition1();
    00287     virtual double getPosition1Rate();
    00288     virtual void setParam(int parameter, double value);
    00289     virtual double getParam(int parameter);
    00290
    00291   protected:
    00292     OSGPrimitive* visual;
    00293     double visualSize;
    00294     OsgHandle osgHandle;
    00295   };
    00296
    00297   /***************************************************************************/
    00298
    00299
    00300
    00301 }
    00302
    00303 #endif