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

ROS2: Publish an array with rqt #23

Open
George-Gi opened this issue Feb 12, 2021 · 4 comments
Open

ROS2: Publish an array with rqt #23

George-Gi opened this issue Feb 12, 2021 · 4 comments

Comments

@George-Gi
Copy link

Hi everyone, I have been using rqt to publish messages to test my applications, however I still haven't found a way to publish a message that includes an array.
In my custom message I have a variable size array declared as uint8[]. I notice in rqt that the expected type is "sequence".
I have tried different expressions, but couldn't figure out the correct one. Could someone provide an example please?

@RyanDelGizzi
Copy link

RyanDelGizzi commented Mar 13, 2021

If we assume get_slot_types functions correctly, then my fix here allows us to publish arrays. However, as mentioned in this related ticket, a much larger PR should probably be merged first, before addressing this issue. My fix is not compatible with @mlautman's PR, but I would be happy to resolve the issue against that PR if that is the right thing to do.

If anyone has any guidance on the guidance to help get these changes through, I'll be happy to help where fit.

@wienans
Copy link

wienans commented Jan 10, 2023

As porposed in #34 i tried to compile the rolling release and still got the error

Traceback (most recent call last):
  File "/colcon_ws/install/rqt_publisher/lib/python3.10/site-packages/rqt_publisher/publisher.py", line 158, in change_publisher
    new_text = handler(self._publishers[publisher_id], topic_name, new_value)
  File "/colcon_ws/install/rqt_publisher/lib/python3.10/site-packages/rqt_publisher/publisher.py", line 257, in _change_publisher_expression
    success, _ = self._evaluate_expression(computed_expression, slot_type)
  File "/colcon_ws/install/rqt_publisher/lib/python3.10/site-packages/rqt_publisher/publisher.py", line 376, in _evaluate_expression
    if successful_eval and isinstance(value, slot_type):
TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

after i typed array('I',[1,2,3])
or got this error if i used array.array('I',[1,2,3])

[ERROR] [1673339078.788973249] [get_message_class]: Malformed message_type: sequence<uint32>
Python eval failed for expression "array.array('I',[1,2,3])" with an exception "type object 'array.array' has no attribute 'array'"
Publisher._evaluate_expression(): failed to evaluate expression: "array.array('I',[1,2,3])" as Python type "None"
Traceback (most recent call last):
  File "/colcon_ws/install/rqt_publisher/lib/python3.10/site-packages/rqt_publisher/publisher.py", line 158, in change_publisher
    new_text = handler(self._publishers[publisher_id], topic_name, new_value)
  File "/colcon_ws/install/rqt_publisher/lib/python3.10/site-packages/rqt_publisher/publisher.py", line 274, in _change_publisher_expression
    user_expression, slot_type.__name__)
AttributeError: 'NoneType' object has no attribute '__name__'. Did you mean: '__ne__'?

If i understood the other Issue #34 correctly this should have worked? I am using a UInt32 MultiArray

@baldhat
Copy link

baldhat commented Mar 20, 2023

There is still no way, or at least no documented way on doing this. Can anybody help out?

@egordon
Copy link

egordon commented Apr 11, 2023

Right now there is no way to do this since rqt_publisher does not support the array.array type and the rqt_py_common libraries don't support sequence<X> builtin types. I just submitted #39 to humble to fix the former and bypass the latter.

If you want to use it, strings are represented as normal lists, e.g.: ["joint_1", "joint_2"]
Numerical arrays are represented as array types, e.g.: array('d', [5.5, 4.5]) or array('i', [3, 2]).

See a complete list of numerical typecodes at https://docs.python.org/3/library/array.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants