Skip to content

Commit 1f59fe3

Browse files
Karsten1987pohzhieeyoutalk
authored
Dashing updates (ros-controls#19)
* use dashing rclcpp logger interface Signed-off-by: Karsten Knese <[email protected]> * use dashing parameter API Signed-off-by: Karsten Knese <[email protected]> * fixed typo on nullptr check (ros-controls#20) Fixed a nullptr check typo causing exceptions to be thrown whenever input command is set to 0. Signed-off-by: Poh Zhi-Ee <[email protected]> * remove if/else Signed-off-by: Yutaka Kondo <[email protected]> * update travis JOB_TYPE Signed-off-by: Yutaka Kondo <[email protected]> * Update joint_command_handle.cpp Co-authored-by: Poh Zhi-Ee <[email protected]> Co-authored-by: Yutaka Kondo <[email protected]>
1 parent e651cc8 commit 1f59fe3

File tree

7 files changed

+31
-50
lines changed

7 files changed

+31
-50
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ install:
66

77
matrix:
88
include:
9-
- env: JOB_TYPE=crystal
9+
- env: JOB_TYPE=dashing
1010
script: .ros2ci/travis.bash $JOB_TYPE
11-
# Uncomment the following to test against ROS 2 Dashing
12-
# - env: JOB_TYPE=dashing
13-
# script: .ros2ci/travis.bash $JOB_TYPE
1411
# Uncomment the following to test against ROS 2 nightly build
1512
# - env: JOB_TYPE=nightly
1613
# script: .ros2ci/travis.bash $JOB_TYPE

controller_interface/include/controller_interface/controller_interface.hpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,24 @@ class ControllerInterface : public rclcpp_lifecycle::node_interfaces::LifecycleN
4343
~ControllerInterface() = default;
4444

4545
CONTROLLER_INTERFACE_PUBLIC
46-
controller_interface_ret_t
4746
virtual
47+
controller_interface_ret_t
4848
init(
4949
std::weak_ptr<hardware_interface::RobotHardware> robot_hardware,
5050
const std::string & controller_name);
5151

52-
CONTROLLER_INTERFACE_PUBLIC
53-
std::shared_ptr<rclcpp_lifecycle::LifecycleNode>
54-
get_lifecycle_node();
55-
5652
CONTROLLER_INTERFACE_PUBLIC
5753
virtual
5854
controller_interface_ret_t
5955
update() = 0;
6056

57+
CONTROLLER_INTERFACE_PUBLIC
58+
std::shared_ptr<rclcpp_lifecycle::LifecycleNode>
59+
get_lifecycle_node();
60+
6161
protected:
6262
std::weak_ptr<hardware_interface::RobotHardware> robot_hardware_;
6363
std::shared_ptr<rclcpp_lifecycle::LifecycleNode> lifecycle_node_;
64-
std::shared_ptr<rclcpp::AsyncParametersClient> parameters_client_;
65-
66-
private:
67-
std::shared_ptr<rclcpp::Node> parameter_client_node_;
6864
};
6965

7066
} // namespace controller_interface

controller_interface/src/controller_interface.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ ControllerInterface::init(
4646
lifecycle_node_->register_on_error(
4747
std::bind(&ControllerInterface::on_error, this, std::placeholders::_1));
4848

49-
std::string remote_controller_parameter_server = "controller_parameter_server";
50-
parameters_client_ = std::make_shared<rclcpp::AsyncParametersClient>(
51-
lifecycle_node_->get_node_base_interface(),
52-
lifecycle_node_->get_node_topics_interface(),
53-
lifecycle_node_->get_node_graph_interface(),
54-
lifecycle_node_->get_node_services_interface(),
55-
remote_controller_parameter_server);
56-
5749
return CONTROLLER_INTERFACE_RET_SUCCESS;
5850
}
5951

controller_manager/src/controller_manager.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,40 +67,36 @@ namespace
6767
std::string
6868
parse_library_path(
6969
const std::string & package_name,
70-
const std::string & class_name)
70+
const std::string & class_name,
71+
const rclcpp::Logger logger) // should be const ref when possible
7172
{
72-
std::string library_path = "";
73-
74-
auto allocator = rcutils_get_default_allocator();
7573
// get node plugin resource from package
7674
std::string content;
7775
std::string base_path;
7876
if (!ament_index_cpp::get_resource(resource_index, package_name, content, &base_path)) {
79-
auto error_msg = rcutils_format_string(
80-
allocator, "unable to load resource for package %s", package_name.c_str());
81-
RCUTILS_LOG_ERROR(error_msg);
77+
auto error_msg = std::string("unable to load resource for package ") + package_name;
78+
RCLCPP_ERROR(logger, error_msg);
8279
throw std::runtime_error(error_msg);
8380
}
8481

82+
auto allocator = rcutils_get_default_allocator();
8583
rcutils_string_array_t controller_array = rcutils_get_zero_initialized_string_array();
8684
rcutils_split(content.c_str(), '\n', allocator, &controller_array);
8785
if (controller_array.size == 0) {
88-
auto error_msg = rcutils_format_string(
89-
allocator, "no ros controllers found in package %s", package_name.c_str());
90-
RCUTILS_LOG_ERROR(error_msg);
86+
auto error_msg = std::string("no ros controllers found in package " + package_name);
87+
RCLCPP_ERROR(logger, error_msg);
9188
throw std::runtime_error(error_msg);
9289
}
9390

91+
std::string library_path = "";
9492
bool controller_is_available = false;
9593
for (auto i = 0u; i < controller_array.size; ++i) {
9694
rcutils_string_array_t controller_details = rcutils_get_zero_initialized_string_array();
9795
rcutils_split(controller_array.data[i], ';', allocator, &controller_details);
9896
if (controller_details.size != 2) {
99-
auto error_msg = rcutils_format_string(
100-
allocator,
101-
"package resource content has wrong format. should be <class_name>;<library_path>",
102-
package_name.c_str());
103-
RCUTILS_LOG_ERROR(error_msg);
97+
auto error_msg = std::string("package resource content has wrong format") +
98+
" - should be <class_name>;<library_path> but is " + controller_array.data[i];
99+
RCLCPP_ERROR(logger, error_msg);
104100
throw std::runtime_error(error_msg);
105101
}
106102

@@ -115,9 +111,8 @@ parse_library_path(
115111
}
116112

117113
if (!controller_is_available) {
118-
auto error_msg = rcutils_format_string(
119-
allocator, "couldn't find controller class %s", class_name.c_str());
120-
RCUTILS_LOG_ERROR(error_msg);
114+
auto error_msg = std::string("couldn't find controller class ") + class_name;
115+
RCLCPP_ERROR(logger, error_msg);
121116
throw std::runtime_error(error_msg);
122117
}
123118

@@ -141,9 +136,9 @@ ControllerManager::load_controller(
141136
const std::string & class_name,
142137
const std::string & controller_name)
143138
{
144-
auto library_path = parse_library_path(package_name, class_name);
139+
auto library_path = parse_library_path(package_name, class_name, this->get_logger());
145140

146-
RCUTILS_LOG_INFO("going to load controller %s from library %s\n",
141+
RCLCPP_INFO(this->get_logger(), "going to load controller %s from library %s",
147142
class_name.c_str(), library_path.c_str());
148143

149144
// let possible exceptions escalate

controller_parameter_server/include/controller_parameter_server/parameter_server.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ class ParameterServer : public rclcpp::Node
2929
{
3030
public:
3131
CONTROLLER_PARAMETER_SERVER_PUBLIC
32-
ParameterServer();
32+
explicit ParameterServer(
33+
const rclcpp::NodeOptions & options = (
34+
rclcpp::NodeOptions()
35+
.allow_undeclared_parameters(true)
36+
.automatically_declare_parameters_from_overrides(true)));
3337

3438
CONTROLLER_PARAMETER_SERVER_PUBLIC
3539
virtual

controller_parameter_server/src/parameter_server.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
namespace controller_parameter_server
2222
{
2323

24-
ParameterServer::ParameterServer()
25-
: rclcpp::Node("controller_parameter_server")
24+
ParameterServer::ParameterServer(const rclcpp::NodeOptions & options)
25+
: rclcpp::Node("controller_parameter_server", options)
2626
{}
2727

2828
void

hardware_interface/src/robot_hardware.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@ RobotHardware::register_joint_state_handle(const JointStateHandle * joint_handle
3030
auto handle_pos = std::find_if(
3131
registered_joint_state_handles_.begin(), registered_joint_state_handles_.end(),
3232
[&](auto joint_handle_ptr) -> bool {
33-
if (joint_handle_ptr->get_name() == joint_handle->get_name()) {
34-
return true;
35-
}
36-
return false;
37-
}
38-
);
33+
return joint_handle_ptr->get_name() == joint_handle->get_name();
34+
});
35+
3936
// handle exist already
4037
if (handle_pos != registered_joint_state_handles_.end()) {
4138
return HW_RET_ERROR;

0 commit comments

Comments
 (0)