robotiq_3f_gripper_ros.cpp
Go to the documentation of this file.
1 // Copyright (c) 2016, Toyota Research Institute. All rights reserved.
2 
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
5 
6 // 1. Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 
9 // 2. Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 
13 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 // POSSIBILITY OF SUCH DAMAGE.
24 
26 
27 using namespace robotiq_3f_gripper_control;
28 
29 Robotiq3FGripperROS::Robotiq3FGripperROS(ros::NodeHandle &nh, boost::shared_ptr<Robotiq3FGripperAPI> driver, std::vector<std::string> joint_names, ros::Duration desired_update_freq)
30  :nh_(nh)
31  ,driver_(driver)
32  ,desired_update_freq_(desired_update_freq)
33 {
40 
42  input_status_pub_ = nh.advertise<robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotInput>("input", 10);
43 
45  output_sub_ = nh.subscribe("output", 10, &Robotiq3FGripperROS::handleRawCmd, this);
46 
49  ReconfigureServer::CallbackType f = boost::bind(&Robotiq3FGripperROS::handleReconfigure, this, _1, _2);
50  reconfigure_->setCallback(f);
51 
52  if(joint_names.size() != 4)
53  {
54  ROS_FATAL("Joint name size must be 4");
55  }
56 }
57 
59 {
60  driver_->getRaw(&input_status_msg_);
62 }
63 
64 bool Robotiq3FGripperROS::handleInit(std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &resp)
65 {
66  ROS_DEBUG_NAMED("RobotiqCANROS", "entered handle_init");
68  driver_->setInitialization(INIT_ACTIVATION);
70  while(!driver_->isReady())
71  {
73  }
74  resp.message += "Init succeeded. ";
76  driver_->setActionMode(ACTION_GO);
78  while(driver_->isHalted())
79  {
81  }
82  resp.success = true;
83  resp.message += "Ready to command. ";
84  return true;
85 }
86 
87 bool Robotiq3FGripperROS::handleReset(std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &resp)
88 {
89  ROS_DEBUG_NAMED("RobotiqCANROS", "entered handle_reset");
91  handleShutdown(req, resp);
93  handleInit(req, resp);
94  return true;
95 }
96 
97 bool Robotiq3FGripperROS::handleHalt(std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &resp)
98 {
99  ROS_DEBUG_NAMED("RobotiqCANROS", "entered handle_halt");
101  if(!driver_->isInitialized())
102  {
103  resp.success = false;
104  resp.message = "Not initialized. ";
105  return true;
106  }
108  driver_->setActionMode(ACTION_STOP);
110  while(!driver_->isHalted())
111  {
113  }
114  resp.success = true;
115  resp.message += "Device halted. ";
116  return true;
117 }
118 
119 bool Robotiq3FGripperROS::handleEmergRelease(std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &resp)
120 {
121  ROS_DEBUG_NAMED("RobotiqCANROS", "entered handle_emerg_release");
123  handleHalt(req, resp);
125  driver_->setEmergencyRelease(EMERGENCY_RELEASE_ENGAGED);
127  while(!driver_->isEmergReleaseComplete())
128  {
130  }
131  driver_->setEmergencyRelease(EMERGENCY_RELEASE_IDLE);
132  resp.success = true;
133  resp.message += "Emergency release complete. ";
134 
135 }
136 
137 bool Robotiq3FGripperROS::handleShutdown(std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &resp)
138 {
139  ROS_DEBUG_NAMED("RobotiqCANROS", "entered handle_shutdown");
141  handleHalt(req, resp);
143  driver_->setInitialization(INIT_RESET);
145  while(driver_->isInitialized())
146  {
148  }
149  resp.success = true;
150  resp.message += "Shutdown complete. ";
151  return true;
152 
153 }
154 
155 void Robotiq3FGripperROS::handleReconfigure(robotiq_3f_gripper_control::Robotiq3FGripperConfig &config, uint32_t level)
156 {
157  ROS_DEBUG_NAMED("RobotiqCANROS", "entered handle_reconfigure");
158  driver_->setInidividualControlMode((robotiq::IndividualControl)config.ind_control_fingers, (robotiq::IndividualControl)config.ind_control_scissor);
159  if (!config.ind_control_scissor)
160  {
161  driver_->setGraspingMode((robotiq::GraspingMode)config.mode);
162 
163  while(!driver_->isModeSet((robotiq::GraspingMode)config.mode))
164  {
166  ROS_DEBUG_STREAM("waiting for mode "<<config.mode<<" to be set");
167  }
168  }
171 
172  driver_->setVelocity(config.velocity, config.velocity, config.velocity, config.velocity);
173  driver_->setForce(config.force, config.force, config.force, config.force);
174 
175  config_ = config;
176 }
177 
178 void Robotiq3FGripperROS::updateConfig(const robotiq_3f_gripper_control::Robotiq3FGripperConfig &config)
179 {
180  reconfigure_->updateConfig(config);
181 }
182 
183 void Robotiq3FGripperROS::getCurrentConfig(robotiq_3f_gripper_control::Robotiq3FGripperConfig &config)
184 {
185  config = config_;
186 }
187 
188 void Robotiq3FGripperROS::handleRawCmd(const robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput::ConstPtr &msg)
189 {
190  ROS_DEBUG_NAMED("RobotiqCANROS", "entered handle_raw_cmd");
191  driver_->setRaw(*msg);
192 }
#define ROS_FATAL(...)
void publish(const boost::shared_ptr< M > &message) const
void handleRawCmd(const robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotOutput::ConstPtr &msg)
f
bool handleHalt(std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &resp)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool sleep() const
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
#define ROS_DEBUG_NAMED(name,...)
unsigned int uint32_t
bool handleShutdown(std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &resp)
void updateConfig(const robotiq_3f_gripper_control::Robotiq3FGripperConfig &config)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_DEBUG_STREAM(args)
Robotiq3FGripperROS(ros::NodeHandle &nh, boost::shared_ptr< robotiq_3f_gripper_control::Robotiq3FGripperAPI > driver, std::vector< std::string > joint_names, ros::Duration desired_update_freq)
boost::shared_ptr< ReconfigureServer > reconfigure_
void handleReconfigure(robotiq_3f_gripper_control::Robotiq3FGripperConfig &config, uint32_t level=0)
robotiq_3f_gripper_articulated_msgs::Robotiq3FGripperRobotInput input_status_msg_
robotiq_3f_gripper_control::Robotiq3FGripperConfig config_
bool handleEmergRelease(std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &resp)
boost::shared_ptr< robotiq_3f_gripper_control::Robotiq3FGripperAPI > driver_
void getCurrentConfig(robotiq_3f_gripper_control::Robotiq3FGripperConfig &config)
bool handleReset(std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &resp)
dynamic_reconfigure::Server< robotiq_3f_gripper_control::Robotiq3FGripperConfig > ReconfigureServer
Reconfigure.
bool handleInit(std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &resp)


robotiq_3f_gripper_control
Author(s): Nicolas Lauzier (Robotiq inc.), Allison Thackston
autogenerated on Tue Jun 1 2021 02:29:58