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

Revision history [back]

click to hide/show revision 1
initial version

Hello sir,

You need to use request responce messages specific to ros_control package, in particular the controller_manager/switch_controller service . These are defined here: https://github.com/ros-controls/ros_control/tree/noetic-devel/controller_manager_msgs/srv

The code then would look something like:

#include "controller_manager_msgs/SwitchController.h"
#include <ros/ros.h>

bool switchController(...){
controller_manager_msgs::SwitchControllerRequest req;
controller_manager_msgs::SwitchControllerResponse res;
//Choose which controller to load/unload
req.start_controllers = ...;
req.stop_controllers = ...;
req.strictness = 1;
req.start_asap = true;
req.timeout = 2.;
ros::service::call("/myrobot/controller_manager/switch_controller", res, req);
return res.ok;
}

Hello sir,

You need to use request responce messages specific to ros_control package, in particular the controller_manager/switch_controller service . These are defined here: https://github.com/ros-controls/ros_control/tree/noetic-devel/controller_manager_msgs/srv

The code then would look something like:

#include "controller_manager_msgs/SwitchController.h"
#include <ros/ros.h>

bool switchController(...){
controller_manager_msgs::SwitchControllerRequest req;
controller_manager_msgs::SwitchControllerResponse res;
//Choose which controller to load/unload
req.start_controllers = ...;
req.stop_controllers = ...;
req.strictness = 1;
req.start_asap = true;
req.timeout = 2.;
ros::service::call("/myrobot/controller_manager/switch_controller", res, req);
&res, &req);
return res.ok;
}

Hello sir,

You need to use request responce messages specific to ros_control package, in particular the controller_manager/switch_controller service . These are defined here: https://github.com/ros-controls/ros_control/tree/noetic-devel/controller_manager_msgs/srv

The code then would look something like:

#include "controller_manager_msgs/SwitchController.h"
#include <ros/ros.h>

bool switchController(...){
controller_manager_msgs::SwitchControllerRequest req;
controller_manager_msgs::SwitchControllerResponse res;
//Choose which controller to load/unload
req.start_controllers = ...;
req.stop_controllers = ...;
req.strictness = 1;
req.start_asap = true;
req.timeout = 2.;
ros::service::call("/myrobot/controller_manager/switch_controller", &res, &req);
res, req);
return res.ok;
}