Issue switching controller in code

asked 2021-03-27 06:40:59 -0500

Steven55555 gravatar image

I am trying to switch the controller in code but it keeps returning false and i don't know why, this is the code:

 ros::ServiceClient switch_controller = n.serviceClient<controller_manager_msgs::SwitchController>("egm/controller_manager/switch_controller");

std::vector<std::string> start_controller;
      start_controller.push_back("joint_group_velocity_controller");
      std::vector<std::string> stop_controller;
      stop_controller.push_back("");
      switch_controller_req.start_controllers = start_controller;
      switch_controller_req.stop_controllers = stop_controller;
      switch_controller_req.strictness = 1;
      switch_controller_req.start_asap = false;
      switch_controller_req.timeout = 0.0;
      ros::service::waitForService("egm/controller_manager/switch_controller", ros::Duration(5));
      success = stop_rapid.call(switch_controller_req,switch_controller_resp);
      if (success)
      {
        ROS_INFO_STREAM("Controller switch correctly");

      }
      else
      {
        ROS_ERROR_STREAM("Error occured trying to switch controller");
        return 0;
      }
edit retag flag offensive close merge delete