skeleton.h

Go to the documentation of this file.
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 __SKELETON_H
00025 #define __SKELETON_H
00026 
00027 #include <ode_robots/oderobot.h>
00028 #include <ode_robots/raysensorbank.h>
00029 #include <ode_robots/gripper.h>
00030 
00031 namespace lpzrobots {
00032 
00033   class Primitive; 
00034   class Joint;  
00035   class OneAxisServo;  
00036   class TwoAxisServo;  
00037   class AngularMotor;  
00038 
00039 
00040   typedef struct {
00041   public:
00042     double size;       ///< scaling factor for robot (height)
00043     double massfactor; ///< mass factor for all parts
00044 
00045     bool   useVelocityServos; ///< if true the more stable velocity controlling servos are used
00046 
00047     double relLegmass; ///< relative overall leg mass
00048     double relArmmass; ///< relative overall arm mass
00049     double relFeetmass; ///< relative overall feet mass
00050     double hipPower;   ///< maximal force for at hip joint motors
00051     double hipDamping; ///< damping of hip joint servos
00052     double hipVelocity; ///< velocity of hip joint servos
00053     double hipJointLimit; ///< angle range for legs
00054     double hip2Power;   ///< maximal force for at hip2 (sagital joint axis) joint motors
00055     double hip2Damping; ///< damping of hip2 joint servos
00056     double hip2JointLimit; ///< angle range for hip joint in lateral direction
00057     double neckPower;  ///< spring strength in the neck
00058     double neckDamping; ///< damping in the neck
00059     double neckVelocity; ///< velocity in the neck
00060     double neckJointLimit; ///< angle range for neck
00061     double kneePower;  ///< spring strength in the knees
00062     double kneeDamping; ///< damping in the knees
00063     double kneeVelocity; ///< velocity in the knees
00064     double kneeJointLimit; ///< angle range for knees
00065     double anklePower;  ///< spring strength in the ankles
00066     double ankleDamping; ///< damping in the ankles
00067     double ankleVelocity; ///< velocity in the ankles
00068     double ankleJointLimit; ///< angle range for ankles
00069     double armPower;   ///< maximal force for at arm (shoulder) joint motors
00070     double armDamping; ///< damping of arm ((shoulder)) joint servos
00071     double armVelocity; ///< velocity of arm ((shoulder)) joint servos
00072     double armJointLimit; ///< angle range of arm joint
00073     double elbowPower;   ///< maximal force for at elbow (shoulder) joint motors
00074     double elbowDamping; ///< damping of elbow ((shoulder)) joint servos
00075     double elbowVelocity; ///< velocity of elbow ((shoulder)) joint servos
00076     double elbowJointLimit; ///< angle range of elbow joint
00077     double pelvisPower;   ///< maximal force for at pelvis joint motor
00078     double pelvisDamping; ///< damping of pelvis joint servo
00079     double pelvisVelocity; ///< velocity of pelvis joint servo
00080     double pelvisJointLimit; ///< angle range of pelvis joint
00081     double backPower;   ///< maximal force for at back joint motor
00082     double backDamping; ///< damping of back joint servo
00083     double backVelocity; ///< velocity of back joint servo
00084     double backJointLimit; ///< angle range of back joint
00085 
00086     double powerFactor; ///< scale factor for maximal forces of the servos    
00087     double relForce;    ///< factor between arm force and rest 
00088     double dampingFactor; ///< scale factor for damping of the servos
00089     
00090     double jointLimitFactor; ///< factor between servo range (XXXJointLimit, see above) and physical joint limit
00091 
00092 
00093     bool onlyPrimaryFunctions; ///< true: only leg and arm are controlable, false: all joints
00094     bool onlyMainParameters; ///< true: only a few parameters are exported for configuration
00095 
00096     bool handsRotating; ///< hands are attached with a ball joint
00097     bool useGripper;        ///< hands have a gripper: use getGrippers and add grippables
00098     double gripDuration;    ///< time the gripper can grasp
00099     double releaseDuration; ///< time the gripper has to release before grasping again
00100 
00101     bool movableHead;  ///< if false then no neck movement 
00102 
00103     bool useBackJoint; ///< whether to use the joint in the back
00104 
00105     bool irSensors; ///< whether to use the irsensor eyes
00106 
00107     std::string headColor;   ///< special color of head (typically like body)
00108     std::string bodyColor;   ///< color of skin
00109     std::string trunkColor;  ///< color of upper body (pullover-color)
00110     std::string trouserColor;///< color of upper legs and hands (trousers-color)
00111 
00112 
00113     std::string headTexture; // texture of the head
00114     std::string bodyTexture; // texture of the body
00115     std::string trunkTexture; // texture of the trunk and thorax
00116         
00117 
00118   } SkeletonConf;
00119 
00120 
00121   /** should look like a humanoid
00122    */
00123   class Skeleton : public OdeRobot, public Inspectable{
00124   public:
00125 
00126     enum SkelParts {Hip,Trunk_comp, Belly, Thorax, Neck, 
00127                     Head_comp, 
00128                     Left_Shoulder, Left_Forearm, Left_Hand,
00129                     Right_Shoulder, Right_Forearm, Right_Hand, 
00130                     Left_Thigh, Left_Shin, Left_Foot,
00131                     Right_Thigh, Right_Shin, Right_Foot,
00132                     LastPart };
00133     
00134   
00135     /**
00136      * constructor of Skeleton robot
00137      * @param odeHandle data structure for accessing ODE
00138      * @param osgHandle ata structure for accessing OSG
00139      * @param conf configuration object
00140      */
00141     Skeleton(const OdeHandle& odeHandle, const OsgHandle& osgHandle, SkeletonConf& conf, 
00142                const std::string& name);
00143 
00144     virtual ~Skeleton(){ destroy(); };
00145 
00146     static SkeletonConf getDefaultConf(){
00147       SkeletonConf c;
00148       c.size        = 1;
00149       c.massfactor  = 1;
00150       c.relLegmass  = 1;        // unused
00151       c.relFeetmass = 1;        // .1; unused
00152       c.relArmmass  = 1;        // 0.3; unused
00153 
00154       c.useVelocityServos = false;
00155       c.powerFactor       = 1.0;
00156       c.relForce          = 1.0;      
00157       c.dampingFactor     = 1.0;
00158       c.jointLimitFactor  = 1.1; // factor between servo range and physical limit
00159 
00160       c.hipPower    = 20; 
00161       c.hipDamping  = 0.2;
00162       c.hipVelocity = 20;
00163 
00164       c.hip2Power   = 20;
00165       c.hip2Damping = 0.2;
00166 
00167       c.neckPower    = 2;
00168       c.neckDamping  = 0.1;
00169       c.neckVelocity = 20;
00170 
00171       c.kneePower    = 10;
00172       c.kneeDamping  = 0.1;
00173       c.kneeVelocity = 20;
00174 
00175       c.anklePower    = 3;
00176       c.ankleDamping  = 0.1;
00177       c.ankleVelocity = 20;
00178 
00179       c.armPower    = 8;
00180       c.armDamping  = 0.1;
00181       c.armVelocity = 20;
00182 
00183       c.elbowPower    = 4;
00184       c.elbowDamping  = 0.1;
00185       c.elbowVelocity = 20;
00186 
00187       c.pelvisPower    = 20;
00188       c.pelvisDamping  = 0.2;
00189       c.pelvisVelocity = 20;
00190 
00191       c.backPower    = 20;
00192       c.backDamping  = 0.1;
00193       c.backVelocity = 20;
00194 
00195       c.hipJointLimit  = 2.1;   //1.6;
00196       c.hip2JointLimit = .8;    //
00197 
00198       c.kneeJointLimit  = 2;    // 2.8; // + 300, -20 degree
00199       c.ankleJointLimit = M_PI/2; // - 90 + 45 degree
00200 
00201       c.armJointLimit   = M_PI/2; // +- 90 degree
00202       c.elbowJointLimit = 1.4;
00203 
00204       c.pelvisJointLimit = M_PI/10; // +- 18 degree
00205 
00206       c.neckJointLimit = M_PI/5;
00207       c.backJointLimit = M_PI/3;//4// // +- 60 degree (half of it to the back)
00208 
00209       c.onlyMainParameters   = true;
00210       c.onlyPrimaryFunctions = false;
00211       c.handsRotating        = false;
00212       c.movableHead          = false;
00213       c.useBackJoint         = true;
00214       c.irSensors            = false;
00215       c.useGripper           = false;
00216       c.gripDuration         = 30;
00217       c.releaseDuration      = 1;
00218 
00219       //      c.headTexture = "Images/really_white.rgb";
00220       c.headTexture     = "Images/dusty.rgb";
00221       c.headColor       = "robot4";  
00222       //  c.bodyTexture = "Images/whitemetal_farbig_small.rgb";
00223       c.bodyTexture     = "Images/dusty.rgb";
00224       c.bodyColor       = "robot4";
00225       c.trunkTexture    = "Images/dusty.rgb"; //"Images/whitemetal_farbig_small.rgb";
00226       c.trunkColor      = "robot1";
00227       c.trouserColor    = "robot2";
00228       return c;
00229     }
00230 
00231     static SkeletonConf getDefaultConfVelServos(){
00232       SkeletonConf c = getDefaultConf();
00233 
00234       c.useVelocityServos = true;
00235 
00236       c.hipDamping    = 0.01;
00237       c.hip2Damping   = 0.01;
00238       c.neckDamping   = 0.01;
00239       c.kneeDamping   = 0.01;
00240       c.ankleDamping  = 0.01;
00241       c.armDamping    = 0.01;
00242       c.elbowDamping  = 0.01;
00243       c.pelvisDamping = 0.01;
00244       c.backDamping   = 0.01;
00245 
00246       
00247       return c;
00248     }
00249 
00250 
00251     /**
00252      * updates the OSG nodes of the vehicle
00253      */
00254     virtual void update();
00255 
00256 
00257     /** sets the pose of the vehicle
00258         @param pose desired pose matrix
00259     */
00260     virtual void place(const osg::Matrix& pose);
00261 
00262     /** returns actual sensorvalues
00263         @param sensors sensors scaled to [-1,1] 
00264         @param sensornumber length of the sensor array
00265         @return number of actually written sensors
00266     */
00267     virtual int getSensors(sensor* sensors, int sensornumber);
00268 
00269     /** sets actual motorcommands
00270         @param motors motors scaled to [-1,1] 
00271         @param motornumber length of the motor array
00272     */
00273     virtual void setMotors(const motor* motors, int motornumber);
00274 
00275     /** returns number of sensors
00276      */
00277     virtual int getSensorNumber();
00278 
00279     /** returns number of motors
00280      */
00281     virtual int getMotorNumber();
00282 
00283     /** this function is called in each timestep. It should perform robot-internal checks, 
00284         like space-internal collision detection, sensor resets/update etc.
00285         @param globalData structure that contains global data from the simulation environment
00286     */
00287     virtual void doInternalStuff(GlobalData& globalData);
00288 
00289     /******** CONFIGURABLE ***********/
00290     virtual void notifyOnChange(const paramkey& key);
00291 
00292     /** the main object of the robot, which is used for position and speed tracking */
00293     virtual Primitive* getMainPrimitive() const { return objects[Thorax]; } // Trunk_comp
00294 
00295     /** returns the position of the head */
00296     virtual Position getHeadPosition();
00297 
00298     /** returns the position of the trunk */
00299     virtual Position getTrunkPosition();
00300 
00301     /// returns a the gripper list
00302     GripperList& getGrippers();
00303     
00304 
00305   protected:
00306 
00307     /** creates vehicle at desired pose
00308         @param pose 4x4 pose matrix
00309     */
00310     virtual void create(const osg::Matrix& pose); 
00311 
00312     /** destroys vehicle and space
00313      */
00314     virtual void destroy();
00315 
00316     SkeletonConf conf; 
00317 
00318     bool created;      // true if robot was created
00319 
00320     OdeHandle ignoreColSpace; // odehandle with space within collisions are ignored
00321 
00322     std::vector<TwoAxisServo*> hipservos; // motors
00323     std::vector<OneAxisServo*> kneeservos; // motors
00324     std::vector<OneAxisServo*> ankleservos; // motors
00325     std::vector<TwoAxisServo*> armservos; // motors
00326     std::vector<OneAxisServo*> arm1servos; // motors
00327 /*     std::vector<OneAxisServo*> headservos; // motors */
00328     std::vector<TwoAxisServo*> headservos; // motors
00329 
00330     OneAxisServo* pelvisservo; // between Hip and Trunk_comp
00331     std::vector<OneAxisServo*> backservos;   // between Trunk_comp and Thorax
00332     //TwoAxisServo* backservo;   // between Trunk_comp and Thorax
00333 
00334     std::vector<AngularMotor*> frictionmotors;
00335 
00336     RaySensorBank irSensorBank;
00337     GripperList grippers;
00338   };
00339 
00340 }
00341 
00342 #endif
Generated on Thu Jun 28 14:45:37 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3