my_robot_hw_4.cpp
Go to the documentation of this file.
1 // Copyright (C) 2015, Shadow Robot Company Ltd.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of Shadow Robot Company Ltd. nor the names of its
12 // contributors may be used to endorse or promote products derived from
13 // this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 // POSSIBILITY OF SUCH DAMAGE.
27 
28 
30 
32 {
33 
34 bool MyRobotHW4::init(ros::NodeHandle& /*root_nh*/, ros::NodeHandle &/*robot_hw_nh*/)
35 {
36  using namespace hardware_interface;
37 
38  force_[0] = 0.0;
39  force_[1] = 0.1;
40  force_[2] = 0.2;
41  torque_[0] = 0.0;
42  torque_[1] = 0.1;
43  torque_[2] = 0.2;
44  sensor_name_ = "ft_sensor_1";
45  frame_id_ = "link_1";
46 
48 
51 
52  return true;
53 }
54 
55 
56 void MyRobotHW4::read(const ros::Time& /*time*/, const ros::Duration& /*period*/)
57 {
58  force_[2] = 1.2;
59 }
60 
61 void MyRobotHW4::write(const ros::Time& /*time*/, const ros::Duration& /*period*/)
62 {
63 }
64 
65 bool MyRobotHW4::prepareSwitch(const std::list<hardware_interface::ControllerInfo>& start_list,
66  const std::list<hardware_interface::ControllerInfo>& stop_list)
67 {
68  // To easily test a failure case, any controller that claims resources on MyRobotHW4 will fail
69  if (!start_list.empty() || !stop_list.empty())
70  {
71  for (const auto& controller : start_list)
72  {
73  if (controller.claimed_resources.empty())
74  {
75  continue;
76  }
77  else
78  {
79  return false;
80  }
81  }
82  }
83  return true;
84 }
85 
86 void MyRobotHW4::doSwitch(const std::list<hardware_interface::ControllerInfo>& start_list,
87  const std::list<hardware_interface::ControllerInfo>& stop_list)
88 {
89  // To easily test a failure case, any controller that claims resources on MyRobotHW4 will fail
90  if (!start_list.empty() || !stop_list.empty())
91  {
92  for (const auto& controller : start_list)
93  {
94  if (controller.claimed_resources.empty())
95  {
96  continue;
97  }
98  else
99  {
100  throw hardware_interface::HardwareInterfaceException("MyRobotHW4 can't switch controllers");
101  }
102  }
103  }
104 }
105 
106 }
107 
combined_robot_hw_tests::MyRobotHW4::sensor_name_
std::string sensor_name_
Definition: my_robot_hw_4.h:57
combined_robot_hw_tests::MyRobotHW4
Definition: my_robot_hw_4.h:38
hardware_interface::InterfaceManager::registerInterface
void registerInterface(T *iface)
combined_robot_hw_tests::MyRobotHW4::write
void write(const ros::Time &time, const ros::Duration &period) override
Definition: my_robot_hw_4.cpp:61
my_robot_hw_4.h
combined_robot_hw_tests::MyRobotHW4::frame_id_
std::string frame_id_
Definition: my_robot_hw_4.h:58
combined_robot_hw_tests::MyRobotHW4::force_
double force_[3]
Definition: my_robot_hw_4.h:55
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
hardware_interface
controller
controller
hardware_interface::RobotHW
combined_robot_hw_tests::MyRobotHW4::read
void read(const ros::Time &time, const ros::Duration &period) override
Definition: my_robot_hw_4.cpp:56
ResourceManager< ForceTorqueSensorHandle >::registerHandle
void registerHandle(const ForceTorqueSensorHandle &handle)
hardware_interface::ForceTorqueSensorHandle
hardware_interface::HardwareInterfaceException
combined_robot_hw_tests::MyRobotHW4::prepareSwitch
bool prepareSwitch(const std::list< hardware_interface::ControllerInfo > &start_list, const std::list< hardware_interface::ControllerInfo > &stop_list) override
Definition: my_robot_hw_4.cpp:65
ros::Time
combined_robot_hw_tests::MyRobotHW4::init
bool init(ros::NodeHandle &root_nh, ros::NodeHandle &robot_hw_nh) override
Definition: my_robot_hw_4.cpp:34
combined_robot_hw_tests::MyRobotHW4::torque_
double torque_[3]
Definition: my_robot_hw_4.h:56
combined_robot_hw_tests::MyRobotHW4::ft_sensor_interface_
hardware_interface::ForceTorqueSensorInterface ft_sensor_interface_
Definition: my_robot_hw_4.h:52
combined_robot_hw_tests
Definition: my_robot_hw_1.h:35
ros::Duration
combined_robot_hw_tests::MyRobotHW4::a_plain_hw_interface_
hardware_interface::HardwareInterface a_plain_hw_interface_
Definition: my_robot_hw_4.h:53
combined_robot_hw_tests::MyRobotHW4::doSwitch
void doSwitch(const std::list< hardware_interface::ControllerInfo > &start_list, const std::list< hardware_interface::ControllerInfo > &stop_list) override
Definition: my_robot_hw_4.cpp:86
ros::NodeHandle


combined_robot_hw_tests
Author(s): Toni Oliver
autogenerated on Tue Oct 15 2024 02:08:26