Call service from arduino?
Hi,
I am trying to call a ROS service to turn on/off relays from an arduino. The service works from the command line and also from a python service client call. How do I call a service from an arduino?
The relay service message is:
int32 channel
bool state
---
bool success
I made the ros_lib library and the new service is listed.
rosrun rosserial_client make_libraries .
How do you call the service?
#include <WProgram.h>
#include "ros.h"
#include <ros/service_client.h>
#include "turtlebot/relayCmd.h"
ros::NodeHandle nh;
ros::ServiceClient<turtlebot::relayCmd::Request, turtlebot::relayCmd::Response> client("/relay_cmd");
turtlebot::relayCmd::Request relay_request;
turtlebot::relayCmd::Response response;
void setup() {
nh.initNode();
nh.getHardware()->setBaud(57600);
while (!nh.connected())
{
nh.spinOnce();
}
nh.loginfo("Teensy is connected");
delay(1);
}
void loop() {
relay_request.channel = 2;
relay_request.state = 1;
response.success = false;
nh.loginfo("Calling relay server");
if ( client.call(relay_request, response) ) {
nh.loginfo("service callback true");
}
delay(1000);
}
Error Message during compiling:
Compiling .pioenvs/teensy31/src/main.cpp.o
src/main.cpp: In function 'void loop()':
src/main.cpp:42:21: error: could not convert 'client.ros::ServiceClient<MReq, MRes>::call<turtlebot::relayCmdRequest, turtlebot::relayCmdResponse>(relay_request, response)' from 'void' to 'bool'
if ( client.call(relay_request, response) ) {