robotiq_3f_gripper_hw_interface.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 
30  :hw_driver_(driver)
31 {
32  double rate;
33  nh.param<double>("update_rate", rate, 20);
34 
35  std::string hw_name;
36  hw_name = nh.param<std::string>("hw_name", "robotiq_s");
37 
38  std::string prefix;
39  prefix = nh.param<std::string>("prefix", "");
40 
41  joint_names_.push_back(prefix+"finger_1_joint_1");
42  joint_names_.push_back(prefix+"finger_2_joint_1");
43  joint_names_.push_back(prefix+"finger_middle_joint_1");
44  joint_names_.push_back(prefix+"palm_finger_1_joint");
45 
46  joint_names_ = nh.param< std::vector<std::string> >("joint_names", joint_names_);
47 
48  if(joint_names_.size()!=4)
49  {
50  throw std::runtime_error("There must be 4 joint names");
51  }
52 
53  j_curr_pos_.resize(4, 0);
54  j_curr_vel_.resize(4, 0);
55  j_curr_eff_.resize(4, 0);
56 
57  j_cmd_pos_.resize(4, 0);
58 
61 }
62 
64 {
66  for (std::size_t joint_id = 0; joint_id < 4; ++joint_id)
67  {
68  // Create joint state interface
70  joint_names_[joint_id],
71  &j_curr_pos_[joint_id],
72  &j_curr_vel_[joint_id],
73  &j_curr_eff_[joint_id]));
74 
75  }
76 
78  for(std::size_t joint_id = 0; joint_id < 4; ++joint_id)
79  {
80  // Create joint position interface
81  joint_position_interface.registerHandle(hardware_interface::JointHandle(
82  joint_state_interface.getHandle(joint_names_[joint_id]),
83  &j_cmd_pos_[joint_id]));
84  }
85 }
86 
88 {
89  hw_driver_->read();
90  hw_driver_->getPosition(&j_curr_pos_[0], &j_curr_pos_[1], &j_curr_pos_[2], &j_curr_pos_[3]);
91  hw_driver_->getCommandPos(&j_cmd_pos_[0], &j_cmd_pos_[1], &j_cmd_pos_[2], &j_cmd_pos_[3]);
92 
93  hw_diagnostics_->update();
94  hw_ros_->publish();
95 }
96 
98 {
99  hw_driver_->setPosition(j_cmd_pos_[0], j_cmd_pos_[1], j_cmd_pos_[2], j_cmd_pos_[3]);
100  hw_driver_->write();
101 }
boost::shared_ptr< Robotiq3FGripperDiagnostics > hw_diagnostics_
bool param(const std::string &param_name, T &param_val, const T &default_val) const
void configure(hardware_interface::JointStateInterface &joint_state_interface, hardware_interface::PositionJointInterface &joint_position_interface)
void registerHandle(const JointStateHandle &handle)
JointStateHandle getHandle(const std::string &name)
Robotiq3FGripperHWInterface(ros::NodeHandle nh, boost::shared_ptr< Robotiq3FGripperAPI > driver)


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