Robot Simulator of the Robotics Group for Self-Organization of Control: nimm2.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# nimm2.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  *   $Log: nimm2.h,v $
    00023  *   Revision 1.28  2007/11/07 13:21:16  martius
    00024  *   doInternal stuff changed signature
    00025  *
    00026  *   Revision 1.27  2007/09/27 16:01:28  der
    00027  *   added to nimm2 the box version
    00028  *
    00029  *   Revision 1.26  2007/05/07 21:12:19  robot3
    00030  *   added experimental force sensors
    00031  *
    00032  *   Revision 1.25  2007/03/06 10:11:04  fhesse
    00033  *   food removed
    00034  *
    00035  *   Revision 1.24  2007/03/05 10:49:32  fhesse
    00036  *   food at position x=0, y=0 added
    00037  *   motorcommand y set to zero when near food (controller doesn't know)
    00038  *   after eating_time food is empty and motorcommand executed again
    00039  *
    00040  *   Revision 1.23  2007/02/23 15:14:17  martius
    00041  *   *** empty log message ***
    00042  *
    00043  *   Revision 1.22  2006/12/21 11:43:05  martius
    00044  *   commenting style for doxygen //< -> ///<
    00045  *   new sensors for spherical robots
    00046  *
    00047  *   Revision 1.21  2006/12/11 18:24:36  martius
    00048  *   memory freed
    00049  *
    00050  *   Revision 1.20  2006/09/21 22:09:58  martius
    00051  *   collision for mesh
    00052  *
    00053  *   Revision 1.19  2006/07/20 17:19:44  martius
    00054  *   removed using namespace std from matrix.h
    00055  *
    00056  *   Revision 1.18  2006/07/14 12:23:40  martius
    00057  *   selforg becomes HEAD
    00058  *
    00059  *   Revision 1.17.4.10  2006/06/25 16:57:14  martius
    00060  *   abstractrobot is configureable
    00061  *   name and revision
    00062  *
    00063  *   Revision 1.17.4.9  2006/03/30 12:34:56  martius
    00064  *   documentation updated
    00065  *
    00066  *   Revision 1.17.4.8  2006/01/31 15:36:14  martius
    00067  *   irRange in config
    00068  *
    00069  *   Revision 1.17.4.7  2006/01/17 17:02:19  martius
    00070  *   faster, stronger, more friction
    00071  *
    00072  *   Revision 1.17.4.6  2005/12/15 17:04:08  martius
    00073  *   Primitives are not longer inherited from OSGPrimitive, moreover
    00074  *   they aggregate them.
    00075  *   Joint have better getter and setter
    00076  *
    00077  *   Revision 1.17.4.5  2005/12/14 15:37:09  martius
    00078  *   robots are working with osg
    00079  *
    00080  *   Revision 1.17.4.4  2005/12/13 18:11:39  martius
    00081  *   still trying to port robots
    00082  *
    00083  *   Revision 1.17.4.3  2005/11/16 11:26:52  martius
    00084  *   moved to selforg
    00085  *
    00086  *   Revision 1.17.4.2  2005/11/15 12:29:26  martius
    00087  *   new selforg structure and OdeAgent, OdeRobot ...
    00088  *
    00089  *   Revision 1.17.4.1  2005/11/14 17:37:17  martius
    00090  *   moved to selforg
    00091  *
    00092  *   Revision 1.17  2005/09/27 14:11:37  martius
    00093  *   changed to use of Nimm2Conf
    00094  *   IR sensors at front
    00095  *
    00096  *   Revision 1.16  2005/09/22 12:24:37  martius
    00097  *   removed global variables
    00098  *   OdeHandle and GlobalData are used instead
    00099  *   sensor prepared
    00100  *
    00101  *   Revision 1.15  2005/09/22 11:22:15  martius
    00102  *   removed global variables
    00103  *   OdeHandle and GlobalData are used instead
    00104  *   sensor prepared
    00105  *
    00106  *   Revision 1.14  2005/08/31 11:12:46  martius
    00107  *   removed unused vars
    00108  *
    00109  *   Revision 1.13  2005/08/03 11:43:03  fhesse
    00110  *   wheels moved out of center in cigarMode
    00111  *
    00112  *   Revision 1.12  2005/08/02 13:35:53  fhesse
    00113  *   cigarMode added
    00114  *
    00115  *   Revision 1.11  2005/08/02 13:17:10  fhesse
    00116  *   bumper added
    00117  *
    00118  *   Revision 1.10  2005/07/31 22:31:15  martius
    00119  *   textures
    00120  *
    00121  *   Revision 1.9  2005/07/29 15:12:51  martius
    00122  *   color modified
    00123  *   spherical wheels are standart but adjustable
    00124  *
    00125  *   Revision 1.8  2005/07/26 17:03:25  martius
    00126  *   resizeable
    00127  *   forces and collisions fixed
    00128  *
    00129  *   Revision 1.7  2005/07/18 14:47:41  martius
    00130  *   world, space, contactgroup are not pointers anymore.
    00131  *
    00132  *   Revision 1.6  2005/07/08 09:33:28  martius
    00133  *   speed and force as optional constuctor parameter
    00134  *
    00135  *   Revision 1.5  2005/07/07 09:27:40  martius
    00136  *   proper collision detection in car_space
    00137  *
    00138  *   Revision 1.4  2005/07/06 16:04:39  martius
    00139  *   added collisioncallback to robot to perform smoother collisions of wheels with ground
    00140  *
    00141  *   Revision 1.3  2005/06/23 13:31:15  fhesse
    00142  *   Vehicle changed to Nimm2
    00143  *
    00144  *                                                                 *
    00145  ***************************************************************************/
    00146 #ifndef __NIMM2_H
    00147 #define __NIMM2_H
    00148
    00149 #include "oderobot.h"
    00150 #include "raysensorbank.h"
    00151
    00152 #include "primitive.h"
    00153 #include "joint.h"
    00154 #include <selforg/inspectable.h>
    00155
    00156
    00157 namespace lpzrobots {
    00158
    00159 typedef struct Bumper{
    00160   Bumper() { trans = 0; bump = 0;}
    00161   Primitive* trans;
    00162   Primitive* bump;
    00163 } Bumper;
    00164
    00165 typedef struct {
    00166   double size;
    00167   double force;
    00168   double speed;
    00169   bool sphereWheels;
    00170   double wheelSize; ///< size of the wheels in body diameters
    00171   bool bumper;
    00172   bool cigarMode;
    00173   bool irFront;
    00174   bool irBack;
    00175   bool irSide;
    00176   double irRange;
    00177   bool singleMotor;
    00178   bool visForce;
    00179   bool boxMode;
    00180 } Nimm2Conf;
    00181
    00182 /** Robot that looks like a Nimm 2 Bonbon :-)
    00183     2 wheels and a cylinder like body
    00184 */
    00185 class Nimm2 : public OdeRobot /*, public Inspectable*/ {
    00186 public:
    00187
    00188   Nimm2(const OdeHandle& odehandle, const OsgHandle& osgHandle,
    00189         const Nimm2Conf& conf, const std::string& name);
    00190
    00191   static Nimm2Conf getDefaultConf(){
    00192     Nimm2Conf conf;
    00193     conf.size=1;
    00194     conf.force=5;
    00195     conf.speed=12;
    00196     conf.sphereWheels=true;
    00197     conf.wheelSize=1;
    00198     conf.bumper=false;
    00199     conf.cigarMode=false;
    00200     conf.irFront=false;
    00201     conf.irBack=false;
    00202     conf.irSide=false;
    00203     conf.irRange=3;
    00204     conf.singleMotor=false;
    00205           conf.visForce=false;
    00206     conf.boxMode=false;
    00207     return conf;
    00208   }
    00209
    00210   virtual ~Nimm2();
    00211
    00212   /**
    00213    * updates the OSG nodes of the vehicle
    00214    */
    00215   virtual void update();
    00216
    00217   /** sets the pose of the vehicle
    00218       @param pose desired 4x4 pose matrix
    00219   */
    00220   virtual void place(const osg::Matrix& pose);
    00221
    00222   /** returns actual sensorvalues
    00223       @param sensors sensors scaled to [-1,1]
    00224       @param sensornumber length of the sensor array
    00225       @return number of actually written sensors
    00226   */
    00227   virtual int getSensors(sensor* sensors, int sensornumber);
    00228
    00229   /** sets actual motorcommands
    00230       @param motors motors scaled to [-1,1]
    00231       @param motornumber length of the motor array
    00232   */
    00233   virtual void setMotors(const motor* motors, int motornumber);
    00234
    00235   /** returns number of sensors
    00236    */
    00237   virtual int getSensorNumber(){
    00238     return sensorno;
    00239   };
    00240
    00241   /** returns number of motors
    00242    */
    00243   virtual int getMotorNumber(){
    00244     return motorno;
    00245   };
    00246
    00247   /** returns a vector with the positions of all segments of the robot
    00248       @param poslist vector of positions (of all robot segments)
    00249       @return length of the list
    00250   */
    00251   virtual int getSegmentsPosition(std::vector<Position> &poslist);
    00252
    00253   virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2);
    00254
    00255     /** this function is called in each timestep. It should perform robot-internal checks,
    00256       like space-internal collision detection, sensor resets/update etc.
    00257       @param globalData structure that contains global data from the simulation environment
    00258    */
    00259   virtual void doInternalStuff(GlobalData& globalData);
    00260
    00261         virtual double& getSumForce() { return sumForce; }
    00262
    00263         virtual double& getContactPoints() { return contactPoints; }
    00264
    00265 protected:
    00266
    00267         double contactPoints;
    00268
    00269 /** the main object of the robot, which is used for position and speed tracking */
    00270   virtual Primitive* getMainPrimitive() const { return object[0]; }
    00271
    00272   /** creates vehicle at desired pose
    00273       @param pose 4x4 pose matrix
    00274   */
    00275   virtual void create(const osg::Matrix& pose);
    00276
    00277
    00278
    00279   /** destroys vehicle and space
    00280    */
    00281   virtual void destroy();
    00282   static void mycallback(void *data, dGeomID o1, dGeomID o2);
    00283
    00284         /**
    00285          * Inspectable interface
    00286          */
    00287         /*
    00288         virtual std::list<iparamkey> getInternalParamNames() const  { return std::list<iparamkey>(); }
    00289
    00290         virtual std::list<iparamval> getInternalParams() const { return std::list<iparamval>(); }*/
    00291         /*
    00292         virtual std::list<Inspectable::iparamkey> getInternalParamNames() const;
    00293
    00294         virtual std::list<Inspectable::iparamval> getInternalParams() const;
    00295         */
    00296
    00297   Nimm2Conf conf;
    00298
    00299   double length;  // chassis length
    00300   double width;  // chassis width
    00301   double height;   // chassis height
    00302   double radius;  // wheel radius
    00303   double wheelthickness; // thickness of the wheels
    00304   double cmass;    // chassis mass
    00305   double wmass;    // wheel mass
    00306   int sensorno;      //number of sensors
    00307   int motorno;       // number of motors
    00308
    00309   bool created;      // true if robot was created
    00310   double max_force;
    00311
    00312   Primitive* object[3];  // 1 cylinder, 2 wheels
    00313   double  wheeloffset; // offset from center when in cigarMode
    00314   int number_bumpers;  // number of bumpers (1 -> bumpers at one side, 2 -> bumpers at 2 sides)
    00315   Bumper bumper[2];
    00316   Hinge2Joint* joint[2]; // joints between cylinder and each wheel
    00317
    00318   RaySensorBank irSensorBank; // a collection of ir sensors
    00319
    00320         bool visForce; // decides if contact force is made visible in guilogger
    00321         double sumForce; // stores the contact force made by collisions with external objects
    00322
    00323 };
    00324
    00325 }
    00326
    00327 #endif