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.12  2006/08/04 15:07:27  martius
00024  *   documentation
00025  *
00026  *   Revision 1.11  2006/07/20 17:19:45  martius
00027  *   removed using namespace std from matrix.h
00028  *
00029  *   Revision 1.10  2006/07/14 12:23:42  martius
00030  *   selforg becomes HEAD
00031  *
00032  *   Revision 1.9.4.7  2006/06/25 16:57:16  martius
00033  *   abstractrobot is configureable
00034  *   name and revision
00035  *
00036  *   Revision 1.9.4.6  2006/03/30 12:34:57  martius
00037  *   documentation updated
00038  *
00039  *   Revision 1.9.4.5  2006/01/10 15:10:24  martius
00040  *   fine tuning, fuer controllinterval 1
00041  *   still not transparent
00042  *
00043  *   Revision 1.9.4.4  2005/12/30 22:51:45  martius
00044  *   moved to osg
00045  *
00046  *   Revision 1.9.4.3  2005/11/16 11:26:53  martius
00047  *   moved to selforg
00048  *
00049  *   Revision 1.9.4.2  2005/11/15 12:29:27  martius
00050  *   new selforg structure and OdeAgent, OdeRobot ...
00051  *
00052  *   Revision 1.9.4.1  2005/11/14 17:37:18  martius
00053  *   moved to selforg
00054  *
00055  *   Revision 1.9  2005/11/09 13:24:42  martius
00056  *   added GPL
00057  *
00058  *                                                                 *
00059  ***************************************************************************/
00060 
00061 #ifndef __SPHEREROBOT_H
00062 #define __SPHEREROBOT_H
00063 
00064 #include "oderobot.h"
00065 #include "sliderservo.h"
00066 
00067 namespace lpzrobots {
00068 
00069   class Primitive;
00070   class Joint;
00071   class SliderJoint;
00072   class SliderServo;  
00073 
00074   typedef struct {
00075   public:
00076     double diameter;
00077     double spheremass;
00078     double pendulardiameter;
00079     double pendularmass;
00080     double slidermass;
00081     double sliderrange;
00082   
00083     double force;      // forcefactor of the servo power (1 is usual)
00084     double hingeRange; //the angle (in rad) of the hinges that connect pendular with poles
00085   } SphererobotConf;
00086 
00087 
00088   /**
00089    *This is a class, which models a snake like robot. It consists of a number of equal elements, each linked 
00090    *by a joint. This class is based upon the class roboter by the same author.
00091    *@author Marcel Kretschmann
00092    *@version beta
00093    **/
00094   class Sphererobot : public OdeRobot
00095   {
00096   public:
00097     typedef enum objects { Base, Pendular, Pole1Bot, Pole2Bot, Pole3Bot, 
00098                            Pole1Top , Pole2Top, Pole3Top, Last};
00099 
00100   protected:
00101     const static int sensorno = 9;
00102   
00103     SphererobotConf conf;
00104     bool created;
00105 
00106   public:
00107     SliderServo* servo[3];
00108     Primitive* object[Last];
00109     SliderJoint* slider[3];
00110     Joint* joint[6];
00111 
00112   public:
00113 
00114     Sphererobot ( const OdeHandle& odeHandle, const OsgHandle& osgHandle, 
00115                   const SphererobotConf& conf, const std::string& name );
00116         
00117     virtual ~Sphererobot();
00118         
00119     static SphererobotConf getDefaultConf(){
00120       SphererobotConf c;
00121       c.diameter     = 1;
00122       c.spheremass   = 0.2;
00123       c.pendulardiameter = 0.2;
00124       c.pendularmass = 1.0;
00125       c.slidermass   = 0.005;
00126       c.sliderrange  = 0.1; // range of the slider from center in multiple of diameter [-range,range]
00127       c.force        = 1;
00128       c.hingeRange   = M_PI/180*30;
00129       return c;
00130     }
00131 
00132     /// update the subcomponents
00133     virtual void update();
00134         
00135     /** sets the pose of the vehicle
00136         @param pose desired 4x4 pose matrix
00137     */
00138     virtual void place(const osg::Matrix& pose);
00139   
00140     /**
00141      *This is the collision handling function for snake robots.
00142      *This overwrides the function collisionCallback of the class robot.
00143      *@param data
00144      *@param o1 first geometrical object, which has taken part in the collision
00145      *@param o2 second geometrical object, which has taken part in the collision
00146      *@return true if the collision was threated  by the robot, false if not
00147      **/
00148     virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2);
00149     /** this function is called in each timestep. It should perform robot-internal checks, 
00150         like space-internal collision detection, sensor resets/update etc.
00151         @param globalData structure that contains global data from the simulation environment
00152     */
00153     virtual void doInternalStuff(const GlobalData& globalData);
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 );
00162         
00163     /**
00164      *Reads the actual motor commands from an array, an sets all motors of the snake to this values.
00165      *It is an linear allocation.
00166      *@param motors pointer to the array, motor values are scaled to [-1,1] 
00167      *@param motornumber length of the motor array
00168      **/
00169     virtual void setMotors ( const motor* motors, int motornumber );
00170         
00171     /**
00172      *Returns the number of motors used by the snake.
00173      *@return number of motors
00174      **/
00175     virtual int getMotorNumber();
00176   
00177     /**
00178      *Returns the number of sensors used by the robot.
00179      *@return number of sensors
00180      **/
00181     virtual int getSensorNumber();
00182         
00183     /** returns a vector with the positions of all segments of the robot
00184     */
00185     virtual int getSegmentsPosition(std::vector<Position> &poslist);    
00186 
00187     /** the main object of the robot, which is used for position and speed tracking */
00188     virtual Primitive* getMainPrimitive() const { return object[Base]; }
00189 
00190   protected:
00191     /** creates vehicle at desired pose
00192         @param pose 4x4 pose matrix
00193     */
00194     virtual void create(const osg::Matrix& pose); 
00195     virtual void destroy(); 
00196     
00197 
00198 
00199   };
00200 
00201 }
00202 
00203 #endif

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