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

Generated on Tue Jan 16 02:14:36 2007 for Robotsystem of the Robot Group Leipzig by doxygen 1.3.8