defaultCaterpillar.h

Go to the documentation of this file.
00001 /************************************************************************/ 00002 /* originally from: */ 00003 /* schlange.h */ 00004 /* Abstract class for Snakes */ 00005 /* @author Georg Martius */ 00006 /************************************************************************/ 00007 /* here: */ 00008 /* defaultCaterpillar.h */ 00009 /* Abstract class for Caterpillars */ 00010 /* @author Frank Guettler */ 00011 /************************************************************************/ 00012 /*************************************************************************** 00013 * Copyright (C) 2005 by Robot Group Leipzig * 00014 * martius@informatik.uni-leipzig.de * 00015 * fhesse@informatik.uni-leipzig.de * 00016 * der@informatik.uni-leipzig.de * 00017 * frankguettler@gmx.de * 00018 * * 00019 * This program is free software; you can redistribute it and/or modify * 00020 * it under the terms of the GNU General Public License as published by * 00021 * the Free Software Foundation; either version 2 of the License, or * 00022 * (at your option) any later version. * 00023 * * 00024 * This program is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU General Public License * 00030 * along with this program; if not, write to the * 00031 * Free Software Foundation, Inc., * 00032 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00033 * * 00034 * $Log: defaultCaterpillar.h,v $ 00035 * Revision 1.3 2006/12/21 11:43:05 martius 00036 * commenting style for doxygen //< -> ///< 00037 * new sensors for spherical robots 00038 * 00039 * Revision 1.2 2006/07/14 12:23:39 martius 00040 * selforg becomes HEAD 00041 * 00042 * Revision 1.1.2.6 2006/06/25 16:57:12 martius 00043 * abstractrobot is configureable 00044 * name and revision 00045 * 00046 * Revision 1.1.2.5 2006/05/29 20:28:43 robot5 00047 * Annular placement of segments. 00048 * 00049 * Revision 1.1.2.4 2006/05/22 14:19:11 robot5 00050 * Added variable conf.firstJoint to represent the first slider type in the alternating sequence. 00051 * Code cleaning. 00052 * 00053 * Revision 1.1.2.3 2006/05/09 04:24:34 robot5 00054 * *** empty log message *** 00055 * 00056 * Revision 1.1.2.2 2006/04/11 13:27:48 robot3 00057 * caterpillar is using now methods from schlangeservo2 00058 * 00059 * Revision 1.1.2.1 2006/04/11 08:30:46 robot3 00060 * first version 00061 * 00062 * 00063 * * 00064 ***************************************************************************/ 00065 #ifndef __DEFAULTCATERPILLAR_H 00066 #define __DEFAULTCATERPILLAR_H 00067 00068 #include<vector> 00069 #include<assert.h> 00070 00071 #include"primitive.h" 00072 #include "joint.h" 00073 #include "angularmotor.h" 00074 00075 #include "oderobot.h" 00076 #include <selforg/configurable.h> 00077 00078 namespace lpzrobots { 00079 00080 typedef struct { 00081 public: 00082 int segmNumber; ///< number of snake elements 00083 double segmLength; ///< length of one snake element 00084 double segmDia; ///< diameter of a snake element 00085 double segmMass; ///< mass of one snake element 00086 double motorPower; ///< power of the motors / servos 00087 double sensorFactor; ///< scale for sensors 00088 double frictionGround; ///< friction with ground 00089 double frictionJoint; ///< friction within joint 00090 double jointLimit; ///< maximal angle for the joints (M_PI/2 = 90 degree) 00091 int firstJoint; ///< first joint type to use: 0=sliderJoint, 1=universalJoint 00092 } CaterPillarConf; 00093 00094 00095 /** 00096 * This is a class, which models a snake like robot. 00097 * It consists of a number of equal elements, each linked 00098 * by a joint 00099 **/ 00100 class DefaultCaterPillar: public OdeRobot 00101 { 00102 protected: 00103 00104 bool created; 00105 00106 std::vector <Primitive*> objects; 00107 std::vector <Joint*> joints; 00108 std::vector <AngularMotor*> frictionmotors; 00109 CaterPillarConf conf; 00110 00111 public: 00112 DefaultCaterPillar ( const OdeHandle& odeHandle, const OsgHandle& osgHandle, 00113 const CaterPillarConf& conf, const std::string& name, const std::string& revision); 00114 00115 static CaterPillarConf getDefaultConf(){ 00116 CaterPillarConf conf; 00117 conf.segmNumber = 6; // number of snake elements 00118 conf.segmLength = 0.4; // length of one snake element 00119 conf.segmDia = 0.2; // diameter of a snake element 00120 conf.segmMass = 0.4; // mass of one snake element 00121 conf.motorPower = 1; // power of the servos 00122 conf.sensorFactor = 1; // scale for sensors 00123 conf.frictionGround = 1.0; // friction with ground 00124 conf.frictionJoint = 0.1; // friction within joint 00125 conf.jointLimit = M_PI/8; 00126 conf.firstJoint=1; 00127 return conf; 00128 } 00129 00130 virtual ~DefaultCaterPillar(); 00131 00132 00133 /** sets the pose of the vehicle 00134 @param pose desired 4x4 pose matrix 00135 */ 00136 virtual void place(const osg::Matrix& pose); 00137 00138 /// update all primitives and joints 00139 virtual void update(); 00140 00141 /** 00142 *This is the collision handling function for snake robots. 00143 *This overwrides the function collisionCallback of the class robot. 00144 *@param data 00145 *@param o1 first geometrical object, which has taken part in the collision 00146 *@param o2 second geometrical object, which has taken part in the collision 00147 *@return true if the collision was threated by the robot, false if not 00148 **/ 00149 virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2); 00150 00151 static void mycallback(void *data, dGeomID o1, dGeomID o2); 00152 00153 virtual void doInternalStuff(const GlobalData& global); 00154 00155 /** 00156 *Reads the actual motor commands from an array, 00157 *an sets all motors of the snake to this values. 00158 *It is an linear allocation. 00159 *@param motors pointer to the array, motor values are scaled to [-1,1] 00160 *@param motornumber length of the motor array 00161 **/ 00162 virtual void setMotors ( const motor* motors, int motornumber ) = 0; 00163 00164 /** 00165 *Writes the sensor values to an array in the memory. 00166 *@param sensors pointer to the array 00167 *@param sensornumber length of the sensor array 00168 *@return number of actually written sensors 00169 **/ 00170 virtual int getSensors ( sensor* sensors, int sensornumber ) = 0; 00171 00172 /** returns number of sensors 00173 */ 00174 virtual int getSensorNumber() = 0; 00175 00176 /** returns number of motors 00177 */ 00178 virtual int getMotorNumber() = 0; 00179 00180 /** returns a vector with the positions of all segments of the robot 00181 @param poslist vector of positions (of all robot segments) 00182 @return length of the list 00183 */ 00184 virtual int getSegmentsPosition(std::vector<Position> &poslist); 00185 00186 /** The list of all parameters with there value as allocated lists. 00187 */ 00188 virtual paramlist getParamList() const; 00189 00190 virtual paramval getParam(const paramkey& key) const;; 00191 00192 virtual bool setParam(const paramkey& key, paramval val); 00193 00194 /** the main object of the robot, which is used for position and speed tracking */ 00195 virtual Primitive* getMainPrimitive() const { 00196 if(!objects.empty()){ 00197 // int half = objects.size()/2; 00198 // return (objects[half]); 00199 return (objects[0]); 00200 }else return 0; 00201 } 00202 protected: 00203 00204 /** creates vehicle at desired pose 00205 @param pose 4x4 pose matrix 00206 */ 00207 virtual void create(const osg::Matrix& pose); 00208 virtual void destroy(); 00209 }; 00210 00211 } 00212 00213 #endif

Generated on Tue Jan 16 02:14:35 2007 for Robotsystem of the Robot Group Leipzig by doxygen 1.3.8