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