00001 /*************************************************************************** 00002 * Copyright (C) 2007 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: vierbeiner.h,v $ 00023 * Revision 1.7 2007/12/11 14:41:54 martius 00024 * *** empty log message *** 00025 * 00026 * Revision 1.6 2007/11/07 13:21:16 martius 00027 * doInternal stuff changed signature 00028 * 00029 * Revision 1.5 2007/07/04 13:16:17 martius 00030 * no friction parameter anymore 00031 * 00032 * Revision 1.4 2007/07/03 13:00:14 martius 00033 * new servo parameter, for current servo implementation 00034 * 00035 * Revision 1.3 2007/04/03 16:37:13 der 00036 * *** empty log message *** 00037 * 00038 * Revision 1.2 2007/03/16 10:57:26 martius 00039 * no elasticity, since substance support allows to make Playground soft 00040 * 00041 * Revision 1.1 2007/02/23 09:30:13 der 00042 * dog :-) 00043 * 00044 * Revision 1.3 2007/02/21 16:08:45 der 00045 * frontlegs no feet 00046 * ankles are powered 00047 * invisible pole (or box) in top 00048 * 00049 * Revision 1.2 2007/02/12 13:30:40 martius 00050 * dog looks allready nicer 00051 * 00052 * Revision 1.1 2007/02/02 08:58:15 martius 00053 * dog 00054 * 00055 * 00056 * * 00057 ***************************************************************************/ 00058 #ifndef __VIERBEINER_H 00059 #define __VIERBEINER_H 00060 00061 #include "oderobot.h" 00062 00063 namespace lpzrobots { 00064 00065 class Primitive; 00066 class Joint; 00067 class OneAxisServo; 00068 00069 typedef struct { 00070 public: 00071 double size; ///< scaling factor for robot (diameter of body) 00072 double legLength; ///< length of the legs in units of size 00073 int legNumber; ///< number of snake elements 00074 double mass; ///< chassis mass 00075 double relLegmass; ///< relative overall leg mass 00076 double hipPower; ///< maximal force for at hip joint motors 00077 double hipDamping; ///< damping of hio joint servos 00078 double hipJointLimit; ///< angle range for legs 00079 double kneePower; ///< spring strength in the knees 00080 double kneeJointLimit; ///< angle range for knees 00081 double kneeDamping; ///< damping in the knees 00082 double anklePower; ///< spring strength in the ankles 00083 double ankleDamping; ///< damping in the ankles 00084 } VierBeinerConf; 00085 00086 00087 /** robot that should look like a dog 00088 00089 sensors/motors: 0: neck, 1: tail 00090 2,3,4,5 : hip: rh, lh, rf, lf 00091 6,7,8,9 : knee: rh, lh, rf, lf 00092 10,11 : ankle rh, lh 00093 */ 00094 class VierBeiner : public OdeRobot { 00095 public: 00096 00097 /** 00098 * constructor of VierBeiner robot 00099 * @param odeHandle data structure for accessing ODE 00100 * @param osgHandle ata structure for accessing OSG 00101 * @param conf configuration object 00102 */ 00103 VierBeiner(const OdeHandle& odeHandle, const OsgHandle& osgHandle, const VierBeinerConf& conf, 00104 const std::string& name); 00105 00106 virtual ~VierBeiner(){}; 00107 00108 static VierBeinerConf getDefaultConf(){ 00109 VierBeinerConf c; 00110 c.size = 1; 00111 c.legNumber = 4; 00112 c.legLength = 0.6; 00113 c.mass = 1; 00114 c.relLegmass = 1; 00115 c.hipPower = 3; 00116 c.hipDamping = 0.1; 00117 c.kneePower = 2; 00118 c.kneeDamping = 0.05; 00119 c.anklePower = 0.5; 00120 c.ankleDamping = 0.02; 00121 c.hipJointLimit = M_PI/3; // +- 60 degree 00122 c.kneeJointLimit = M_PI/4; // +- 45 degree 00123 // c.elasticity = 10; 00124 return c; 00125 } 00126 00127 /** 00128 * updates the OSG nodes of the vehicle 00129 */ 00130 virtual void update(); 00131 00132 00133 /** sets the pose of the vehicle 00134 @param pose desired pose matrix 00135 */ 00136 virtual void place(const osg::Matrix& pose); 00137 00138 /** returns actual sensorvalues 00139 @param sensors sensors scaled to [-1,1] 00140 @param sensornumber length of the sensor array 00141 @return number of actually written sensors 00142 */ 00143 virtual int getSensors(sensor* sensors, int sensornumber); 00144 00145 /** sets actual motorcommands 00146 @param motors motors scaled to [-1,1] 00147 @param motornumber length of the motor array 00148 */ 00149 virtual void setMotors(const motor* motors, int motornumber); 00150 00151 /** returns number of sensors 00152 */ 00153 virtual int getSensorNumber(); 00154 00155 /** returns number of motors 00156 */ 00157 virtual int getMotorNumber(); 00158 /** checks for internal collisions and treats them. 00159 * In case of a treatment return true (collision will be ignored by other objects 00160 * and the default routine) else false (collision is passed to other objects and 00161 * (if not treated) to the default routine). 00162 */ 00163 virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2); 00164 00165 /** this function is called in each timestep. It should perform robot-internal checks, 00166 like space-internal collision detection, sensor resets/update etc. 00167 @param globalData structure that contains global data from the simulation environment 00168 */ 00169 virtual void doInternalStuff(GlobalData& globalData); 00170 00171 00172 /** The list of all parameters with there value as allocated lists. 00173 */ 00174 virtual paramlist getParamList() const; 00175 00176 virtual paramval getParam(const paramkey& key) const;; 00177 00178 virtual bool setParam(const paramkey& key, paramval val); 00179 00180 /** the main object of the robot, which is used for position and speed tracking */ 00181 virtual Primitive* getMainPrimitive() const { return objects[0]; } 00182 protected: 00183 00184 /** creates vehicle at desired pose 00185 @param pose 4x4 pose matrix 00186 */ 00187 virtual void create(const osg::Matrix& pose); 00188 00189 /** destroys vehicle and space 00190 */ 00191 virtual void destroy(); 00192 00193 VierBeinerConf conf; 00194 double legmass; // leg mass 00195 00196 bool created; // true if robot was created 00197 00198 00199 // some objects explicitly needed for ignored collision pairs 00200 Primitive *trunk, *headtrans, *bigboxtransform, *neck, *tail; 00201 std::vector<Primitive*> objects; // all the objects 00202 std::vector<Joint*> joints; // joints legs 00203 std::vector <OneAxisServo*> hipservos; // motors 00204 std::vector <OneAxisServo*> kneeservos; // motors 00205 std::vector <OneAxisServo*> ankleservos; // motors 00206 std::vector <OneAxisServo*> headtailservos; // motors 00207 00208 }; 00209 00210 } 00211 00212 #endif