DFKI-NI / rospy_message_converter

Converts between Python dictionaries and JSON to ROS messages.
BSD 3-Clause "New" or "Revised" License
226 stars 101 forks source link

How to send a Twist message #65

Open vbelkina opened 1 year ago

vbelkina commented 1 year ago

Hello,

I am wondering if you could give an example of formatting the JSON to send a Twist message.

Thank you!

danielcranston commented 11 months ago

I assume you're asking about the required format (data layout) of the JSON string in order to create a Twist message.

To answer these kinds of questions you can always "go the opposite direction": take a arbitrarily instantiated Twist message (or whatever ROS message you're interested in) and convert it to JSON:

>>> from geometry_msgs.msg import Twist
>>> from rospy_message_converter import json_message_converter
>>> json_message_converter.convert_ros_message_to_json(Twist())
'{"linear": {"x": 0.0, "y": 0.0, "z": 0.0}, "angular": {"x": 0.0, "y": 0.0, "z": 0.0}}'

Likewise for convert_ros_message_to_dictionary obviously.