Giter VIP home page Giter VIP logo

Comments (19)

relffok avatar relffok commented on August 15, 2024 6

I forked and ported this to foxy (also for MiR support) a while ago as well and didn't see this conversation. I just opened a PR. I hope someone can find something useful in it or maybe give feedback on it: #56

from rospy_message_converter.

bbferka avatar bbferka commented on August 15, 2024 2

@ljaniec good find; I tested this package today; seems to work fine, except for timestamps; I've opened a PR for that (mehmetkillioglu/ros2_message_converter#1) ;

from rospy_message_converter.

mehmetkillioglu avatar mehmetkillioglu commented on August 15, 2024 1

Thank you for finding my repository and opening a PR. I will soon update and test the codes. The main use-case for my fork is to handle messages during communication with MiR100 mobile robot, which has a ROS1 based "rosbridge_suite" acting as a WebSocket server. I will update the package to be more generic and not specifically for our use case.

from rospy_message_converter.

mintar avatar mintar commented on August 15, 2024 1

The ros2_message_converter package is just a fork of rospy_message_converter (without attribution), with relatively minor changes. I think it would be better to integrate it into a new ros2 branch of rospy_message_converter instead of having two separate repositories. I would be willing to review and accept a pull request; however, there are some code quality issues with ros2_message_converter that have to be addressed first:

  • All the tests were removed. Instead, they should be converted to ROS2 and verified to work. The tests are one of the most valuable parts of this repo.
  • rospy_message_converter carefully avoids depending on Numpy, but supports it if installed.
  • Some recent additions to rospy_message_converter are missing. I suspect ros2_message_converter was forked from an outdated version of rospy_message_converter, but it's impossible to tell which one because the git history was destroyed.

In summary, I guess it's easier to start with the current state of rospy_message_converter and redo the changes necessary to work with ROS2 than to take ros2_message_converter and port all the updates to rospy_message_converter since the fork happened.

from rospy_message_converter.

mintar avatar mintar commented on August 15, 2024 1

@ljaniec : You can help by testing the PR and reviewing the code, documenting what works and what doesn't and submitting bugfixes. I won't have time before the end of January unfortunately.

from rospy_message_converter.

mintar avatar mintar commented on August 15, 2024

Sorry for the late reply, I'm super busy at the moment. ROS2 support would be awesome, and I would be glad to merge PRs to that effect! It's probably best if you open the PR against the master branch at first; I'll create a ros2 or eloquent branch before merging.

from rospy_message_converter.

nyxaria avatar nyxaria commented on August 15, 2024

Hi, is there any update on this? It would be great to have this functionality.

See these for implementation ideas:

ros2/ros2#857 (comment)
https://answers.ros.org/question/359681/generic-subscriber-in-ros2/
https://answers.ros.org/question/346810/ros2-python-add-arguments-to-callback/
https://stackoverflow.com/questions/13303100/how-to-access-the-class-variable-by-string-in-python

from rospy_message_converter.

mintar avatar mintar commented on August 15, 2024

I'm willing to accept pull requests for this, but there has been nobody stepping up so far.

from rospy_message_converter.

yfedi avatar yfedi commented on August 15, 2024

Hello all,

I did some research and tried to port this solution to ROS2.
So, I have a solution, but it doesn't work for all scenarios. In ROS2 we are not allowed to create field names in msg file with uppercase(ros2/rosidl#25), so if JSON has fields with uppercase(e.g. {"Test":"data"}), convertation to ROS2 msg will fail.
In ROS1 we don't have such restriction and we are able to create field name "Test".

So far, I don't see "easy" solution for this .

BR,
Yuriy

from rospy_message_converter.

nyxaria avatar nyxaria commented on August 15, 2024

Do you have code which shows the solution you tried? Maybe I can help @yfedi

from rospy_message_converter.

mintar avatar mintar commented on August 15, 2024

In ROS2 we are not allowed to create field names in msg file with uppercase(ros2/rosidl#25), so if JSON has fields with uppercase(e.g. {"Test":"data"}), convertation to ROS2 msg will fail.

That shouldn't be a problem. rospy_message_converter fills out ROS message fields from a JSON dictionary; if the message doesn't have a matching field for some key in the dict, conversion fails. So for example, if I have a dict like {"Test":"data"} and try to convert it into a geometry_msgs/Point, conversion will fail because Point doesn't have a field called Test. So it doesn't matter if the field Test just isn't present in the message definition, or if it's even impossible to specify uppercase field names. All that matters is that the field isn't present, so conversion fails (as expected).

from rospy_message_converter.

yfedi avatar yfedi commented on August 15, 2024

Let's imagine the next situation, where we have a predefined JSON structure and this JSON is received in ROS2. So I would like to use ROS2 msg inside ROS instead of JSON string, as this message should be spread to different nodes.

If we have predefined JSON like "{"test_fieldname": "name"}", so we can create custom ROS2 msg test_msgs/TestMsg: string test_fieldname
In this situation, we are able to fill out ROS message fields from a JSON dictionary:

json_str = '{"test_fieldname": "name"}'
message = json_message_converter.convert_json_to_ros_message('test_msgs/TestMsg', json_str) 

But what if the JSON structure has a field names like testFieldname? We are not allowed to create custom ROS2 msg test_msgs/TestMsg: string testFieldname and we can't converse this JSON to ROS2 msg using rospy_message_converter.

Sure, we have different solutions for this, like changing JSON field names to lowercase or parse JSON messages and fill the ROS2 msg field by field. But those methods are not so great as the solution provided by rospy_message_converter

from rospy_message_converter.

mintar avatar mintar commented on August 15, 2024

The convention for ROS message fields has always been that they should be lower case: http://wiki.ros.org/ROS/Patterns/Conventions#Messages. I'm glad that ROS2 finally enforces that. So yes, you're right, you'll have to change the JSON field names. But that's much better than creating a ROS message definition that is not standards compliant.

from rospy_message_converter.

dheera avatar dheera commented on August 15, 2024

Here's what I do for converting ROS2 messages to JSON.

#!/usr/bin/env python3

import numpy as np
import array

def ros2dict(msg):
    if type(msg) in (str, bool, int, float):
        return msg

    output = {}
    for field in msg.get_fields_and_field_types():
        value = getattr(msg, field)
        if type(value) in (str, bool, int, float):
            output[field] = value

        elif type(value) is list:
            output[field] = [ros2dict(el) for el in value]

        elif type(value) in (np.ndarray, array.array):
            output[field] = [ros2dict(el) for el in value.tolist()]

        else:
            output[field] = ros2dict(value)

    return output

if __name__ == "__main__":
    print("Path")
    from nav_msgs.msg import Path
    print(ros2dict(Path()))
    print("NavSatFix")
    from sensor_msgs.msg import NavSatFix
    print(ros2dict(NavSatFix()))
    print("Int32MultiArray")
    from std_msgs.msg import Int32MultiArray
    print(ros2dict(Int32MultiArray()))

from rospy_message_converter.

ljaniec avatar ljaniec commented on August 15, 2024

I have found this repository with the update of this package to ROS 2. Maybe you could contact with it's author (@mehmetkillioglu) for PR + possible updates and debug?

from rospy_message_converter.

marshallpt avatar marshallpt commented on August 15, 2024

Chiming in to say I've also begun using the ros2_message_converter. I also ran into the timestamp issue @bbferka mentioned, so I forked that fix. I then ran into an issue with the uint8[] field type, which I addressed in my fork.

from rospy_message_converter.

ljaniec avatar ljaniec commented on August 15, 2024

Any update on this PR #56 ?

from rospy_message_converter.

Interpause avatar Interpause commented on August 15, 2024

I discovered functionality for conversion to and between Python dictionaries (& consequently JSON) seem to be present in rosidl_runtime_py:

https://github.com/ros2/rosidl_runtime_py/blob/1979f566c3b446ddbc5c3fb6896e1f03ccbc6a27/rosidl_runtime_py/set_message.py#L28-L37

https://github.com/ros2/rosidl_runtime_py/blob/1979f566c3b446ddbc5c3fb6896e1f03ccbc6a27/rosidl_runtime_py/convert.py#L159-L176

Honestly, ROS2's Documentation is a mess.

from rospy_message_converter.

mintar avatar mintar commented on August 15, 2024

I have just finished converting uos/rospy_message_converter to ROS2 and released it (as rclpy_message_converter) to ROS2 foxy, galactic, humble and rolling. It should be available as binary package after the next sync.

from rospy_message_converter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.