00001 /*************************************************************************** 00002 * * 00003 * TruckMesh robot, an example for using Meshes for robot bodies * 00004 * basic code taken from the nimm4 robot * 00005 * * 00006 **************************************************************************/ 00007 /*************************************************************************** 00008 * Copyright (C) 2005 by Robot Group Leipzig * 00009 * martius@informatik.uni-leipzig.de * 00010 * fhesse@informatik.uni-leipzig.de * 00011 * der@informatik.uni-leipzig.de * 00012 * frankguettler@gmx.de * 00013 * * 00014 * This program is free software; you can redistribute it and/or modify * 00015 * it under the terms of the GNU General Public License as published by * 00016 * the Free Software Foundation; either version 2 of the License, or * 00017 * (at your option) any later version. * 00018 * * 00019 * This program is distributed in the hope that it will be useful, * 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00022 * GNU General Public License for more details. * 00023 * * 00024 * You should have received a copy of the GNU General Public License * 00025 * along with this program; if not, write to the * 00026 * Free Software Foundation, Inc., * 00027 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00028 * * 00029 * $Log: truckmesh.h,v $ 00030 * Revision 1.4 2007/11/07 13:21:16 martius 00031 * doInternal stuff changed signature 00032 * 00033 * Revision 1.3 2007/07/31 08:19:26 martius 00034 * mesh without global 00035 * 00036 * Revision 1.2 2006/07/14 12:23:42 martius 00037 * selforg becomes HEAD 00038 * 00039 * Revision 1.1.2.3 2006/07/06 12:33:31 robot3 00040 * -mass of the truck can be set by the constructor now 00041 * -code cleaned up 00042 * -all 6 wheels have now contact to the ground (instead of only 4) 00043 * 00044 * Revision 1.1.2.2 2006/06/29 16:36:46 robot3 00045 * -controller now gets 6 wheels for control 00046 * -wheels are on the right position now 00047 * 00048 * Revision 1.1.2.1 2006/06/27 15:19:52 robot3 00049 * truckmesh uses a mesh for the body of the robot 00050 * 00051 * Revision 1.5.4.13 2006/06/25 16:57:14 martius 00052 * abstractrobot is configureable 00053 * name and revision 00054 * 00055 * Revision 1.5.4.12 2006/04/04 14:13:24 fhesse 00056 * documentation improved 00057 * 00058 * Revision 1.5.4.11 2006/03/31 16:20:28 fhesse 00059 * class Joint; changed to: class Hinge2Joint; 00060 * 00061 * Revision 1.5.4.10 2006/03/30 12:34:56 martius 00062 * documentation updated 00063 * 00064 * Revision 1.5.4.9 2005/12/15 17:04:08 martius 00065 * Primitives are not longer inherited from OSGPrimitive, moreover 00066 * they aggregate them. 00067 * Joint have better getter and setter 00068 * 00069 * Revision 1.5.4.8 2005/12/14 15:37:09 martius 00070 * robots are working with osg 00071 * 00072 * Revision 1.5.4.7 2005/12/13 18:11:40 martius 00073 * still trying to port robots 00074 * 00075 * Revision 1.5.4.6 2005/12/12 23:41:19 martius 00076 * added Joint wrapper 00077 * 00078 * Revision 1.5.4.5 2005/12/11 23:35:08 martius 00079 * *** empty log message *** 00080 * 00081 * Revision 1.5.4.4 2005/12/06 10:13:25 martius 00082 * openscenegraph integration started 00083 * 00084 * Revision 1.5.4.3 2005/11/16 11:26:52 martius 00085 * moved to selforg 00086 * 00087 * Revision 1.5.4.2 2005/11/15 12:29:26 martius 00088 * new selforg structure and OdeAgent, OdeRobot ... 00089 * 00090 * Revision 1.5.4.1 2005/11/14 17:37:18 martius 00091 * moved to selforg 00092 * 00093 * Revision 1.5 2005/10/27 16:10:41 fhesse 00094 * nimm4 as example 00095 * 00096 * Revision 1.4 2005/09/22 12:24:37 martius 00097 * removed global variables 00098 * OdeHandle and GlobalData are used instead 00099 * sensor prepared 00100 * 00101 * Revision 1.3 2005/08/31 11:14:06 martius 00102 * removed unused vars 00103 * 00104 * Revision 1.2 2005/08/03 20:38:56 martius 00105 * added textures and correct placement 00106 * 00107 * Revision 1.1 2005/07/29 15:13:11 martius 00108 * a robot with 4 independent wheels 00109 * 00110 * * 00111 ***************************************************************************/ 00112 #ifndef __TRUCKMESH_H 00113 #define __TRUCKMESH_H 00114 00115 #include "oderobot.h" 00116 00117 namespace lpzrobots { 00118 00119 class Primitive; 00120 class Hinge2Joint; 00121 00122 /** Robot that looks like a Nimm 2 Bonbon :-) 00123 4 wheels and a truck mesh like body 00124 */ 00125 class TruckMesh : public OdeRobot{ 00126 public: 00127 00128 /** 00129 * constructor of TruckMesh robot 00130 * @param odeHandle data structure for accessing ODE 00131 * @param osgHandle ata structure for accessing OSG 00132 * @param size scaling of robot 00133 * @param force maximal used force to realize motorcommand 00134 * @param speed factor for changing speed of robot 00135 */ 00136 TruckMesh(const OdeHandle& odeHandle, const OsgHandle& osgHandle, const std::string& name, 00137 double size=1, double force=3, double speed=15, double mass=1); 00138 00139 00140 virtual ~TruckMesh(){}; 00141 00142 /** 00143 * updates the OSG nodes of the vehicle 00144 */ 00145 virtual void update(); 00146 00147 00148 /** sets the pose of the vehicle 00149 @param pose desired pose matrix 00150 */ 00151 virtual void place(const osg::Matrix& pose); 00152 00153 /** returns actual sensorvalues 00154 @param sensors sensors scaled to [-1,1] 00155 @param sensornumber length of the sensor array 00156 @return number of actually written sensors 00157 */ 00158 virtual int getSensors(sensor* sensors, int sensornumber); 00159 00160 /** sets actual motorcommands 00161 @param motors motors scaled to [-1,1] 00162 @param motornumber length of the motor array 00163 */ 00164 virtual void setMotors(const motor* motors, int motornumber); 00165 00166 /** returns number of sensors 00167 */ 00168 virtual int getSensorNumber(){ 00169 return sensorno; 00170 }; 00171 00172 /** returns number of motors 00173 */ 00174 virtual int getMotorNumber(){ 00175 return motorno; 00176 }; 00177 00178 /** checks for internal collisions and treats them. 00179 * In case of a treatment return true (collision will be ignored by other objects 00180 * and the default routine) else false (collision is passed to other objects and 00181 * (if not treated) to the default routine). 00182 */ 00183 virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2); 00184 00185 /** this function is called in each timestep. It should perform robot-internal checks, 00186 like space-internal collision detection, sensor resets/update etc. 00187 @param globalData structure that contains global data from the simulation environment 00188 */ 00189 virtual void doInternalStuff(GlobalData& globalData); 00190 00191 00192 protected: 00193 /** the main object of the robot, which is used for position and speed tracking */ 00194 virtual Primitive* getMainPrimitive() const { return object[0]; } 00195 00196 /** creates vehicle at desired pose 00197 @param pose 4x4 pose matrix 00198 */ 00199 virtual void create(const osg::Matrix& pose); 00200 00201 /** destroys vehicle and space 00202 */ 00203 virtual void destroy(); 00204 00205 /** additional things for collision handling can be done here 00206 */ 00207 static void mycallback(void *data, dGeomID o1, dGeomID o2); 00208 00209 double length; // chassis length 00210 double width; // chassis width 00211 double middlewidth; // chassis middle position of width 00212 double middlelength; // chassis middle position of length 00213 double height; // chassis height 00214 double radius; // wheel radius 00215 double wheelthickness; // thickness of the wheels 00216 double cmass; // chassis mass 00217 double wmass; // wheel mass 00218 int sensorno; // number of sensors 00219 int motorno; // number of motors 00220 int segmentsno; // number of motorsvehicle segments 00221 double speed; // factor for adjusting speed of robot 00222 00223 bool drawBoundings; // if bounding shapes of the body are drawed 00224 double max_force; // maximal force for motors 00225 00226 bool created; // true if robot was created 00227 00228 Primitive* object[7]; // 1 mesh, 6 wheels 00229 Hinge2Joint* joint[6]; // joints between mesh and each wheel 00230 00231 }; 00232 00233 } 00234 00235 #endif