Robotsystem of the Robot Group Leipzig: schlange.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# 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.23  2007/11/07 13:21:16  martius
    00030  *   doInternal stuff changed signature
    00031  *
    00032  *   Revision 1.22  2007/07/03 13:05:23  martius
    00033  *   new servo constants
    00034  *
    00035  *   Revision 1.21  2007/01/26 12:05:04  martius
    00036  *   servos combinied into OneAxisServo
    00037  *
    00038  *   Revision 1.20  2006/12/21 11:43:05  martius
    00039  *   commenting style for doxygen //< -> ///<
    00040  *   new sensors for spherical robots
    00041  *
    00042  *   Revision 1.19  2006/09/20 12:56:16  martius
    00043  *   Snakes have CreateSegment
    00044  *
    00045  *   Revision 1.18  2006/07/20 17:19:44  martius
    00046  *   removed using namespace std from matrix.h
    00047  *
    00048  *   Revision 1.17  2006/07/14 13:52:01  der
    00049  *   setheadcolor
    00050  *
    00051  *   Revision 1.15.4.9  2006/06/25 16:57:15  martius
    00052  *   abstractrobot is configureable
    00053  *   name and revision
    00054  *
    00055  *   Revision 1.15.4.8  2006/05/19 09:04:38  der
    00056  *   -setTexture and setHeadTexture added
    00057  *   -uses now whitemetal texture
    00058  *
    00059  *   Revision 1.15.4.7  2006/03/30 12:34:56  martius
    00060  *   documentation updated
    00061  *
    00062  *   Revision 1.15.4.6  2006/03/29 15:08:54  martius
    00063  *   getMainPrimitive is public now
    00064  *
    00065  *   Revision 1.15.4.5  2006/02/23 18:05:04  martius
    00066  *   friction with angularmotor
    00067  *
    00068  *   Revision 1.15.4.4  2006/02/01 18:33:40  martius
    00069  *   use Axis type for Joint axis. very important, since otherwise Vec3 * pose is not the right direction vector anymore
    00070  *
    00071  *   Revision 1.15.4.3  2005/12/30 22:53:13  martius
    00072  *   removed parentspace!
    00073  *
    00074  *   Revision 1.15.4.2  2005/12/29 16:45:46  martius
    00075  *   does not inherit from Roboter
    00076  *   moved to osg
    00077  *
    00078  *
    00079  *                                                                 *
    00080  ***************************************************************************/
    00081 #ifndef __SCHLANGE_H
    00082 #define __SCHLANGE_H
    00083
    00084 #include<vector>
    00085 #include<assert.h>
    00086
    00087 #include "primitive.h"
    00088 #include "joint.h"
    00089 #include "angularmotor.h"
    00090 #include "pid.h"
    00091
    00092 #include "oderobot.h"
    00093 #include <selforg/configurable.h>
    00094
    00095 namespace lpzrobots {
    00096
    00097 typedef struct {
    00098 public:
    00099   int    segmNumber;  ///<  number of snake elements
    00100   double segmLength;  ///< length of one snake element
    00101   double segmDia;     ///<  diameter of a snake element
    00102   double segmMass;    ///<  mass of one snake element
    00103   double motorPower;  ///<  power of the motors / servos
    00104   double sensorFactor;    ///<  scale for sensors
    00105   double frictionGround;  ///< friction with ground
    00106   double frictionJoint;   ///< friction within joint
    00107   double jointLimit;      ///< maximal angle for the joints (M_PI/2 = 90 degree)
    00108 } SchlangeConf;
    00109
    00110
    00111 /**
    00112  * This is a class, which models a snake like robot.
    00113  * It consists of a number of equal elements, each linked
    00114  * by a joint
    00115  **/
    00116 class Schlange: public OdeRobot
    00117 {
    00118 protected:
    00119
    00120   bool created;
    00121
    00122   std::vector <Primitive*> objects;
    00123   std::vector <Joint*> joints;
    00124   std::vector <AngularMotor*> frictionmotors;
    00125   SchlangeConf conf;
    00126
    00127 public:
    00128   Schlange ( const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00129              const SchlangeConf& conf, const std::string& name, const std::string& revision);
    00130
    00131   static SchlangeConf getDefaultConf(){
    00132     SchlangeConf conf;
    00133     conf.segmNumber = 10;    //  number of snake elements
    00134     conf.segmLength = 0.8;   // length of one snake element
    00135     conf.segmDia    = 0.2;   //  diameter of a snake element
    00136     conf.segmMass   = 0.1;//0.4   //  mass of one snake element
    00137     conf.motorPower = 1;    //  power of the servos
    00138     conf.sensorFactor = 1;    //  scale for sensors
    00139     conf.frictionGround = 1.0; // friction with ground
    00140     conf.frictionJoint = 0.02; // friction within joint
    00141     conf.jointLimit =  M_PI/4;
    00142     return conf;
    00143   }
    00144
    00145   virtual ~Schlange();
    00146
    00147
    00148   /** sets the pose of the vehicle
    00149       @param pose desired 4x4 pose matrix
    00150   */
    00151   virtual void place(const osg::Matrix& pose);
    00152
    00153   /// update all primitives and joints
    00154   virtual void update();
    00155
    00156   /**
    00157    *This is the collision handling function for snake robots.
    00158    *This overwrides the function collisionCallback of the class robot.
    00159    *@param data
    00160    *@param o1 first geometrical object, which has taken part in the collision
    00161    *@param o2 second geometrical object, which has taken part in the collision
    00162    *@return true if the collision was threated  by the robot, false if not
    00163    **/
    00164   virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2);
    00165
    00166   static void mycallback(void *data, dGeomID o1, dGeomID o2);
    00167
    00168   virtual void doInternalStuff(GlobalData& global);
    00169
    00170   /**
    00171    *Reads the actual motor commands from an array,
    00172    *an sets all motors of the snake to this values.
    00173    *It is an linear allocation.
    00174    *@param motors pointer to the array, motor values are scaled to [-1,1]
    00175    *@param motornumber length of the motor array
    00176    **/
    00177   virtual void setMotors ( const motor* motors, int motornumber ) = 0;
    00178
    00179   /**
    00180    *Writes the sensor values to an array in the memory.
    00181    *@param sensors pointer to the array
    00182    *@param sensornumber length of the sensor array
    00183    *@return number of actually written sensors
    00184    **/
    00185   virtual int getSensors ( sensor* sensors, int sensornumber ) = 0;
    00186
    00187   /** returns number of sensors
    00188    */
    00189   virtual int getSensorNumber() = 0;
    00190
    00191   /** returns number of motors
    00192    */
    00193   virtual int getMotorNumber() = 0;
    00194
    00195   /** returns a vector with the positions of all segments of the robot
    00196       @param poslist vector of positions (of all robot segments)
    00197       @return length of the list
    00198   */
    00199   virtual int getSegmentsPosition(std::vector<Position> &poslist);
    00200
    00201
    00202   /** The list of all parameters with there value as allocated lists.
    00203   */
    00204   virtual paramlist getParamList() const;
    00205
    00206   virtual paramval getParam(const paramkey& key) const;;
    00207
    00208   virtual bool setParam(const paramkey& key, paramval val);
    00209
    00210   /** the main object of the robot, which is used for position and speed tracking */
    00211   virtual Primitive* getMainPrimitive() const {
    00212     if(!objects.empty()){
    00213       //      int half = objects.size()/2;
    00214       //      return (objects[half]);
    00215       return (objects[0]);
    00216     }else return 0;
    00217   }
    00218
    00219   /** sets a texture to the body of the snake
    00220    * note: the head texture of the snake is set by
    00221    * this method too!
    00222    */
    00223   virtual void setTexture(const std::string& filename);
    00224
    00225   /** sets a texture to the head of the snake
    00226    */
    00227   virtual void setHeadTexture(const std::string& filename);
    00228
    00229   /**
    00230    * sets the color of the head element
    00231    */
    00232   virtual void setHeadColor(const Color& color);
    00233
    00234
    00235 protected:
    00236
    00237   /** creates vehicle at desired pose
    00238       @param pose 4x4 pose matrix
    00239   */
    00240   virtual void create(const osg::Matrix& pose);
    00241   /**
    00242      creates and initialised the segment with the given index
    00243    */
    00244   virtual Primitive* createSegment(int index);
    00245   virtual void destroy();
    00246 };
    00247
    00248 }
    00249
    00250 #endif