Why am I getting unicode message types?

asked 2018-10-22 00:16:56 -0500

stevemartin gravatar image

I am using this plugin: LINK

Basically, I am retrieving a json from web server, converting the dictionary into string with "latin1" encoding (did the same with utf-8) and pass it to the rospy_message_converter. It works well, but the rospy_message_converter sends python unicode message types even though I have converted into a different format earlier, why is that?

Here is my code:

#! /usr/bin/python

import rospy
import yaml
import sys
import json
import requests
from std_msgs.msg import String
from geometry_msgs.msg import PoseStamped
from rospy_message_converter import json_message_converter

HOST, PORT = "127.0.0.1", 3000

def talker():
    pub = rospy.Publisher('/move_base_simple/goal', PoseStamped, queue_size=20)
    rospy.init_node('api_handler_rospy_node', anonymous=True)
    rate = rospy.Rate(10)


    while not rospy.is_shutdown():
        resp = requests.get("http://127.0.0.1:3000/api")
        data = resp.json()
        data = json.dumps(data).encode('latin1')
        rospy.loginfo(data)
        message = json_message_converter.convert_json_to_ros_message('geometry_msgs/PoseStamped', data)
        rospy.loginfo(message)
        pub.publish(message)
        rate.sleep()


if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException:
        pass

The converted dictionary into string message looks like this:

{"header": {"stamp": "now", "frame_id": "map"}, "pose": {"position": {"y": "0.0", "x": "1.0", "z": "0.0"}, "orientation": {"y": "0.0", "x": "0.0", "z": "0.0", "w": "1.0"}}}

However, the converted through plugin into ROS message looks like this:

header: 
  seq: 0
  stamp: 
    secs: 1540185098
    nsecs:  24347066
  frame_id: !!python/unicode "map"
pose: 
  position: 
    x: !!python/unicode "1.0"
    y: !!python/unicode "0.0"
    z: !!python/unicode "0.0"
  orientation: 
    x: !!python/unicode "0.0"
    y: !!python/unicode "0.0"
    z: !!python/unicode "0.0"
    w: !!python/unicode "1.0"
edit retag flag offensive close merge delete

Comments

Some expectation management: you're asking a question about a very specific package and the intersection between ppl visiting ROS Answers and those using this package is not necessarily very big.

You might want to ask this on the package's issue tracker.

gvdhoorn gravatar imagegvdhoorn ( 2018-10-22 02:18:20 -0500 )edit