schlange.h

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

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