ros-drivers / rosserial

A ROS client library for small, embedded devices, such as Arduino. See: http://wiki.ros.org/rosserial
517 stars 525 forks source link

rosserial_windows service client has some problem? #545

Open Camixxx opened 3 years ago

Camixxx commented 3 years ago

It seems that client.call have some problem

 roscpp_tutorials::TwoInts::Request req;
  roscpp_tutorials::TwoInts::Response res;
  ros::ServiceClient <roscpp_tutorials::TwoInts::Request, roscpp_tutorials::TwoInts::Response>
      client("/add_two_ints");
  req.a = int64_t(3);
  req.b = int64_t(4);
  nh.serviceClient(client);
  client.call(req, res);

I found it didn't work. In serviceclient, the pub.nh->connected() is false.

  virtual void call(const MReq & request, MRes & response)
  {
    if (!pub.nh_->connected()) return;
    ret = &response;
    waiting = true;
    pub.publish(&request);
    while (waiting && pub.nh_->connected())
      if (pub.nh_->spinOnce() < 0) break;
  }

So I change my code as below:

 roscpp_tutorials::TwoInts::Request req;
  roscpp_tutorials::TwoInts::Response res;
  ros::ServiceClient <roscpp_tutorials::TwoInts::Request, roscpp_tutorials::TwoInts::Response>
      client("/add_two_ints");
  req.a = int64_t(3);
  req.b = int64_t(4);
  nh.serviceClient(client);
    nh.serviceClient(client);
    //client.call(req, res);
    client.ret = &res;
    client.waiting = true;
    client.pub.publish(&req);
    while (client.waiting) {
        printf("=========");
        if (client.pub.nh_->spinOnce() < 0)
            break;

    }

Then the terminal have such log infos:

rosrun rosserial_server socket_node
[ INFO] [1611535710.993019300]: Listening for rosserial TCP connections on port 11411
[ INFO] [1611535838.401030000]: waitForService: Service [/service_info] has not been advertised, waiting...
[ WARN] [1611535843.415169100]: Timed out waiting for service_info service to become available.
[ WARN] [1611535843.417027600]: Failed to call service_info service. The service client will be created with blank md5sum.
[ WARN] [1611535843.418184600]: Service client setup: Request message MD5 mismatch between rosserial client and ROS
[ WARN] [1611535843.419765800]: Service client setup: Response message MD5 mismatch between rosserial client and ROS

I try to run the <node pkg="rosserial_python" type="message_info_service.py" name="rosserial_message_info"

and it works. But the result is wrong and still have logs warning.

===

ROS_WARN("Received message with unrecognized topicId (%d).", topic_id);
        // TODO: Resynchronize on multiples?

Tested in both ros-kinetic(linux) and ros-melodic(win). rosserial_server version: 0.8.0 visual studio 2019

lidonghui-ai commented 2 years ago

I have met the same problem, can I ask you how you solve it?