oderobot.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 __ODEROBOT_H
00025 #define __ODEROBOT_H
00026 
00027 #include <vector>
00028  
00029 #include <selforg/abstractrobot.h>
00030 #include <selforg/storeable.h>
00031 #include "odehandle.h"
00032 #include "osghandle.h"
00033 #include "globaldata.h"
00034 #include "color.h"
00035 #include "pos.h"
00036 #include "osgforwarddecl.h"
00037 
00038 namespace lpzrobots {
00039   
00040   class Primitive;
00041   class Joint;
00042 
00043   typedef std::vector<Primitive*> Primitives;
00044 
00045   /**
00046    * Abstract class  for ODE robots
00047    * 
00048    */
00049   class OdeRobot : public AbstractRobot, public Storeable {
00050   public:
00051 
00052     friend class OdeAgent;
00053 //    friend class AtomOdeAgent;
00054 
00055     /**
00056      * Constructor
00057      */
00058     OdeRobot(const OdeHandle& odeHandle, const OsgHandle& osgHandle, 
00059              const std::string& name, const std::string& revision);
00060 
00061     /// calls cleanup()
00062     virtual ~OdeRobot();
00063 
00064 
00065     /// update the OSG notes here
00066     virtual void update() = 0;
00067 
00068     /** sets the vehicle to position pos
00069         @param pos desired position of the robot
00070     */
00071     virtual void place(const Pos& pos);
00072 
00073     /** sets the pose of the vehicle
00074         @param pose desired 4x4 pose matrix
00075     */
00076     virtual void place(const osg::Matrix& pose) = 0;
00077 
00078     /** @deprecated This function will be removed in 0.8 
00079      *  Do not use it anymore, collision control is done automatically. 
00080      *  In case of a routine return true 
00081      *  (collision will be ignored by other objects and the default routine)
00082      *  else false (collision is passed to other objects and (if not treated) 
00083      *   to the default routine). 
00084      */
00085     virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2){ return false; };
00086 
00087     /** this function is called each controlstep before control. 
00088         This is the place the perform active sensing (e.g. Image processing)
00089         @param globalData structure that contains global data from the simulation environment
00090     */
00091     virtual void sense(GlobalData& globalData) {};
00092 
00093     /** this function is called in each simulation timestep (always after control). It
00094         should perform robot-internal checks and actions
00095         like resetting certain sensors or implement velocity dependend friction and the like.
00096         The attached Motors should act here.
00097         @param globalData structure that contains global data from the simulation environment
00098     */
00099     virtual void doInternalStuff(GlobalData& globalData) {};
00100 
00101     /** sets color of the robot
00102         @param col Color struct with desired Color
00103     */
00104     virtual void setColor(const Color& col);
00105 
00106     
00107     /*********** BEGIN TRACKABLE INTERFACE ****************/
00108     
00109     /** returns position of the object
00110         @return vector of position (x,y,z)
00111     */
00112     virtual Position getPosition() const;
00113     
00114     /** returns linear speed vector of the object
00115         @return vector  (vx,vy,vz)
00116     */
00117     virtual Position getSpeed() const;
00118     
00119     /** returns angular velocity vector of the object
00120         @return vector  (wx,wy,wz)
00121     */
00122     virtual Position getAngularSpeed() const;
00123     
00124     /** returns the orientation of the object
00125         @return 3x3 rotation matrix
00126     */
00127     virtual matrix::Matrix getOrientation() const;
00128     /*********** END TRACKABLE INTERFACE ****************/
00129     
00130     /// return the primitive of the robot that is used for tracking and camera following
00131     virtual Primitive* getMainPrimitive() const  { 
00132       if (!objects.empty()) return objects[0]; else return 0;
00133     };
00134 
00135     /// returns a list of all primitives of the robot (used to store and restore the robot)
00136     virtual Primitives getAllPrimitives() const { return objects; };
00137 
00138     virtual Primitives& getAllPrimitives() { return objects; };
00139     /// returns a list of all primitives of the robot (const version) (used to store and restore the robot)
00140 
00141     /* ********** STORABLE INTERFACE **************** */
00142     virtual bool store(FILE* f) const;
00143     
00144     virtual bool restore(FILE* f);  
00145     /* ********** END STORABLE INTERFACE ************ */
00146 
00147     /** relocates robot to new postion (keep current pose)
00148         such that lowest body part is at the given position 
00149         (the center of it, so the bounding box is not checked)
00150      */
00151     virtual void moveToPosition(Pos pos = Pos(0,0,0.5));
00152 
00153   protected:
00154     
00155     static bool isGeomInPrimitiveList(Primitive** ps, int len, dGeomID geom);
00156     static bool isGeomInPrimitiveList(std::list<Primitive*> ps, dGeomID geom);
00157 
00158     /// deletes all objects (primitives) and joints (is called automatically in destructor)
00159     virtual void cleanup();
00160 
00161   protected:
00162     /// list of objects (should be populated by subclasses)
00163     Primitives objects;
00164     /// list of joints (should be populated by subclasses)
00165     std::vector <Joint*> joints;
00166 
00167 
00168     OdeHandle odeHandle;
00169     OsgHandle osgHandle;
00170     dSpaceID parentspace;
00171   };
00172 
00173 }
00174 
00175 #endif
00176  
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