Empty service call is not executed
I implemented the basic empty service as proposed by the tutorial in my program:
bool callback(std_srvs::Empty::Request& request, std_srvs::Empty::Response& response) {
return true;
}
ros::NodeHandle * privateNodeHandle;
int main(int argc, char **argv) {
ros::init(argc, argv, node_name);
ros::NodeHandle n;
privateNodeHandle = new ros::NodeHandle("~");
privateNodeHandle->param("publishFrequency", publishFrequency, 1.0);
privateNodeHandle->param("maximumWaterLevel", maximumWaterLevel, 1.0);
ros::Publisher water_level_pub = n.advertise<std_msgs::float64>(
topic, 1000);
ros::ServiceServer service = n.advertiseService("my_service", callback);
ros::Rate loop_rate(publishFrequency);
tank = new WaterTank(maximumWaterLevel);
int count = 0;
while (ros::ok()) {
std_msgs::Float64 msg;
std::stringstream ss;
ss << "Water level at " << count << " is " << tank->get_water_level();
msg.data = tank->get_water_level();
ROS_INFO("%s", ss.str().c_str());
water_level_pub.publish(msg);
loop_rate.sleep();
++count;
}
delete tank;
delete privateNodeHandle;
return 0;
}
It compiles fine and I see the service with rosservice list
. But when I try to call it rosservice call /my_service
rosservice seems to wait for the service to finish and never returns. This is weird since it is a service with empty parameter and return signature. I also added some debug output to the callback and it seems like it never gets executed. Is there some service blocking part in my main loop?
are you able to see your service in
rosservice list
?Yes it is listed by
rosservice list