read data from serial port and publish over a topic that stores float32'

asked 2016-06-27 05:20:02 -0500

rpxz gravatar image

updated 2016-06-27 05:22:03 -0500

def publish():

    rospy.init_node('modem',anonymous=True)
    acous_node=rospy.Publisher('acoustic_data',Float32,queue_size=10)
    r=rospy.Rate(10)
    while not rospy.is_shutdown():
            g.data=serial_node.read()
            acous_node.publish(g)
            localtime = time.asctime( time.localtime(time.time()) )
            print "Local current time :", localtime
            r.sleep()

this is what i tried but serial data is in str type,i want to convert to float32 type .how do i do? thanx

edit retag flag offensive close merge delete

Comments

Not a ROS question but here is some info: http://www.cplusplus.com/reference/st...

billy gravatar image billy  ( 2016-06-28 23:50:56 -0500 )edit

I think you have more string conversion to get things working. Reading this answer will provide help with serial port. http://answers.ros.org/question/19539...

billy gravatar image billy  ( 2016-06-28 23:51:43 -0500 )edit