sphererobot.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
00003  *    martius@informatik.uni-leipzig.de                                    *
00004  *    fhesse@informatik.uni-leipzig.de                                     *
00005  *    der@informatik.uni-leipzig.de                                        *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  *                                                                         *
00022  *   $Log: sphererobot.h,v $
00023  *   Revision 1.14  2007/11/07 13:21:16  martius
00024  *   doInternal stuff changed signature
00025  *
00026  *   Revision 1.13  2007/01/26 12:05:05  martius
00027  *   servos combinied into OneAxisServo
00028  *
00029  *   Revision 1.12  2006/08/04 15:07:27  martius
00030  *   documentation
00031  *
00032  *   Revision 1.11  2006/07/20 17:19:45  martius
00033  *   removed using namespace std from matrix.h
00034  *
00035  *   Revision 1.10  2006/07/14 12:23:42  martius
00036  *   selforg becomes HEAD
00037  *
00038  *   Revision 1.9.4.7  2006/06/25 16:57:16  martius
00039  *   abstractrobot is configureable
00040  *   name and revision
00041  *
00042  *   Revision 1.9.4.6  2006/03/30 12:34:57  martius
00043  *   documentation updated
00044  *
00045  *   Revision 1.9.4.5  2006/01/10 15:10:24  martius
00046  *   fine tuning, fuer controllinterval 1
00047  *   still not transparent
00048  *
00049  *   Revision 1.9.4.4  2005/12/30 22:51:45  martius
00050  *   moved to osg
00051  *
00052  *   Revision 1.9.4.3  2005/11/16 11:26:53  martius
00053  *   moved to selforg
00054  *
00055  *   Revision 1.9.4.2  2005/11/15 12:29:27  martius
00056  *   new selforg structure and OdeAgent, OdeRobot ...
00057  *
00058  *   Revision 1.9.4.1  2005/11/14 17:37:18  martius
00059  *   moved to selforg
00060  *
00061  *   Revision 1.9  2005/11/09 13:24:42  martius
00062  *   added GPL
00063  *
00064  *                                                                 *
00065  ***************************************************************************/
00066 
00067 #ifndef __SPHEREROBOT_H
00068 #define __SPHEREROBOT_H
00069 
00070 #include "oderobot.h"
00071 #include "oneaxisservo.h"
00072 
00073 namespace lpzrobots {
00074 
00075   class Primitive;
00076   class Joint;
00077   class SliderJoint;
00078 
00079   typedef struct {
00080   public:
00081     double diameter;
00082     double spheremass;
00083     double pendulardiameter;
00084     double pendularmass;
00085     double slidermass;
00086     double sliderrange;
00087   
00088     double force;      // forcefactor of the servo power (1 is usual)
00089     double hingeRange; //the angle (in rad) of the hinges that connect pendular with poles
00090   } SphererobotConf;
00091 
00092 
00093   /**
00094    *This is a class, which models a snake like robot. It consists of a number of equal elements, each linked 
00095    *by a joint. This class is based upon the class roboter by the same author.
00096    *@author Marcel Kretschmann
00097    *@version beta
00098    **/
00099   class Sphererobot : public OdeRobot
00100   {
00101   public:
00102     typedef enum objects { Base, Pendular, Pole1Bot, Pole2Bot, Pole3Bot, 
00103                            Pole1Top , Pole2Top, Pole3Top, Last};
00104 
00105   protected:
00106     const static int sensorno = 9;
00107   
00108     SphererobotConf conf;
00109     bool created;
00110 
00111   public:
00112     SliderServo* servo[3];
00113     Primitive* object[Last];
00114     SliderJoint* slider[3];
00115     Joint* joint[6];
00116 
00117   public:
00118 
00119     Sphererobot ( const OdeHandle& odeHandle, const OsgHandle& osgHandle, 
00120                   const SphererobotConf& conf, const std::string& name );
00121         
00122     virtual ~Sphererobot();
00123         
00124     static SphererobotConf getDefaultConf(){
00125       SphererobotConf c;
00126       c.diameter     = 1;
00127       c.spheremass   = 0.2;
00128       c.pendulardiameter = 0.2;
00129       c.pendularmass = 1.0;
00130       c.slidermass   = 0.005;
00131       c.sliderrange  = 0.1; // range of the slider from center in multiple of diameter [-range,range]
00132       c.force        = 1;
00133       c.hingeRange   = M_PI/180*30;
00134       return c;
00135     }
00136 
00137     /// update the subcomponents
00138     virtual void update();
00139         
00140     /** sets the pose of the vehicle
00141         @param pose desired 4x4 pose matrix
00142     */
00143     virtual void place(const osg::Matrix& pose);
00144   
00145     /**
00146      *This is the collision handling function for snake robots.
00147      *This overwrides the function collisionCallback of the class robot.
00148      *@param data
00149      *@param o1 first geometrical object, which has taken part in the collision
00150      *@param o2 second geometrical object, which has taken part in the collision
00151      *@return true if the collision was threated  by the robot, false if not
00152      **/
00153     virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2);
00154     /** this function is called in each timestep. It should perform robot-internal checks, 
00155         like space-internal collision detection, sensor resets/update etc.
00156         @param globalData structure that contains global data from the simulation environment
00157     */
00158     virtual void doInternalStuff(GlobalData& globalData);
00159         
00160     /**
00161      *Writes the sensor values to an array in the memory.
00162      *@param sensors pointer to the array
00163      *@param sensornumber length of the sensor array
00164      *@return number of actually written sensors
00165      **/
00166     virtual int getSensors ( sensor* sensors, int sensornumber );
00167         
00168     /**
00169      *Reads the actual motor commands from an array, an sets all motors of the snake to this values.
00170      *It is an linear allocation.
00171      *@param motors pointer to the array, motor values are scaled to [-1,1] 
00172      *@param motornumber length of the motor array
00173      **/
00174     virtual void setMotors ( const motor* motors, int motornumber );
00175         
00176     /**
00177      *Returns the number of motors used by the snake.
00178      *@return number of motors
00179      **/
00180     virtual int getMotorNumber();
00181   
00182     /**
00183      *Returns the number of sensors used by the robot.
00184      *@return number of sensors
00185      **/
00186     virtual int getSensorNumber();
00187         
00188     /** returns a vector with the positions of all segments of the robot
00189     */
00190     virtual int getSegmentsPosition(std::vector<Position> &poslist);    
00191 
00192     /** the main object of the robot, which is used for position and speed tracking */
00193     virtual Primitive* getMainPrimitive() const { return object[Base]; }
00194 
00195   protected:
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 
00206 }
00207 
00208 #endif

Generated on Tue Sep 16 22:00:22 2008 for Robotsystem of the Robot Group Leipzig by  doxygen 1.4.7