My service client script is not working

Nevermind, I found the issue. Turns out that my service client somehow is too fast so I had to put some sleep rate in between to create a delay once the server is created. Somewhere along this line :

#include <ros/ros.h>
#include <std_srvs/Empty.h>

int main(int argc, char **argv) {

  ros::init(argc, argv, "move_bb8_in_circle_service_client");
  ros::NodeHandle nh;

  ros::ServiceClient move_bb8_in_circle_service;

  move_bb8_in_circle_service =
      nh.serviceClient<std_srvs::Empty>("/move_bb8_in_circle");

  std_srvs::Empty srv;

 ros::Rate rate(0.5);

    rate.sleep();

  if (move_bb8_in_circle_service.call(srv)) {
    ROS_INFO("Service client called");
  } else {
    ROS_ERROR("Failed to call /move_bb8_in_circle");
    return 1;
  };

  return 0;
}
1 Like