Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Thanks to mali's comment I changed my code. Following script works for me. My topic name is rwheel_angular_vel_motor and it publishes std_msgs/Float32 message. It turns out for converting messages to json package, json_message_converter is not necessary.

import rospy
from std_msgs.msg import Float32
import json

def callback(data):
   rospy.loginfo("I heard %s",
   dict_data = {'rwheel':}
   json_data = json.dumps(str(dict_data), ensure_ascii=False)

def listener():
   rospy.Subscriber("rwheel_angular_vel_motor", Float32, callback)
   # spin() simply keeps python from exiting until this node is stopped

if __name__ == '__main__':