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-2011 LpzRobots development team                    *
00009  *    Georg Martius  <georg dot martius at web dot de>                     *
00010  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
00011  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
00012  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
00013  *                                                                         *
00014  *   This program is free software; you can redistribute it and/or modify  *
00015  *   it under the terms of the GNU General Public License as published by  *
00016  *   the Free Software Foundation; either version 2 of the License, or     *
00017  *   (at your option) any later version.                                   *
00018  *                                                                         *
00019  *   This program is distributed in the hope that it will be useful,       *
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00022  *   GNU General Public License for more details.                          *
00023  *                                                                         *
00024  *   You should have received a copy of the GNU General Public License     *
00025  *   along with this program; if not, write to the                         *
00026  *   Free Software Foundation, Inc.,                                       *
00027  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00028  *                                                                         *
00029  ***************************************************************************/
00030 #ifndef __SCHLANGE_H
00031 #define __SCHLANGE_H
00032 
00033 #include<vector>
00034 #include<assert.h>
00035 
00036 #include "primitive.h"
00037 #include "joint.h"
00038 #include "angularmotor.h"
00039 #include "pid.h"
00040 
00041 #include "oderobot.h"
00042 #include <selforg/configurable.h>
00043 
00044 namespace lpzrobots {
00045 
00046 typedef struct {
00047 public:
00048   int    segmNumber;  ///<  number of snake elements
00049   double segmLength;  ///< length of one snake element
00050   double segmDia;     ///<  diameter of a snake element
00051   double segmMass;    ///<  mass of one snake element
00052   double motorPower;  ///<  power of the motors / servos
00053   double sensorFactor;    ///<  scale for sensors
00054   double frictionJoint;   ///< friction within joint
00055   double frictionRatio;   ///< if != 1 then friction along the snake is the ratio fold 
00056   double jointLimit;      ///< maximal angle for the joints (M_PI/4 = 45 degree)
00057   bool   useServoVel;     ///< if true the new Servos are used (only for schlangeservo)
00058   double velocity;        ///< maximal velocity of servos
00059 
00060   bool useSpaces;        ///< if true the snake is divided into subspaces (performance)
00061 
00062   std::string headColor;
00063   std::string bodyColor;
00064 } SchlangeConf;
00065 
00066 
00067 /**
00068  * This is a class, which models a snake like robot. 
00069  * It consists of a number of equal elements, each linked 
00070  * by a joint
00071  **/
00072 class Schlange: public OdeRobot
00073 {
00074 protected:
00075   
00076   bool created;
00077   
00078   std::vector <AngularMotor*> frictionmotors;
00079   SchlangeConf conf;
00080 
00081 public:
00082   Schlange ( const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00083              const SchlangeConf& conf, const std::string& name, const std::string& revision);
00084 
00085   static SchlangeConf getDefaultConf(){
00086     SchlangeConf conf;
00087     conf.segmNumber = 10;    //  number of snake elements
00088     conf.segmLength = 0.8;   // length of one snake element
00089     conf.segmDia    = 0.2;   //  diameter of a snake element
00090     conf.segmMass   = 0.1;//0.4   //  mass of one snake element
00091     conf.motorPower = 1;    //  power of the servos
00092     conf.sensorFactor = 1;    //  scale for sensors
00093     conf.frictionJoint = 0.02; // friction within joint
00094     conf.frictionRatio = 1; // friction ratio
00095     conf.jointLimit =  M_PI/4;
00096     conf.useServoVel = false;
00097     conf.velocity    = 20;     // maximal velocity of servos
00098     conf.useSpaces   = true;
00099     conf.headColor   = "robot2";
00100     conf.bodyColor   = "robot1";
00101     return conf;
00102   }
00103 
00104   virtual ~Schlange();
00105         
00106  
00107   /** sets the pose of the vehicle
00108       @param pose desired 4x4 pose matrix
00109   */
00110   virtual void place(const osg::Matrix& pose);
00111 
00112   /// update all primitives and joints
00113   virtual void update();
00114 
00115   virtual void doInternalStuff(GlobalData& global);
00116         
00117   /**
00118    *Reads the actual motor commands from an array, 
00119    *an sets all motors of the snake to this values.
00120    *It is an linear allocation.
00121    *@param motors pointer to the array, motor values are scaled to [-1,1] 
00122    *@param motornumber length of the motor array
00123    **/
00124   virtual void setMotors ( const motor* motors, int motornumber ) = 0;
00125 
00126   /**
00127    *Writes the sensor values to an array in the memory.
00128    *@param sensors pointer to the array
00129    *@param sensornumber length of the sensor array
00130    *@return number of actually written sensors
00131    **/
00132   virtual int getSensors ( sensor* sensors, int sensornumber ) = 0;
00133         
00134   /** returns number of sensors
00135    */
00136   virtual int getSensorNumber() = 0;
00137 
00138   /** returns number of motors
00139    */
00140   virtual int getMotorNumber() = 0;
00141 
00142   /** returns a vector with the positions of all segments of the robot
00143       @param poslist vector of positions (of all robot segments) 
00144       @return length of the list
00145   */
00146   virtual int getSegmentsPosition(std::vector<Position> &poslist);
00147 
00148 
00149   /******** CONFIGURABLE ***********/
00150   virtual void notifyOnChange(const paramkey& key);
00151 
00152   /** the main object of the robot, which is used for position and speed tracking */
00153   virtual Primitive* getMainPrimitive() const {
00154     if(!objects.empty()){
00155       //      int half = objects.size()/2;
00156       //      return (objects[half]);
00157       return (objects[0]);
00158     }else return 0;
00159   }
00160 
00161   virtual std::vector<Primitive*> getAllPrimitives() const { return objects;}    
00162 
00163   /** sets a texture to the body of the snake
00164    * note: the head texture of the snake is set by
00165    * this method too!
00166    */
00167   virtual void setTexture(const std::string& filename);
00168   
00169   /** sets a texture to the head of the snake
00170    */
00171   virtual void setHeadTexture(const std::string& filename);
00172 
00173   /**
00174    * sets the color of the head element
00175    */
00176   virtual void setHeadColor(const Color& color);
00177 
00178 
00179 protected:
00180   std::vector<OdeHandle> spaces;
00181 
00182   /** creates vehicle at desired pose
00183       @param pose 4x4 pose matrix
00184   */
00185   virtual void create(const osg::Matrix& pose); 
00186   /**
00187      creates and initialised the segment with the given index
00188    */
00189   virtual Primitive* createSegment(int index, const OdeHandle& odeHandle); 
00190   virtual void destroy();
00191 };
00192 
00193 }
00194 
00195 #endif
Generated on Thu Jun 28 14:45:37 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3