ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

TypeError: Object of type 'Pose' is not JSON serializable

asked 2020-10-25 17:44:48 -0600

Varun gravatar image

Hello Everyone

I will try to make this question as clear as possible I am getting an array with two coordinates [ x, y ] ie. 665.5218, 460.50098 and so on from my py program in the PC which i wise to send it as Pose message to a rostopic like /chatter to my robot

I am using roslibpy for this and host IP of my robot This is my code

import time
import roslibpy
import localisation.shedrobot_localisation as loc
from geometry_msgs.msg import Pose
client = roslibpy.Ros(host='10.0.0.1', port=9090)
client.run()
talker = roslibpy.Topic(client, '/chatter', 'Pose')

while client.is_connected:
    loc.tracking_robot()
    goal = Pose()
    goal.position.x = str(loc.output[0])[0:-1]
    goal.position.y = str(loc.output[1])[0:-1]
    goal.position.z = 0.0

    goal.orientation.x = 0.0
    goal.orientation.y = 0.0
    goal.orientation.z = 0.0
    goal.orientation.w = 1.0


    talker.publish(roslibpy.Message({'data': goal }))
    # talker.publish(roslibpy.Message({'data': goalx}))
    # talker.publish(roslibpy.Message({'data': goaly}))
    print('Sending message to SHEDROBOT from FLOX-BOX...')
    print('x : ',loc.output[0])
    print('y : ',loc.output[1])
    print('SHEDROBOT :',goal)
    time.sleep(0.1)

talker.unadvertise()
client.terminate()

The error i am getting is

    Failed to send message, Object of type 'Pose' is not JSON serializable
    Traceback (most recent call last):
      File "/home/varun-flox/.local/lib/python3.6/site-packages/roslibpy/comm/comm.py", line 47, in send_ros_message
        json_message = json.dumps(dict(message)).encode('utf8')
      File "/usr/lib/python3.6/json/__init__.py", line 231, in dumps
        return _default_encoder.encode(obj)
      File "/usr/lib/python3.6/json/encoder.py", line 199, in encode
        chunks = self.iterencode(o, _one_shot=True)
      File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode
        return _iterencode(o, 0)
      File "/usr/lib/python3.6/json/encoder.py", line 180, in default
        o.__class__.__name__)
   TypeError: Object of type 'Pose' is not JSON serializable

My final goal is to use these points which come in goal.position.x and goal.position.y to be called by another py program for navigation tasks. Thanks in advance for any solution to this.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-10-25 19:00:34 -0600

talker = roslibpy.Topic(client, '/chatter', 'Pose')

needs to be

talker = roslibpy.Topic(client, '/chatter', 'geometry_msgs/Pose')

see https://roslibpy.readthedocs.io/en/la....

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-10-25 17:44:48 -0600

Seen: 1,378 times

Last updated: Oct 25 '20