defaultWheelie.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 /* defaultWheelie.h                                                     */
00009 /* Abstract class for Wheelies                                          */
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: defaultWheelie.h,v $
00035  *   Revision 1.3  2006/07/20 17:19:44  martius
00036  *   removed using namespace std from matrix.h
00037  *
00038  *   Revision 1.2  2006/07/14 12:23:40  martius
00039  *   selforg becomes HEAD
00040  *
00041  *   Revision 1.1.2.3  2006/06/25 16:57:12  martius
00042  *   abstractrobot is configureable
00043  *   name and revision
00044  *
00045  *   Revision 1.1.2.2  2006/06/20 07:18:29  robot3
00046  *   -added cvs log
00047  *   -changed some behaviour of wheelie
00048  *
00049  *                                                                         *
00050  ***************************************************************************/
00051 #ifndef __DEFAULTWHEELIE_H
00052 #define __DEFAULTWHEELIE_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 } WheelieConf;
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 DefaultWheelie: public OdeRobot
00086 {
00087 protected:
00088   
00089   bool created;
00090 
00091   std::vector <Primitive*> objects;
00092   std::vector <Joint*> joints;
00093   std::vector <AngularMotor*> frictionmotors;
00094   WheelieConf conf;
00095 
00096 public:
00097   DefaultWheelie(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00098              const WheelieConf& conf, const std::string& name, const std::string& revision);
00099 
00100   static WheelieConf getDefaultConf(){
00101     WheelieConf conf;
00102     conf.segmNumber = 8;    //  number of snake elements
00103     conf.segmLength = 0.4;   // 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/8;
00111     return conf;
00112   }
00113 
00114   virtual ~DefaultWheelie();
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(std::vector<Position> &poslist);
00169 
00170 
00171   /** The list of all parameters with there value as allocated lists.
00172   */
00173   virtual paramlist getParamList() const;
00174 
00175   virtual paramval getParam(const paramkey& key) const;;
00176 
00177   virtual bool setParam(const paramkey& key, paramval val);
00178 
00179   /** the main object of the robot, which is used for position and speed tracking */
00180   virtual Primitive* getMainPrimitive() const {
00181     if(!objects.empty()){
00182       //      int half = objects.size()/2;
00183       //      return (objects[half]);
00184       return (objects[0]);
00185     }else return 0;
00186   }
00187 protected:
00188 
00189   /** creates vehicle at desired pose
00190       @param pose 4x4 pose matrix
00191   */
00192   virtual void create(const osg::Matrix& pose); 
00193   virtual void destroy();
00194 };
00195 
00196 }
00197 
00198 #endif

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