RobotiqHandPlugin.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Open Source Robotics Foundation
3  * Copyright 2015 Clearpath Robotics
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */
18 
19 #ifndef GAZEBO_ROBOTIQ_HAND_PLUGIN_HH
20 #define GAZEBO_ROBOTIQ_HAND_PLUGIN_HH
21 
22 #include <robotiq_3f_gripper_articulated_msgs/Robotiq3FGripperRobotInput.h>
23 #include <robotiq_3f_gripper_articulated_msgs/Robotiq3FGripperRobotOutput.h>
25 #include <ros/advertise_options.h>
26 #include <ros/callback_queue.h>
27 #include <ros/ros.h>
28 #include <ros/subscribe_options.h>
29 #include <sensor_msgs/JointState.h>
30 #include <string>
31 #include <vector>
32 #include <boost/scoped_ptr.hpp>
33 #include <boost/thread/mutex.hpp>
34 #include <gazebo/common/Plugin.hh>
35 #include <gazebo/common/Time.hh>
36 #include <gazebo/physics/physics.hh>
37 
56 class RobotiqHandPlugin : public gazebo::ModelPlugin
57 {
58 
59 
60 
61  friend class gazebo::common::PID;
63  enum State
64  {
65  Disabled = 0,
67  ICS,
68  ICF,
71  };
72 
75  {
76  Basic = 0,
80  };
81 
83  public: RobotiqHandPlugin();
84 
86  public: virtual ~RobotiqHandPlugin();
87 
88  // Documentation inherited.
89  public: void Load(gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf);
90 
92  private: void RosQueueThread();
93 
96  private: void SetHandleCommand(
97  const robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput::ConstPtr &_msg);
98 
101  private: void UpdatePIDControl(double _dt);
102 
104  private: void GetAndPublishHandleState();
105 
107  private: void GetAndPublishJointState(const gazebo::common::Time &_curTime);
108 
110  private: void UpdateStates();
111 
114  private: bool FindJoints();
115 
117  private: void ReleaseHand();
118 
120  private: void StopHand();
121 
124  private: bool IsHandFullyOpen();
125 
136  private: uint8_t GetObjectDetection(const gazebo::physics::JointPtr &_joint,
137  int _index, uint8_t _rPR, uint8_t _prevrPR);
138 
143  private: uint8_t GetCurrentPosition(const gazebo::physics::JointPtr &_joint);
144 
150  private: bool GetAndPushBackJoint(const std::string& _jointName,
151  gazebo::physics::Joint_V& _joints);
152 
159  private: bool VerifyField(const std::string &_label, int _min,
160  int _max, int _v);
161 
166  private: bool VerifyCommand(
167  const robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput::ConstPtr &_command);
168 
172  private: static const int NumJoints = 5;
173 
176  private: static constexpr double VelTolerance = 0.002;
177 
181  private: static constexpr double PoseTolerance = 0.002;
182 
184  private: static constexpr double MinVelocity = 0.176;
185 
187  private: static constexpr double MaxVelocity = 0.88;
188 
190  private: static const std::string DefaultLeftTopicCommand;
191 
193  private: static const std::string DefaultLeftTopicState;
194 
196  private: static const std::string DefaultRightTopicCommand;
197 
199  private: static const std::string DefaultRightTopicState;
200 
202  private: boost::scoped_ptr<ros::NodeHandle> rosNode;
203 
206 
208  private: boost::thread callbackQueueThread;
209 
210  // ROS publish multi queue, prevents publish() blocking
211  private: PubMultiQueue pmq;
212 
215 
218  // changing the grasping mode.
219  private: robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput handleCommand;
220 
223  private: robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput lastHandleCommand;
224 
227  private: robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput prevCommand;
228 
230  private: robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput userHandleCommand;
231 
233  private: gazebo::event::ConnectionPtr updateConnection;
234 
236  private: gazebo::common::Time lastControllerUpdateTime;
237 
239  private: robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotInput handleState;
240 
242  private: boost::mutex controlMutex;
243 
246 
248  private: State handState;
249 
252 
255 
258 
261 
263  private: sensor_msgs::JointState jointStates;
264 
266  private: gazebo::physics::WorldPtr world;
267 
269  private: gazebo::physics::ModelPtr model;
270 
272  private: sdf::ElementPtr sdf;
273 
275  private: std::string side;
276 
278  private: std::vector<std::string> jointNames;
279 
281  private: gazebo::physics::Joint_V fingerJoints;
282 
284  private: gazebo::physics::Joint_V joints;
285 
288 };
289 
290 #endif // GAZEBO_ROBOTIQ_HAND_PLUGIN_HH
robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput prevCommand
Previous command received. We know if the hand is opening or closing by comparing the current command...
robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotInput handleState
Robotiq Hand State.
gazebo::common::Time lastControllerUpdateTime
keep track of controller update sim-time.
void Load(gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf)
static const int NumJoints
Number of joints in the hand. The three fingers can do abduction/adduction. Fingers 1 and 2 can do ci...
ros::Publisher pubHandleState
ROS publisher for Robotiq Hand state.
bool VerifyField(const std::string &_label, int _min, int _max, int _v)
Verify that one command field is within the correct range.
void UpdatePIDControl(double _dt)
Update PID Joint controllers.
static constexpr double MinVelocity
Min. joint speed (rad/s). Finger is 125mm and tip speed is 22mm/s.
sdf::ElementPtr sdf
Pointer to the SDF of this plugin.
std::string side
Used to select between &#39;left&#39; or &#39;right&#39; hand.
friend class gazebo::common::PID
gazebo::event::ConnectionPtr updateConnection
gazebo world update connection.
void GetAndPublishHandleState()
Publish Robotiq Hand state.
gazebo::physics::Joint_V joints
Vector containing all the joints.
static constexpr double PoseTolerance
Position tolerance. If the difference between target position and current position is within this val...
static constexpr double MaxVelocity
Max. joint speed (rad/s). Finger is 125mm and tip speed is 110mm/s.
boost::mutex controlMutex
Controller update mutex.
robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput userHandleCommand
Original HandleControl message (published by user and unmodified).
std::vector< std::string > jointNames
Vector containing all the joint names.
gazebo::physics::WorldPtr world
World pointer.
robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput lastHandleCommand
HandleControl message. Last command received before changing the grasping mode.
gazebo::physics::ModelPtr model
Parent model of the hand.
void SetHandleCommand(const robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput::ConstPtr &_msg)
ROS topic callback to update Robotiq Hand Control Commands.
gazebo::physics::Joint_V fingerJoints
Vector containing all the actuated finger joints.
sensor_msgs::JointState jointStates
ROS joint state message.
static const std::string DefaultRightTopicCommand
Default topic name for sending control updates to the right hand.
GraspingMode
Different grasping modes.
bool FindJoints()
Grab pointers to all the joints.
PubQueue< robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotInput >::Ptr pubHandleStateQueue
ROS publisher queue for Robotiq Hand state.
static const std::string DefaultLeftTopicState
Default topic name for receiving state updates from the left hand.
GraspingMode graspingMode
Grasping mode.
uint8_t GetObjectDetection(const gazebo::physics::JointPtr &_joint, int _index, uint8_t _rPR, uint8_t _prevrPR)
Internal helper to get the object detection value.
static constexpr double VelTolerance
Velocity tolerance. Below this value we assume that the joint is stopped (rad/s). ...
State handState
Hand state.
ros::CallbackQueue rosQueue
ROS callback queue.
ros::Publisher pubJointStates
Joint state publisher (rviz visualization).
void GetAndPublishJointState(const gazebo::common::Time &_curTime)
Publish Robotiq Joint state.
A plugin that implements the Robotiq 3-Finger Adaptative Gripper. The plugin exposes the next paramet...
boost::scoped_ptr< ros::NodeHandle > rosNode
ROS NodeHandle.
static const std::string DefaultLeftTopicCommand
Default topic name for sending control updates to the left hand.
bool IsHandFullyOpen()
Checks if the hand is fully open. return True when all the fingers are fully open or false otherwise...
static const std::string DefaultRightTopicState
Default topic name for receiving state updates from the right hand.
bool GetAndPushBackJoint(const std::string &_jointName, gazebo::physics::Joint_V &_joints)
Internal helper to reduce code duplication. If the joint name is found, a pointer to the joint is add...
boost::thread callbackQueueThread
ROS callback queue thread.
void RosQueueThread()
ROS callback queue thread.
ros::Subscriber subHandleCommand
ROS control interface.
PubQueue< sensor_msgs::JointState >::Ptr pubJointStatesQueue
ROS publisher queue for joint states.
void StopHand()
Stop the fingers.
virtual ~RobotiqHandPlugin()
Destructor.
gazebo::common::PID posePID[NumJoints]
PIDs used to control the finger positions.
uint8_t GetCurrentPosition(const gazebo::physics::JointPtr &_joint)
Internal helper to get the actual position of the finger.
bool VerifyCommand(const robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput::ConstPtr &_command)
Verify that all the command fields are within the correct range.
void UpdateStates()
Update the controller.
void ReleaseHand()
Fully open the hand at half of the maximum speed.
RobotiqHandPlugin()
Constructor.
robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput handleCommand
HandleControl message. Originally published by user but some of the fields might be internally modifi...


robotiq_3f_gripper_articulated_gazebo_plugins
Author(s): Devon Ash , John Hsu
autogenerated on Tue Jun 1 2021 02:29:50