Robotics StackExchange | Archived questions

No return from arduino service server

Hello, I just ran in a similar isse like this one.

I configured a service server on my arduino and trying to make a service call from my PC using python. The content inside of my service callback function gets executed properly. However, the service request gets stuck and does not return any kind of response.

A minimal example of my arduino code looks like this:

#define ROSSERIAL_ARDUINO_TCP
#include <ros.h>
#include <std_srvs/Empty.h>
#include <std_msgs/String.h>
#include <rosserial_arduino/Test.h>

// ROS initialization
ros::NodeHandle  nh;
using rosserial_arduino::Test;

ros::ServiceClient<Test::Request, Test::Response> service_client("service_client_name");
Test::Request test_req;
Test::Response test_resp;

void service_callback(const Test::Request & req, Test::Response & res){
// Perform some operations here
}    

ros::ServiceServer<Test::Request, Test::Response> service_server("service_server_name",&service_callback); 

void setup()
{     
 Ethernet.begin(mac, ip);
 // give the Ethernet shield a second to initialize:
 delay(1000);  
 nh.getHardware()->setConnection(server, serverPort);
 nh.initNode();
 nh.advertiseService(service_server);  
 nh.serviceClient(service_client);
 while(!nh.connected()) nh.spinOnce();
}

void loop()
{
 nh.spinOnce();
 delay(10);
}

FYI, the service client is called in another interrupt routine which I have not mentioned in my minimal example.

So using python from y PC, the service gets stuck. However, when I am calling the ervice using the terminal

rosservice call /service_server_name "input: 'some_request'"

everything works fine and I get a proper return message from the arduino.

Any Ideas? Is this a well known bug from rosserial using python?

Asked by nmelchert on 2019-11-13 09:55:09 UTC

Comments

Answers

The rosservice call <service_name> <request> is in fact a python script: https://github.com/ros/ros_comm/blob/melodic-devel/tools/rosservice/src/rosservice/_init_.py

So I would suggest that you are either not in the same network setup with your other python script or you misspelled the used .srv or service_name. There is no point why the ros_comm cli tools work from the same shell and a custom written python client would not.

Maybe you want to check out the new Micro-ROS for ROS2: https://micro-ros.github.io/

rosserial is known to be a bit buggy on Arduinos. At least to my knowledge. Consider upgrading to a more powerful STM32 or Teensy. They have faster clock rates that helps to come up with more complex protocols etc.

You can see here a similar situation where we believed that there was some error between cli and a python client node: https://github.com/micro-ROS/zephyr_apps/issues/4#issuecomment-631409686

In the end it was just a wrong spelled server_name ..

Asked by flo on 2020-05-22 07:49:09 UTC

Comments