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.3 2008/05/07 16:45:51 martius 00027 * code cosmetics and documentation 00028 * 00029 * Revision 1.2 2007/11/07 13:20:25 martius 00030 * also motors can be added 00031 * 00032 * Revision 1.1 2007/08/24 11:48:56 martius 00033 * initial 00034 * 00035 * * 00036 ***************************************************************************/ 00037 #ifndef __ADDSENSORS2ROBOTADAPTER__ 00038 #define __ADDSENSORS2ROBOTADAPTER__ 00039 00040 #include "oderobot.h" 00041 #include "sensor.h" 00042 #include "motor.h" 00043 00044 namespace lpzrobots { 00045 00046 /** Robot adapter to add sensors and also motors to robots without the 00047 need to modify the robot itself. 00048 Examples are Speed sensors, microphons and beepers and so forth 00049 */ 00050 class AddSensors2RobotAdapter : public OdeRobot { 00051 public: 00052 00053 /** 00054 * constructor of adapter 00055 * @param robot robot the wrap and plug sensors in 00056 * @param sensors list of sensors to add 00057 * @param motors list of motors to add 00058 */ 00059 AddSensors2RobotAdapter( const OdeHandle& odeHandle, const OsgHandle& osgHandle, 00060 OdeRobot* robot, 00061 const std::list<Sensor*>& sensors = std::list<Sensor*>(), 00062 const std::list<Motor*>& motors = std::list<Motor*>(), 00063 bool sensors_before_rest = false); 00064 00065 virtual ~AddSensors2RobotAdapter(); 00066 00067 /// adds a sensor to the robot. Must be called before placement of the robot, otherwise it has no affect 00068 virtual void addSensor(Sensor* sensor); 00069 00070 /// adds a motor to the robot. Must be called before placement of the robot, otherwise it has no affect 00071 virtual void addMotor(Motor* motor); 00072 00073 virtual void update(){ robot->update(); } 00074 00075 virtual void place(const osg::Matrix& pose); 00076 00077 virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2){ 00078 return robot->collisionCallback(data,o1,o2); 00079 } 00080 00081 virtual int getSensorNumber(); 00082 virtual int getSensors(sensor* sensors_, int sensornumber); 00083 00084 virtual int getMotorNumber(); 00085 virtual void setMotors(const motor* motors_, int motornumber); 00086 00087 void doInternalStuff(GlobalData& globalData); 00088 00089 virtual Primitive* getMainPrimitive() const { return robot->getMainPrimitive();} 00090 00091 protected: 00092 OdeRobot* robot; 00093 std::list<Sensor*> sensors; 00094 std::list<Motor*> motors; 00095 bool sensors_before_rest; 00096 }; 00097 00098 } 00099 00100 #endif