|
29 | 29 | #include "controller_manager/controller_manager.hpp" |
30 | 30 | #include "controller_manager_msgs/srv/switch_controller.hpp" |
31 | 31 |
|
| 32 | +#include "rclcpp/rclcpp.hpp" |
32 | 33 | #include "rclcpp/utilities.hpp" |
33 | 34 |
|
| 35 | +#include "std_msgs/msg/string.hpp" |
| 36 | + |
34 | 37 | #include "ros2_control_test_assets/descriptions.hpp" |
35 | 38 | #include "test_controller_failed_init/test_controller_failed_init.hpp" |
36 | 39 |
|
@@ -60,21 +63,54 @@ template <typename CtrlMgr> |
60 | 63 | class ControllerManagerFixture : public ::testing::Test |
61 | 64 | { |
62 | 65 | public: |
| 66 | + //TODO parameter hinzufügen, welche hw erwartet wird |
| 67 | + explicit ControllerManagerFixture( |
| 68 | + const std::string & robot_description = ros2_control_test_assets::minimal_robot_urdf, |
| 69 | + const std::string ns = "/", const bool & pass_urdf_as_parameter = false) |
| 70 | + : robot_description_(robot_description), ns_(ns), pass_urdf_as_parameter_(pass_urdf_as_parameter) |
| 71 | + { |
| 72 | + executor_ = std::make_shared<rclcpp::executors::SingleThreadedExecutor>(); |
| 73 | + // We want ot be able to create a ResourceManager where no urdf file has been passed to |
| 74 | + if (robot_description_.empty()) |
| 75 | + { |
| 76 | + cm_ = std::make_shared<CtrlMgr>( |
| 77 | + std::make_unique<hardware_interface::ResourceManager>(), executor_, TEST_CM_NAME); |
| 78 | + } |
| 79 | + else |
| 80 | + { |
| 81 | + // can be removed later, needed if we want to have the deprecated way of passing the robot |
| 82 | + // description file to the controller manager covered by tests |
| 83 | + if (pass_urdf_as_parameter_) |
| 84 | + { |
| 85 | + cm_ = std::make_shared<CtrlMgr>( |
| 86 | + std::make_unique<hardware_interface::ResourceManager>(robot_description_, true, true), |
| 87 | + executor_, TEST_CM_NAME); |
| 88 | + } |
| 89 | + else |
| 90 | + { |
| 91 | + urdf_publisher_node_ = std::make_shared<rclcpp::Node>("robot_description_publisher", ns_); |
| 92 | + description_pub_ = urdf_publisher_node_->create_publisher<std_msgs::msg::String>( |
| 93 | + "robot_description", rclcpp::QoS(1).transient_local()); |
| 94 | + executor_->add_node(urdf_publisher_node_); |
| 95 | + publish_robot_description_file(robot_description_); |
| 96 | + |
| 97 | + cm_ = std::make_shared<CtrlMgr>( |
| 98 | + std::make_unique<hardware_interface::ResourceManager>(), executor_, TEST_CM_NAME); |
| 99 | + |
| 100 | + //TODO warten bis hw da ist und initialisiert |
| 101 | + // von urdf wissen wir was da sein soll |
| 102 | + // list hw |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + |
63 | 107 | static void SetUpTestCase() { rclcpp::init(0, nullptr); } |
64 | 108 |
|
65 | 109 | static void TearDownTestCase() { rclcpp::shutdown(); } |
66 | 110 |
|
67 | | - void SetUp() |
68 | | - { |
69 | | - executor_ = std::make_shared<rclcpp::executors::SingleThreadedExecutor>(); |
70 | | - cm_ = std::make_shared<CtrlMgr>( |
71 | | - std::make_unique<hardware_interface::ResourceManager>( |
72 | | - ros2_control_test_assets::minimal_robot_urdf, true, true), |
73 | | - executor_, TEST_CM_NAME); |
74 | | - run_updater_ = false; |
75 | | - } |
| 111 | + void SetUp() override { run_updater_ = false; } |
76 | 112 |
|
77 | | - void TearDown() { stopCmUpdater(); } |
| 113 | + void TearDown() override { stopCmUpdater(); } |
78 | 114 |
|
79 | 115 | void startCmUpdater() |
80 | 116 | { |
@@ -115,11 +151,23 @@ class ControllerManagerFixture : public ::testing::Test |
115 | 151 | EXPECT_EQ(expected_return, switch_future.get()); |
116 | 152 | } |
117 | 153 |
|
| 154 | + void publish_robot_description_file(const std::string & robot_description_file) |
| 155 | + { |
| 156 | + auto msg = std::make_unique<std_msgs::msg::String>(); |
| 157 | + msg->data = robot_description_file; |
| 158 | + description_pub_->publish(std::move(msg)); |
| 159 | + } |
| 160 | + |
118 | 161 | std::shared_ptr<rclcpp::Executor> executor_; |
119 | 162 | std::shared_ptr<CtrlMgr> cm_; |
120 | 163 |
|
121 | 164 | std::thread updater_; |
122 | 165 | bool run_updater_; |
| 166 | + const std::string robot_description_; |
| 167 | + const std::string ns_; |
| 168 | + const bool pass_urdf_as_parameter_; |
| 169 | + std::shared_ptr<rclcpp::Node> urdf_publisher_node_; |
| 170 | + rclcpp::Publisher<std_msgs::msg::String>::SharedPtr description_pub_; |
123 | 171 | }; |
124 | 172 |
|
125 | 173 | class TestControllerManagerSrvs |
|
0 commit comments