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