ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

[ROS2][dashing] is there any roslibpy-like lib for ros2 frontend? [closed]

asked 2020-02-03 18:42:34 -0500

lin404 gravatar image

updated 2020-02-04 17:53:36 -0500

I am looking for a way for a non-ROS machine (my local computer) to access the ROS2 robot(Rasberry pi) to, for example, call the service. Is there any method to do so? I found a similar post, but it's about a year ago.

Since I confirmed that both ros-dashing-rosbridge-server and tf2 are already available in ROS2, I tried to use roslibpy. Seems it can connect to the ros2 without any problem. I am wondering if it is the proper way to use roslibpy for my purpose?

Below is what I did, however, I got FieldTypeMismatchException error.

I followed the online examples to create a service '/set_ludicrous_speed', 'std_srvs/srv/SetBool'.

import roslibpy

def handler(request, response):
    print('Setting speed to {}'.format(request['data']))
    response['success'] = True
    return True

client = roslibpy.Ros(host='10.3.xxx.xxx', port=9090)

service = roslibpy.Service(client, '/set_ludicrous_speed', 'std_srvs/srv/SetBool')
service.advertise(handler)
print('Service advertised.')

client.run_forever()
client.terminate()

While, when I try to call the service like below:

import roslibpy

client = roslibpy.Ros(host='10.3.xxx.xxx', port=9090)
client.run()

service = roslibpy.Service(client, '/set_ludicrous_speed', 'std_srvs/srv/SetBool')
request = roslibpy.ServiceRequest({'data': True})

result = service.call(request)
print('Service response: {}'.format(result))

client.terminate()

I got error like this, but I can see the node is connected and the service is created:

[INFO] [rosbridge_websocket]: Client disconnected. 0 clients total.
[INFO] [rosbridge_websocket]: Client connected. 1 clients total.
[INFO] [rosbridge_websocket]: [Client 1] Advertised service /set_ludicrous_speed.
[INFO] [rosbridge_websocket]: Client connected. 2 clients total.
[ERROR] [rosbridge_websocket]: [Client 2] [id: call_service:/set_ludicrous_speed:1] call_service FieldTypeMismatchException: std_srvs/SetBool_Request message requires a boolean for field data, but got a <class 'bool'>

Any idea what did I miss? Thank you very much.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by lin404
close date 2020-02-11 04:31:38.258033

Comments

You tagged this ros2 and dashing. Afaik, roslibpy and rosbridge are ROS 1 libraries/nodes.

Could you please clarify?

gvdhoorn gravatar image gvdhoorn  ( 2020-02-04 04:42:26 -0500 )edit

@gvdhoorn I am sorry for the confusion. Actually, I need a frontend (ideally in python) to access ROS2-dashing env. Then I found this post. It mentioned Robot web tool and rosbridge_suite. Since seems both ros-dashing-rosbridge-server and tf2 are already available in ROS2, so I thought maybe I could use roslibpy to access the ROS2 dashing. Seems my whole approach was wrong. >.<

I have changed my question. Thank you.

lin404 gravatar image lin404  ( 2020-02-04 06:02:12 -0500 )edit

Seems my whole approach was wrong. >.<

Well, I'm not saying that's the case, I just wanted to make sure I understood the context correctly.

gvdhoorn gravatar image gvdhoorn  ( 2020-02-04 07:05:49 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-02-07 02:15:53 -0500

lin404 gravatar image

I SOLVED it!
Sum up, roslibpy can be used to connect to a ROS2 machine, as well as rosbridge.
FieldTypeMismatchException here is just a bug in rosbridge. It's caused by python version (>3).
Here is my commit to the bug.
A small bug, very simple to fix, but cost me much time to find it.

edit flag offensive delete link more

Comments

1

Nice.

Thanks for reporting, investigating and fixing it!

gvdhoorn gravatar image gvdhoorn  ( 2020-02-07 02:47:29 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-02-03 18:42:34 -0500

Seen: 763 times

Last updated: Feb 07 '20