SVHRosControlHWInterface.cpp
Go to the documentation of this file.
1 //
3 // © Copyright 2022 SCHUNK Mobile Greifsysteme GmbH, Lauffen/Neckar Germany
4 // © Copyright 2022 FZI Forschungszentrum Informatik, Karlsruhe, Germany
5 //
6 // This file is part of the Schunk SVH Driver.
7 //
8 // The Schunk SVH Driver is free software: you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or (at your
11 // option) any later version.
12 //
13 // The Schunk SVH Driver is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 // Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License along with
19 // the Schunk SVH Driver. If not, see <https://www.gnu.org/licenses/>.
20 //
22 
23 //----------------------------------------------------------------------
30 //----------------------------------------------------------------------
31 
32 #include <urdf/model.h>
33 #include <urdf_model/model.h>
34 #include <urdf_parser/urdf_parser.h>
35 
37 
38 // Driver Specific things
42 
44 
46 
47 using namespace hardware_interface;
48 
50 
52 
53 
55 {
56  m_svh.reset(new SVHWrapper(robot_hw_nh));
57 
58  m_hardware_ready = false;
59 
60  m_joint_position_commands.resize(driver_svh::SVH_DIMENSION);
61  m_joint_positions.resize(driver_svh::SVH_DIMENSION);
62  m_joint_velocity.resize(driver_svh::SVH_DIMENSION);
63  m_joint_effort.resize(driver_svh::SVH_DIMENSION);
64  m_channel_names.resize(driver_svh::SVH_DIMENSION);
65 
66  // Initialize controller
67  for (std::size_t channel = 0; channel < driver_svh::SVH_DIMENSION; ++channel)
68  {
69  m_channel_names[channel] =
70  m_svh->getNamePrefix() + "_" + driver_svh::SVHController::m_channel_description[channel];
71 
72  ROS_DEBUG_STREAM("Controller Hardware interface: Loading joint with id "
73  << channel << " named " << m_channel_names[channel]);
74  if (m_channel_names[channel] == "")
75  {
76  ROS_ERROR_STREAM("Could not find joint name for SVH device "
77  << channel
78  << ". You will not be able to use this device with the controller!");
79  }
80  else
81  {
82  // Create joint state interface
83  m_joint_state_interface.registerHandle(
84  hardware_interface::JointStateHandle(m_channel_names[channel],
85  &m_joint_positions[channel],
86  &m_joint_velocity[channel],
87  &m_joint_effort[channel]));
88 
89  // Create position joint interface
91  m_joint_state_interface.getHandle(m_channel_names[channel]),
92  &m_joint_position_commands[channel]);
93  m_position_joint_interface.registerHandle(hwi_handle);
94  }
95  }
96 
97 
98  registerInterface(&m_joint_state_interface); // From RobotHW base class.
99  registerInterface(&m_position_joint_interface); // From RobotHW base class.
100 
101  return true;
102 }
103 
105 {
106  m_joint_positions.resize(driver_svh::SVH_DIMENSION);
107  m_joint_effort.resize(driver_svh::SVH_DIMENSION);
108 
109  if (m_svh->getFingerManager()->isConnected())
110  {
111  // Get positions in rad
112  for (size_t channel = 0; channel < driver_svh::SVH_DIMENSION; ++channel)
113  {
114  double cur_pos = 0.0;
115  double cur_cur = 0.0;
116  if (m_svh->getFingerManager()->isHomed(static_cast<driver_svh::SVHChannel>(channel)))
117  {
118  m_svh->getFingerManager()->getPosition(static_cast<driver_svh::SVHChannel>(channel),
119  cur_pos);
120  m_svh->getFingerManager()->getCurrent(static_cast<driver_svh::SVHChannel>(channel),
121  cur_cur);
122  }
123  else
124  {
125  if (isEnabled())
126  {
128  "Channel "
130  << " is not Homed");
131  }
132  }
133  m_joint_positions[channel] = cur_pos;
134  m_joint_effort[channel] = m_svh->getFingerManager()->convertmAtoN(
135  static_cast<driver_svh::SVHChannel>(channel), cur_cur);
136  }
137 
138  ROS_DEBUG_STREAM("read Position: " << m_joint_positions[0] << " " << m_joint_positions[1] << " "
139  << m_joint_positions[2] << " " << m_joint_positions[3] << " "
140  << m_joint_positions[4] << " " << m_joint_positions[5] << " "
141  << m_joint_positions[6] << " " << m_joint_positions[7] << " "
142  << m_joint_positions[8]);
143  }
144 }
145 
147 {
148  m_hardware_ready = m_svh->channelsEnabled();
149 
150  if (!isEnabled())
151  {
152  ROS_DEBUG_THROTTLE(2, "ros-control-loop is not enabeled!");
153  return;
154  }
155 
156  ROS_DEBUG_STREAM("write Position: "
157  << m_joint_position_commands[0] << " " << m_joint_position_commands[1] << " "
158  << m_joint_position_commands[2] << " " << m_joint_position_commands[3] << " "
159  << m_joint_position_commands[4] << " " << m_joint_position_commands[5] << " "
160  << m_joint_position_commands[6] << " " << m_joint_position_commands[7] << " "
161  << m_joint_position_commands[8]);
162 
163  if (driver_svh::SVH_DIMENSION == m_joint_position_commands.size())
164  {
165  if (!m_svh->getFingerManager()->setAllTargetPositions(m_joint_position_commands))
166  {
167  ROS_WARN_ONCE("Set target position command rejected!");
168  }
169  }
170  else
171  {
172  // TODO: Send individual commands instead of all joints at once.
173  ROS_ERROR("Number of known joints and number of commanded joints do not match!");
174  }
175 }
176 
178  const std::list<hardware_interface::ControllerInfo>& start_list,
179  const std::list<hardware_interface::ControllerInfo>& stop_list)
180 {
181  return hardware_interface::RobotHW::prepareSwitch(start_list, stop_list);
182 }
183 
185  const std::list<hardware_interface::ControllerInfo>& start_list,
186  const std::list<hardware_interface::ControllerInfo>& stop_list)
187 {
188  hardware_interface::RobotHW::doSwitch(start_list, stop_list);
189 }
190 
192 {
193  return m_hardware_ready;
194 }
SVHPositionSettings.h
SVHRosControlHWInterface::doSwitch
void doSwitch(const std::list< hardware_interface::ControllerInfo > &start_list, const std::list< hardware_interface::ControllerInfo > &stop_list)
Definition: SVHRosControlHWInterface.cpp:184
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(args)
driver_svh::SVHController::m_channel_description
static const char * m_channel_description[]
hardware_interface::RobotHW::doSwitch
virtual void doSwitch(const std::list< ControllerInfo > &, const std::list< ControllerInfo > &)
driver_svh::SVH_DIMENSION
SVH_DIMENSION
ROS_WARN_ONCE
#define ROS_WARN_ONCE(...)
ROS_DEBUG_STREAM
#define ROS_DEBUG_STREAM(args)
SVHRosControlHWInterface::SVHRosControlHWInterface
SVHRosControlHWInterface()
Definition: SVHRosControlHWInterface.cpp:49
SVHRosControlHWInterface::init
virtual bool init(ros::NodeHandle &root_nh, ros::NodeHandle &robot_hw_nh)
Initialize the hardware interface.
Definition: SVHRosControlHWInterface.cpp:54
SVHRosControlHWInterface::prepareSwitch
bool prepareSwitch(const std::list< hardware_interface::ControllerInfo > &start_list, const std::list< hardware_interface::ControllerInfo > &stop_list)
Definition: SVHRosControlHWInterface.cpp:177
class_list_macros.h
SVHRosControlHWInterface.h
ROS_WARN_STREAM_THROTTLE
#define ROS_WARN_STREAM_THROTTLE(period, args)
SVHRosControlHWInterface::~SVHRosControlHWInterface
~SVHRosControlHWInterface()
Definition: SVHRosControlHWInterface.cpp:51
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
hardware_interface
hardware_interface::RobotHW
SVHCurrentSettings.h
SVHFingerManager.h
model.h
hardware_interface::JointStateHandle
ROS_ERROR
#define ROS_ERROR(...)
hardware_interface::RobotHW::prepareSwitch
virtual bool prepareSwitch(const std::list< ControllerInfo > &, const std::list< ControllerInfo > &)
driver_svh::SVHChannel
SVHChannel
SVHRosControlHWInterface::read
virtual void read(const ros::Time &time, const ros::Duration &period)
Read the state from the robot hardware.
Definition: SVHRosControlHWInterface.cpp:104
hardware_interface::JointHandle
SVHRosControlHWInterface
This class defines a ros-control hardware interface.
Definition: SVHRosControlHWInterface.h:51
ros::Time
SVHWrapper
Definition: SVHWrapper.h:53
SVHRosControlHWInterface::write
virtual void write(const ros::Time &time, const ros::Duration &period)
write the command to the robot hardware.
Definition: SVHRosControlHWInterface.cpp:146
SVHRosControlHWInterface::isEnabled
bool isEnabled() const
Definition: SVHRosControlHWInterface.cpp:191
ros::Duration
ROS_DEBUG_THROTTLE
#define ROS_DEBUG_THROTTLE(period,...)
ros::NodeHandle


schunk_svh_driver
Author(s): Georg Heppner , Felix Exner , Pascal Becker , Johannes Mangler
autogenerated on Sat Apr 15 2023 02:24:55