Skip to content

Commit 55105d2

Browse files
authored
Replace RCUTILS_ with RCLCPP_ for logging (ros-controls#62)
1 parent e3e22a3 commit 55105d2

File tree

12 files changed

+56
-41
lines changed

12 files changed

+56
-41
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ int main()
122122
{
123123
// do all the init stuff
124124

125+
// Logger
126+
const rclcpp::Logger logger = rclcpp::get_logger("my_robot_logger");
127+
125128
// create my_robot instance
126129
auto my_robot = std::make_shared<MyRobot>();
127130

@@ -156,12 +159,12 @@ int main()
156159
// we can either configure each controller individually through its services
157160
// or we use the controller manager to configure every loaded controller
158161
if (cm.configure() != controller_interface::CONTROLLER_INTERFACE_RET_SUCCESS) {
159-
RCUTILS_LOG_ERROR("at least one controller failed to configure")
162+
RCLCPP_ERROR(logger, "at least one controller failed to configure")
160163
return -1;
161164
}
162165
// and activate all controller
163166
if (cm.activate() != controller_interface::CONTROLLER_INTERFACE_RET_SUCCESS) {
164-
RCUTILS_LOG_ERROR("at least one controller failed to activate")
167+
RCLCPP_ERROR(logger, "at least one controller failed to activate")
165168
return -1;
166169
}
167170

controller_manager/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ find_package(controller_interface REQUIRED)
1717
find_package(hardware_interface REQUIRED)
1818
find_package(pluginlib REQUIRED)
1919
find_package(rclcpp REQUIRED)
20-
find_package(rcpputils REQUIRED)
2120

2221
add_library(controller_manager SHARED src/controller_manager.cpp src/controller_loader_pluginlib.cpp)
2322
target_include_directories(controller_manager PRIVATE include)
@@ -27,7 +26,6 @@ ament_target_dependencies(controller_manager
2726
"hardware_interface"
2827
"pluginlib"
2928
"rclcpp"
30-
"rcpputils"
3129
)
3230
# Causes the visibility macros to use dllexport rather than dllimport,
3331
# which is appropriate when building the dll but not consuming it.

controller_manager/src/controller_manager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "lifecycle_msgs/msg/state.hpp"
2626

27-
#include "rcutils/logging_macros.h"
27+
#include "rclcpp/rclcpp.hpp"
2828

2929
namespace controller_manager
3030
{
@@ -46,7 +46,7 @@ ControllerManager::load_controller(
4646
const std::string & controller_name,
4747
const std::string & controller_type)
4848
{
49-
RCUTILS_LOG_INFO("Loading controller '%s'\n", controller_name.c_str());
49+
RCLCPP_INFO(get_logger(), "Loading controller '%s'\n", controller_name.c_str());
5050

5151
auto it = std::find_if(
5252
loaders_.cbegin(), loaders_.cend(),
@@ -58,7 +58,7 @@ ControllerManager::load_controller(
5858
controller = (*it)->create(controller_type);
5959
} else {
6060
const std::string error_msg("Loader for controller '" + controller_name + "' not found\n");
61-
RCUTILS_LOG_ERROR("%s", error_msg.c_str());
61+
RCLCPP_ERROR(get_logger(), "%s", error_msg.c_str());
6262
throw std::runtime_error(error_msg);
6363
}
6464

controller_parameter_server/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ if(BUILD_TESTING)
6565
test_parameter_server test/test_parameter_server.cpp
6666
ENV config_file=${test_config_file})
6767
target_link_libraries(test_parameter_server parameter_server)
68+
ament_target_dependencies(
69+
test_parameter_server
70+
rclcpp
71+
)
6872
endif()
6973

7074
ament_export_include_directories(

controller_parameter_server/test/test_parameter_server.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ TEST_F(TestControllerParameterServer, load_config_file) {
8787
std::this_thread::sleep_for(1s);
8888
while (!parameters_client->wait_for_service(1s)) {
8989
if (!rclcpp::ok()) {
90-
RCUTILS_LOG_ERROR("Interrupted while waiting for the service. Exiting.");
90+
RCLCPP_ERROR(
91+
client_node->get_logger(),
92+
"Interrupted while waiting for the service. Exiting.");
9193
FAIL();
9294
}
93-
RCUTILS_LOG_INFO("service not available, waiting again...");
95+
RCLCPP_INFO(client_node->get_logger(), "service not available, waiting again...");
9496
}
9597

9698
std::vector<std::string> expected_keys =

hardware_interface/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1111
endif()
1212

1313
find_package(ament_cmake REQUIRED)
14+
find_package(rclcpp REQUIRED)
1415
find_package(rcpputils REQUIRED)
15-
find_package(rcutils REQUIRED)
1616

1717
add_library(
1818
hardware_interface
@@ -28,8 +28,8 @@ target_include_directories(
2828
include)
2929
ament_target_dependencies(
3030
hardware_interface
31+
"rclcpp"
3132
"rcpputils"
32-
"rcutils"
3333
)
3434

3535
# Causes the visibility macros to use dllexport rather than dllimport,

hardware_interface/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
<buildtool_depend>ament_cmake</buildtool_depend>
1111

12+
<depend>rclcpp</depend>
1213
<depend>rcpputils</depend>
13-
<depend>rcutils</depend>
1414

1515
<test_depend>ament_cmake_gtest</test_depend>
1616
<test_depend>ament_lint_auto</test_depend>

hardware_interface/src/robot_hardware.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <vector>
2020

2121
#include "hardware_interface/macros.hpp"
22-
#include "rcutils/logging_macros.h"
22+
#include "rclcpp/rclcpp.hpp"
2323

2424
namespace hardware_interface
2525
{
@@ -80,8 +80,9 @@ RobotHardware::get_joint_state_handle(
8080
const std::string & name, const JointStateHandle ** joint_state_handle)
8181
{
8282
if (name.empty()) {
83-
RCUTILS_LOG_ERROR_NAMED(
84-
"joint state handle", "cannot get handle! No name given");
83+
RCLCPP_ERROR(
84+
rclcpp::get_logger("joint state handle"),
85+
"cannot get handle! No name given");
8586
return HW_RET_ERROR;
8687
}
8788

@@ -94,8 +95,9 @@ RobotHardware::get_joint_state_handle(
9495
});
9596

9697
if (handle_pos == registered_joint_state_handles_.end()) {
97-
RCUTILS_LOG_ERROR_NAMED(
98-
"joint state handle", "cannot get handle. No joint %s found.\n", name.c_str());
98+
RCLCPP_ERROR(
99+
rclcpp::get_logger("joint state handle"),
100+
"cannot get handle. No joint %s found.\n", name.c_str());
99101
return HW_RET_ERROR;
100102
}
101103

@@ -108,8 +110,9 @@ RobotHardware::get_joint_command_handle(
108110
const std::string & name, JointCommandHandle ** joint_command_handle)
109111
{
110112
if (name.empty()) {
111-
RCUTILS_LOG_ERROR_NAMED(
112-
"joint cmd handle", "cannot get handle! No name given");
113+
RCLCPP_ERROR(
114+
rclcpp::get_logger("joint cmd handle"),
115+
"cannot get handle! No name given");
113116
return HW_RET_ERROR;
114117
}
115118

@@ -122,8 +125,9 @@ RobotHardware::get_joint_command_handle(
122125
});
123126

124127
if (handle_pos == registered_joint_command_handles_.end()) {
125-
RCUTILS_LOG_ERROR_NAMED(
126-
"joint cmd handle", "cannot get handle. No joint %s found.\n", name.c_str());
128+
RCLCPP_ERROR(
129+
rclcpp::get_logger("joint cmd handle"),
130+
"cannot get handle. No joint %s found.\n", name.c_str());
127131
return HW_RET_ERROR;
128132
}
129133

@@ -136,8 +140,9 @@ RobotHardware::get_operation_mode_handle(
136140
const std::string & name, OperationModeHandle ** operation_mode_handle)
137141
{
138142
if (name.empty()) {
139-
RCUTILS_LOG_ERROR_NAMED(
140-
"joint operation mode handle", "cannot get handle! No name given");
143+
RCLCPP_ERROR(
144+
rclcpp::get_logger("joint operation mode handle"),
145+
"cannot get handle! No name given");
141146
return HW_RET_ERROR;
142147
}
143148

@@ -150,8 +155,9 @@ RobotHardware::get_operation_mode_handle(
150155
});
151156

152157
if (handle_pos == registered_operation_mode_handles_.end()) {
153-
RCUTILS_LOG_ERROR_NAMED(
154-
"joint operation mode handle", "cannot get handle. No joint %s found.\n", name.c_str());
158+
RCLCPP_ERROR(
159+
rclcpp::get_logger("joint operation mode handle"),
160+
"cannot get handle. No joint %s found.\n", name.c_str());
155161
return HW_RET_ERROR;
156162
}
157163

test_robot_hardware/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ endif()
1212

1313
find_package(ament_cmake REQUIRED)
1414
find_package(hardware_interface REQUIRED)
15-
find_package(rcutils REQUIRED)
15+
find_package(rclcpp REQUIRED)
1616

1717
add_library(test_robot_hardware SHARED src/test_robot_hardware.cpp)
1818
target_include_directories(test_robot_hardware PRIVATE include)
1919
ament_target_dependencies(
2020
test_robot_hardware
2121
hardware_interface
22-
rcutils
22+
rclcpp
2323
)
2424

2525
# Causes the visibility macros to use dllexport rather than dllimport,

test_robot_hardware/include/test_robot_hardware/test_robot_hardware.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "hardware_interface/robot_hardware.hpp"
2121
#include "hardware_interface/types/hardware_interface_return_values.hpp"
2222

23+
#include "rclcpp/rclcpp.hpp"
24+
2325
#include "test_robot_hardware/visibility_control.h"
2426

2527
namespace test_robot_hardware
@@ -84,6 +86,8 @@ class TestRobotHardware : public hardware_interface::RobotHardware
8486

8587
hardware_interface::OperationModeHandle write_op_handle1;
8688
hardware_interface::OperationModeHandle write_op_handle2;
89+
90+
const rclcpp::Logger logger = rclcpp::get_logger("test_robot_hardware");
8791
};
8892

8993
} // namespace test_robot_hardware

0 commit comments

Comments
 (0)