hand.h

Go to the documentation of this file.
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: hand.h,v $
00023  *   Revision 1.9  2007/11/07 13:21:16  martius
00024  *   doInternal stuff changed signature
00025  *
00026  *   Revision 1.8  2007/09/21 17:05:05  fhesse
00027  *   IR sensors at fingertip added
00028  *
00029  *   Revision 1.7  2007/09/18 16:01:20  fhesse
00030  *   ir options in conf added
00031  *
00032  *   Revision 1.6  2007/09/18 11:03:02  fhesse
00033  *   conf.finger_winkel and conf.number_of_ir_sensors removed
00034  *   conf.initWithOpenHand and conf.fingerBendAngle added
00035  *   servo stuff commented out (todo: readd cleaned version)
00036  *
00037  *   Revision 1.5  2007/09/17 19:31:57  fhesse
00038  *   changes in setMotor() and getSensors() (tried to tidy up)
00039  *
00040  *   Revision 1.4  2007/09/17 13:11:20  fhesse
00041  *   conf option drawFingernails added
00042  *   box inside palm added to have collisions between palm and fingers
00043  *   fixing stops of angular motor at forearm-palm-joint
00044  *   thumb center element removed (now thumb has only 2 parts)
00045  *
00046  *   Revision 1.3  2007/09/14 19:18:36  fhesse
00047  *   pose added and cleaned up in create, HandConf adapted
00048  *
00049  *   Revision 1.2  2007/09/12 14:25:44  fhesse
00050  *   collisionCallback() emtied
00051  *   comments added
00052  *   started cleaning up
00053  *
00054  *   Revision 1.1  2007/09/12 11:23:11  fhesse
00055  *   moved from simulation/hand to here (to oderobots/robot)
00056  *
00057  *   Revision 1.4  2007/07/05 11:20:02  robot6
00058  *   hingeservo.h substituted by oneaxismotor.h (includes Hingeservo)
00059  *   "hand" added in Makefile
00060  *
00061  *   Revision 1.3  2007/05/07 09:07:21  robot3
00062  *   intended region for converting the code from nonreadable to human readable
00063  *
00064  *   Revision 1.2  2006/09/21 16:15:57  der
00065  *   *** empty log message ***
00066  *
00067  *   Revision 1.6.4.9  2006/06/25 16:57:13  martius
00068  *   abstractrobot is configureable
00069  *   name and revision
00070  *
00071  *   Revision 1.6.4.8  2006/03/30 12:34:56  martius
00072  *   documentation updated
00073  *
00074  *   Revision 1.6.4.7  2006/03/30 08:43:05  fhesse
00075  *   getTracePrimitive removed
00076  *
00077  *   Revision 1.6.4.6  2006/03/28 14:20:28  fhesse
00078  *   getTracePrimitive() added
00079  *
00080  *   Revision 1.6.4.5  2005/12/30 22:54:38  martius
00081  *   removed parentspace!
00082  *
00083  *   Revision 1.6.4.4  2005/12/21 17:35:09  martius
00084  *   moved to osg
00085  *
00086  *   Revision 1.6.4.3  2005/11/16 11:26:52  martius
00087  *   moved to selforg
00088  *
00089  *   Revision 1.6.4.2  2005/11/15 12:29:26  martius
00090  *   new selforg structure and OdeAgent, OdeRobot ...
00091  *
00092  *   Revision 1.6.4.1  2005/11/14 17:37:17  martius
00093  *   moved to selforg
00094  *
00095  *   Revision 1.6  2005/11/09 13:26:21  martius
00096  *   added factorSensor
00097  *
00098  *   Revision 1.5  2005/10/06 17:14:24  martius
00099  *   switched to stl lists
00100  *
00101  *   Revision 1.4  2005/09/22 12:24:37  martius
00102  *   removed global variables
00103  *   OdeHandle and GlobalData are used instead
00104  *   sensor prepared
00105  *
00106  *   Revision 1.3  2005/08/31 17:18:15  fhesse
00107  *   setTextures added, Mass is now sphere (not box anymore)
00108  *
00109  *   Revision 1.2  2005/07/26 17:04:21  martius
00110  *   lives in its own space now
00111  *
00112  *   Revision 1.1  2005/07/21 12:17:04  fhesse
00113  *   new hurling snake, todo: add collision space, clean up, comment
00114  *
00115  *         
00116  *                                                                 *
00117  ***************************************************************************/
00118 #ifndef __HAND_H
00119 #define __HAND_H
00120 
00121 #include "oderobot.h"
00122 #include <selforg/configurable.h>
00123 #include "primitive.h"
00124 #include "joint.h"
00125 #include "angularmotor.h"
00126 #include "oneaxisservo.h"
00127 
00128 #include "primitive.h"
00129 #include "osgforwarddecl.h"
00130 #include "axis.h"
00131 
00132 #include "irsensor.h"
00133 #include "raysensorbank.h"
00134 #include "raysensor.h"
00135 
00136 namespace lpzrobots {
00137 
00138   enum Motor_type
00139     {
00140       With_servo_motor,
00141       Without_servo_motor
00142     };
00143 
00144   enum IrSensor_Type{
00145     irDrawAll,
00146     irBack,
00147     irSide,
00148     irFront
00149   };
00150 
00151   // struct containing geom and body for each beam (= box, (cappped)cylinder, sphere)
00152   typedef struct {
00153     
00154     public:
00155     double velocity;
00156     double power;       // used when non-servo motor is used
00157     double servo_motor_Power;  // used when servo motor is used
00158     bool show_contacts;
00159     enum Motor_type set_typ_of_motor;
00160     double factorSensor;
00161     bool fix_palm_joint;
00162     bool one_finger_as_one_motor;
00163     bool draw_joints;
00164     bool showFingernails;
00165     double fingerJointBendAngle;
00166     bool initWithOpenHand; // init hand with open or half closed hand
00167 
00168     //---------------InfrarRedSensor--------------------------  
00169     double irRange;
00170     bool ir_sensor_used;
00171     bool irs_at_fingertip;
00172     bool irs_at_fingertop;
00173     bool irs_at_fingercenter;
00174     bool irs_at_fingerbottom;
00175     enum RaySensor::rayDrawMode ray_draw_mode; // for possible modes see sensors/raysensor.h
00176   } HandConf;
00177 
00178   enum GripMode{
00179     lateral,
00180     precision
00181   };
00182 
00183   /**
00184    * Artificial Hand 
00185    * 
00186    */
00187   class Hand : public OdeRobot{
00188   public:
00189 
00190     /**
00191      * constructor of hand
00192      * @param odeHandle data structure for accessing ODE
00193      * @param osgHandle ata structure for accessing OSG
00194      * @param conf configuration of robot
00195      */
00196     Hand(const OdeHandle& odeHandle, const OsgHandle& osgHandle, const HandConf& conf, const std::string& name);
00197 
00198     static HandConf getDefaultConf()
00199       {
00200         HandConf conf;
00201         conf.velocity = 0.2;
00202         conf.power = 5;
00203         conf.servo_motor_Power = 0.1;
00204         conf.show_contacts = true;
00205         conf.set_typ_of_motor = Without_servo_motor;
00206         conf.irRange = 2;
00207         conf.ir_sensor_used=true;
00208         conf.irs_at_fingerbottom=true;
00209         conf.irs_at_fingercenter=true;
00210         conf.irs_at_fingertop =true;
00211         conf.irs_at_fingertip =false;
00212         conf.ray_draw_mode=RaySensor::drawAll;
00213         conf.factorSensor=1.0;
00214         conf.fix_palm_joint=true;
00215         conf.one_finger_as_one_motor=false;
00216         conf.draw_joints=false;
00217         conf.showFingernails=true;
00218         conf.fingerJointBendAngle=M_PI/2;
00219         conf.initWithOpenHand=true; // init with open hand
00220         return conf;
00221       }
00222 
00223   
00224     /** 
00225      * update the subcomponents
00226      */
00227     virtual void update();
00228 
00229     /** 
00230      * sets the pose of the vehicle
00231      * @param pose desired 4x4 pose matrix
00232      */
00233     virtual void place(const osg::Matrix& pose);
00234 
00235     /** 
00236      * checks for internal collisions and treats them. 
00237      * In case of a treatment return true (collision will be ignored by other objects and the default routine)
00238      * else false (collision is passed to other objects and (if not treated) to the default routine).
00239      */
00240     virtual bool collisionCallback(void *data, dGeomID o1, dGeomID o2);
00241 
00242     /** this function is called in each timestep. It should perform robot-internal checks, 
00243         like space-internal collision detection, sensor resets/update etc.
00244         @param globalData structure that contains global data from the simulation environment
00245     */
00246     virtual void doInternalStuff(GlobalData& globalData);
00247   
00248 
00249     /** returns actual sensorvalues
00250         @param sensors sensors scaled to [-1,1] 
00251         @param sensornumber length of the sensor array
00252         @return number of actually written sensors
00253     */
00254     virtual int getSensors(sensor* sensors, int sensornumber);
00255 
00256     /** sets actual motorcommands
00257         @param motors motors scaled to [-1,1] 
00258         @param motornumber length of the motor array
00259     */
00260     virtual void setMotors(const motor* motors, int motornumber);
00261 
00262     /** returns number of sensors
00263      */
00264     virtual int getSensorNumber();
00265 
00266     /** returns number of motors
00267      */
00268     virtual int getMotorNumber();
00269 
00270     /** returns a vector with the positions of all segments of the robot
00271         @param poslist vector of positions (of all robot segments) 
00272         @return length of the list
00273     */
00274     //  virtual int getSegmentsPosition(vector<Position> &poslist);
00275   
00276     /** 
00277      * The list of all parameters with their value as allocated lists.       
00278      */
00279     virtual paramlist getParamList() const;
00280   
00281     /** 
00282      * Returns the value of the given parameter.       
00283      * @param key name of the parameter
00284      */
00285     virtual paramval getParam(const paramkey& key) const;
00286 
00287     /** 
00288      * Sets the values of the given parameter.       
00289      * @param key name of the parameter
00290      * @param val value to which the parameter will be set
00291      */
00292     virtual bool setParam(const paramkey& key, paramval val);
00293 
00294 
00295   protected:
00296     /** 
00297      * Returns the palm as the main object of the robot, 
00298      * which is used for position and speed tracking.
00299      */
00300     virtual Primitive* getMainPrimitive() const {
00301       if(!objects.empty()){
00302         return (objects[0]); // returns forearm for fixation
00303         //return (objects[1]); // returns palm
00304       }else return 0;
00305     }
00306 
00307 
00308   private:
00309 
00310     /** 
00311      * creates the hand at the desired pose
00312      * @param pose 4x4 pose matrix
00313      */
00314     virtual void create(const osg::Matrix& pose); 
00315 
00316     /** 
00317      * destroys robot and space
00318      */
00319     virtual void destroy();
00320 
00321     static void mycallback(void *data, dGeomID o1, dGeomID o2);
00322        
00323     /** true if robot was created */
00324     bool created;      
00325 
00326   protected:
00327 
00328     /** configuration of hand */
00329     HandConf conf;
00330 
00331     /** vector containing Primitives */
00332     std::vector <Primitive*> objects;
00333     /** vector containing OSGPrimitives */
00334     std::vector <OSGPrimitive*> osg_objects;
00335     /** vector containing Primitivesinfrared sensors */
00336     std::vector <IRSensor*> ir_sensors;
00337 
00338     /** true if contact joint is created  */
00339     bool contact_joint_created;
00340 
00341     //std::vector <HingeServo*> servos;
00342     //objects.reserve(number_beams);
00343 
00344     /** vector of the joints used in hand */
00345     std::vector <Joint*> joints;
00346 
00347     /** vector of the angular motors */
00348     std::vector <AngularMotor*> frictionmotors;
00349 
00350     /** vector of the used hinge servos*/
00351     std::vector <HingeServo*> servos;
00352 
00353     /**  a collection of ir sensors */
00354     RaySensorBank irSensorBank; 
00355 
00356 
00357     /** space containing the hand */
00358     dSpaceID hand_space;     
00359 
00360     //Beam beam[number_beams]; // array of elements (rectangle and cylinders)
00361     //dJointID joint[number_joints];  // array containg "normal" joints for connecting the elementsconf
00362     //dJointID fix_joint[number_fix_joints]; //joints for keeping index, middle, ring and little finger together to achieve mor prosthetic like motion
00363 
00364     /** motorjoint for actuating the forearm_palm joint (ball joint) */
00365     AngularMotor* palm_motor_joint;
00366 
00367     /** motorjoint for actuating the palm_thumb joint (ball joint) */
00368     AngularMotor* thumb_motor_joint;
00369 
00370     /** Hinge Joint between thumb_buttom and thumb_top*/
00371     HingeJoint* thumb_bt;
00372 
00373     /** Hinge Joint between buttom, center and top part of the index finger*/
00374     Joint *palm_index, *index_bc, *index_ct;
00375 
00376     /** Hinge Joint between buttom, center and top part of the middle finger*/
00377     Joint *palm_middle, *middle_bc, *middle_ct;
00378 
00379     /** Hinge Joint between buttom, center and top part of the ring finger*/
00380     Joint *palm_ring, *ring_bc, *ring_ct;
00381 
00382     /** Hinge Joint between buttom, center and top part of the little finger*/
00383     Joint *palm_little, *little_bc, *little_ct;
00384 
00385 
00386 
00387     /** for handling lateral and precision grip modes */
00388     GripMode gripmode; 
00389 
00390 
00391 
00392     /** initial position of robot */
00393     Position initial_pos;    
00394 
00395 
00396     Pos oldp;
00397 
00398     int sensorno;
00399     int motorno;
00400     int sensor_number;
00401     paramval factorForce;
00402     paramval frictionGround;
00403     
00404     double velocity;
00405 
00406  
00407   };
00408 
00409 }
00410 
00411 #endif
00412  

Generated on Fri Oct 30 16:29:01 2009 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.4.7