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