Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to call a ROS2 service from Zenoh #249

Open
sumitpaulde opened this issue Sep 5, 2024 · 7 comments
Open

Unable to call a ROS2 service from Zenoh #249

sumitpaulde opened this issue Sep 5, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@sumitpaulde
Copy link

sumitpaulde commented Sep 5, 2024

Describe the bug

I am using 2 physical machines.
node1 host ROS2 service
node2 host Zenoh client

Both running zenoh_bridge_ros2dds to establish communication between nodes.

ROS2 service requires a simple string as its service call.
Service description

string taskname
---
string response

But I am trying to call the service with zenoh

@cdr
class Request:
       taskname: str

request_data = Request(taskname='ooo').serialize()
resource_name = "set_task_service"
for reply in session.get(resource_name, zenoh.Queue(), value=request_data):
    try:
        print(f"Received '{reply.ok.key_expr}': '{reply.ok.payload.decode('utf-8')}'")
    except:
        print(f"Received ERROR: '{reply.err.payload.decode('utf-8')}'")

the client request is not reaching to the ROS2 service server.

 rx-2 ThreadId(20) zenoh_plugin_ros2dds::route_service_srv: Route Service Server (ROS:/set_task_service <-> Zenoh:set_task_service): received invalid request: [7b, 22, 74, 61, 73, 6b, 6e, 61, 6d, 65, 22, 3a, 20, 22, 62, 6c, 61, 62, 6c, 61, 22, 7d]

The ros2 service code

#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from hare_robot_interfaces.srv import SetTask
from functools import partial

class SetTaskCleintNode(Node):
    
    def __init__(self):
        super().__init__("set_task_client")
        for x in range(10):
            self.call_set_task_service("image detection " + str(x))
    
        
    def call_set_task_service(self, value1):
        
        client = self.create_client(SetTask, "set_task_service")
        while not client.wait_for_service(1.0):
            self.get_logger().warn("Waiting for servers response!!")
        request = SetTask.Request()
        request.taskname = value1
        
        future = client.call_async(request)
     
        future.add_done_callback(partial(self.callback_call_set_task, value1 = value1))
    
    def callback_call_set_task(self, future, value1):
        try:
            response = future.result()
            self.get_logger().info("task send: " + value1 + " received " + response)
            
        except Exception as e:
            self.get_logger().error("Service call failed %r" % (e,))

                  
def main(args=None):
    rclpy.init(args= args)
    node = SetTaskCleintNode()
    rclpy.spin(node)
    rclpy.shutdown()
    
if __name__ == "__main__":
    main()

To reproduce

to reproduce you can use the ROS2 service running on one machine and try to send the server the request from zenoh.

System info

Ubuntu 22.04 arm 64
zenoh-bridge-ros2dds v0.11.0-dev-127-gb147cc7

@sumitpaulde sumitpaulde added the bug Something isn't working label Sep 5, 2024
@Mallets Mallets transferred this issue from eclipse-zenoh/zenoh Sep 9, 2024
@TanJunKiat
Copy link

Are you using ROS2 humble?

@sumitpaulde
Copy link
Author

Ya I am using ROS2 humble

@JEnoch
Copy link
Member

JEnoch commented Sep 30, 2024

I think #277 might fix this.
Could you please test again with latest commit (1aaa0c6) ?

@sumitpaulde
Copy link
Author

Hi @JEnoch,
Thanks a lot for replying!

I have tried the latest commit; the problem is the previous error is gone, but there is no communication happening between the zenoh client and ros2 Server. Earlier, after sending the service call from the zenoh client, the zenoh_bridge_ros2dds used to receive data and show some error logs on the terminal; now, even that is not happening.

sample zenoh client code:

import sys
import time
import argparse
import json
import zenoh
from zenoh import config, QueryTarget
from pycdr import cdr

conf = zenoh.Config()
selector = "set_task_service"
target= QueryTarget.ALL()

@cdr
class Request:
       taskname: str


def main():
    zenoh.init_logger()

    print("Opening session...")
    session = zenoh.open(conf)

# here we tried with JSON/ Request Type/ simple string but nothing worked.

# update the JSON data according to your need
#    json_data = {
#        "taskname": "abcabc"}
#    req = json.dumps(json_data).encode('utf-8')

#  req = Request(taskname='abcabc').serialize()

    req = ("abcabc").encode("utf-8")
    print("Sending Query '{}'...".format(selector))
    replies = session.get(selector, zenoh.Queue(), target=target, value=req, consolidation=zenoh.QueryConsolidation.NONE())
    for reply in replies.receiver:
        try:
            print(">> Received ('{}': '{}')"
                .format(reply.ok.key_expr, reply.ok.payload.decode("utf-8")))
        except:
            print(">> Received (ERROR: '{}')"
                .format(reply.err.payload.decode("utf-8")))


    session.close()

main()

On the ros2 service node

zenoh_bridge_ros2dds

On the zenoh client side

zenoh_bridge_ros2dds -e tcp/192.168.1.72:7447

Output from the zenoh_bridge_ros2dds

2024-10-15T15:13:17.082287Z  INFO tokio-runtime-worker ThreadId(03) zenoh_plugin_ros2dds::routes_mgr: Route Service Client (ROS:/set_task_server/list_parameters <-> Zenoh:set_task_server/list_parameters) created
2024-10-15T15:13:17.176353Z  INFO tokio-runtime-worker ThreadId(02) zenoh_plugin_ros2dds: Node /zenoh_bridge_ros2dds declares Service Client /set_task_server/set_parameters: rcl_interfaces/srv/SetParameters - Allowed
2024-10-15T15:13:17.177230Z  INFO tokio-runtime-worker ThreadId(02) zenoh_plugin_ros2dds: Node /zenoh_bridge_ros2dds declares Service Client /set_task_server/describe_parameters: rcl_interfaces/srv/DescribeParameters - Allowed
2024-10-15T15:13:17.177824Z  INFO tokio-runtime-worker ThreadId(02) zenoh_plugin_ros2dds: Node /zenoh_bridge_ros2dds declares Service Client /set_task_service: hare_robot_interfaces/srv/SetTask - Allowed
2024-10-15T15:13:17.178387Z  INFO tokio-runtime-worker ThreadId(02) zenoh_plugin_ros2dds: Node /zenoh_bridge_ros2dds declares Service Client /set_task_server/list_parameters: rcl_interfaces/srv/ListParameters - Allowed
2024-10-15T15:13:17.178771Z  INFO tokio-runtime-worker ThreadId(02) zenoh_plugin_ros2dds: Node /zenoh_bridge_ros2dds declares Service Client /set_task_server/set_parameters_atomically: rcl_interfaces/srv/SetParametersAtomically - Allowed
2024-10-15T15:13:17.179429Z  INFO tokio-runtime-worker ThreadId(02) zenoh_plugin_ros2dds: Node /zenoh_bridge_ros2dds declares Service Client /set_task_server/get_parameters: rcl_interfaces/srv/GetParameters - Allowed
2024-10-15T15:13:17.179787Z  INFO tokio-runtime-worker ThreadId(02) zenoh_plugin_ros2dds: Node /zenoh_bridge_ros2dds declares Service Client /set_task_server/get_parameter_types: rcl_interfaces/srv/GetParameterTypes - Allowed


Kind Regards

@JEnoch
Copy link
Member

JEnoch commented Oct 18, 2024

Can you make sure you're using the same version for the bridge and for zenoh-python.
If still not working, please run your client with RUST_LOG=debug environment variable and provide the logs.

@sumitpaulde
Copy link
Author

sumitpaulde commented Oct 18, 2024

Yeah, I can confirm that I am using the same version, as I built the Docker container on one device and used the same Docker container on the second machine.

So the zenoh-python and zenoh_bridge_ros2dds are same on the both nodes, both nodes are physically with same coniguration as well.

I would like to know Can you make sure you're using the same version for the bridge and for zenoh-python what do you mean by this?

@sumitpaulde
Copy link
Author

Hi @JEnoch, you are right there is some version mismatching I understood from the log, but I do not understand which versions it is speaking about.

2024-10-22T09:51:02.912484Z  INFO tokio-runtime-worker ThreadId(05) zenoh_plugin_ros2dds: Node /zenoh_bridge_ros2dds declares Service Client /set_task_service: hare_robot_interfaces/srv/SetTask - Allowed
2024-10-22T09:51:02.912671Z DEBUG tokio-runtime-worker ThreadId(05) zenoh_plugin_ros2dds::route_service_cli: Route Service Client (ROS:/set_task_service <-> Zenoh:set_task_service): now serving local nodes {"/zenoh_bridge_ros2dds"}
2024-10-22T09:51:02.912845Z DEBUG tokio-runtime-worker ThreadId(05) zenoh_plugin_ros2dds::route_service_cli: Route Service Client (ROS:/set_task_service <-> Zenoh:set_task_service): announce via token @/f9cd6f8e79e88d43aa14144ed271a4ed/@ros2_lv/SC/set_task_service/hare_robot_interfaces§srv§SetTask
2024-10-22T09:51:02.913058Z DEBUG tokio-runtime-worker ThreadId(05) zenoh::net::routing::dispatcher::token: Face{1, f9cd6f8e79e88d43aa14144ed271a4ed} Declare token 36 (@/f9cd6f8e79e88d43aa14144ed271a4ed/@ros2_lv/SC/set_task_service/hare_robot_interfaces§srv§SetTask)
2024-10-22T09:51:02.913279Z DEBUG tokio-runtime-worker ThreadId(05) zenoh::net::routing::dispatcher::resource: Register resource @/f9cd6f8e79e88d43aa14144ed271a4ed/@ros2_lv/SC/set_task_service/hare_robot_interfaces§srv§SetTask
2024-10-22T09:51:29.417185Z DEBUG                acc-0 ThreadId(07) zenoh_link_tcp::unicast: Accepted TCP connection on [::ffff:192.168.1.72]:7447: [::ffff:192.168.1.49]:44038
2024-10-22T09:51:29.417942Z DEBUG                acc-0 ThreadId(07) zenoh_transport::unicast::establishment::accept: Rejecting InitSyn on tcp/[::ffff:192.168.1.72]:7447 => tcp/[::ffff:192.168.1.49]:44038 because of unsupported Zenoh protocol version (expected: 9, received: 8) from: 7f40d4d0775a530447beb7c29002e6ab at /root/.cargo/git/checkouts/zenoh-cc237f2570fab813/e79c800/io/zenoh-transport/src/unicast/establishment/accept.rs:186.
2024-10-22T09:51:30.439713Z DEBUG                acc-0 ThreadId(07) zenoh_link_tcp::unicast: Accepted TCP connection on [::ffff:192.168.1.72]:7447: [::ffff:192.168.1.49]:44050
2024-10-22T09:51:30.440309Z DEBUG                acc-0 ThreadId(07) zenoh_transport::unicast::establishment::accept: Rejecting InitSyn on tcp/[::ffff:192.168.1.72]:7447 => tcp/[::ffff:192.168.1.49]:44050 because of unsupported Zenoh protocol version (expected: 9, received: 8) from: 7f40d4d0775a530447beb7c29002e6ab at /root/.cargo/git/checkouts/zenoh-cc237f2570fab813/e79c800/io/zenoh-transport/src/unicast/establishment/accept.rs:186.
2024-10-22T09:51:32.385476Z DEBUG                acc-0 ThreadId(07) zenoh_link_tcp::unicast: Accepted TCP connection on [::ffff:192.168.1.72]:7447: [::ffff:192.168.1.49]:44908
2024-10-22T09:51:32.386135Z DEBUG                acc-0 ThreadId(07) zenoh_transport::unicast::establishment::accept: Rejecting InitSyn on tcp/[::ffff:192.168.1.72]:7447 => tcp/[::ffff:192.168.1.49]:44908 because of unsupported Zenoh protocol version (expected: 9, received: 8) from: 7f40d4d0775a530447beb7c29002e6ab at /root/.cargo/git/checkouts/zenoh-cc237f2570fab813/e79c800/io/zenoh-transport/src/unicast/establishment/accept.rs:186.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants