Robot Simulator of the Robotics Group for Self-Organization of Control: gripper.h Source File

# gripper.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 __GRIPPER_H
    00025 #define __GRIPPER_H
    00026
    00027 #include "substance.h"
    00028 #include "primitive.h"
    00029 #include "color.h"
    00030 #include <selforg/configurable.h>
    00031 #include <selforg/stl_map.h>
    00032 #include <vector>
    00033
    00034 namespace lpzrobots {
    00035
    00036   /**
    00037      Configure object for Gripper
    00038    */
    00039   struct GripperConf {
    00040     std::string name; ///< name of gripper for configuration
    00041
    00042     double gripDuration; ///< time in seconds for how long the gripper grasps
    00043     /** releaseDuration time in seconds for how long the gripper
    00044         cannot grasp after release */
    00045     double releaseDuration;
    00046     Color  color;
    00047     double size; ///< diameter of the drawn sphere (if 0 nothing is drawn)
    00048     /** sphere is drawn at contact point (true)
    00049         or at center of attached primitive (false)
    00050     */
    00051     bool   drawAtContactPoint;
    00052     /** if true the last grasped object cannot be directly grasped again
    00053      */
    00054     bool   forbitLastPrimitive;
    00055     //     bool incOrExc; ///< include (false) or exclude (true) grippables;
    00056     bool   fixedOrBallJoint; ///< use fixed joint (true) or ball joint (false)
    00057   };
    00058
    00059   /**
    00060      A gripper can be attached to a primitive via its substance
    00061      and implements gripping (a fixed joint) on collision with
    00062      specified objects.
    00063      Usage: in your robot, create a Gripper object and attach
    00064       it to the primitive that grips (e.g. hand). Then you
    00065       need make the gripper(s) available to you simulation
    00066       in order to set call the addGrippables from there
    00067       (e.g. with otherrobot->getAllPrimitives()), see Skeleton.
    00068    */
    00069   class Gripper : public Configurable {
    00070   public:
    00071     /**
    00072        @param gripDuration time in seconds for how long the gripper grasps
    00073        @param releaseDuration time in seconds for how long the gripper cannot grasp
    00074         after release
    00075        @param size diameter of the drawn sphere (if 0 nothing is drawn)
    00076        @param drawAtContactPoint sphere is drawn at contact point (true)
    00077               or at center of attached primitive (false)
    00078     */
    00079     Gripper(const GripperConf& conf = getDefaultConf());
    00080
    00081     static GripperConf getDefaultConf(){
    00082       GripperConf conf;
    00083       conf.name                = "Gripper";
    00084       conf.gripDuration        = 10;
    00085       conf.releaseDuration     = 1;
    00086       conf.color               = Color(1,1,1);
    00087       conf.size                = 0.2;
    00088       conf.drawAtContactPoint  = true;
    00089       conf.forbitLastPrimitive = true;
    00090       conf.fixedOrBallJoint    = true;
    00091       return conf;
    00092     }
    00093
    00094     /// call this to attach the gripper to the given primitive
    00095     bool attach(Primitive* p);
    00096
    00097     virtual void addGrippables(const std::vector<Primitive*>& ps);
    00098     virtual void removeGrippables(const std::vector<Primitive*>& ps);
    00099     virtual void removeAllGrippables();
    00100
    00101     static int onCollision(dSurfaceParameters& params, GlobalData& globaldata,
    00102                            void *userdata,
    00103                            dContact* contacts, int numContacts,
    00104                            dGeomID o1, dGeomID o2,
    00105                            const Substance& s1, const Substance& s2);
    00106
    00107   private:
    00108     GripperConf conf;
    00109     bool   isAttached;
    00110
    00111     dGeomID last;
    00112     HashSet<dGeomID> grippables;
    00113     double gripStartTime;
    00114   };
    00115
    00116   typedef std::vector<Gripper*> GripperList;
    00117
    00118 }
    00119
    00120 #endif