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