Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GAZEBO_ROBOTIQ_HAND_PLUGIN_HH
00020 #define GAZEBO_ROBOTIQ_HAND_PLUGIN_HH
00021
00022 #include <robotiq_s_model_articulated_msgs/SModelRobotInput.h>
00023 #include <robotiq_s_model_articulated_msgs/SModelRobotOutput.h>
00024 #include <gazebo_plugins/PubQueue.h>
00025 #include <ros/advertise_options.h>
00026 #include <ros/callback_queue.h>
00027 #include <ros/ros.h>
00028 #include <ros/subscribe_options.h>
00029 #include <sensor_msgs/JointState.h>
00030 #include <string>
00031 #include <vector>
00032 #include <boost/scoped_ptr.hpp>
00033 #include <boost/thread/mutex.hpp>
00034 #include <gazebo/common/Plugin.hh>
00035 #include <gazebo/common/Time.hh>
00036 #include <gazebo/physics/physics.hh>
00037
00056 class RobotiqHandPlugin : public gazebo::ModelPlugin
00057 {
00058
00059
00060
00061 friend class gazebo::common::PID;
00063 enum State
00064 {
00065 Disabled = 0,
00066 Emergency,
00067 ICS,
00068 ICF,
00069 ChangeModeInProgress,
00070 Simplified
00071 };
00072
00074 enum GraspingMode
00075 {
00076 Basic = 0,
00077 Pinch,
00078 Wide,
00079 Scissor
00080 };
00081
00083 public: RobotiqHandPlugin();
00084
00086 public: virtual ~RobotiqHandPlugin();
00087
00088
00089 public: void Load(gazebo::physics::ModelPtr _parent, sdf::ElementPtr _sdf);
00090
00092 private: void RosQueueThread();
00093
00096 private: void SetHandleCommand(
00097 const robotiq_s_model_articulated_msgs::SModelRobotOutput::ConstPtr &_msg);
00098
00101 private: void UpdatePIDControl(double _dt);
00102
00104 private: void GetAndPublishHandleState();
00105
00107 private: void GetAndPublishJointState(const gazebo::common::Time &_curTime);
00108
00110 private: void UpdateStates();
00111
00114 private: bool FindJoints();
00115
00117 private: void ReleaseHand();
00118
00120 private: void StopHand();
00121
00124 private: bool IsHandFullyOpen();
00125
00136 private: uint8_t GetObjectDetection(const gazebo::physics::JointPtr &_joint,
00137 int _index, uint8_t _rPR, uint8_t _prevrPR);
00138
00143 private: uint8_t GetCurrentPosition(const gazebo::physics::JointPtr &_joint);
00144
00150 private: bool GetAndPushBackJoint(const std::string& _jointName,
00151 gazebo::physics::Joint_V& _joints);
00152
00159 private: bool VerifyField(const std::string &_label, int _min,
00160 int _max, int _v);
00161
00166 private: bool VerifyCommand(
00167 const robotiq_s_model_articulated_msgs::SModelRobotOutput::ConstPtr &_command);
00168
00172 private: static const int NumJoints = 5;
00173
00176 private: static const double VelTolerance = 0.002;
00177
00181 private: static const double PoseTolerance = 0.002;
00182
00184 private: static const double MinVelocity = 0.176;
00185
00187 private: static const double MaxVelocity = 0.88;
00188
00190 private: static const std::string DefaultLeftTopicCommand;
00191
00193 private: static const std::string DefaultLeftTopicState;
00194
00196 private: static const std::string DefaultRightTopicCommand;
00197
00199 private: static const std::string DefaultRightTopicState;
00200
00202 private: boost::scoped_ptr<ros::NodeHandle> rosNode;
00203
00205 private: ros::CallbackQueue rosQueue;
00206
00208 private: boost::thread callbackQueueThread;
00209
00210
00211 private: PubMultiQueue pmq;
00212
00214 private: ros::Subscriber subHandleCommand;
00215
00218
00219 private: robotiq_s_model_articulated_msgs::SModelRobotOutput handleCommand;
00220
00223 private: robotiq_s_model_articulated_msgs::SModelRobotOutput lastHandleCommand;
00224
00227 private: robotiq_s_model_articulated_msgs::SModelRobotOutput prevCommand;
00228
00230 private: robotiq_s_model_articulated_msgs::SModelRobotOutput userHandleCommand;
00231
00233 private: gazebo::event::ConnectionPtr updateConnection;
00234
00236 private: gazebo::common::Time lastControllerUpdateTime;
00237
00239 private: robotiq_s_model_articulated_msgs::SModelRobotInput handleState;
00240
00242 private: boost::mutex controlMutex;
00243
00245 private: GraspingMode graspingMode;
00246
00248 private: State handState;
00249
00251 private: ros::Publisher pubHandleState;
00252
00254 private: PubQueue<robotiq_s_model_articulated_msgs::SModelRobotInput>::Ptr pubHandleStateQueue;
00255
00257 private: ros::Publisher pubJointStates;
00258
00260 private: PubQueue<sensor_msgs::JointState>::Ptr pubJointStatesQueue;
00261
00263 private: sensor_msgs::JointState jointStates;
00264
00266 private: gazebo::physics::WorldPtr world;
00267
00269 private: gazebo::physics::ModelPtr model;
00270
00272 private: sdf::ElementPtr sdf;
00273
00275 private: std::string side;
00276
00278 private: std::vector<std::string> jointNames;
00279
00281 private: gazebo::physics::Joint_V fingerJoints;
00282
00284 private: gazebo::physics::Joint_V joints;
00285
00287 private: gazebo::common::PID posePID[NumJoints];
00288 };
00289
00290 #endif // GAZEBO_ROBOTIQ_HAND_PLUGIN_HH