24
24
#include " controller_manager_msgs/msg/hardware_component_state.hpp"
25
25
#include " hardware_interface/types/lifecycle_state_names.hpp"
26
26
#include " lifecycle_msgs/msg/state.hpp"
27
+ #include " rcl/arguments.h"
27
28
#include " rclcpp/version.h"
28
29
#include " rclcpp_lifecycle/state.hpp"
29
30
@@ -197,7 +198,8 @@ ControllerManager::ControllerManager(
197
198
kControllerInterfaceNamespace , kControllerInterfaceClassName )),
198
199
chainable_loader_(
199
200
std::make_shared<pluginlib::ClassLoader<controller_interface::ChainableControllerInterface>>(
200
- kControllerInterfaceNamespace , kChainableControllerInterfaceClassName ))
201
+ kControllerInterfaceNamespace , kChainableControllerInterfaceClassName )),
202
+ cm_node_options_(options)
201
203
{
202
204
init_controller_manager ();
203
205
}
@@ -217,7 +219,8 @@ ControllerManager::ControllerManager(
217
219
kControllerInterfaceNamespace , kControllerInterfaceClassName )),
218
220
chainable_loader_(
219
221
std::make_shared<pluginlib::ClassLoader<controller_interface::ChainableControllerInterface>>(
220
- kControllerInterfaceNamespace , kChainableControllerInterfaceClassName ))
222
+ kControllerInterfaceNamespace , kChainableControllerInterfaceClassName )),
223
+ cm_node_options_(options)
221
224
{
222
225
init_controller_manager ();
223
226
}
@@ -234,7 +237,8 @@ ControllerManager::ControllerManager(
234
237
kControllerInterfaceNamespace , kControllerInterfaceClassName )),
235
238
chainable_loader_(
236
239
std::make_shared<pluginlib::ClassLoader<controller_interface::ChainableControllerInterface>>(
237
- kControllerInterfaceNamespace , kChainableControllerInterfaceClassName ))
240
+ kControllerInterfaceNamespace , kChainableControllerInterfaceClassName )),
241
+ cm_node_options_(options)
238
242
{
239
243
init_controller_manager ();
240
244
}
@@ -2819,29 +2823,56 @@ rclcpp::NodeOptions ControllerManager::determine_controller_node_options(
2819
2823
2820
2824
rclcpp::NodeOptions controller_node_options = controller.c ->define_custom_node_options ();
2821
2825
std::vector<std::string> node_options_arguments = controller_node_options.arguments ();
2822
- const std::string ros_args_arg = " --ros-args" ;
2826
+
2827
+ for (const std::string & arg : cm_node_options_.arguments ())
2828
+ {
2829
+ if (arg.find (" __ns" ) != std::string::npos || arg.find (" __node" ) != std::string::npos)
2830
+ {
2831
+ if (
2832
+ node_options_arguments.back () == RCL_REMAP_FLAG ||
2833
+ node_options_arguments.back () == RCL_SHORT_REMAP_FLAG)
2834
+ {
2835
+ node_options_arguments.pop_back ();
2836
+ }
2837
+ continue ;
2838
+ }
2839
+
2840
+ node_options_arguments.push_back (arg);
2841
+ }
2842
+
2823
2843
if (controller.info .parameters_file .has_value ())
2824
2844
{
2825
- if (!check_for_element (node_options_arguments, ros_args_arg ))
2845
+ if (!check_for_element (node_options_arguments, RCL_ROS_ARGS_FLAG ))
2826
2846
{
2827
- node_options_arguments.push_back (ros_args_arg );
2847
+ node_options_arguments.push_back (RCL_ROS_ARGS_FLAG );
2828
2848
}
2829
- node_options_arguments.push_back (" --params-file " );
2849
+ node_options_arguments.push_back (RCL_PARAM_FILE_FLAG );
2830
2850
node_options_arguments.push_back (controller.info .parameters_file .value ());
2831
2851
}
2832
2852
2833
2853
// ensure controller's `use_sim_time` parameter matches controller_manager's
2834
2854
const rclcpp::Parameter use_sim_time = this ->get_parameter (" use_sim_time" );
2835
2855
if (use_sim_time.as_bool ())
2836
2856
{
2837
- if (!check_for_element (node_options_arguments, ros_args_arg ))
2857
+ if (!check_for_element (node_options_arguments, RCL_ROS_ARGS_FLAG ))
2838
2858
{
2839
- node_options_arguments.push_back (ros_args_arg );
2859
+ node_options_arguments.push_back (RCL_ROS_ARGS_FLAG );
2840
2860
}
2841
- node_options_arguments.push_back (" -p " );
2861
+ node_options_arguments.push_back (RCL_PARAM_FLAG );
2842
2862
node_options_arguments.push_back (" use_sim_time:=true" );
2843
2863
}
2844
2864
2865
+ std::string arguments;
2866
+ arguments.reserve (1000 );
2867
+ for (const auto & arg : node_options_arguments)
2868
+ {
2869
+ arguments.append (arg);
2870
+ arguments.append (" " );
2871
+ }
2872
+ RCLCPP_INFO (
2873
+ get_logger (), " Controller '%s' node arguments: %s" , controller.info .name .c_str (),
2874
+ arguments.c_str ());
2875
+
2845
2876
controller_node_options = controller_node_options.arguments (node_options_arguments);
2846
2877
controller_node_options.use_global_arguments (false );
2847
2878
return controller_node_options;
0 commit comments