defaultCaterpillar.h

Go to the documentation of this file.
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 by Robot Group Leipzig                             *
00014  *    martius@informatik.uni-leipzig.de                                    *
00015  *    fhesse@informatik.uni-leipzig.de                                     *
00016  *    der@informatik.uni-leipzig.de                                        *
00017  *    frankguettler@gmx.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  *   $Log: defaultCaterpillar.h,v $
00035  *   Revision 1.2  2006/07/14 12:23:39  martius
00036  *   selforg becomes HEAD
00037  *
00038  *   Revision 1.1.2.6  2006/06/25 16:57:12  martius
00039  *   abstractrobot is configureable
00040  *   name and revision
00041  *
00042  *   Revision 1.1.2.5  2006/05/29 20:28:43  robot5
00043  *   Annular placement of segments.
00044  *
00045  *   Revision 1.1.2.4  2006/05/22 14:19:11  robot5
00046  *   Added variable conf.firstJoint to represent the first slider type in the alternating sequence.
00047  *   Code cleaning.
00048  *
00049  *   Revision 1.1.2.3  2006/05/09 04:24:34  robot5
00050  *   *** empty log message ***
00051  *
00052  *   Revision 1.1.2.2  2006/04/11 13:27:48  robot3
00053  *   caterpillar is using now methods from schlangeservo2
00054  *
00055  *   Revision 1.1.2.1  2006/04/11 08:30:46  robot3
00056  *   first version
00057  *
00058  *
00059  *                                                                         *
00060  ***************************************************************************/
00061 #ifndef __DEFAULTCATERPILLAR_H
00062 #define __DEFAULTCATERPILLAR_H
00063 
00064 #include<vector>
00065 #include<assert.h>
00066 
00067 #include"primitive.h"
00068 #include "joint.h"
00069 #include "angularmotor.h"
00070 
00071 #include "oderobot.h"
00072 #include <selforg/configurable.h>
00073 
00074 namespace lpzrobots {
00075 
00076 typedef struct {
00077 public:
00078   int    segmNumber;  //<  number of snake elements
00079   double segmLength;  //< length of one snake element
00080   double segmDia;     //<  diameter of a snake element
00081   double segmMass;    //<  mass of one snake element
00082   double motorPower;  //<  power of the motors / servos
00083   double sensorFactor;    //<  scale for sensors
00084   double frictionGround;  //< friction with ground
00085   double frictionJoint;   //< friction within joint
00086   double jointLimit;      //< maximal angle for the joints (M_PI/2 = 90 degree)
00087   int firstJoint;       //< first joint type to use: 0=sliderJoint, 1=universalJoint
00088 } CaterPillarConf;
00089 
00090 
00091 /**
00092  * This is a class, which models a snake like robot. 
00093  * It consists of a number of equal elements, each linked 
00094  * by a joint
00095  **/
00096 class DefaultCaterPillar: public OdeRobot
00097 {
00098 protected:
00099   
00100   bool created;
00101 
00102   std::vector <Primitive*> objects;
00103   std::vector <Joint*> joints;
00104   std::vector <AngularMotor*> frictionmotors;
00105   CaterPillarConf conf;
00106 
00107 public:
00108   DefaultCaterPillar ( const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00109              const CaterPillarConf& conf, const std::string& name, const std::string& revision);
00110 
00111   static CaterPillarConf getDefaultConf(){
00112     CaterPillarConf conf;
00113     conf.segmNumber = 6;    //  number of snake elements
00114     conf.segmLength = 0.4;   // length of one snake element
00115     conf.segmDia    = 0.2;   //  diameter of a snake element
00116     conf.segmMass   = 0.4;   //  mass of one snake element
00117     conf.motorPower = 1;    //  power of the servos
00118     conf.sensorFactor = 1;    //  scale for sensors
00119     conf.frictionGround = 1.0; // friction with ground
00120     conf.frictionJoint = 0.1; // friction within joint
00121     conf.jointLimit =  M_PI/8;
00122     conf.firstJoint=1;
00123     return conf;
00124   }
00125 
00126   virtual ~DefaultCaterPillar();
00127         
00128  
00129   /** sets the pose of the vehicle
00130       @param pose desired 4x4 pose matrix
00131   */
00132   virtual void place(const osg::Matrix& pose);
00133 
00134   /// update all primitives and joints
00135   virtual void update();
00136 
00137   /**
00138    *This is the collision handling function for snake robots.
00139    *This overwrides the function collisionCallback of the class robot.
00140    *@param data
00141    *@param o1 first geometrical object, which has taken part in the collision
00142    *@param o2 second geometrical object, which has taken part in the collision
00143    *@return true if the collision was threated  by the robot, false if not
00144    **/
00145   virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2);   
00146 
00147   static void mycallback(void *data, dGeomID o1, dGeomID o2);
00148 
00149   virtual void doInternalStuff(const GlobalData& global);
00150         
00151   /**
00152    *Reads the actual motor commands from an array, 
00153    *an sets all motors of the snake to this values.
00154    *It is an linear allocation.
00155    *@param motors pointer to the array, motor values are scaled to [-1,1] 
00156    *@param motornumber length of the motor array
00157    **/
00158   virtual void setMotors ( const motor* motors, int motornumber ) = 0;
00159 
00160   /**
00161    *Writes the sensor values to an array in the memory.
00162    *@param sensors pointer to the array
00163    *@param sensornumber length of the sensor array
00164    *@return number of actually written sensors
00165    **/
00166   virtual int getSensors ( sensor* sensors, int sensornumber ) = 0;
00167         
00168   /** returns number of sensors
00169    */
00170   virtual int getSensorNumber() = 0;
00171 
00172   /** returns number of motors
00173    */
00174   virtual int getMotorNumber() = 0;
00175 
00176   /** returns a vector with the positions of all segments of the robot
00177       @param poslist vector of positions (of all robot segments) 
00178       @return length of the list
00179   */
00180   virtual int getSegmentsPosition(std::vector<Position> &poslist);
00181 
00182   /** The list of all parameters with there value as allocated lists.
00183   */
00184   virtual paramlist getParamList() const;
00185 
00186   virtual paramval getParam(const paramkey& key) const;;
00187 
00188   virtual bool setParam(const paramkey& key, paramval val);
00189 
00190   /** the main object of the robot, which is used for position and speed tracking */
00191   virtual Primitive* getMainPrimitive() const {
00192     if(!objects.empty()){
00193       //      int half = objects.size()/2;
00194       //      return (objects[half]);
00195       return (objects[0]);
00196     }else return 0;
00197   }
00198 protected:
00199 
00200   /** creates vehicle at desired pose
00201       @param pose 4x4 pose matrix
00202   */
00203   virtual void create(const osg::Matrix& pose); 
00204   virtual void destroy();
00205 };
00206 
00207 }
00208 
00209 #endif

Generated on Mon Aug 7 16:40:14 2006 for Robotsystem of the Robot Group Leipzig by  doxygen 1.4.7