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

# sliderwheelie.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 #ifndef __SLIDERWHEELIE_H
    00025 #define __SLIDERWHEELIE_H
    00026
    00027 #include<vector>
    00028 #include<assert.h>
    00029
    00030 #include "oderobot.h"
    00031 #include"primitive.h"
    00032 #include "joint.h"
    00033 #include "angularmotor.h"
    00034
    00035 #include "oneaxisservo.h"
    00036
    00037
    00038 namespace lpzrobots {
    00039
    00040   typedef struct {
    00041   public:
    00042     /* typedef */ enum MotorType {Servo, CenteredServo, AngularMotor };
    00043
    00044     int    segmNumber;    ///<  number of snake elements
    00045     double segmLength;    ///< length of one snake element
    00046     double segmDia;       ///<  diameter of a snake element
    00047     double segmMass;      ///<  mass of one snake element
    00048     double motorPower;    ///<  power of the motors / servos
    00049     double motorDamp;     ///<  damping of motors
    00050     double powerRatio;    ///< ratio of motorpower for hinge vs. slider
    00051     double sensorFactor;  ///<  scale for sensors
    00052     double frictionGround;///< friction with ground
    00053     double frictionJoint; ///< friction within joint
    00054     double jointLimitIn;  ///< maximal angle for the joints to the inside (M_PI/2 = 90 degree)
    00055     double jointLimitOut; ///< maximal angle for the joints to the outside
    00056     double sliderLength;  ///< length of the slider in segmLength (0 for no sliders)
    00057     MotorType motorType;  ///< whether to use servos or angular motors
    00058     bool   showCenter;    ///< whether to show the virtual center
    00059
    00060     std::string texture;  ///< texture for segments
    00061   } SliderWheelieConf;
    00062
    00063
    00064   /**
    00065    * This is a class, which models an annular robot.
    00066    * It consists of a number of equal elements, each linked
    00067    * by a joint powered by 1 servo
    00068    **/
    00069   class SliderWheelie : public OdeRobot
    00070   {
    00071   private:
    00072     bool created;
    00073
    00074  std::vector <AngularMotor*> angularMotors;
    00075     SliderWheelieConf conf;
    00076
    00077     std::vector <HingeServo*> hingeServos;
    00078     std::vector <SliderServo*> sliderServos;
    00079
    00080     Primitive* center; // virtual center object (position updated on setMotors)
    00081     DummyPrimitive* dummycenter; // virtual center object (here we can also update velocity)
    00082   public:
    00083     SliderWheelie(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00084                   const SliderWheelieConf& conf, const std::string& name,
    00085                   const std::string& revision = "");
    00086
    00087     virtual ~SliderWheelie();
    00088
    00089     static SliderWheelieConf getDefaultConf(){
    00090       SliderWheelieConf conf;
    00091       conf.segmNumber = 8;       //  number of snake elements
    00092       conf.segmLength = 0.4;     // length of one snake element
    00093       conf.segmDia    = 0.2;     //  diameter of a snake element
    00094       conf.segmMass   = 0.4;     //  mass of one snake element
    00095       conf.motorPower = 5;       //  power of the servos
    00096       conf.motorDamp  = 0.01;    //  damping of servos
    00097       conf.powerRatio = 2;       //  power of the servos
    00098       conf.sensorFactor    = 1;   //  scale for sensors
    00099       conf.frictionGround  = 0.8; // friction with ground
    00100       conf.frictionJoint   = 0.0; // friction within joint
    00101       conf.jointLimitIn    =  M_PI/3;
    00102       conf.jointLimitOut   =  -1; // automatically set to 2*M_PI/segm_num
    00103       conf.sliderLength    =  1;
    00104       conf.motorType       = SliderWheelieConf::CenteredServo; // use centered servos
    00105       conf.showCenter      = false;
    00106       conf.texture         = "";
    00107       return conf;
    00108     }
    00109
    00110     virtual void place(const osg::Matrix& pose);
    00111
    00112     virtual void update();
    00113
    00114     void doInternalStuff(GlobalData& global);
    00115
    00116     virtual void setMotors ( const motor* motors, int motornumber );
    00117
    00118     virtual int getSensors ( sensor* sensors, int sensornumber );
    00119
    00120     virtual int getSensorNumber() { assert(created);
    00121       return hingeServos.size()+angularMotors.size()+sliderServos.size(); }
    00122
    00123     virtual int getMotorNumber(){ assert(created);
    00124       return hingeServos.size()+angularMotors.size()+sliderServos.size(); }
    00125
    00126     virtual Primitive* getMainPrimitive() const {
    00127       if(dummycenter) return dummycenter;
    00128       else if(!objects.empty()){
    00129         return (objects[0]);
    00130       }else return 0;
    00131     }
    00132
    00133     virtual std::vector<Primitive*> getAllPrimitives() const { return objects;}
    00134
    00135     /******** CONFIGURABLE ***********/
    00136     virtual void notifyOnChange(const paramkey& key);
    00137
    00138   private:
    00139     static void mycallback(void *data, dGeomID o1, dGeomID o2);
    00140
    00141     virtual void create(const osg::Matrix& pose);
    00142     virtual void destroy();
    00143   };
    00144
    00145 }
    00146
    00147 #endif