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: sphererobot.h,v $ 00023 * Revision 1.15 2009/08/10 07:48:55 guettler 00024 * removed typedef to avoid compiler warnings 00025 * 00026 * Revision 1.14 2007/11/07 13:21:16 martius 00027 * doInternal stuff changed signature 00028 * 00029 * Revision 1.13 2007/01/26 12:05:05 martius 00030 * servos combinied into OneAxisServo 00031 * 00032 * Revision 1.12 2006/08/04 15:07:27 martius 00033 * documentation 00034 * 00035 * Revision 1.11 2006/07/20 17:19:45 martius 00036 * removed using namespace std from matrix.h 00037 * 00038 * Revision 1.10 2006/07/14 12:23:42 martius 00039 * selforg becomes HEAD 00040 * 00041 * Revision 1.9.4.7 2006/06/25 16:57:16 martius 00042 * abstractrobot is configureable 00043 * name and revision 00044 * 00045 * Revision 1.9.4.6 2006/03/30 12:34:57 martius 00046 * documentation updated 00047 * 00048 * Revision 1.9.4.5 2006/01/10 15:10:24 martius 00049 * fine tuning, fuer controllinterval 1 00050 * still not transparent 00051 * 00052 * Revision 1.9.4.4 2005/12/30 22:51:45 martius 00053 * moved to osg 00054 * 00055 * Revision 1.9.4.3 2005/11/16 11:26:53 martius 00056 * moved to selforg 00057 * 00058 * Revision 1.9.4.2 2005/11/15 12:29:27 martius 00059 * new selforg structure and OdeAgent, OdeRobot ... 00060 * 00061 * Revision 1.9.4.1 2005/11/14 17:37:18 martius 00062 * moved to selforg 00063 * 00064 * Revision 1.9 2005/11/09 13:24:42 martius 00065 * added GPL 00066 * 00067 * * 00068 ***************************************************************************/ 00069 00070 #ifndef __SPHEREROBOT_H 00071 #define __SPHEREROBOT_H 00072 00073 #include "oderobot.h" 00074 #include "oneaxisservo.h" 00075 00076 namespace lpzrobots { 00077 00078 class Primitive; 00079 class Joint; 00080 class SliderJoint; 00081 00082 typedef struct { 00083 public: 00084 double diameter; 00085 double spheremass; 00086 double pendulardiameter; 00087 double pendularmass; 00088 double slidermass; 00089 double sliderrange; 00090 00091 double force; // forcefactor of the servo power (1 is usual) 00092 double hingeRange; //the angle (in rad) of the hinges that connect pendular with poles 00093 } SphererobotConf; 00094 00095 00096 /** 00097 *This is a class, which models a snake like robot. It consists of a number of equal elements, each linked 00098 *by a joint. This class is based upon the class roboter by the same author. 00099 *@author Marcel Kretschmann 00100 *@version beta 00101 **/ 00102 class Sphererobot : public OdeRobot 00103 { 00104 public: 00105 /* typedef */ enum objects { Base, Pendular, Pole1Bot, Pole2Bot, Pole3Bot, 00106 Pole1Top , Pole2Top, Pole3Top, Last}; 00107 00108 protected: 00109 const static int sensorno = 9; 00110 00111 SphererobotConf conf; 00112 bool created; 00113 00114 public: 00115 SliderServo* servo[3]; 00116 Primitive* object[Last]; 00117 SliderJoint* slider[3]; 00118 Joint* joint[6]; 00119 00120 public: 00121 00122 Sphererobot ( const OdeHandle& odeHandle, const OsgHandle& osgHandle, 00123 const SphererobotConf& conf, const std::string& name ); 00124 00125 virtual ~Sphererobot(); 00126 00127 static SphererobotConf getDefaultConf(){ 00128 SphererobotConf c; 00129 c.diameter = 1; 00130 c.spheremass = 0.2; 00131 c.pendulardiameter = 0.2; 00132 c.pendularmass = 1.0; 00133 c.slidermass = 0.005; 00134 c.sliderrange = 0.1; // range of the slider from center in multiple of diameter [-range,range] 00135 c.force = 1; 00136 c.hingeRange = M_PI/180*30; 00137 return c; 00138 } 00139 00140 /// update the subcomponents 00141 virtual void update(); 00142 00143 /** sets the pose of the vehicle 00144 @param pose desired 4x4 pose matrix 00145 */ 00146 virtual void place(const osg::Matrix& pose); 00147 00148 /** 00149 *This is the collision handling function for snake robots. 00150 *This overwrides the function collisionCallback of the class robot. 00151 *@param data 00152 *@param o1 first geometrical object, which has taken part in the collision 00153 *@param o2 second geometrical object, which has taken part in the collision 00154 *@return true if the collision was threated by the robot, false if not 00155 **/ 00156 virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2); 00157 /** this function is called in each timestep. It should perform robot-internal checks, 00158 like space-internal collision detection, sensor resets/update etc. 00159 @param globalData structure that contains global data from the simulation environment 00160 */ 00161 virtual void doInternalStuff(GlobalData& globalData); 00162 00163 /** 00164 *Writes the sensor values to an array in the memory. 00165 *@param sensors pointer to the array 00166 *@param sensornumber length of the sensor array 00167 *@return number of actually written sensors 00168 **/ 00169 virtual int getSensors ( sensor* sensors, int sensornumber ); 00170 00171 /** 00172 *Reads the actual motor commands from an array, an sets all motors of the snake to this values. 00173 *It is an linear allocation. 00174 *@param motors pointer to the array, motor values are scaled to [-1,1] 00175 *@param motornumber length of the motor array 00176 **/ 00177 virtual void setMotors ( const motor* motors, int motornumber ); 00178 00179 /** 00180 *Returns the number of motors used by the snake. 00181 *@return number of motors 00182 **/ 00183 virtual int getMotorNumber(); 00184 00185 /** 00186 *Returns the number of sensors used by the robot. 00187 *@return number of sensors 00188 **/ 00189 virtual int getSensorNumber(); 00190 00191 /** returns a vector with the positions of all segments of the robot 00192 */ 00193 virtual int getSegmentsPosition(std::vector<Position> &poslist); 00194 00195 /** the main object of the robot, which is used for position and speed tracking */ 00196 virtual Primitive* getMainPrimitive() const { return object[Base]; } 00197 00198 protected: 00199 /** creates vehicle at desired pose 00200 @param pose 4x4 pose matrix 00201 */ 00202 virtual void create(const osg::Matrix& pose); 00203 virtual void destroy(); 00204 00205 00206 00207 }; 00208 00209 } 00210 00211 #endif