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 __VIERBEINER_H 00025 #define __VIERBEINER_H 00026 00027 #include <ode_robots/oderobot.h> 00028 00029 namespace lpzrobots { 00030 00031 class Primitive; 00032 class Joint; 00033 class OneAxisServo; 00034 00035 typedef struct { 00036 public: 00037 double size; ///< scaling factor for robot (diameter of body) 00038 double legLength; ///< length of the legs in units of size 00039 int legNumber; ///< number of snake elements 00040 double mass; ///< chassis mass 00041 double relLegmass; ///< relative overall leg mass 00042 double powerFactor; ///< global factor for power parameters 00043 double dampingFactor; ///< global factor for damping parameters 00044 double hipPower; ///< maximal force for at hip joint motors 00045 double hipDamping; ///< damping of hio joint servos 00046 double hipJointLimit; ///< angle range for legs 00047 double kneePower; ///< spring strength in the knees 00048 double kneeJointLimit; ///< angle range for knees 00049 double kneeDamping; ///< damping in the knees 00050 double anklePower; ///< spring strength in the ankles 00051 double ankleDamping; ///< damping in the ankles 00052 bool hippo; ///< "dog" looks like a hippopotamus 00053 bool drawstupidface; 00054 bool useBigBox; ///< use big box on back or not 00055 bool legBodyCollisions; ///< legs and body collide 00056 } VierBeinerConf; 00057 00058 00059 /** robot that should look like a dog 00060 00061 sensors/motors: 0: neck, 1: tail 00062 2,3,4,5 : hip: rh, lh, rf, lf 00063 6,7,8,9 : knee: rh, lh, rf, lf 00064 10,11 : ankle rh, lh 00065 */ 00066 class VierBeiner : public OdeRobot { 00067 public: 00068 00069 /** 00070 * constructor of VierBeiner robot 00071 * @param odeHandle data structure for accessing ODE 00072 * @param osgHandle ata structure for accessing OSG 00073 * @param conf configuration object 00074 */ 00075 VierBeiner(const OdeHandle& odeHandle, const OsgHandle& osgHandle, const VierBeinerConf& conf, 00076 const std::string& name); 00077 00078 virtual ~VierBeiner(){}; 00079 00080 static VierBeinerConf getDefaultConf(){ 00081 VierBeinerConf c; 00082 c.size = 1; 00083 c.legNumber = 4; 00084 c.legLength = 0.6; 00085 c.mass = 1; 00086 c.relLegmass = 1; 00087 c.powerFactor = 1; 00088 c.dampingFactor = 1; 00089 c.hipPower = 2; //3; 00090 c.hipDamping = 0.1; 00091 c.kneePower = 1; //2; 00092 c.kneeDamping = 0.05; 00093 c.anklePower = 0.1; //5; 00094 c.ankleDamping = 0.02; 00095 c.hipJointLimit = M_PI/3; // +- 60 degree 00096 c.kneeJointLimit = M_PI/4; // +- 45 degree 00097 // c.elasticity = 10; 00098 c.hippo = false; 00099 c.drawstupidface = 1; 00100 c.useBigBox = true; 00101 c.legBodyCollisions = false; 00102 return c; 00103 } 00104 00105 /** 00106 * updates the OSG nodes of the vehicle 00107 */ 00108 virtual void update(); 00109 00110 00111 /** sets the pose of the vehicle 00112 @param pose desired pose matrix 00113 */ 00114 virtual void place(const osg::Matrix& pose); 00115 00116 /** returns actual sensorvalues 00117 @param sensors sensors scaled to [-1,1] 00118 @param sensornumber length of the sensor array 00119 @return number of actually written sensors 00120 */ 00121 virtual int getSensors(sensor* sensors, int sensornumber); 00122 00123 /** sets actual motorcommands 00124 @param motors motors scaled to [-1,1] 00125 @param motornumber length of the motor array 00126 */ 00127 virtual void setMotors(const motor* motors, int motornumber); 00128 00129 /** returns number of sensors 00130 */ 00131 virtual int getSensorNumber(); 00132 00133 /** returns number of motors 00134 */ 00135 virtual int getMotorNumber(); 00136 00137 /** this function is called in each timestep. It should perform robot-internal checks, 00138 like space-internal collision detection, sensor resets/update etc. 00139 @param globalData structure that contains global data from the simulation environment 00140 */ 00141 virtual void doInternalStuff(GlobalData& globalData); 00142 00143 00144 /******** CONFIGURABLE ***********/ 00145 virtual void notifyOnChange(const paramkey& key); 00146 00147 /** the main object of the robot, which is used for position and speed tracking */ 00148 virtual Primitive* getMainPrimitive() const { return objects[0]; } 00149 protected: 00150 00151 /** creates vehicle at desired pose 00152 @param pose 4x4 pose matrix 00153 */ 00154 virtual void create(const osg::Matrix& pose); 00155 00156 /** destroys vehicle and space 00157 */ 00158 virtual void destroy(); 00159 00160 VierBeinerConf conf; 00161 double legmass; // leg mass 00162 00163 bool created; // true if robot was created 00164 00165 00166 // some objects explicitly needed for ignored collision pairs 00167 Primitive *trunk, *headtrans, *bigboxtransform, *neck, *tail; 00168 // these ones are only need if a face is to be drawn 00169 Primitive *eye_r_trans, *eye_l_trans, *ear_l_trans,*ear_r_trans, *mouth_trans; 00170 00171 00172 std::vector <OneAxisServo*> hipservos; // motors 00173 std::vector <OneAxisServo*> kneeservos; // motors 00174 std::vector <OneAxisServo*> ankleservos; // motors 00175 std::vector <OneAxisServo*> headtailservos; // motors 00176 00177 std::list <Primitive*> legparts; // lower leg parts (lower legs and feet) if collisions are ignored 00178 00179 }; 00180 00181 } 00182 00183 #endif