ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS2 spawn controllers (launch.py)

asked 2021-03-27 09:20:48 -0600

RandyD gravatar image

Hi,

For my mecanum robot, i'm trying to build everything using ROS2. Currently i'm at the point where i implemented a hardware interface class for controlling the motors and reading the sensors.

Following the documentation on ros2_control github, i'm at the point where i need to run "ros2 contol load_start_controller", where i'm testing with the diff_drive_controller before implementing a custom controller for mecanum drive.

I can't find any information on how to automatically spawn the controller in ROS2 so i don't have to run the ros2 control load_start_controller every time i launch my robot nodes.

Can the controller be defined in the URDF as we do with hardware interface or can the controller be spawned trough python launch files?

edit retag flag offensive close merge delete

Comments

You certainly can start the controller in your launch file. At the very least, anything that can be run from the commandline can be run from a python launch file by adding an ExecuteProcess action to your launch description. Something to the effect of: return LaunchDescritpion([... ,ExecuteProcess( cmd=['ros2', 'control', 'load_start_controller', 'differential_drive_controller'], output='screen' ])

shonigmann gravatar image shonigmann  ( 2021-03-30 11:38:48 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2022-01-17 21:44:15 -0600

To start a controller immediately you should add a spawner node to your launch file. You can even control if controller should be started or only configured on the beginning using the flag "--stoppped" to only load and configure a controller.

joint_state_broadcaster_spawner = Node(
    package="controller_manager",
    executable="spawner",
    arguments=["joint_state_broadcaster", "--controller-manager", "/controller_manager"],
)
edit flag offensive delete link more
-1

answered 2021-03-27 13:11:40 -0600

RandyD gravatar image

updated 2021-03-27 13:12:55 -0600

As workaround i duplicated the "ros2_control_node.cpp" into my mecanum_control package and added the following code above the executor->add_node / executor->spin();

// Load the controllers
std::vector<std::string> start_controllers;
std::vector<std::string> stop_controllers;
controller_manager_node->load_controller("joint_state_controller", "joint_state_controller/JointStateController");
controller_manager_node->load_controller("mecanumbot_drive_controller", "mecanumbot_controller/MecanumbotDriveController");
controller_manager_node->configure_controller("joint_state_controller");
controller_manager_node->configure_controller("mecanumbot_drive_controller");

start_controllers.push_back("joint_state_controller");
start_controllers.push_back("mecanumbot_drive_controller");
controller_manager_node->switch_controller(start_controllers, stop_controllers, 1, controller_manager_msgs::srv::SwitchController::Request::BEST_EFFORT);
edit flag offensive delete link more

Comments

This approach is suboptimal. If you want to control this from a different node, then ok, but ros2_control_node if definitely misused for this.

destogl gravatar image destogl  ( 2022-01-17 21:46:12 -0600 )edit

Question Tools

4 followers

Stats

Asked: 2021-03-27 09:20:48 -0600

Seen: 2,812 times

Last updated: Jan 17 '22