Skip to content

Commit e92707d

Browse files
committed
update test fixture to use publishing, some tests are failing
1 parent 6cca539 commit e92707d

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed

controller_manager/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set(THIS_PACKAGE_INCLUDE_DEPENDS
1414
pluginlib
1515
rclcpp
1616
realtime_tools
17+
std_msgs
1718
)
1819

1920
find_package(ament_cmake REQUIRED)

controller_manager/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<depend>ros2_control_test_assets</depend>
2727
<depend>ros2param</depend>
2828
<depend>ros2run</depend>
29+
<depend>std_msgs</depend>
2930

3031
<test_depend>ament_cmake_gmock</test_depend>
3132
<test_depend>ros2_control_test_assets</test_depend>

controller_manager/src/controller_manager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ ControllerManager::ControllerManager(
195195
{
196196
RCLCPP_WARN(get_logger(), "'update_rate' parameter not set, using default value.");
197197
}
198+
199+
// set QoS to transient local to get messages that have already been published
200+
// (if robot state publisher starts before controller manager)
201+
RCLCPP_INFO(get_logger(), "Subscribing to ~/robot_description topic for robot description file.");
202+
robot_description_subscription_ = create_subscription<std_msgs::msg::String>(
203+
namespace_ + "/robot_description", rclcpp::QoS(1).transient_local(),
204+
std::bind(&ControllerManager::robot_description_callback, this, std::placeholders::_1));
205+
198206
diagnostics_updater_.setHardwareID("ros2_control");
199207
diagnostics_updater_.add(
200208
"Controllers Activity", this, &ControllerManager::controller_activity_diagnostic_callback);

controller_manager/test/controller_manager_test_common.hpp

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929
#include "controller_manager/controller_manager.hpp"
3030
#include "controller_manager_msgs/srv/switch_controller.hpp"
3131

32+
#include "rclcpp/rclcpp.hpp"
3233
#include "rclcpp/utilities.hpp"
3334

35+
#include "std_msgs/msg/string.hpp"
36+
3437
#include "ros2_control_test_assets/descriptions.hpp"
3538
#include "test_controller_failed_init/test_controller_failed_init.hpp"
3639

@@ -60,21 +63,54 @@ template <typename CtrlMgr>
6063
class ControllerManagerFixture : public ::testing::Test
6164
{
6265
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+
63107
static void SetUpTestCase() { rclcpp::init(0, nullptr); }
64108

65109
static void TearDownTestCase() { rclcpp::shutdown(); }
66110

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; }
76112

77-
void TearDown() { stopCmUpdater(); }
113+
void TearDown() override { stopCmUpdater(); }
78114

79115
void startCmUpdater()
80116
{
@@ -115,11 +151,23 @@ class ControllerManagerFixture : public ::testing::Test
115151
EXPECT_EQ(expected_return, switch_future.get());
116152
}
117153

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+
118161
std::shared_ptr<rclcpp::Executor> executor_;
119162
std::shared_ptr<CtrlMgr> cm_;
120163

121164
std::thread updater_;
122165
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_;
123171
};
124172

125173
class TestControllerManagerSrvs

0 commit comments

Comments
 (0)