sliderwheelie.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  *    frankguettler@gmx.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  *   $Log: sliderwheelie.h,v $
00024  *   Revision 1.16  2010/01/29 13:38:12  martius
00025  *   resolved conflict with show- and drawCenter
00026  *
00027  *   Revision 1.15  2010/01/27 10:19:14  martius
00028  *   showCenter variable added
00029  *
00030  *   Revision 1.14  2010/01/26 09:56:31  martius
00031  *   added dummy center also with velocity
00032  *
00033  *   Revision 1.13  2009/08/10 07:48:55  guettler
00034  *   removed typedef to avoid compiler warnings
00035  *
00036  *   Revision 1.12  2009/03/27 20:45:03  martius
00037  *   motor type can be selected
00038  *
00039  *   Revision 1.11  2009/03/26 18:01:59  martius
00040  *   angular motors possible
00041  *   sliders can be switched off -> defaultwheelie is obsolete
00042  *   better drawing of joints
00043  *   all motors are set (was a bug before)
00044  *
00045  *   Revision 1.10  2008/09/16 14:53:24  martius
00046  *   provide a virtual center of the robot as main primitive
00047  *
00048  *   Revision 1.9  2007/11/07 13:21:16  martius
00049  *   doInternal stuff changed signature
00050  *
00051  *   Revision 1.8  2007/01/26 12:05:04  martius
00052  *   servos combinied into OneAxisServo
00053  *
00054  *   Revision 1.7  2006/12/21 11:43:05  martius
00055  *   commenting style for doxygen //< -> ///<
00056  *   new sensors for spherical robots
00057  *
00058  *   Revision 1.6  2006/09/21 22:09:58  martius
00059  *   collision for mesh
00060  *
00061  *   Revision 1.5  2006/09/21 16:17:18  der
00062  *   *** empty log message ***
00063  *
00064  *   Revision 1.4  2006/09/21 08:15:15  martius
00065  *   with sliders inside a segment
00066  *
00067  *   Revision 1.3  2006/07/20 17:19:44  martius
00068  *   removed using namespace std from matrix.h
00069  *
00070  *   Revision 1.2  2006/07/14 12:23:42  martius
00071  *   selforg becomes HEAD
00072  *
00073  *   Revision 1.1.2.3  2006/06/25 21:57:20  martius
00074  *   abstractrobot is configureable
00075  *   name and revision
00076  *
00077  *   Revision 1.1.2.2  2006/06/20 07:18:29  robot3
00078  *   -added cvs log
00079  *   -changed some behaviour of wheelie
00080  *
00081  *                                                                         *
00082  ***************************************************************************/
00083 #ifndef __SLIDERWHEELIE_H
00084 #define __SLIDERWHEELIE_H
00085 
00086 #include<vector>
00087 #include<assert.h>
00088 
00089 #include "oderobot.h"
00090 #include"primitive.h"
00091 #include "joint.h"
00092 #include "angularmotor.h"
00093 
00094 #include "oneaxisservo.h"
00095 
00096 
00097 namespace lpzrobots {
00098 
00099   typedef struct {
00100   public:
00101     /* typedef */ enum MotorType {Servo, CenteredServo, AngularMotor };
00102 
00103     int    segmNumber;    ///<  number of snake elements
00104     double segmLength;    ///< length of one snake element
00105     double segmDia;       ///<  diameter of a snake element
00106     double segmMass;      ///<  mass of one snake element
00107     double motorPower;    ///<  power of the motors / servos
00108     double motorDamp;     ///<  damping of motors
00109     double powerRatio;    ///< ratio of motorpower for hinge vs. slider
00110     double sensorFactor;  ///<  scale for sensors
00111     double frictionGround;///< friction with ground
00112     double frictionJoint; ///< friction within joint
00113     double jointLimitIn;  ///< maximal angle for the joints to the inside (M_PI/2 = 90 degree)
00114     double jointLimitOut; ///< maximal angle for the joints to the outside
00115     double sliderLength;  ///< length of the slider in segmLength (0 for no sliders)
00116     MotorType motorType;  ///< whether to use servos or angular motors
00117     bool   showCenter;    ///< whether to show the virtual center
00118   } SliderWheelieConf;
00119   
00120 
00121   /**
00122    * This is a class, which models an annular robot. 
00123    * It consists of a number of equal elements, each linked 
00124    * by a joint powered by 1 servo
00125    **/
00126   class SliderWheelie : public OdeRobot
00127   {
00128   private:
00129     bool created;
00130       
00131     
00132     std::vector <Primitive*> objects;
00133     std::vector <Joint*> joints;
00134     std::vector <AngularMotor*> angularMotors;
00135     SliderWheelieConf conf;
00136 
00137     std::vector <HingeServo*> hingeServos;
00138     std::vector <SliderServo*> sliderServos;
00139 
00140     Primitive* center; // virtual center object (position updated on setMotors)
00141     DummyPrimitive* dummycenter; // virtual center object (here we can also update velocity)
00142   public:
00143     SliderWheelie(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00144                   const SliderWheelieConf& conf, const std::string& name, 
00145                   const std::string& revision = "");
00146     
00147     virtual ~SliderWheelie();
00148         
00149     static SliderWheelieConf getDefaultConf(){
00150       SliderWheelieConf conf;
00151       conf.segmNumber = 8;       //  number of snake elements
00152       conf.segmLength = 0.4;     // length of one snake element
00153       conf.segmDia    = 0.2;     //  diameter of a snake element
00154       conf.segmMass   = 0.4;     //  mass of one snake element
00155       conf.motorPower = 5;       //  power of the servos
00156       conf.motorDamp  = 0.01;    //  damping of servos
00157       conf.powerRatio = 2;       //  power of the servos
00158       conf.sensorFactor    = 1;   //  scale for sensors
00159       conf.frictionGround  = 0.8; // friction with ground
00160       conf.frictionJoint   = 0.0; // friction within joint
00161       conf.jointLimitIn    =  M_PI/3;
00162       conf.jointLimitOut   =  -1; // automatically set to 2*M_PI/segm_num
00163       conf.sliderLength    =  1;  
00164       conf.motorType       = SliderWheelieConf::CenteredServo; // use centered servos
00165       conf.showCenter      = false;
00166       return conf;
00167     }
00168 
00169     virtual void place(const osg::Matrix& pose);
00170     
00171     virtual void update();
00172 
00173     void doInternalStuff(GlobalData& global);
00174 
00175     bool collisionCallback(void *data, dGeomID o1, dGeomID o2);
00176 
00177     virtual void setMotors ( const motor* motors, int motornumber );
00178 
00179     virtual int getSensors ( sensor* sensors, int sensornumber );
00180         
00181     virtual int getSensorNumber() { assert(created); 
00182       return hingeServos.size()+angularMotors.size()+sliderServos.size(); }
00183 
00184     virtual int getMotorNumber(){ assert(created); 
00185       return hingeServos.size()+angularMotors.size()+sliderServos.size(); }
00186 
00187     virtual Primitive* getMainPrimitive() const {
00188       if(dummycenter) return dummycenter;
00189       else if(!objects.empty()){
00190         return (objects[0]);
00191       }else return 0;
00192     } 
00193     
00194     virtual paramlist getParamList() const;
00195     
00196     virtual paramval getParam(const paramkey& key) const;
00197     
00198     virtual bool setParam(const paramkey& key, paramval val);
00199 
00200   private:
00201     static void mycallback(void *data, dGeomID o1, dGeomID o2);
00202 
00203     virtual void create(const osg::Matrix& pose);
00204     virtual void destroy();
00205   };
00206 
00207 }
00208 
00209 #endif
Generated on Fri Nov 4 10:59:39 2011 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3