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-2011 LpzRobots development team * 00014 * Georg Martius <georg dot martius at web dot de> * 00015 * Frank Guettler <guettler at informatik dot uni-leipzig dot de * 00016 * Frank Hesse <frank at nld dot ds dot mpg dot de> * 00017 * Ralf Der <ralfder at mis dot mpg dot 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 ***************************************************************************/ 00035 #ifndef __DEFAULTCATERPILLAR_H 00036 #define __DEFAULTCATERPILLAR_H 00037 00038 #include<vector> 00039 #include<assert.h> 00040 00041 #include"primitive.h" 00042 #include "joint.h" 00043 #include "angularmotor.h" 00044 00045 #include "oderobot.h" 00046 #include <selforg/configurable.h> 00047 00048 namespace lpzrobots { 00049 00050 typedef struct { 00051 public: 00052 int segmNumber; ///< number of snake elements 00053 double segmLength; ///< length of one snake element 00054 double segmDia; ///< diameter of a snake element 00055 double segmMass; ///< mass of one snake element 00056 double motorPower; ///< power of the motors / servos 00057 double sensorFactor; ///< scale for sensors 00058 double frictionGround; ///< friction with ground 00059 double frictionJoint; ///< friction within joint 00060 double jointLimit; ///< maximal angle for the joints (M_PI/2 = 90 degree) 00061 int firstJoint; ///< first joint type to use: 0=sliderJoint, 1=universalJoint 00062 } CaterPillarConf; 00063 00064 00065 /** 00066 * This is a class, which models a snake like robot. 00067 * It consists of a number of equal elements, each linked 00068 * by a joint 00069 **/ 00070 class DefaultCaterPillar: public OdeRobot 00071 { 00072 protected: 00073 00074 bool created; 00075 00076 std::vector <AngularMotor*> frictionmotors; 00077 CaterPillarConf conf; 00078 00079 public: 00080 DefaultCaterPillar ( const OdeHandle& odeHandle, const OsgHandle& osgHandle, 00081 const CaterPillarConf& conf, const std::string& name, const std::string& revision); 00082 00083 static CaterPillarConf getDefaultConf(){ 00084 CaterPillarConf conf; 00085 conf.segmNumber = 6; // number of snake elements 00086 conf.segmLength = 0.4; // length of one snake element 00087 conf.segmDia = 0.2; // diameter of a snake element 00088 conf.segmMass = 0.4; // mass of one snake element 00089 conf.motorPower = 1; // power of the servos 00090 conf.sensorFactor = 1; // scale for sensors 00091 conf.frictionGround = 1.0; // friction with ground 00092 conf.frictionJoint = 0.1; // friction within joint 00093 conf.jointLimit = M_PI/8; 00094 conf.firstJoint=1; 00095 return conf; 00096 } 00097 00098 virtual ~DefaultCaterPillar(); 00099 00100 00101 /** sets the pose of the vehicle 00102 @param pose desired 4x4 pose matrix 00103 */ 00104 virtual void place(const osg::Matrix& pose); 00105 00106 /// update all primitives and joints 00107 virtual void update(); 00108 00109 /** 00110 *Reads the actual motor commands from an array, 00111 *an sets all motors of the snake to this values. 00112 *It is an linear allocation. 00113 *@param motors pointer to the array, motor values are scaled to [-1,1] 00114 *@param motornumber length of the motor array 00115 **/ 00116 virtual void setMotors ( const motor* motors, int motornumber ) = 0; 00117 00118 /** 00119 *Writes the sensor values to an array in the memory. 00120 *@param sensors pointer to the array 00121 *@param sensornumber length of the sensor array 00122 *@return number of actually written sensors 00123 **/ 00124 virtual int getSensors ( sensor* sensors, int sensornumber ) = 0; 00125 00126 /** returns number of sensors 00127 */ 00128 virtual int getSensorNumber() = 0; 00129 00130 /** returns number of motors 00131 */ 00132 virtual int getMotorNumber() = 0; 00133 00134 /** returns a vector with the positions of all segments of the robot 00135 @param poslist vector of positions (of all robot segments) 00136 @return length of the list 00137 */ 00138 virtual int getSegmentsPosition(std::vector<Position> &poslist); 00139 00140 /******** CONFIGURABLE ***********/ 00141 virtual void notifyOnChange(const paramkey& key); 00142 00143 /** the main object of the robot, which is used for position and speed tracking */ 00144 virtual Primitive* getMainPrimitive() const { 00145 if(!objects.empty()){ 00146 // int half = objects.size()/2; 00147 // return (objects[half]); 00148 return (objects[0]); 00149 }else return 0; 00150 } 00151 protected: 00152 00153 /** creates vehicle at desired pose 00154 @param pose 4x4 pose matrix 00155 */ 00156 virtual void create(const osg::Matrix& pose); 00157 virtual void destroy(); 00158 }; 00159 00160 } 00161 00162 #endif