franka_combinable_hw_controller_switching_test.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019 Franka Emika GmbH
2 // Use of this source code is governed by the Apache-2.0 license, see LICENSE
3 #include <array>
4 #include <list>
5 #include <memory>
6 #include <random>
7 #include <set>
8 #include <string>
9 
10 #include <gtest/gtest.h>
15 #include <ros/ros.h>
16 #include <urdf/model.h>
17 
20 
21 extern std::string arm_id;
22 extern std::array<std::string, 7> joint_names;
23 
25  const std::string& name,
26  const std::string& type,
27  const hardware_interface::InterfaceResources& resource1) {
29  info.claimed_resources.clear();
30  info.name = name;
31  info.type = type;
32  info.claimed_resources.push_back(resource1);
33  return info;
34 }
35 
37  const std::string& name,
38  const std::string& type,
40  const hardware_interface::InterfaceResources& resource2) {
41  hardware_interface::ControllerInfo info = newInfo(name, type, resource1);
42  info.claimed_resources.push_back(resource2);
43  return info;
44 }
45 
47  const std::string& name,
48  const std::string& type,
51  const hardware_interface::InterfaceResources& resource3) {
52  hardware_interface::ControllerInfo info = newInfo(name, type, resource1, resource2);
53  info.claimed_resources.push_back(resource3);
54  return info;
55 }
56 
58  : public ::testing::TestWithParam<std::list<hardware_interface::ControllerInfo>> {
59  public:
60  CombinableControllerConflict() : robot_(std::make_unique<franka_hw::FrankaCombinableHW>()) {
61  ros::NodeHandle root_nh;
62  ros::NodeHandle robot_hw_nh("~");
63  robot_->initParameters(root_nh, robot_hw_nh);
64  robot_->initROSInterfaces(robot_hw_nh);
65  robot_->setupParameterCallbacks(robot_hw_nh);
66  }
67  bool callCheckForConflict(const std::list<hardware_interface::ControllerInfo> info_list) {
68  return robot_->checkForConflict(info_list);
69  }
70  bool callPrepareSwitch(const std::list<hardware_interface::ControllerInfo> info_list) {
71  return robot_->prepareSwitch(info_list, info_list);
72  }
73 
74  private:
75  std::unique_ptr<franka_hw::FrankaCombinableHW> robot_;
76 };
77 
79  : public ::testing::TestWithParam<std::list<hardware_interface::ControllerInfo>> {
80  public:
81  CombinableNoControllerConflict() : robot_(std::make_unique<franka_hw::FrankaCombinableHW>()) {
82  ros::NodeHandle root_nh;
83  ros::NodeHandle robot_hw_nh("~");
84  robot_->initParameters(root_nh, robot_hw_nh);
85  robot_->initROSInterfaces(robot_hw_nh);
86  robot_->setupParameterCallbacks(robot_hw_nh);
87  }
88  bool callCheckForConflict(const std::list<hardware_interface::ControllerInfo> info_list) {
89  return robot_->checkForConflict(info_list);
90  }
91  bool callPrepareSwitch(const std::list<hardware_interface::ControllerInfo> info_list) {
92  return robot_->prepareSwitch(info_list, info_list);
93  }
94 
95  private:
96  std::unique_ptr<franka_hw::FrankaCombinableHW> robot_;
97 };
98 
99 std::string arm_id2("panda2");
100 std::string jp_iface_str("hardware_interface::PositionJointInterface");
101 std::string jv_iface_str("hardware_interface::VelocityJointInterface");
102 std::string jt_iface_str("hardware_interface::EffortJointInterface");
103 std::string cv_iface_str("franka_hw::FrankaVelocityCartesianInterface");
104 std::string cp_iface_str("franka_hw::FrankaPoseCartesianInterface");
105 std::string unknown_iface_str("hardware_interface::UnknownInterface");
106 std::string name_str("some_controller");
107 std::string type_str("SomeControllerClass");
108 std::set<std::string> joints_set = {joint_names[0], joint_names[1], joint_names[2], joint_names[3],
109  joint_names[4], joint_names[5], joint_names[6]};
110 std::set<std::string> cartesian_set = {arm_id + "_robot"};
111 std::set<std::string> cartesian_arm2_set = {arm_id2 + "_robot"};
112 std::set<std::string> no_id_set = {"joint1"};
124  newInfo(name_str, type_str, unknown_iface_res);
137  newInfo(name_str, type_str, jp_res, jp_res, jp_res);
147 
149  combinableNonAdmissibleRequests,
151  ::testing::Values(std::list<hardware_interface::ControllerInfo>{no_id_info},
152  std::list<hardware_interface::ControllerInfo>{unknown_iface_info},
153  std::list<hardware_interface::ControllerInfo>{jp_info},
154  std::list<hardware_interface::ControllerInfo>{jv_info},
155  std::list<hardware_interface::ControllerInfo>{cv_info},
156  std::list<hardware_interface::ControllerInfo>{cp_info},
157  std::list<hardware_interface::ControllerInfo>{jt_jp_info},
158  std::list<hardware_interface::ControllerInfo>{jt_jv_info},
159  std::list<hardware_interface::ControllerInfo>{jt_jt_info},
160  std::list<hardware_interface::ControllerInfo>{jp_jp_info},
161  std::list<hardware_interface::ControllerInfo>{jp_jv_info},
162  std::list<hardware_interface::ControllerInfo>{jp_cv_info},
163  std::list<hardware_interface::ControllerInfo>{jp_cp_info},
164  std::list<hardware_interface::ControllerInfo>{jv_jv_info},
165  std::list<hardware_interface::ControllerInfo>{jv_cv_info},
166  std::list<hardware_interface::ControllerInfo>{jv_cp_info},
167  std::list<hardware_interface::ControllerInfo>{cv_cv_info},
168  std::list<hardware_interface::ControllerInfo>{cv_cp_info},
169  std::list<hardware_interface::ControllerInfo>{cp_cp_info},
170  std::list<hardware_interface::ControllerInfo>{jp_jp_jp_info},
171  std::list<hardware_interface::ControllerInfo>{jt_cv_info},
172  std::list<hardware_interface::ControllerInfo>{jt_cp_info}));
173 
174 INSTANTIATE_TEST_CASE_P(combinableAdmissibleRequests,
176  ::testing::Values(std::list<hardware_interface::ControllerInfo>{jt_info},
177  std::list<hardware_interface::ControllerInfo>{
178  jt_info, cp_arm2_info}));
179 
180 TEST(FrankaCombinableHWTests, CanInitROSInterfaces) {
182  ros::NodeHandle root_nh;
183  ros::NodeHandle robot_hw_nh("~");
184  EXPECT_TRUE(hw.initParameters(root_nh, robot_hw_nh));
185  EXPECT_NO_THROW(hw.initROSInterfaces(robot_hw_nh));
186 }
187 
188 TEST_P(CombinableControllerConflict, ConflictsForIncompatibleControllers) {
189  EXPECT_TRUE(callCheckForConflict(GetParam()));
190 }
191 
192 TEST_P(CombinableNoControllerConflict, DoesNotConflictForCompatibleControllers) {
193  EXPECT_FALSE(callCheckForConflict(GetParam()));
194 }
195 
196 TEST_P(CombinableNoControllerConflict, CanPrepareSwitchForCompatibleControllers) {
197  EXPECT_TRUE(callPrepareSwitch(GetParam()));
198 }
hardware_interface::ControllerInfo cp_cp_info
std::string jv_iface_str("hardware_interface::VelocityJointInterface")
std::unique_ptr< franka_hw::FrankaCombinableHW > robot_
hardware_interface::ControllerInfo jt_cv_info
hardware_interface::ControllerInfo jt_cp_info
hardware_interface::ControllerInfo jp_jv_info
std::string arm_id
hardware_interface::ControllerInfo jp_info
std::string cp_iface_str("franka_hw::FrankaPoseCartesianInterface")
std::set< std::string > joints_set
hardware_interface::InterfaceResources no_id_res(jp_iface_str, no_id_set)
hardware_interface::ControllerInfo cv_info
hardware_interface::ControllerInfo jv_cv_info
hardware_interface::ControllerInfo jt_jp_info
A hardware class for a Panda robot based on the ros_control framework.
hardware_interface::ControllerInfo jp_cp_info
bool callCheckForConflict(const std::list< hardware_interface::ControllerInfo > info_list)
void initROSInterfaces(ros::NodeHandle &robot_hw_nh) override
Initializes the class in terms of ros_control interfaces.
std::set< std::string > cartesian_arm2_set
std::string name_str("some_controller")
std::array< std::string, 7 > joint_names
hardware_interface::ControllerInfo jt_jt_info
hardware_interface::ControllerInfo cv_cv_info
hardware_interface::ControllerInfo jv_info
hardware_interface::InterfaceResources cp_res(cp_iface_str, cartesian_set)
std::string cv_iface_str("franka_hw::FrankaVelocityCartesianInterface")
hardware_interface::InterfaceResources jp_res(jp_iface_str, joints_set)
hardware_interface::InterfaceResources jt_res(jt_iface_str, joints_set)
std::vector< InterfaceResources > claimed_resources
TEST_P(CombinableControllerConflict, ConflictsForIncompatibleControllers)
hardware_interface::ControllerInfo jv_cp_info
hardware_interface::ControllerInfo cp_info
std::string arm_id2("panda2")
bool callPrepareSwitch(const std::list< hardware_interface::ControllerInfo > info_list)
hardware_interface::ControllerInfo cp_arm2_info
std::string jp_iface_str("hardware_interface::PositionJointInterface")
hardware_interface::ControllerInfo newInfo(const std::string &name, const std::string &type, const hardware_interface::InterfaceResources &resource1)
hardware_interface::InterfaceResources jv_res(jv_iface_str, joints_set)
hardware_interface::ControllerInfo unknown_iface_info
bool callCheckForConflict(const std::list< hardware_interface::ControllerInfo > info_list)
virtual bool initParameters(ros::NodeHandle &root_nh, ros::NodeHandle &robot_hw_nh)
Reads the parameterization of the hardware class from the ROS parameter server (e.g.
Definition: franka_hw.cpp:82
TEST(FrankaCombinableHWTests, CanInitROSInterfaces)
hardware_interface::ControllerInfo jp_cv_info
bool callPrepareSwitch(const std::list< hardware_interface::ControllerInfo > info_list)
hardware_interface::InterfaceResources unknown_iface_res(unknown_iface_str, joints_set)
std::string unknown_iface_str("hardware_interface::UnknownInterface")
std::string type_str("SomeControllerClass")
INSTANTIATE_TEST_CASE_P(combinableNonAdmissibleRequests, CombinableControllerConflict,::testing::Values(std::list< hardware_interface::ControllerInfo >{no_id_info}, std::list< hardware_interface::ControllerInfo >{unknown_iface_info}, std::list< hardware_interface::ControllerInfo >{jp_info}, std::list< hardware_interface::ControllerInfo >{jv_info}, std::list< hardware_interface::ControllerInfo >{cv_info}, std::list< hardware_interface::ControllerInfo >{cp_info}, std::list< hardware_interface::ControllerInfo >{jt_jp_info}, std::list< hardware_interface::ControllerInfo >{jt_jv_info}, std::list< hardware_interface::ControllerInfo >{jt_jt_info}, std::list< hardware_interface::ControllerInfo >{jp_jp_info}, std::list< hardware_interface::ControllerInfo >{jp_jv_info}, std::list< hardware_interface::ControllerInfo >{jp_cv_info}, std::list< hardware_interface::ControllerInfo >{jp_cp_info}, std::list< hardware_interface::ControllerInfo >{jv_jv_info}, std::list< hardware_interface::ControllerInfo >{jv_cv_info}, std::list< hardware_interface::ControllerInfo >{jv_cp_info}, std::list< hardware_interface::ControllerInfo >{cv_cv_info}, std::list< hardware_interface::ControllerInfo >{cv_cp_info}, std::list< hardware_interface::ControllerInfo >{cp_cp_info}, std::list< hardware_interface::ControllerInfo >{jp_jp_jp_info}, std::list< hardware_interface::ControllerInfo >{jt_cv_info}, std::list< hardware_interface::ControllerInfo >{jt_cp_info}))
hardware_interface::ControllerInfo jt_info
std::unique_ptr< franka_hw::FrankaCombinableHW > robot_
hardware_interface::ControllerInfo jp_jp_jp_info
std::set< std::string > cartesian_set
hardware_interface::ControllerInfo no_id_info
hardware_interface::InterfaceResources cv_res(cv_iface_str, cartesian_set)
std::set< std::string > no_id_set
hardware_interface::ControllerInfo jt_jv_info
std::string jt_iface_str("hardware_interface::EffortJointInterface")
hardware_interface::ControllerInfo jv_jv_info
hardware_interface::ControllerInfo jp_jp_info
hardware_interface::ControllerInfo cv_cp_info
hardware_interface::InterfaceResources cp_arm2_res(cp_iface_str, cartesian_arm2_set)


franka_hw
Author(s): Franka Emika GmbH
autogenerated on Fri Oct 23 2020 03:47:05