ros-controls / ros_control

Generic and simple controls framework for ROS
http://wiki.ros.org/ros_control
BSD 3-Clause "New" or "Revised" License
487 stars 307 forks source link

SwitchController function gets stuck and does not return #520

Closed pucciland95 closed 1 year ago

pucciland95 commented 1 year ago

Hi,

I am writing the hardware interface for the Gofa robot from ABB. I have a launch file where I specify all the ros_controllers that I would like to load through the controller manager. Therefore, in my code, after that I instantiate the hardware_interface and the controller_manager, I do the following:

if(!controller_manager->loadController("joint_state_controller"))
    ROS_INFO("Cannot load joint_state_controller");

if(!controller_manager->loadController(this->ros_controller_spawned))
    ROS_INFO("Cannot load %s", this->ros_controller_spawned.c_str());

// Loading ros_controllers
const std::vector<std::string> start_controllers = {"joint_state_controller"};
const std::vector<std::string> stop_controllers  = {};
controller_manager->switchController(start_controllers, stop_controllers, controller_manager_msgs::SwitchController::Request::STRICT, false);
ROS_INFO("Controller switched");

I the first 2 load functions work fine. However, when I try to call SwitchController() I get indefinitely stuck. On the other hand, if I comment the SwitchController part and call it through the service, it works perfectly.

Can I ask what I am doing wrong?

pucciland95 commented 1 year ago

TLDR: you can use SwitchController only from its respective service.

Ok, after looking at the source code, I think what I was trying to do was no feasible.

Basically SwitchController() requires to be launched in a parallel thread wrt the main loop that calls for Update().

Therefore it is not feasible to start ros_controllers with the switch function after loading them.

In my opinion this is not very intuitive since the method SwitchController() is public and can be used without invoking the service.

I would open a pull request about this but I would like to know the opinion of the authors first.

Cheers