Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gripper.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __GRIPPER_H
25 #define __GRIPPER_H
26 
27 #include "substance.h"
28 #include "primitive.h"
29 #include "color.h"
30 #include <selforg/configurable.h>
31 #include <selforg/stl_map.h>
32 #include <vector>
33 
34 namespace lpzrobots {
35 
36  /**
37  Configure object for Gripper
38  */
39  struct GripperConf {
40  std::string name; ///< name of gripper for configuration
41 
42  double gripDuration; ///< time in seconds for how long the gripper grasps
43  /** releaseDuration time in seconds for how long the gripper
44  cannot grasp after release */
47  double size; ///< diameter of the drawn sphere (if 0 nothing is drawn)
48  /** sphere is drawn at contact point (true)
49  or at center of attached primitive (false)
50  */
52  /** if true the last grasped object cannot be directly grasped again
53  */
55  // bool incOrExc; ///< include (false) or exclude (true) grippables;
56  bool fixedOrBallJoint; ///< use fixed joint (true) or ball joint (false)
57  };
58 
59  /**
60  A gripper can be attached to a primitive via its substance
61  and implements gripping (a fixed joint) on collision with
62  specified objects.
63  Usage: in your robot, create a Gripper object and attach
64  it to the primitive that grips (e.g. hand). Then you
65  need make the gripper(s) available to you simulation
66  in order to set call the addGrippables from there
67  (e.g. with otherrobot->getAllPrimitives()), see Skeleton.
68  */
69  class Gripper : public Configurable {
70  public:
71  /**
72  @param gripDuration time in seconds for how long the gripper grasps
73  @param releaseDuration time in seconds for how long the gripper cannot grasp
74  after release
75  @param size diameter of the drawn sphere (if 0 nothing is drawn)
76  @param drawAtContactPoint sphere is drawn at contact point (true)
77  or at center of attached primitive (false)
78  */
79  Gripper(const GripperConf& conf = getDefaultConf());
80 
82  GripperConf conf;
83  conf.name = "Gripper";
84  conf.gripDuration = 10;
85  conf.releaseDuration = 1;
86  conf.color = Color(1,1,1);
87  conf.size = 0.2;
88  conf.drawAtContactPoint = true;
89  conf.forbitLastPrimitive = true;
90  conf.fixedOrBallJoint = true;
91  return conf;
92  }
93 
94  /// call this to attach the gripper to the given primitive
95  bool attach(Primitive* p);
96 
97  virtual void addGrippables(const std::vector<Primitive*>& ps);
98  virtual void removeGrippables(const std::vector<Primitive*>& ps);
99  virtual void removeAllGrippables();
100 
101  static int onCollision(dSurfaceParameters& params, GlobalData& globaldata,
102  void *userdata,
103  dContact* contacts, int numContacts,
104  dGeomID o1, dGeomID o2,
105  const Substance& s1, const Substance& s2);
106 
107  private:
108  GripperConf conf;
109  bool isAttached;
110 
111  dGeomID last;
112  HashSet<dGeomID> grippables;
113  double gripStartTime;
114  };
115 
116  typedef std::vector<Gripper*> GripperList;
117 
118 }
119 
120 #endif
Color color
Definition: gripper.h:46
bool attach(Primitive *p)
call this to attach the gripper to the given primitive
Definition: gripper.cpp:48
double size
diameter of the drawn sphere (if 0 nothing is drawn)
Definition: gripper.h:47
Physical substance definition, used for collision detection/treatment What we need is mu...
Definition: substance.h:103
virtual void removeGrippables(const std::vector< Primitive * > &ps)
Definition: gripper.cpp:71
bool forbitLastPrimitive
if true the last grasped object cannot be directly grasped again
Definition: gripper.h:54
std::vector< Gripper * > GripperList
Definition: gripper.h:116
bool fixedOrBallJoint
use fixed joint (true) or ball joint (false)
Definition: gripper.h:56
virtual void addGrippables(const std::vector< Primitive * > &ps)
Definition: gripper.cpp:63
double releaseDuration
releaseDuration time in seconds for how long the gripper cannot grasp after release ...
Definition: gripper.h:45
Configure object for Gripper.
Definition: gripper.h:39
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
Data structure holding all essential global information.
Definition: globaldata.h:57
Definition: color.h:32
Abstact class for configurable objects.
Definition: configurable.h:81
std::string name
name of gripper for configuration
Definition: gripper.h:40
static GripperConf getDefaultConf()
Definition: gripper.h:81
Gripper(const GripperConf &conf=getDefaultConf())
Definition: gripper.cpp:37
A gripper can be attached to a primitive via its substance and implements gripping (a fixed joint) on...
Definition: gripper.h:69
static int onCollision(dSurfaceParameters &params, GlobalData &globaldata, void *userdata, dContact *contacts, int numContacts, dGeomID o1, dGeomID o2, const Substance &s1, const Substance &s2)
Definition: gripper.cpp:81
double gripDuration
time in seconds for how long the gripper grasps
Definition: gripper.h:42
bool drawAtContactPoint
sphere is drawn at contact point (true) or at center of attached primitive (false) ...
Definition: gripper.h:51
virtual void removeAllGrippables()
Definition: gripper.cpp:77