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