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_SIMULATEDTOOL_
00026 #define _ROBOT_SIM_SIMULATEDTOOL_
00027
00028 #include <robot/sim/sim>
00029
00030 #include <robot/Robot>
00031
00032 #include <robot/sim/SimulatedKinematicChain>
00033
00034 #include <physics/SolidSystem>
00035 #include <physics/Solid>
00036 #include <physics/Spatial>
00037 #include <physics/SpatialGroup>
00038 #include <physics/SpatialTransform>
00039 #include <physics/Motor>
00040
00041 #include <robot/ToolDescription>
00042 #include <robot/KinematicChain>
00043
00044
00045 namespace robot {
00046 namespace sim {
00047
00048
00049
00050
00051
00052
00053
00054 class SimulatedTool : public SimulatedKinematicChain
00055 {
00056 public:
00057
00058
00059
00060
00061
00062 SimulatedTool(ref<const robot::ToolDescription> toolDescription,
00063 const base::Point3& initialPosition, const base::Orient& initialOrientation,
00064 ref<physics::SolidSystem> solidSystem, bool dynamic=true);
00065
00066 virtual String className() const { return String("SimulatedTool"); }
00067
00068 virtual void setDynamic(bool enabled) { dynamic = enabled; }
00069
00070 virtual void setSolidSystem(ref<physics::SolidSystem> solidSystem)
00071 { this->solidSystem = solidSystem; }
00072
00073 ref<const robot::ToolDescription> getToolDescription() const { return toolDescr; }
00074
00075 ref<physics::Solid> getFirstLinkSolid() const
00076 { return firstSolid; }
00077
00078 ref<physics::Collidable> getFirstLinkCollidable() const
00079 { Assert(collidables.size() > 1); return collidables[1]; }
00080
00081 ref<physics::Collidable> getFirstLinkProximitySensorCollidable() const
00082 { Assert(proximityCollidables.size() > 1); return proximityCollidables[1]; }
00083
00084
00085 void setJointForce(Int j, Real f);
00086
00087
00088
00089 void setJointVel(Int j, Real v, Real maxForce=10.0);
00090
00091
00092
00093
00094
00095
00096
00097
00098 void setJointPos(Int j, Real p);
00099
00100
00101
00102
00103 Real getJointPos(Int j) const;
00104
00105
00106 Real getJointVel(Int j) const;
00107
00108
00109
00110 void attachTo(ref<physics::Solid> manipEESolid);
00111
00112
00113 void detatch();
00114
00115
00116
00117
00118
00119 Real getClosestObjectDistance(Int link) const;
00120
00121
00122 Vector3 getClosestObjectDirection(Int link) const;
00123
00124
00125 Real getClosestObjectSensorPosition(Int link) const;
00126
00127
00128
00129 virtual void setPosition(const Point3& pos);
00130 virtual Point3 getPosition() const;
00131 virtual void setOrientation(const Orient& orient);
00132 virtual Orient getOrientation() const;
00133 virtual void setConfiguration(const base::Transform& configuration);
00134 virtual base::Transform getConfiguration() const;
00135
00136
00137 virtual ref<physics::Collidable> createCollidable(CollidableFlags flags = 0);
00138
00139
00140 virtual bool formatSupported(const String format, Real version = 1.0, ExternalizationType type = IO) const;
00141 virtual void externalize(base::Externalizer& e, const String format = "", Real version = 1.0);
00142 void externalize(base::Externalizer& e, const String format = "", Real version = 1.0) const
00143 { Externalizable::externalize(e,format,version); }
00144
00145 protected:
00146 SimulatedTool(const SimulatedTool& st) { Unimplemented; }
00147
00148 ref<const robot::ToolDescription> toolDescr;
00149
00150
00151 void construct(const base::Point3& initialPosition, const base::Orient& initialOrientation);
00152
00153
00154
00155 TransformInfo computeLinkTransforms(const Transform& mountTransform, const base::Vector& q) const;
00156
00157
00158
00159 virtual void createLinks(const array<base::Dimension3>& linkDims);
00160
00161
00162 virtual void positionLinks(const TransformInfo& transformInfo);
00163
00164 virtual void disableCollisions(const array<ref<physics::Collidable> >& collidables,
00165 const array<ref<physics::Collidable> >& proximityCollidables);
00166
00167 virtual void attachJoints(const TransformInfo& transformInfo);
00168
00169 virtual void handleCollision(ref<physics::CollisionState> collisionState);
00170
00171
00172 ref<physics::Solid> firstSolid;
00173 ref<physics::Solid> endSolid;
00174 base::Transform firstLinkSolidToMount;
00175 ref<physics::SpatialTransform> mountSpatial;
00176 ref<physics::SpatialGroup> spatialGroup;
00177 bool attached;
00178 ref<physics::ConstraintGroup> mountConstraintGroup;
00179
00180
00181 friend class SimulatedRobot;
00182 friend class base::Serializable::SerializableDerivedInstantiator<SimulatedTool>;
00183
00184 };
00185
00186
00187
00188 }
00189 }
00190
00191 #endif