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 #ifndef _ROBOT_SIM_SIMULATEDKINEMATICCHAIN_
00026 #define _ROBOT_SIM_SIMULATEDKINEMATICCHAIN_
00027
00028 #include <robot/sim/sim>
00029
00030 #include <base/ReferencedObject>
00031 #include <base/Dimension3>
00032 #include <base/Externalizable>
00033
00034 #include <physics/SolidSystem>
00035 #include <physics/Solid>
00036 #include <physics/SpatialGroup>
00037 #include <physics/CollidableProvider>
00038 #include <physics/CollisionDetector>
00039 #include <physics/CollisionResponseHandler>
00040
00041 #include <robot/KinematicChain>
00042
00043
00044 namespace robot {
00045 namespace sim {
00046
00047
00048
00049
00050
00051 class SimulatedKinematicChain : public physics::Spatial, public physics::CollidableProvider, public base::Externalizable
00052 {
00053 public:
00054 SimulatedKinematicChain(bool dynamic=true)
00055 : dynamic(dynamic) {}
00056 SimulatedKinematicChain(ref<physics::SolidSystem> solidSystem, bool dynamic=true)
00057 : solidSystem(solidSystem), dynamic(dynamic) {}
00058
00059
00060 virtual void setDynamic(bool enabled) { dynamic = enabled; }
00061
00062 virtual void setSolidSystem(ref<physics::SolidSystem> solidSystem)
00063 { this->solidSystem = solidSystem; }
00064
00065
00066 virtual void setJointForce(Int j, Real f) = 0;
00067
00068
00069
00070 virtual void setJointVel(Int j, Real v, Real maxForce=10.0) = 0;
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 virtual void setJointPos(Int j, Real p) = 0;
00081
00082
00083
00084
00085 virtual Real getJointPos(Int j) const = 0;
00086
00087
00088 virtual Real getJointVel(Int j) const = 0;
00089
00090
00091
00092
00093
00094 static const Real maxDist;
00095
00096
00097 virtual Real getClosestObjectDistance(Int link) const = 0;
00098
00099
00100 virtual Vector3 getClosestObjectDirection(Int link) const = 0;
00101
00102
00103 virtual Real getClosestObjectSensorPosition(Int link) const = 0;
00104
00105
00106 protected:
00107 SimulatedKinematicChain(const SimulatedKinematicChain& kc) { Unimplemented; }
00108
00109 KinematicChain chain;
00110 ref<physics::SolidSystem> solidSystem;
00111
00112
00113 bool dynamic;
00114
00115
00116 virtual void construct(const base::Point3& initialPosition, const base::Orient& initialOrientation) = 0;
00117
00118
00119
00120 virtual array<base::Dimension3> computeLinkDimensions(const array<Real>& linkRadii);
00121
00122
00123 struct TransformInfo {
00124 base::Transform mountTransform;
00125 array<base::Transform> A;
00126 array<base::Transform> T;
00127 array<base::Transform> SLT;
00128 base::Vector q;
00129 base::Transform mountToBaseSolid;
00130 base::Transform eeToEESolid;
00131 };
00132
00133
00134
00135 virtual void createLinks(const array<base::Dimension3>& linkDims) = 0;
00136
00137
00138 virtual void positionLinks(const TransformInfo& transformInfo) = 0;
00139
00140 virtual void disableCollisions(const array<ref<physics::Collidable> >& collidables,
00141 const array<ref<physics::Collidable> >& proximityCollidables) = 0;
00142
00143 virtual void attachJoints(const TransformInfo& transformInfo) = 0;
00144
00145 array<ref<physics::SpatialGroup> > linkGroups;
00146
00147 array<ref<physics::Solid> > links;
00148 array<ref<physics::Joint> > joints;
00149 array<Real> linkLengths;
00150 array<ref<physics::Collidable> > collidables;
00151 array<ref<physics::Collidable> > proximityCollidables;
00152
00153 mutable base::Vector q;
00154
00155
00156
00157
00158
00159 class ProximityCollisionResponseHandler : public physics::CollisionResponseHandler
00160 {
00161 public:
00162 ProximityCollisionResponseHandler(ref<SimulatedKinematicChain> kc, ref<physics::CollisionDetector> collisionDetector);
00163
00164 virtual String className() const { return String("ProximityCollisionResponseHandler"); }
00165
00166 virtual void reset();
00167 virtual void collide(ref<const physics::Collidable> collidable1, ref<const physics::Collidable> collidable2);
00168 virtual void handleCollision(ref<physics::CollisionState> collisionState);
00169
00170 protected:
00171 ref<SimulatedKinematicChain> kc;
00172 bool resetCalled;
00173 };
00174
00175 virtual void handleCollision(ref<physics::CollisionState> collisionState) = 0;
00176
00177 enum CollidableClasses { SensorCollidableClass = 1 };
00178
00179 ref<physics::CollidableGroup> proximityCollidableGroup;
00180
00181 struct ProximityData {
00182 ProximityData() : dist(SimulatedKinematicChain::maxDist+1.0) {}
00183 ProximityData(Real dist, Real intersect, const Vector3& dir)
00184 : dist(dist), intersect(intersect), dir(dir) {}
00185
00186 Real dist;
00187 Real intersect;
00188 Vector3 dir;
00189 };
00190
00191 array< ProximityData > linkProximity;
00192
00193 array< Real > linkProximitySurfPosition;
00194
00195 friend class SimulatedRobot;
00196 friend class ProximityCollisionResponseHandler;
00197 };
00198
00199
00200
00201 }
00202 }
00203
00204 #endif