IRobotSim.H
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 #ifndef IRobotSim_H_DEFINED
00040 #define IRobotSim_H_DEFINED
00041
00042 #include "Component/ModelComponent.H"
00043 #include "Component/ModelParam.H"
00044 #include "Image/Image.H"
00045 #include "Image/Pixels.H"
00046 #include "GUI/ViewPort.H"
00047 #include "GUI/XWinManaged.H"
00048 #include "Util/Types.H"
00049 #include <deque>
00050 #include <pthread.h>
00051 #include <stdarg.h>
00052 #include <ode/ode.h>
00053 #include <ode/collision.h>
00054
00055 #include <vector>
00056
00057 class IRobotSim : public ModelComponent
00058 {
00059 public:
00060
00061 #define ROBOT_BITFIELD 1
00062 #define GROUND_BITFIELD 2
00063 #define OBJ_BITFIELD 4
00064
00065 enum OBJECT_TYPE {BOX, CYLINDER, SPHERE, TREE, DS, TOBJ};
00066 typedef struct{
00067 dBodyID body;
00068 dGeomID geom;
00069 OBJECT_TYPE type;
00070 float color[3];
00071 ViewPort::TEXTURES texture;
00072 ViewPort::DSObject object;
00073 Texture *texturePtr;
00074 int textureID;
00075 } Object;
00076
00077
00078 IRobotSim(OptionManager& mgr,
00079 const std::string& descrName = "IRobotSim",
00080 const std::string& tagName = "IRobotSim",
00081 bool showWorld=false);
00082 ~IRobotSim();
00083
00084
00085 void start2();
00086 void handleWinEvents(XEvent& event);
00087
00088 void simLoop();
00089 void startSim(void);
00090 void updateSensors();
00091 Image<PixRGB<byte> > getFrame(int camera);
00092
00093 void getSensors(float &xPos, float &yPos, float &ori);
00094
00095 void setMotors(double rightSpeed, double leftSpeed);
00096
00097 dWorldID getWorld() { return world; }
00098 dJointGroupID getContactgroup() { return contactgroup; }
00099
00100 void addObject(OBJECT_TYPE objType,double initPos[3],double objSize[3],
00101 bool addToSpace = true,
00102 const char* texture=NULL);
00103
00104
00105
00106
00107 float getXPos() { return itsXPos; }
00108 float getYPos() { return itsYPos; }
00109 float getOri() { return itsOri; }
00110
00111
00112 void initViewport();
00113
00114
00115 dGeomID getCasterGeom() { return itsCasterGeom; }
00116 dGeomID getRobotGeom() { return itsRobotGeom; }
00117 dGeomID getGroundGeom() { return ground; }
00118
00119 private:
00120
00121 void makeRobot();
00122 void drawRobot();
00123
00124
00125 void drawWorld();
00126 void makeWorld();
00127
00128 dWorldID world;
00129 dSpaceID space;
00130 dGeomID ground;
00131 dJointGroupID contactgroup;
00132
00133 float itsRobotStartZ;
00134 dBodyID itsRobotBody;
00135 dGeomID itsRobotGeom;
00136
00137 dBodyID itsRightWheelBody;
00138 dGeomID itsRightWheelGeom;
00139 dJointID itsRightWheelJoint;
00140
00141 dBodyID itsLeftWheelBody;
00142 dGeomID itsLeftWheelGeom;
00143 dJointID itsLeftWheelJoint;
00144
00145 dBodyID itsCasterBody;
00146 dGeomID itsCasterGeom;
00147
00148 double itsRobotRadius;
00149 double itsRobotHeight;
00150 double itsRobotWeight;
00151 double itsRobotWheelRadius;
00152
00153 ViewPort *itsVP;
00154
00155 double itsRightWheelSpeed;
00156 double itsLeftWheelSpeed;
00157
00158
00159 double itsXPos;
00160 double itsYPos;
00161 double itsOri;
00162 double itsRightEncoder;
00163 double itsLeftEncoder;
00164 int itsPrevRightWheelAng;
00165 int itsPrevLeftWheelAng;
00166
00167 bool itsWorldView;
00168 bool itsShowWorld;
00169 XWinManaged *itsWorldDisp;
00170
00171 std::vector<Object> itsObjects;
00172
00173 pthread_mutex_t itsDispLock;
00174 };
00175
00176 #endif
00177
00178
00179
00180
00181
00182