rospy message_converter outputs zero while in the terminal I got different output for the same topic
ROS Kinetic Ubuntu 16.04 Python 3.5
I am using diff_drive_controller to publish rwheel_angular_vel_motor and lwheel_angular_vel_motor topics. My goal is to take messages published by those topics and transmit them via tcp/ip.
Currently, I am trying to convert ros msgs into a json file by using following script.
from rospy_message_converter import json_message_converter
from std_msgs.msg import Float32
while True:
message = Float32()
json_str = json_message_converter.convert_ros_message_to_json(message)
print(json_str)
When I run it I always see {"data": 0.0} in the output. But when I use:
rostopic echo rwheel_angular_vel_motor
I am able to see the data. I also used rostopic info rwheel_angular_vel_motor
command and got the following output:
Type: std_msgs/Float32
Publishers: * /gopigo_controller (http://R2:34603/)
Subscribers: * /gopigo_state_updater (http://R2:45111/)
So anyone knows why I am getting 0 as output?
it seems that you define
Float32
msg and convert it without assigning any value. where do you subscribe to the topicrwheel_angular_vel_motor
in your code?Actually, I am not subscribing to that topic. I am only reading
std_msg/FLoat32
. I thought since rwheel_angular_vel_motor publishes that message, I don't need to subscribe to that topic or thefrom std_msgs.msg import Float32
part handles it itself.from std_msgs.msg import Float32
imports the definition of the message so that you can use it in your code. To access the data published on any topic, you should subscribe to that topic first. so, you need to write a subscriber torwheel_angular_vel_motor
and then assign the coming data to a variable and then convert the data.