schlange.h

Go to the documentation of this file.
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.15.4.7  2006/03/30 12:34:56  martius
00030  *   documentation updated
00031  *
00032  *   Revision 1.15.4.6  2006/03/29 15:08:54  martius
00033  *   getMainPrimitive is public now
00034  *
00035  *   Revision 1.15.4.5  2006/02/23 18:05:04  martius
00036  *   friction with angularmotor
00037  *
00038  *   Revision 1.15.4.4  2006/02/01 18:33:40  martius
00039  *   use Axis type for Joint axis. very important, since otherwise Vec3 * pose is not the right direction vector anymore
00040  *
00041  *   Revision 1.15.4.3  2005/12/30 22:53:13  martius
00042  *   removed parentspace!
00043  *
00044  *   Revision 1.15.4.2  2005/12/29 16:45:46  martius
00045  *   does not inherit from Roboter
00046  *   moved to osg
00047  *
00048  *
00049  *                                                                 *
00050  ***************************************************************************/
00051 #ifndef __SCHLANGE_H
00052 #define __SCHLANGE_H
00053 
00054 #include<vector>
00055 #include<assert.h>
00056 
00057 #include"primitive.h"
00058 #include "joint.h"
00059 #include "angularmotor.h"
00060 
00061 #include "oderobot.h"
00062 #include <selforg/configurable.h>
00063 
00064 namespace lpzrobots {
00065 
00066 typedef struct {
00067 public:
00068   int    segmNumber;  //<  number of snake elements
00069   double segmLength;  //< length of one snake element
00070   double segmDia;     //<  diameter of a snake element
00071   double segmMass;    //<  mass of one snake element
00072   double motorPower;  //<  power of the motors / servos
00073   double sensorFactor;    //<  scale for sensors
00074   double frictionGround;  //< friction with ground
00075   double frictionJoint;   //< friction within joint
00076   double jointLimit;      //< maximal angle for the joints (M_PI/2 = 90 degree)
00077 } SchlangeConf;
00078 
00079 
00080 /**
00081  * This is a class, which models a snake like robot. 
00082  * It consists of a number of equal elements, each linked 
00083  * by a joint
00084  **/
00085 class Schlange: public OdeRobot, public Configurable
00086 {
00087 protected:
00088   
00089   bool created;
00090 
00091   vector <Primitive*> objects;
00092   vector <Joint*> joints;
00093   vector <AngularMotor*> frictionmotors;
00094   SchlangeConf conf;
00095 
00096 public:
00097   Schlange ( const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00098              const SchlangeConf& conf, const char* name);
00099 
00100   static SchlangeConf getDefaultConf(){
00101     SchlangeConf conf;
00102     conf.segmNumber = 10;    //  number of snake elements
00103     conf.segmLength = 0.8;   // length of one snake element
00104     conf.segmDia    = 0.2;   //  diameter of a snake element
00105     conf.segmMass   = 0.4;   //  mass of one snake element
00106     conf.motorPower = 1;    //  power of the servos
00107     conf.sensorFactor = 1;    //  scale for sensors
00108     conf.frictionGround = 1.0; // friction with ground
00109     conf.frictionJoint = 0.1; // friction within joint
00110     conf.jointLimit =  M_PI/4;
00111     return conf;
00112   }
00113 
00114   virtual ~Schlange();
00115         
00116  
00117   /** sets the pose of the vehicle
00118       @param pose desired 4x4 pose matrix
00119   */
00120   virtual void place(const osg::Matrix& pose);
00121 
00122   /// update all primitives and joints
00123   virtual void update();
00124 
00125   /**
00126    *This is the collision handling function for snake robots.
00127    *This overwrides the function collisionCallback of the class robot.
00128    *@param data
00129    *@param o1 first geometrical object, which has taken part in the collision
00130    *@param o2 second geometrical object, which has taken part in the collision
00131    *@return true if the collision was threated  by the robot, false if not
00132    **/
00133   virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2);   
00134 
00135   static void mycallback(void *data, dGeomID o1, dGeomID o2);
00136 
00137   virtual void doInternalStuff(const GlobalData& global);
00138         
00139   /**
00140    *Reads the actual motor commands from an array, 
00141    *an sets all motors of the snake to this values.
00142    *It is an linear allocation.
00143    *@param motors pointer to the array, motor values are scaled to [-1,1] 
00144    *@param motornumber length of the motor array
00145    **/
00146   virtual void setMotors ( const motor* motors, int motornumber ) = 0;
00147 
00148   /**
00149    *Writes the sensor values to an array in the memory.
00150    *@param sensors pointer to the array
00151    *@param sensornumber length of the sensor array
00152    *@return number of actually written sensors
00153    **/
00154   virtual int getSensors ( sensor* sensors, int sensornumber ) = 0;
00155         
00156   /** returns number of sensors
00157    */
00158   virtual int getSensorNumber() = 0;
00159 
00160   /** returns number of motors
00161    */
00162   virtual int getMotorNumber() = 0;
00163 
00164   /** returns a vector with the positions of all segments of the robot
00165       @param poslist vector of positions (of all robot segments) 
00166       @return length of the list
00167   */
00168   virtual int getSegmentsPosition(vector<Position> &poslist);
00169 
00170   /// returns the name of the object (with version number)
00171   virtual paramkey getName() const { return name; } 
00172 
00173   /** The list of all parameters with there value as allocated lists.
00174   */
00175   virtual paramlist getParamList() const;
00176 
00177   virtual paramval getParam(const paramkey& key) const;;
00178 
00179   virtual bool setParam(const paramkey& key, paramval val);
00180 
00181   /** the main object of the robot, which is used for position and speed tracking */
00182   virtual Primitive* getMainPrimitive() const {
00183     if(!objects.empty()){
00184       //      int half = objects.size()/2;
00185       //      return (objects[half]);
00186       return (objects[0]);
00187     }else return 0;
00188   }
00189 protected:
00190 
00191   /** creates vehicle at desired pose
00192       @param pose 4x4 pose matrix
00193   */
00194   virtual void create(const osg::Matrix& pose); 
00195   virtual void destroy();
00196 };
00197 
00198 }
00199 
00200 #endif

Generated on Tue Apr 4 19:05:04 2006 for Robotsystem from Robot Group Leipzig by  doxygen 1.4.5