RobotiqHandPlugin.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2014 Open Source Robotics Foundation
00003  * Copyright 2015 Clearpath Robotics
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
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   // Documentation inherited.
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   // ROS publish multi queue, prevents publish() blocking
00211   private: PubMultiQueue pmq;
00212 
00214   private: ros::Subscriber subHandleCommand;
00215 
00218   // changing the grasping mode.
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


robotiq_s_model_articulated_gazebo_plugins
Author(s): Devon Ash , John Hsu
autogenerated on Thu Jun 6 2019 17:58:08