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

Generated on Fri Oct 30 16:29:01 2009 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.4.7