Robot Simulator of the Robotics Group for Self-Organization of Control: sphererobot.h Source File

# sphererobot.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
    00003  *    Georg Martius  <georg dot martius at web dot de>                     *
    00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
    00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
    00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
    00007  *                                                                         *
    00008  *   This program is free software; you can redistribute it and/or modify  *
    00009  *   it under the terms of the GNU General Public License as published by  *
    00010  *   the Free Software Foundation; either version 2 of the License, or     *
    00011  *   (at your option) any later version.                                   *
    00012  *                                                                         *
    00013  *   This program is distributed in the hope that it will be useful,       *
    00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00016  *   GNU General Public License for more details.                          *
    00017  *                                                                         *
    00018  *   You should have received a copy of the GNU General Public License     *
    00019  *   along with this program; if not, write to the                         *
    00020  *   Free Software Foundation, Inc.,                                       *
    00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00022  *                                                                         *
    00023  ***************************************************************************/
    00024
    00025 #ifndef __SPHEREROBOT_H
    00026 #define __SPHEREROBOT_H
    00027
    00028 #include "oderobot.h"
    00029 #include "oneaxisservo.h"
    00030
    00031 namespace lpzrobots {
    00032
    00033   class Primitive;
    00034   class Joint;
    00035   class SliderJoint;
    00036
    00037   typedef struct {
    00038   public:
    00039     double diameter;
    00040     double spheremass;
    00041     double pendulardiameter;
    00042     double pendularmass;
    00043     double slidermass;
    00044     double sliderrange;
    00045
    00046     double force;      // forcefactor of the servo power (1 is usual)
    00047     double hingeRange; //the angle (in rad) of the hinges that connect pendular with poles
    00048   } SphererobotConf;
    00049
    00050
    00051   /**
    00052    *This is a class, which models a snake like robot. It consists of a number of equal elements, each linked
    00053    *by a joint. This class is based upon the class roboter by the same author.
    00054    *@author Marcel Kretschmann
    00055    *@version beta
    00056    **/
    00057   class Sphererobot : public OdeRobot
    00058   {
    00059   public:
    00060     /* typedef */ enum objects { Base, Pendular, Pole1Bot, Pole2Bot, Pole3Bot,
    00061                            Pole1Top , Pole2Top, Pole3Top, Last};
    00062
    00063   protected:
    00064     const static int sensorno = 9;
    00065
    00066     SphererobotConf conf;
    00067     bool created;
    00068
    00069   public:
    00070     SliderServo* servo[3];
    00071     Primitive* object[Last];
    00072     SliderJoint* slider[3];
    00073     Joint* joint[6];
    00074
    00075   public:
    00076
    00077     Sphererobot ( const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00078                   const SphererobotConf& conf, const std::string& name );
    00079
    00080     virtual ~Sphererobot();
    00081
    00082     static SphererobotConf getDefaultConf(){
    00083       SphererobotConf c;
    00084       c.diameter     = 1;
    00085       c.spheremass   = 0.2;
    00086       c.pendulardiameter = 0.2;
    00087       c.pendularmass = 1.0;
    00088       c.slidermass   = 0.005;
    00089       c.sliderrange  = 0.1; // range of the slider from center in multiple of diameter [-range,range]
    00090       c.force        = 1;
    00091       c.hingeRange   = M_PI/180*30;
    00092       return c;
    00093     }
    00094
    00095     /// update the subcomponents
    00096     virtual void update();
    00097
    00098     /** sets the pose of the vehicle
    00099         @param pose desired 4x4 pose matrix
    00100     */
    00101     virtual void place(const osg::Matrix& pose);
    00102
    00103     /** this function is called in each timestep. It should perform robot-internal checks,
    00104         like space-internal collision detection, sensor resets/update etc.
    00105         @param globalData structure that contains global data from the simulation environment
    00106     */
    00107     virtual void doInternalStuff(GlobalData& globalData);
    00108
    00109     /**
    00110      *Writes the sensor values to an array in the memory.
    00111      *@param sensors pointer to the array
    00112      *@param sensornumber length of the sensor array
    00113      *@return number of actually written sensors
    00114      **/
    00115     virtual int getSensors ( sensor* sensors, int sensornumber );
    00116
    00117     /**
    00118      *Reads the actual motor commands from an array, an sets all motors of the snake to this values.
    00119      *It is an linear allocation.
    00120      *@param motors pointer to the array, motor values are scaled to [-1,1]
    00121      *@param motornumber length of the motor array
    00122      **/
    00123     virtual void setMotors ( const motor* motors, int motornumber );
    00124
    00125     /**
    00126      *Returns the number of motors used by the snake.
    00127      *@return number of motors
    00128      **/
    00129     virtual int getMotorNumber();
    00130
    00131     /**
    00132      *Returns the number of sensors used by the robot.
    00133      *@return number of sensors
    00134      **/
    00135     virtual int getSensorNumber();
    00136
    00137     /** returns a vector with the positions of all segments of the robot
    00138     */
    00139     virtual int getSegmentsPosition(std::vector<Position> &poslist);
    00140
    00141     /** the main object of the robot, which is used for position and speed tracking */
    00142     virtual Primitive* getMainPrimitive() const { return object[Base]; }
    00143
    00144   protected:
    00145     /** creates vehicle at desired pose
    00146         @param pose 4x4 pose matrix
    00147     */
    00148     virtual void create(const osg::Matrix& pose);
    00149     virtual void destroy();
    00150
    00151
    00152
    00153   };
    00154
    00155 }
    00156
    00157 #endif