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 *************************************************************************** 00023 * * 00024 * Spherical Robot inspired by Julius Popp. * 00025 * * 00026 * $Log: sphererobot3masses.h,v $ 00027 * Revision 1.4 2006/08/04 15:07:27 martius 00028 * documentation 00029 * 00030 * Revision 1.3 2006/07/20 17:19:45 martius 00031 * removed using namespace std from matrix.h 00032 * 00033 * Revision 1.2 2006/07/14 12:23:42 martius 00034 * selforg becomes HEAD 00035 * 00036 * Revision 1.1.2.4 2006/06/25 16:57:17 martius 00037 * abstractrobot is configureable 00038 * name and revision 00039 * 00040 * Revision 1.1.2.3 2006/03/30 12:34:57 martius 00041 * documentation updated 00042 * 00043 * Revision 1.1.2.2 2006/01/10 17:15:44 martius 00044 * removed wrong comment 00045 * 00046 * Revision 1.1.2.1 2006/01/10 17:15:16 martius 00047 * was sphererobotarms 00048 * moved to osg 00049 * 00050 * Revision 1.10.4.3 2005/11/16 11:26:53 martius 00051 * moved to selforg 00052 * 00053 * Revision 1.10.4.2 2005/11/15 12:29:27 martius 00054 * new selforg structure and OdeAgent, OdeRobot ... 00055 * 00056 * Revision 1.10.4.1 2005/11/14 17:37:18 martius 00057 * moved to selforg 00058 * 00059 * Revision 1.10 2005/11/09 13:27:07 martius 00060 * irsensorrange 00061 * 00062 * Revision 1.9 2005/11/07 17:04:56 martius 00063 * irsensorscale added 00064 * 00065 * Revision 1.8 2005/11/04 14:45:18 martius 00066 * GPL added 00067 * 00068 * * 00069 ***************************************************************************/ 00070 00071 #ifndef __SPHEREROBOT3MASSES_H 00072 #define __SPHEREROBOT3MASSES_H 00073 00074 #include "primitive.h" 00075 #include "joint.h" 00076 #include "sliderservo.h" 00077 #include "oderobot.h" 00078 #include "raysensorbank.h" 00079 00080 namespace lpzrobots { 00081 00082 /// configuration object for the Sphererobot3Masses robot. 00083 typedef struct { 00084 public: 00085 double diameter; 00086 double spheremass; 00087 double pendulardiameter; /// automatically set 00088 double pendularmass; 00089 double pendularrange; 00090 bool axisZsensor; 00091 bool axisXYZsensor; 00092 bool motorsensor; 00093 bool irAxis1; 00094 bool irAxis2; 00095 bool irAxis3; 00096 bool drawIRs; 00097 double irsensorscale; /// range of the ir sensors in units of diameter 00098 } Sphererobot3MassesConf; 00099 00100 /** 00101 A spherical robot with 3 internal masses, which can slide on their orthogonal axes. 00102 This robot was inspired by Julius Popp (http://sphericalrobots.com) 00103 */ 00104 class Sphererobot3Masses : public OdeRobot 00105 { 00106 public: 00107 /// enum for the objects of the robot 00108 typedef enum objects { Base, Pendular1, Pendular2, Pendular3, Last } ; 00109 00110 protected: 00111 static const int servono=3; 00112 00113 Primitive* object[Last]; 00114 SliderServo* servo[servono]; 00115 SliderJoint* joint[servono]; 00116 OSGPrimitive* axis[servono]; 00117 double transparency; 00118 bool created; 00119 00120 Sphererobot3MassesConf conf; 00121 RaySensorBank irSensorBank; /// a collection of ir sensors 00122 00123 public: 00124 00125 /** 00126 *constructor 00127 **/ 00128 Sphererobot3Masses ( const OdeHandle& odeHandle, const OsgHandle& osgHandle, 00129 const Sphererobot3MassesConf& conf, const std::string& name, double transparency=0.5 ); 00130 00131 virtual ~Sphererobot3Masses(); 00132 00133 /// default configuration 00134 static Sphererobot3MassesConf getDefaultConf(){ 00135 Sphererobot3MassesConf c; 00136 c.diameter = 1; 00137 c.spheremass = 0.1; 00138 c.pendularmass = 1.0; 00139 c.pendularrange = 0.25; // range of the slider from center in multiple of diameter [-range,range] 00140 c.axisZsensor = true; 00141 c.axisXYZsensor = false; 00142 c.motorsensor = false; 00143 c.irAxis1=false; 00144 c.irAxis2=false; 00145 c.irAxis3=false; 00146 c.drawIRs=true; 00147 c.irsensorscale=2; 00148 return c; 00149 } 00150 00151 /// update all primitives and joints 00152 virtual void update(); 00153 00154 /** sets the pose of the vehicle 00155 @param pose desired 4x4 pose matrix 00156 */ 00157 virtual void place(const osg::Matrix& pose); 00158 00159 /** 00160 *This is the collision handling function for the robot. 00161 *This overwrides the function collisionCallback of the class robot. 00162 *@param data (unused) 00163 *@param o1 first geometrical object, which has taken part in the collision 00164 *@param o2 second geometrical object, which has taken part in the collision 00165 *@return true if the collision was threated by the robot, false if not 00166 **/ 00167 virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2); 00168 00169 /** this function is called in each timestep. It should perform robot-internal checks, 00170 like space-internal collision detection, sensor resets/update etc. 00171 @param globalData structure that contains global data from the simulation environment 00172 */ 00173 virtual void doInternalStuff(const GlobalData& globalData); 00174 00175 /** 00176 *Writes the sensor values to the given an array. 00177 *@param sensors pointer to the array 00178 *@param sensornumber length of the sensor array 00179 *@return number of actually written sensors (should be sensornumber) 00180 **/ 00181 virtual int getSensors ( sensor* sensors, int sensornumber ); 00182 00183 /** 00184 *Reads the actual motor commands from an array, an sets all motors of the robot to this values. 00185 *@param motors pointer to the array, motor values are scaled to [-1,1] 00186 *@param motornumber length of the motor array 00187 **/ 00188 virtual void setMotors ( const motor* motors, int motornumber ); 00189 00190 virtual int getMotorNumber(); 00191 00192 virtual int getSensorNumber(); 00193 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 00200 virtual void create(const osg::Matrix& pose); 00201 virtual void destroy(); 00202 00203 00204 }; 00205 00206 } 00207 00208 #endif
1.4.7