Comments (19)
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.
@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.
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.
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 suspectros2_message_converter
was forked from an outdated version ofrospy_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.
@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.
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.
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.
I'm willing to accept pull requests for this, but there has been nobody stepping up so far.
from rospy_message_converter.
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.
Do you have code which shows the solution you tried? Maybe I can help @yfedi
from rospy_message_converter.
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.
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.
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.
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.
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.
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.
Any update on this PR #56 ?
from rospy_message_converter.
I discovered functionality for conversion to and between Python dictionaries (& consequently JSON) seem to be present in rosidl_runtime_py
:
Honestly, ROS2's Documentation is a mess.
from rospy_message_converter.
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)
- Release into Lunar + Melodic HOT 7
- Test failed HOT 2
- Cannot import roslib.message HOT 6
- String data becomes binary after "convert_dictionary_to_ros_message" HOT 2
- Installation fails with pip3 HOT 10
- Support for custom messages HOT 1
- String conversion to bytes breaks python3 std_msgs/String implementation HOT 2
- Noetic release HOT 1
- Missing field or wrong type field during conversion
- latest version can't handle numpy.float64 HOT 4
- latest version can't use 0/1 as bool HOT 3
- Are uint8[] arrays converted to strings? HOT 10
- time as float HOT 1
- ROS message type "std_msgs/String" has no field named "StrSys" HOT 1
- Output is too verbose when using strict_mode=false HOT 3
- How to convert the nested JSON msg to ros msg ? HOT 6
- catkin_make failed with error: invalid command 'rospy_message_converter' HOT 2
- How to send a Twist message HOT 1
- No way to send dictionary which doesn't have 'data' as a key HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rospy_message_converter.