addsensors2robotadapter.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  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  *                                                                         *
00022  *   This is an adapter class to add sensors to existing robots            *
00023  *    without modifiing them.                                              *
00024  *                                                                         *
00025  *   $Log: addsensors2robotadapter.h,v $
00026  *   Revision 1.6  2010/03/21 21:48:59  martius
00027  *   camera sensor bugfixing (reference to osghandle)
00028  *   twowheeled robot added (nimm2 with camera)
00029  *   sense function added to robots (before control): sensors (type Sensor) are checked here
00030  *   position and optical flow camera sensors added
00031  *
00032  *   Revision 1.5  2010/03/19 17:46:21  martius
00033  *   camerasensors added
00034  *   camera works great now. Near and far plane fixed by hand and optimal positioning
00035  *   many image processings added
00036  *
00037  *   Revision 1.4  2009/10/09 17:17:19  martius
00038  *   This does not work with configurables and inspectable robots
00039  *   comments added.
00040  *
00041  *   Revision 1.3  2008/05/07 16:45:51  martius
00042  *   code cosmetics and documentation
00043  *
00044  *   Revision 1.2  2007/11/07 13:20:25  martius
00045  *   also motors can be added
00046  *
00047  *   Revision 1.1  2007/08/24 11:48:56  martius
00048  *   initial
00049  *
00050  *                                                                 *
00051  ***************************************************************************/
00052 #ifndef __ADDSENSORS2ROBOTADAPTER__
00053 #define __ADDSENSORS2ROBOTADAPTER__
00054 
00055 #include "oderobot.h"
00056 #include "sensor.h"
00057 #include "motor.h"
00058 
00059 namespace lpzrobots {
00060 
00061   /** Robot adapter to add sensors and also motors to robots without the
00062       need to modify the robot itself. 
00063       Examples are Speed sensors, microphons and beepers and so forth            
00064       // TODO: add inspectable, make configurable work!
00065       // Maybe it is easier to add this into OdeRobot itself!
00066   */
00067   class AddSensors2RobotAdapter : public OdeRobot {
00068   public:
00069   
00070     /**
00071      * constructor of adapter
00072      * @param robot robot the wrap and plug sensors in
00073      * @param sensors list of sensors to add
00074      * @param motors list of motors to add
00075      */
00076     AddSensors2RobotAdapter( const OdeHandle& odeHandle, const OsgHandle& osgHandle, 
00077                              OdeRobot* robot, 
00078                              const std::list<Sensor*>& sensors = std::list<Sensor*>(),
00079                              const std::list<Motor*>& motors  = std::list<Motor*>(), 
00080                              bool sensors_before_rest = false);
00081 
00082     virtual ~AddSensors2RobotAdapter();
00083     
00084     /// adds a sensor to the robot. Must be called before placement of the robot, otherwise it has no affect
00085     virtual void addSensor(Sensor* sensor);
00086 
00087     /// adds a motor to the robot. Must be called before placement of the robot, otherwise it has no affect
00088     virtual void addMotor(Motor* motor);
00089 
00090     virtual void update();
00091 
00092     virtual void place(const osg::Matrix& pose);
00093 
00094     virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2){
00095       return robot->collisionCallback(data,o1,o2);
00096     }
00097 
00098     virtual int getSensorNumber();
00099     virtual int getSensors(sensor* sensors_, int sensornumber);
00100 
00101     virtual int getMotorNumber();
00102     virtual void setMotors(const motor* motors_, int motornumber);
00103 
00104     void sense(GlobalData& globalData);
00105     void doInternalStuff(GlobalData& globalData);
00106 
00107     virtual Primitive* getMainPrimitive() const { return robot->getMainPrimitive();}
00108       
00109   protected:
00110     OdeRobot* robot;
00111     std::list<Sensor*> sensors;
00112     std::list<Motor*> motors;
00113     bool sensors_before_rest;
00114     bool initialized;
00115   };
00116 
00117 }
00118 
00119 #endif
Generated on Fri Nov 4 10:59:38 2011 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3