rapid
A ROS robotics library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
gripper.h
Go to the documentation of this file.
1 // A class for opening and closing the grippers.
2 //
3 // Sample usage:
4 // rapid::manipulation::Gripper right_gripper(
5 // Gripper::RIGHT_GRIPPER);
6 // right_gripper.Open();
7 // right_gripper.Close();
8 //
9 // Notes:
10 // 1. The gripper does not work quite right in Gazebo
11 // 2. Return value is based on whether the gripper reached the target position.
12 // So, if the gripper is closing around an object, Close() will typically
13 // return false because the object stalls the gripper before it reaches
14 // the goal position.
15 
16 #ifndef _RAPID_MANIPULATION_GRIPPER_H_
17 #define _RAPID_MANIPULATION_GRIPPER_H_
18 
19 #include "actionlib/client/simple_action_client.h"
20 #include "gmock/gmock.h"
21 #include "pr2_controllers_msgs/Pr2GripperCommandAction.h"
22 #include "ros/ros.h"
23 
26 #include "rapid_ros/tf_listener.h"
27 
28 namespace rapid {
29 namespace manipulation {
31  pr2_controllers_msgs::Pr2GripperCommandAction> GripperClient;
32 
34  public:
35  virtual ~GripperInterface() {}
36 
37  // Gets the gripper to the given position.
38  // position - how wide to open or close the gripper
39  // effort - now much force to exert, negative is full force
40  virtual bool SetPosition(double position, double effort = -1) = 0;
41 
42  // Gets the gripper's current position. Note: may not agree with "SetPosition"
43  virtual double GetPosition() const = 0;
44 
45  // Returns true if the gripper is holding an object, false otherwise.
46  virtual bool HeldObject(rapid::perception::Object* object) const = 0;
47 
48  // Returns whether the gripper is open or not.
49  virtual bool IsOpen() const = 0;
50 
51  // Opens the gripper. Returns true if the gripper opened successfully, false
52  // otherwise.
53  // effort - defaults to -1.0, to open with unlimited effort
54  virtual bool Open(double effort = -1.0) = 0;
55 
56  // Closes the gripper. Returns true if the gripper opened successfully, false
57  // otherwise.
58  // effort - defaults to 50.0 to close gently
59  virtual bool Close(double effort = -1.0) = 0;
60 
61  // Sets the held object.
62  virtual void set_held_object(const rapid::perception::Object& object) = 0;
63 
64  // Returns true if the gripper is holding an object, false otherwise.
65  virtual bool is_holding_object() const = 0;
66 
67  virtual void set_is_holding_object(bool holding) = 0;
68 };
69 
70 // Implementation of the GripperInterface for the PR2.
71 class Gripper : public GripperInterface {
72  public:
73  static const double OPEN; // Canonical "open" position.
74  static const double CLOSED; // Canonical "closed" position.
75 
76  // Gripper ids
77  static const int LEFT_GRIPPER = 0;
78  static const int RIGHT_GRIPPER = 1;
79 
80  // Gripper action topics
81  static const std::string LEFT_GRIPPER_ACTION;
82  static const std::string RIGHT_GRIPPER_ACTION;
83 
84  // Constructor that takes the gripper id and the gripper client.
85  // gripper_id: Gripper::LEFT_GRIPPER or Gripper::RIGHT_GRIPPER
86  // client: a rapid_ros::ActionClient
87  Gripper(const int gripper_id, GripperClient* client,
88  rapid_ros::TfListenerInterface* tf_listener);
89 
90  ~Gripper();
91 
92  bool SetPosition(double position, double effort = -1.0);
93  double GetPosition() const;
94  bool HeldObject(rapid::perception::Object* object) const;
95  bool IsOpen() const;
96  bool Open(double effort = -1.0);
97  bool Close(double effort = -1.0);
98 
99  bool is_holding_object() const;
100  void set_held_object(const rapid::perception::Object& object);
101  void set_is_holding_object(bool holding);
102 
103  private:
104  const int gripper_id_;
105  GripperClient* gripper_client_;
106  rapid_ros::TfListenerInterface* transform_listener_;
107  bool is_holding_object_;
108  rapid::perception::Object held_object_;
109 
110  static const double OPEN_THRESHOLD; // Gripper open threshold
111 };
112 
114  public:
115  MOCK_METHOD2(SetPosition, bool(double position, double effort));
116  MOCK_CONST_METHOD0(GetPosition, double());
118  MOCK_CONST_METHOD0(IsOpen, bool());
119  MOCK_METHOD1(Open, bool(double effort));
120  MOCK_METHOD1(Close, bool(double effort));
122  MOCK_METHOD1(set_is_holding_object, void(bool));
124 };
125 } // namespace manipulation
126 } // namespace rapid
127 
128 #endif // _RAPID_MANIPULATION_GRIPPER_H_
static const double OPEN
Definition: gripper.h:73
static const double CLOSED
Definition: gripper.h:74
MOCK_METHOD2(SetPosition, bool(double position, double effort))
static const int RIGHT_GRIPPER
Definition: gripper.h:78
static const std::string LEFT_GRIPPER_ACTION
Definition: gripper.h:81
virtual bool IsOpen() const =0
Gripper(const int gripper_id, GripperClient *client, rapid_ros::TfListenerInterface *tf_listener)
virtual bool Close(double effort=-1.0)=0
virtual void set_is_holding_object(bool holding)=0
virtual bool SetPosition(double position, double effort=-1)=0
static const std::string RIGHT_GRIPPER_ACTION
Definition: gripper.h:82
virtual bool HeldObject(rapid::perception::Object *object) const =0
void set_is_holding_object(bool holding)
rapid_ros::ActionClientInterface< pr2_controllers_msgs::Pr2GripperCommandAction > GripperClient
Definition: gripper.h:31
bool SetPosition(double position, double effort=-1.0)
bool Close(double effort=-1.0)
bool HeldObject(rapid::perception::Object *object) const
virtual double GetPosition() const =0
virtual bool is_holding_object() const =0
void set_held_object(const rapid::perception::Object &object)
MOCK_CONST_METHOD1(HeldObject, bool(rapid::perception::Object *))
MOCK_METHOD1(Open, bool(double effort))
bool Open(double effort=-1.0)
virtual bool Open(double effort=-1.0)=0
virtual void set_held_object(const rapid::perception::Object &object)=0
static const int LEFT_GRIPPER
Definition: gripper.h:77
MOCK_CONST_METHOD0(GetPosition, double())