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

lin404's profile - activity

2022-09-05 11:10:50 -0500 received badge  Nice Question (source)
2021-12-29 13:59:42 -0500 received badge  Student (source)
2021-04-20 09:18:27 -0500 received badge  Famous Question (source)
2021-04-09 12:38:31 -0500 received badge  Famous Question (source)
2020-09-01 10:25:04 -0500 received badge  Famous Question (source)
2020-05-01 19:28:13 -0500 received badge  Famous Question (source)
2020-04-17 04:22:54 -0500 received badge  Popular Question (source)
2020-04-17 04:22:54 -0500 received badge  Notable Question (source)
2020-04-06 21:30:27 -0500 received badge  Notable Question (source)
2020-04-06 11:12:47 -0500 received badge  Famous Question (source)
2020-03-25 16:57:16 -0500 received badge  Famous Question (source)
2020-03-04 07:36:41 -0500 received badge  Notable Question (source)
2020-02-07 20:36:01 -0500 received badge  Teacher (source)
2020-02-07 20:36:01 -0500 received badge  Self-Learner (source)
2020-02-07 02:47:21 -0500 marked best answer [ROS2][dashing] is there any roslibpy-like lib for ros2 frontend?

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.

2020-02-07 02:47:12 -0500 received badge  Notable Question (source)
2020-02-07 02:15:53 -0500 answered a question [ROS2][dashing] is there any roslibpy-like lib for ros2 frontend?

I SOLVED it! Sum up, roslibpy can be used to connect to a ROS2 machine, as well as rosbridge. FieldTypeMismatchExcepti

2020-02-05 23:22:57 -0500 commented answer ROS2 : How to call a service from the callback function of a subscriber ?

@Marc Testier The key issue is that calling a service synchronously from within a subscriber callback is usually not

2020-02-05 18:18:00 -0500 commented answer How to get ROS2 parameter hosted by another Node

@marguedas Thanks for your help a lot!

2020-02-05 18:16:44 -0500 marked best answer [ROS2][rclpy] how to set parameter hosted by another Node via service

I am looking for a solution to set the Parameter which is host by another node using rclpy.

I found there is a relavent post, but in rclcpp.

While, I tried below. But the error occurred. Any idea how I can fix it? Thank you very much!

import time

import rclpy
from rclpy.node import Node
import rclpy.qos as qos

from rclpy.parameter import Parameter
# from rcl_interfaces.msg import Parameter
from rcl_interfaces.msg import ParameterValue
from rcl_interfaces.srv import SetParameters, GetParameters, ListParameters
from rcl_interfaces.msg import ParameterDescriptor, ParameterValue


class MinimalClientAsync(Node):

    def __init__(self):
        super().__init__('my_node')

        self.cli = self.create_client(SetParameters, '/another_node/set_parameters')
        while not self.cli.wait_for_service(timeout_sec=1.0):
            self.get_logger().info('service not available, waiting again...')
        self.req = SetParameters.Request()

    def send_request(self):
        self.req.parameters = [Parameter(name='parameter_1', value=13)]
        self.future = self.cli.call_async(self.req)


def main(args=None):
    rclpy.init(args=args)

    minimal_client = MinimalClientAsync()
    minimal_client.send_request()

    while rclpy.ok():
        rclpy.spin_once(minimal_client)
        if minimal_client.future.done():
            try:
                response = minimal_client.future.result()
            except Exception as e:
                minimal_client.get_logger().info(
                    'Service call failed %r' % (e,))
            break

    minimal_client.destroy_node()
    rclpy.shutdown()


if __name__ == '__main__':
    main()

The error is:

  File "/opt/ros/dashing/lib/python3.6/site-packages/rcl_interfaces/srv/_set_parameters.py", line 138, in parameters
    "The 'parameters' field must be a set or sequence and each value of type 'Parameter'"
AssertionError: The 'parameters' field must be a set or sequence and each value of type 'Parameter'

I also tried to use rcl_interfaces.msg.Parameter instead of rclpy.parameter.Parameter so it won't failed at rcl_interfaces/srv/_set_parameters.py. However it failed at rcl_interfaces/msg/_parameter.py this time:

  File "/opt/ros/dashing/lib/python3.6/site-packages/rcl_interfaces/msg/_parameter.py", line 80, in __init__
    self.value = kwargs.get('value', ParameterValue())
  File "/opt/ros/dashing/lib/python3.6/site-packages/rcl_interfaces/msg/_parameter.py", line 149, in value
    "The 'value' field must be a sub message of type 'ParameterValue'"
AssertionError: The 'value' field must be a sub message of type 'ParameterValue'

Then I kept trying, used ParameterValue, like this:

Parameter(name='parameter_1', value=ParameterValue(integer_value=3))

It did not cause any error, but when I check the param, it shows Parameter not set.. I am confused. The parameter parameter_1 seems to be undeclared.

2020-02-05 18:16:32 -0500 received badge  Commentator
2020-02-05 18:16:32 -0500 commented answer [ROS2][rclpy] how to set parameter hosted by another Node via service

@marguedas Thank you very much! I have confirmed it, it works perfect!

2020-02-05 18:15:42 -0500 edited question [ROS2][rclpy] how to set parameter hosted by another Node via service

[ROS2][rclpy] how to set parameter hosted by another Node via service I am looking for a solution to set the Parameter w

2020-02-05 10:22:17 -0500 received badge  Popular Question (source)
2020-02-05 02:25:54 -0500 edited question [ROS2][rclpy] how to set parameter hosted by another Node via service

[ROS2][rclpy] how to set parameter hosted by another Node via service I am looking for a solution to set the Parameter w

2020-02-05 01:53:45 -0500 edited question [ROS2][rclpy] how to set parameter hosted by another Node via service

[ROS2][rclpy] how to set parameter hosted by another Node via service I am looking for a solution to set the Parameter w

2020-02-05 01:53:28 -0500 edited question [ROS2][rclpy] how to set parameter hosted by another Node via service

[ROS2][rclpy] how to set parameter hosted by another Node via service I am looking for a solution to set the Parameter w

2020-02-05 01:20:01 -0500 edited question [ROS2][rclpy] how to set parameter hosted by another Node via service

[ROS2][rclpy] how to set parameter hosted by another Node by calling service I am looking for a solution to set the Para

2020-02-05 01:19:44 -0500 edited question [ROS2][rclpy] how to set parameter hosted by another Node via service

[ROS2][rclpy]set parameter hosted by another Node by calling service I am looking for a solution to set the Parameter wh

2020-02-05 01:19:25 -0500 edited question [ROS2][rclpy] how to set parameter hosted by another Node via service

SetParameters I am looking for a solution to set the Parameter which is host by another node using rclpy. I found there

2020-02-05 01:09:44 -0500 asked a question [ROS2][rclpy] how to set parameter hosted by another Node via service

SetParameters I am looking for a solution to set the Parameter which is host by another node using rclpy. I found there

2020-02-05 00:17:44 -0500 commented answer How to get ROS2 parameter hosted by another Node

@marguedas I tried it with rclpy, but no luck. Do you mind to give me a sample in python for this? Also, seems there is

2020-02-04 17:53:36 -0500 edited question [ROS2][dashing] is there any roslibpy-like lib for ros2 frontend?

[ROS2][dashing] is there any roslibpy-like lib for ros2 frontend? I am looking for a way for a non-ROS machine (my local

2020-02-04 09:56:57 -0500 received badge  Popular Question (source)
2020-02-04 06:22:11 -0500 commented question [ROS2][dashing] is there any roslibpy-like lib for ros2 frontend?

@gvdhoorn I am sorry for the confusion. Actually, I need a frontend (ideally in python) to access ROS2-dashing env. Then

2020-02-04 06:21:16 -0500 commented question [ROS2][dashing] is there any roslibpy-like lib for ros2 frontend?

@gvdhoorn I am sorry for the confusion. Actually, I need a frontend (ideally in python) to access ROS2-dashing env. Then

2020-02-04 06:20:50 -0500 commented question [ROS2][dashing] is there any roslibpy-like lib for ros2 frontend?

@gvdhoorn I am sorry for the confusion. Actually, I need a frontend (ideally in python) to access ROS2-dashing env. Then

2020-02-04 06:20:35 -0500 commented question [ROS2][dashing] is there any roslibpy-like lib for ros2 frontend?

@gvdhoom I am sorry for the confusion. Actually, I need a frontend (ideally in python) to access ROS2-dashing env. Then

2020-02-04 06:19:58 -0500 edited question [ROS2][dashing] is there any roslibpy-like lib for ros2 frontend?

[ROS2][dashing] is there any roslibpy like lib for ros2 frontend? I am looking for a way for a non-ROS machine (my local

2020-02-04 06:18:27 -0500 edited question [ROS2][dashing] is there any roslibpy-like lib for ros2 frontend?

[ROS2][dashing] is there any roslibpy like lib for ros2 frontend? I am looking for a way for a non-ROS machine (my local

2020-02-04 06:04:39 -0500 edited question [ROS2][dashing] is there any roslibpy-like lib for ros2 frontend?

[ROS2][Python]roslibpy FieldTypeMismatchException when call 'std_srvs/srv/SetBool' type service I followed the online ex