39 from rospy_message_converter
import message_converter
44 Takes in the message type and a JSON-formatted string and returns a ROS 47 :param message_type: The desired ROS message type of the result 48 :type message_type: str 49 :param json_message: A JSON-formatted string 50 :type json_message: str 51 :param strict_mode: If strict_mode is set, an exception will be thrown if the json message contains extra fields. 52 :type strict_mode: bool, optional 53 :param log_level: The log level to be used. Available levels: debug, info, warning, error, critical 54 :type log_level: str, optional 55 :return: A ROS message 56 :rtype: class:`genpy.Message` 59 >>> msg_type = "std_msgs/String" 60 >>> json_msg = '{"data": "Hello, Robot"}' 61 >>> convert_json_to_ros_message(msg_type, json_msg) 64 dictionary = json.loads(json_message)
65 return message_converter.convert_dictionary_to_ros_message(
66 message_type, dictionary, strict_mode=strict_mode, log_level=log_level
72 Takes in a ROS message and returns a JSON-formatted string. 74 :param message: A ROS message to convert 75 :type message: class:`genpy.Message` 76 :param binary_array_as_bytes: rospy treats `uint8[]` data as a `bytes`, which is the Python representation for byte 77 data. In Python 2, this is the same as `str`. If this parameter is `False`, all `uint8[]` fields will be 78 converted to `list(int)` instead. 79 :type binary_array_as_bytes: bool, optional 80 :return: A JSON-formatted string 84 >>> import std_msgs.msg 85 >>> ros_message = std_msgs.msg.String(data="Hello, Robot") 86 >>> convert_ros_message_to_json(ros_message) 87 '{"data": "Hello, Robot"}' 89 dictionary = message_converter.convert_ros_message_to_dictionary(message, binary_array_as_bytes)
90 json_message = json.dumps(dictionary)
94 if __name__ ==
"__main__":
def convert_json_to_ros_message(message_type, json_message, strict_mode=True, log_level='error')
def convert_ros_message_to_json(message, binary_array_as_bytes=True)