discus.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 __DISCUS_H
00026 #define __DISCUS_H
00027 
00028 #include <ode_robots/primitive.h>
00029 #include <ode_robots/joint.h>
00030 #include <ode_robots/oneaxisservo.h>
00031 #include <ode_robots/oderobot.h>
00032 #include <ode_robots/sensor.h>
00033 #include <ode_robots/raysensorbank.h>
00034 
00035 namespace lpzrobots {
00036 
00037   /// configuration object for the Discus robot.
00038 typedef struct {
00039 public:
00040   double diameter;
00041   double relativewidth;
00042   double stabdiameter;    ///< diameter of capsule relative to diameter of body
00043   unsigned int  numAxes;  ///< number of axes with moving masses
00044   double spheremass;
00045   double pendulardiameter; ///< automatically set
00046   double pendularmass;
00047   double motorpowerfactor; ///< power factor for servos w.r.t. pendularmass 
00048   double pendularrange;    ///< fraction of the diameter the pendular masses can move to one side
00049   double pendularrangeN;   ///< fraction of the diameter the normal pendular masses can move to one side
00050   bool motorsensor;        ///< motor values as sensors
00051   bool irAxis1;
00052   bool irAxis2;
00053   bool irAxis3;
00054   bool irRing;            ///< IR sensors in a ring in x,z plane (collides with irAxis1 and irAxis3)
00055   bool irSide;            ///< 4 IR senors to both side in y direction (collides with irAxis2)
00056   bool drawIRs;
00057   double irsensorscale; ///< range of the ir sensors in units of diameter
00058   double irCharacter;   ///< characteristics of sensor (\f[ x^c \f] where x is the range-distance)
00059   RaySensor* irSensorTempl;  ///< template for creation of the other ir sensors (if 0 then IRSensor(irCharacter))
00060   double motor_ir_before_sensors; ///< if true motor sensors and ir sensors are given before additional sensors
00061   double brake;         ///< if nonzero the robot brakes (deaccelerates actively/magically) (velocity dependend torque)
00062 
00063   /// function that deletes sensors
00064   void destroy(); 
00065   /// list of sensors that are mounted at the robot. (e.g.\ AxisOrientationSensor)
00066   std::list<Sensor*> sensors; 
00067   /// adds a sensor to the list of sensors
00068   void addSensor(Sensor* s) { sensors.push_back(s); }    
00069 } DiscusConf;
00070 
00071 /**
00072    A spherical robot with 3 internal masses, which can slide on their orthogonal axes.
00073    This robot was inspired by Julius Popp (http://sphericalrobots.com)
00074 */
00075 class Discus : public OdeRobot
00076 {
00077 public:
00078   /// enum for the objects of the robot
00079   /* typedef */ enum objects { Base, Stabilizer, Pendular1, Pendular2, Pendular3, Last } ;
00080 
00081 protected:
00082   static const int maxservono=3;
00083 
00084   Primitive* object[Last]; 
00085   SliderServo* servo[maxservono];
00086   SliderJoint* joint[maxservono];
00087   OSGPrimitive* axis[maxservono];
00088 
00089   DiscusConf conf;
00090   RaySensorBank irSensorBank; ///< a collection of ir sensors  
00091   double transparency;
00092   bool created;
00093 
00094 public:
00095 
00096   /**
00097    *constructor
00098    **/ 
00099   Discus ( const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00100                        const DiscusConf& conf, const std::string& name, double transparency=0.5 );
00101 
00102 protected:
00103   /**
00104    *constructor for children
00105    **/ 
00106   Discus ( const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00107                        const DiscusConf& conf, 
00108                        const std::string& name, const std::string& revision, double transparency);
00109   /// initialises some internal variables
00110   void init();
00111 public:  
00112   virtual ~Discus();
00113 
00114         
00115   /// default configuration
00116   static DiscusConf getDefaultConf(){
00117     DiscusConf c;
00118     c.diameter     = 1;
00119     c.relativewidth= 0.2;
00120     c.stabdiameter=0.7;
00121     c.numAxes = 3;
00122     c.spheremass   = 1;// 0.1
00123     c.pendularmass  = 0.75;
00124     c.pendularrange  = 0.20; // range of the slider from center in multiple of diameter [-range,range]
00125     c.pendularrangeN = 0.25;
00126     c.motorpowerfactor  = 100;
00127     c.motorsensor = true; 
00128     c.irAxis1=false;
00129     c.irAxis2=false;
00130     c.irAxis3=false;
00131     c.irRing=false;
00132     c.irSide=false;
00133     c.drawIRs=true;
00134     c.irsensorscale=1.5;
00135     c.irCharacter=1;  
00136     c.irSensorTempl=0;
00137     c.motor_ir_before_sensors=false;
00138     c.brake=0;
00139    return c;
00140   }
00141 
00142   virtual void update();
00143 
00144   virtual void place(const osg::Matrix& pose);
00145   
00146   virtual void doInternalStuff(GlobalData& globalData);
00147         
00148   virtual int getSensors ( sensor* sensors, int sensornumber );
00149         
00150   virtual void setMotors ( const motor* motors, int motornumber );
00151         
00152   virtual int getMotorNumber();
00153   
00154   virtual int getSensorNumber();
00155         
00156   virtual Primitive* getMainPrimitive() const { return object[Base]; }
00157 
00158 protected:
00159 
00160   virtual void create(const osg::Matrix& pose); 
00161   virtual void destroy(); 
00162 
00163 
00164 };
00165 
00166 }
00167 
00168 #endif
Generated on Thu Jun 28 14:45:36 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3