ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
I believe the issue here is that you're supplying the service name to advertiseService(..)
.
According to the code of that function, it only accepts a reference to a ServiceServer
instance, similar to how you advertise(..)
a Publisher
or Subscriber
(see here).
The prototype of advertiseService(..)
is actually:
template<class MReq, class MRes, class ObjT>
bool ros::NodeHandle_<Hardware, MAX_SUBSCRIBERS, MAX_PUBLISHERS, INPUT_SIZE, OUTPUT_SIZE>::advertiseService(ros::ServiceServer<MReq, MRes, ObjT>&)
Note there is no char[]
or std::string
in there anywhere.
To initialise the service server the code should probably be something like:
#include <ros.h>
#include <Arduino.h>
#include <std_srvs/Empty.h>
// Create roscpp's interface for creating subscribers, publishers, etc
ros::NodeHandle n;
// Create a service server that takes nothing and returns nothing
void callback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
{
// Simulate function running for a non-deterministic amount of time
delay(random(5,70));
}
ros::ServiceServer<std_srvs::Empty::Request, std_srvs::Empty::Response> service("get_nothing", &callback);
void setup()
{
// Initialize node
n.initNode();
n.advertiseService(service);
}
void loop()
{
n.spinOnce();
delay(1000);
}
Note the use of advertiseService(..)
in the setup()
function, and the declaration of service
with the service name and the callback.
2 | No.2 Revision |
I believe the issue here is that you're supplying the service name to advertiseService(..)
.
According to the code of that function, it only accepts a reference to a ServiceServer
instance, similar to how you advertise(..)
a Publisher
or Subscriber
in rosserial
(see here).
The prototype of advertiseService(..)
is actually:
template<class MReq, class MRes, class ObjT>
bool ros::NodeHandle_<Hardware, MAX_SUBSCRIBERS, MAX_PUBLISHERS, INPUT_SIZE, OUTPUT_SIZE>::advertiseService(ros::ServiceServer<MReq, MRes, ObjT>&)
Note there is no char[]
or std::string
in there anywhere.
To initialise the service server the code should probably be something like:
#include <ros.h>
#include <Arduino.h>
#include <std_srvs/Empty.h>
// Create roscpp's interface for creating subscribers, publishers, etc
ros::NodeHandle n;
// Create a service server that takes nothing and returns nothing
void callback(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
{
// Simulate function running for a non-deterministic amount of time
delay(random(5,70));
}
ros::ServiceServer<std_srvs::Empty::Request, std_srvs::Empty::Response> service("get_nothing", &callback);
void setup()
{
// Initialize node
n.initNode();
n.advertiseService(service);
}
void loop()
{
n.spinOnce();
delay(1000);
}
Note the use of advertiseService(..)
in the setup()
function, and the declaration of service
with the service name and the callback.