3 from rospy_message_converter
import message_converter
8 Takes in the message type and a JSON-formatted string and returns a ROS 11 :param message_type: The desired ROS message type of the result 12 :type message_type: str 13 :param json_message: A JSON-formatted string 14 :type json_message: str 15 :param strict_mode: If strict_mode is set, an exception will be thrown if the json message contains extra fields. 16 :type strict_mode: bool, optional 17 :return: A ROS message 18 :rtype: class:`genpy.Message` 21 >>> msg_type = "std_msgs/String" 22 >>> json_msg = '{"data": "Hello, Robot"}' 23 >>> convert_json_to_ros_message(msg_type, json_msg) 26 dictionary = json.loads(json_message)
27 return message_converter.convert_dictionary_to_ros_message(message_type, dictionary, strict_mode=strict_mode)
32 Takes in a ROS message and returns a JSON-formatted string. 34 :param message: A ROS message to convert 35 :type message: class:`genpy.Message` 36 :param binary_array_as_bytes: rospy treats `uint8[]` data as a `bytes`, which is the Python representation for byte 37 data. In Python 2, this is the same as `str`. If this parameter is `False`, all `uint8[]` fields will be 38 converted to `list(int)` instead. 39 :type binary_array_as_bytes: bool, optional 40 :return: A JSON-formatted string 44 >>> import std_msgs.msg 45 >>> ros_message = std_msgs.msg.String(data="Hello, Robot") 46 >>> convert_ros_message_to_json(ros_message) 47 '{"data": "Hello, Robot"}' 49 dictionary = message_converter.convert_ros_message_to_dictionary(message, binary_array_as_bytes)
50 json_message = json.dumps(dictionary)
54 if __name__ ==
"__main__":
def convert_ros_message_to_json(message, binary_array_as_bytes=True)
def convert_json_to_ros_message(message_type, json_message, strict_mode=True)