00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
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
00082
00083
00084
00085 virtual void init(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00086 bool withVisual = true, double visualSize = 0.2) = 0;
00087
00088
00089 virtual void update() = 0;
00090
00091 virtual void setParam(int parameter, double value) = 0;
00092
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
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
00164
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
00191
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
00199 virtual void addTorques(double t1, double t2);
00200 virtual double getPosition1();
00201 virtual double getPosition2();
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
00221
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
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
00252
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
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
00277
00278
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