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_SIMULATEDBASICENVIRONMENT_
00026 #define _ROBOT_SIM_SIMULATEDBASICENVIRONMENT_
00027
00028 #include <robot/sim/sim>
00029
00030 #include <robot/sim/BasicEnvironment>
00031
00032 #include <osg/Group>
00033
00034 #include <base/Externalizable>
00035 #include <base/Simulatable>
00036 #include <base/Orient>
00037 #include <base/Trajectory>
00038
00039 #include <gfx/Color3>
00040 #include <gfx/OSGWorld>
00041
00042 #include <physics/Shape>
00043 #include <physics/SolidSystem>
00044 #include <physics/CollisionCuller>
00045
00046 #include <robot/sim/SimulatedRobotDescription>
00047 #include <robot/sim/SimulatedRobot>
00048 #include <robot/sim/SimulatedTool>
00049
00050
00051
00052 namespace robot {
00053 namespace sim {
00054
00055
00056
00057
00058
00059 class SimulatedBasicEnvironment : public robot::sim::BasicEnvironment, public gfx::OSGWorld
00060 {
00061 public:
00062 SimulatedBasicEnvironment(ref<base::VFileSystem> fs, ref<base::Cache> cache, const String& name = "", bool dynamic=true);
00063 SimulatedBasicEnvironment(const SimulatedBasicEnvironment& e);
00064
00065 virtual void setDynamic(bool enabled);
00066
00067 virtual String className() const { return String("SimulatedBasicEnvironment"); }
00068
00069 virtual Object& clone() const { return *(NewObj SimulatedBasicEnvironment(*this)); }
00070
00071
00072
00073 virtual ref<RobotDescription> newRobotDescription() const
00074 { return ref<RobotDescription>(NewObj SimulatedRobotDescription()); }
00075
00076 virtual ref<ToolDescription> newToolDescription() const
00077 { return ref<ToolDescription>(NewObj ToolDescription()); }
00078
00079
00080 virtual ref<Robot> addRobot(ref<const robot::RobotDescription> robotDescription,
00081 const base::Point3& position,
00082 const base::Orient& orientation,
00083 bool anchored = false);
00084
00085 virtual void removeRobot(ref<robot::Robot> robot);
00086
00087 virtual Int numRobots() const { return robots.size(); }
00088 virtual ref<Robot> getRobot(Int i) { return base::elementAt(robots,i); }
00089
00090
00091
00092
00093 virtual ref<Tool> addTool(ref<const robot::ToolDescription> toolDescription,
00094 const base::Point3& position,
00095 const base::Orient& orientation);
00096
00097 virtual void removeTool(ref<Tool> tool);
00098
00099 virtual Int numTools() const { return tools.size(); };
00100 virtual ref<Tool> getTool(Int i) { return base::elementAt(tools,i); }
00101 virtual ref<const Tool> getTool(Int i) const { return base::elementAt(tools,i); }
00102
00103
00104 virtual void placeToolInProximity(ref<Tool> tool, ref<Robot> robot, Int manipulatorIndex=0);
00105
00106
00107
00108
00109 virtual ref<BasicEnvironment::Obstacle> addBoxObstacle(base::Dimension3 dim,
00110 const base::Point3& position,
00111 const base::Orient& orientation,
00112 const String& name = "");
00113
00114 virtual ref<BasicEnvironment::Obstacle> addSphereObstacle(Real radius,
00115 const base::Point3& position,
00116 const base::Orient& orientation,
00117 const String& name = "");
00118
00119 virtual ref<BasicEnvironment::Obstacle> addBoxObstacle(base::Dimension3 dim,
00120 const base::Point3& position,
00121 const base::Orient& orientation,
00122 ref<const physics::Material> material,
00123 const String& name = "");
00124
00125 virtual ref<BasicEnvironment::Obstacle> addSphereObstacle(Real radius,
00126 const base::Point3& position,
00127 const base::Orient& orientation,
00128 ref<const physics::Material> material,
00129 const String& name = "");
00130
00131 virtual void removeObstacle(ref<BasicEnvironment::Obstacle> obstacle);
00132
00133
00134 virtual void setObstacleColor(ref<BasicEnvironment::Obstacle> obstacle, const gfx::Color3& color);
00135 virtual void setObstacleDensity(ref<BasicEnvironment::Obstacle> obstacle, Real density);
00136
00137 virtual Int numObstacles() const { return obstacles.size(); }
00138 virtual ref<Obstacle> getObstacle(Int i) { return base::elementAt(obstacles,i); }
00139 virtual ref<const Obstacle> getObstacle(Int i) const { return base::elementAt(obstacles,i); }
00140
00141
00142
00143 virtual osg::Node* createOSGVisual(Visual::Attributes visualAttributes=0) const;
00144
00145
00146 virtual void preSimulate();
00147 virtual void simulateForSimTime(const base::Time& dt);
00148
00149
00150 virtual bool formatSupported(const String format, Real version = 1.0, ExternalizationType type = IO) const;
00151 virtual void externalize(base::Externalizer& e, const String format = "", Real version = 1.0);
00152
00153 protected:
00154
00155 class SolidObstacle : public Obstacle
00156 {
00157 public:
00158 SolidObstacle(base::Dimension3 dims,
00159 const base::Point3& position,
00160 const base::Orient& orientation,
00161 ref<physics::Solid> solid)
00162 : Obstacle(dims, position, orientation),
00163 solid(solid) {}
00164
00165 SolidObstacle(Real radius,
00166 const base::Point3& position,
00167 const base::Orient& orientation,
00168 ref<physics::Solid> solid)
00169 : Obstacle(radius, position, orientation),
00170 solid(solid) {}
00171
00172 virtual String className() const { return String("SolidObstacle"); }
00173
00174 ref<physics::Solid> solid;
00175 };
00176
00177
00178 class SolidTool : public Tool
00179 {
00180 public:
00181 SolidTool(String name, ref<const robot::ToolDescription> toolDescription,
00182 const base::Point3& position,
00183 const base::Orient& orientation,
00184 ref<SimulatedTool> simTool)
00185 : Tool(name, toolDescription, position, orientation),
00186 simTool(simTool) {}
00187
00188 virtual String className() const { return String("SolidTool"); }
00189
00190 ref<SimulatedTool> simTool;
00191 };
00192
00193
00194 void construct();
00195
00196 ref<physics::Solid> findObstacle(ref<Obstacle> obstacle);
00197
00198
00199 bool dynamic;
00200
00201 ref<physics::SolidSystem> system;
00202 ref<physics::CollidableGroup> collidables;
00203 ref<physics::Collidable> groundCollidable;
00204 ref<physics::CollisionCuller> collisionCuller;
00205 ref<physics::Solid> ground;
00206 ref<physics::ConstraintGroup> cgroup;
00207
00208 typedef reflist<robot::sim::SimulatedRobot> RobotList;
00209 typedef std::list<bool> RobotAnchoredList;
00210 typedef reflist<Tool> ToolList;
00211 typedef reflist<SolidObstacle> ObstacleList;
00212
00213 RobotList robots;
00214 ToolList tools;
00215 ObstacleList obstacles;
00216 RobotAnchoredList robotsAnchored;
00217
00218 mutable Visual::Attributes attributes;
00219 mutable osg::ref_ptr<osg::Group> rootnode;
00220
00221
00222 void checkTools();
00223 };
00224
00225
00226 }
00227 }
00228
00229 #endif