00001 /************************************************************************/ 00002 /* schlange.h */ 00003 /* Abstract class for Snakes */ 00004 /* @author Georg Martius */ 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 * * 00013 * This program is free software; you can redistribute it and/or modify * 00014 * it under the terms of the GNU General Public License as published by * 00015 * the Free Software Foundation; either version 2 of the License, or * 00016 * (at your option) any later version. * 00017 * * 00018 * This program is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00021 * GNU General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU General Public License * 00024 * along with this program; if not, write to the * 00025 * Free Software Foundation, Inc., * 00026 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00027 * * 00028 * $Log: schlange.h,v $ 00029 * Revision 1.24 2009/05/11 15:44:30 martius 00030 * new velocity servos used 00031 * 00032 * Revision 1.23 2007/11/07 13:21:16 martius 00033 * doInternal stuff changed signature 00034 * 00035 * Revision 1.22 2007/07/03 13:05:23 martius 00036 * new servo constants 00037 * 00038 * Revision 1.21 2007/01/26 12:05:04 martius 00039 * servos combinied into OneAxisServo 00040 * 00041 * Revision 1.20 2006/12/21 11:43:05 martius 00042 * commenting style for doxygen //< -> ///< 00043 * new sensors for spherical robots 00044 * 00045 * Revision 1.19 2006/09/20 12:56:16 martius 00046 * Snakes have CreateSegment 00047 * 00048 * Revision 1.18 2006/07/20 17:19:44 martius 00049 * removed using namespace std from matrix.h 00050 * 00051 * Revision 1.17 2006/07/14 13:52:01 der 00052 * setheadcolor 00053 * 00054 * Revision 1.15.4.9 2006/06/25 16:57:15 martius 00055 * abstractrobot is configureable 00056 * name and revision 00057 * 00058 * Revision 1.15.4.8 2006/05/19 09:04:38 der 00059 * -setTexture and setHeadTexture added 00060 * -uses now whitemetal texture 00061 * 00062 * Revision 1.15.4.7 2006/03/30 12:34:56 martius 00063 * documentation updated 00064 * 00065 * Revision 1.15.4.6 2006/03/29 15:08:54 martius 00066 * getMainPrimitive is public now 00067 * 00068 * Revision 1.15.4.5 2006/02/23 18:05:04 martius 00069 * friction with angularmotor 00070 * 00071 * Revision 1.15.4.4 2006/02/01 18:33:40 martius 00072 * use Axis type for Joint axis. very important, since otherwise Vec3 * pose is not the right direction vector anymore 00073 * 00074 * Revision 1.15.4.3 2005/12/30 22:53:13 martius 00075 * removed parentspace! 00076 * 00077 * Revision 1.15.4.2 2005/12/29 16:45:46 martius 00078 * does not inherit from Roboter 00079 * moved to osg 00080 * 00081 * 00082 * * 00083 ***************************************************************************/ 00084 #ifndef __SCHLANGE_H 00085 #define __SCHLANGE_H 00086 00087 #include<vector> 00088 #include<assert.h> 00089 00090 #include "primitive.h" 00091 #include "joint.h" 00092 #include "angularmotor.h" 00093 #include "pid.h" 00094 00095 #include "oderobot.h" 00096 #include <selforg/configurable.h> 00097 00098 namespace lpzrobots { 00099 00100 typedef struct { 00101 public: 00102 int segmNumber; ///< number of snake elements 00103 double segmLength; ///< length of one snake element 00104 double segmDia; ///< diameter of a snake element 00105 double segmMass; ///< mass of one snake element 00106 double motorPower; ///< power of the motors / servos 00107 double sensorFactor; ///< scale for sensors 00108 double frictionGround; ///< friction with ground 00109 double frictionJoint; ///< friction within joint 00110 double jointLimit; ///< maximal angle for the joints (M_PI/2 = 90 degree) 00111 bool useServoVel; ///< if true the new Servos are used (only for schlangeservo) 00112 double velocity; ///< maximal velocity of servos 00113 } SchlangeConf; 00114 00115 00116 /** 00117 * This is a class, which models a snake like robot. 00118 * It consists of a number of equal elements, each linked 00119 * by a joint 00120 **/ 00121 class Schlange: public OdeRobot 00122 { 00123 protected: 00124 00125 bool created; 00126 00127 std::vector <Primitive*> objects; 00128 std::vector <Joint*> joints; 00129 std::vector <AngularMotor*> frictionmotors; 00130 SchlangeConf conf; 00131 00132 public: 00133 Schlange ( const OdeHandle& odeHandle, const OsgHandle& osgHandle, 00134 const SchlangeConf& conf, const std::string& name, const std::string& revision); 00135 00136 static SchlangeConf getDefaultConf(){ 00137 SchlangeConf conf; 00138 conf.segmNumber = 10; // number of snake elements 00139 conf.segmLength = 0.8; // length of one snake element 00140 conf.segmDia = 0.2; // diameter of a snake element 00141 conf.segmMass = 0.1;//0.4 // mass of one snake element 00142 conf.motorPower = 1; // power of the servos 00143 conf.sensorFactor = 1; // scale for sensors 00144 conf.frictionGround = 1.0; // friction with ground 00145 conf.frictionJoint = 0.02; // friction within joint 00146 conf.jointLimit = M_PI/4; 00147 conf.useServoVel = false; 00148 conf.velocity = 20; // maximal velocity of servos 00149 return conf; 00150 } 00151 00152 virtual ~Schlange(); 00153 00154 00155 /** sets the pose of the vehicle 00156 @param pose desired 4x4 pose matrix 00157 */ 00158 virtual void place(const osg::Matrix& pose); 00159 00160 /// update all primitives and joints 00161 virtual void update(); 00162 00163 /** 00164 *This is the collision handling function for snake robots. 00165 *This overwrides the function collisionCallback of the class robot. 00166 *@param data 00167 *@param o1 first geometrical object, which has taken part in the collision 00168 *@param o2 second geometrical object, which has taken part in the collision 00169 *@return true if the collision was threated by the robot, false if not 00170 **/ 00171 virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2); 00172 00173 static void mycallback(void *data, dGeomID o1, dGeomID o2); 00174 00175 virtual void doInternalStuff(GlobalData& global); 00176 00177 /** 00178 *Reads the actual motor commands from an array, 00179 *an sets all motors of the snake to this values. 00180 *It is an linear allocation. 00181 *@param motors pointer to the array, motor values are scaled to [-1,1] 00182 *@param motornumber length of the motor array 00183 **/ 00184 virtual void setMotors ( const motor* motors, int motornumber ) = 0; 00185 00186 /** 00187 *Writes the sensor values to an array in the memory. 00188 *@param sensors pointer to the array 00189 *@param sensornumber length of the sensor array 00190 *@return number of actually written sensors 00191 **/ 00192 virtual int getSensors ( sensor* sensors, int sensornumber ) = 0; 00193 00194 /** returns number of sensors 00195 */ 00196 virtual int getSensorNumber() = 0; 00197 00198 /** returns number of motors 00199 */ 00200 virtual int getMotorNumber() = 0; 00201 00202 /** returns a vector with the positions of all segments of the robot 00203 @param poslist vector of positions (of all robot segments) 00204 @return length of the list 00205 */ 00206 virtual int getSegmentsPosition(std::vector<Position> &poslist); 00207 00208 00209 /** The list of all parameters with there value as allocated lists. 00210 */ 00211 virtual paramlist getParamList() const; 00212 00213 virtual paramval getParam(const paramkey& key) const;; 00214 00215 virtual bool setParam(const paramkey& key, paramval val); 00216 00217 /** the main object of the robot, which is used for position and speed tracking */ 00218 virtual Primitive* getMainPrimitive() const { 00219 if(!objects.empty()){ 00220 // int half = objects.size()/2; 00221 // return (objects[half]); 00222 return (objects[0]); 00223 }else return 0; 00224 } 00225 00226 /** sets a texture to the body of the snake 00227 * note: the head texture of the snake is set by 00228 * this method too! 00229 */ 00230 virtual void setTexture(const std::string& filename); 00231 00232 /** sets a texture to the head of the snake 00233 */ 00234 virtual void setHeadTexture(const std::string& filename); 00235 00236 /** 00237 * sets the color of the head element 00238 */ 00239 virtual void setHeadColor(const Color& color); 00240 00241 00242 protected: 00243 00244 /** creates vehicle at desired pose 00245 @param pose 4x4 pose matrix 00246 */ 00247 virtual void create(const osg::Matrix& pose); 00248 /** 00249 creates and initialised the segment with the given index 00250 */ 00251 virtual Primitive* createSegment(int index); 00252 virtual void destroy(); 00253 }; 00254 00255 } 00256 00257 #endif