addsensors2robotadapter.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 __ADDSENSORS2ROBOTADAPTER__
00025 #define __ADDSENSORS2ROBOTADAPTER__
00026 
00027 #include "oderobot.h"
00028 #include "sensor.h"
00029 #include "motor.h"
00030 
00031 namespace lpzrobots {
00032 
00033   /** Robot adapter to add sensors and also motors to robots without the
00034       need to modify the robot itself. 
00035       Examples are Speed sensors, microphons and beepers and so forth            
00036       // TODO: add inspectable, make configurable work!
00037       // Maybe it is easier to add this into OdeRobot itself!
00038   */
00039   class AddSensors2RobotAdapter : public OdeRobot {
00040   public:
00041   
00042     /**
00043      * constructor of adapter
00044      * @param robot robot the wrap and plug sensors in
00045      * @param sensors list of sensors to add
00046      * @param motors list of motors to add
00047      */
00048     AddSensors2RobotAdapter( const OdeHandle& odeHandle, const OsgHandle& osgHandle, 
00049                              OdeRobot* robot, 
00050                              const std::list<Sensor*>& sensors = std::list<Sensor*>(),
00051                              const std::list<Motor*>& motors  = std::list<Motor*>(), 
00052                              bool sensors_before_rest = false);
00053 
00054     virtual ~AddSensors2RobotAdapter();
00055     
00056     /// adds a sensor to the robot. Must be called before placement of the robot, otherwise it has no affect
00057     virtual void addSensor(Sensor* sensor);
00058 
00059     /// adds a motor to the robot. Must be called before placement of the robot, otherwise it has no affect
00060     virtual void addMotor(Motor* motor);
00061 
00062     virtual void update();
00063 
00064     virtual void place(const osg::Matrix& pose);
00065 
00066     virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2){
00067       return robot->collisionCallback(data,o1,o2);
00068     }
00069 
00070     virtual void setColor(const Color& col) { 
00071       robot->setColor(col); 
00072     }
00073 
00074     virtual int getSensorNumber();
00075     virtual int getSensors(sensor* sensors_, int sensornumber);
00076 
00077     virtual int getMotorNumber();
00078     virtual void setMotors(const motor* motors_, int motornumber);
00079 
00080     virtual std::list<Sensor*> getAttachedSensors(){
00081       return sensors;
00082     }
00083     
00084     void sense(GlobalData& globalData);
00085     void doInternalStuff(GlobalData& globalData);
00086 
00087     virtual void notifyOnChange(const paramkey& key);
00088 
00089     virtual Primitive* getMainPrimitive() const { return robot->getMainPrimitive();}
00090     virtual std::vector<Primitive*> getAllPrimitives() const { 
00091       return robot->getAllPrimitives();
00092     }    
00093     virtual std::vector<Primitive*>& getAllPrimitives() { 
00094       return robot->getAllPrimitives();
00095     }    
00096       
00097   protected:
00098     OdeRobot* robot;
00099     std::list<Sensor*> sensors;
00100     std::list<Motor*> motors;
00101     bool sensors_before_rest;
00102     bool initialized;
00103     bool askedfornumber;
00104   };
00105 
00106 }
00107 
00108 #endif
Generated on Thu Jun 28 14:45:35 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3