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

Float64 to float in python

asked 2014-01-24 15:26:54 -0500

updated 2014-01-28 17:19:09 -0500

ngrennan gravatar image

I'm publishing Float64 type msg via rosserial python node to ros and I want to subscribe those messages. But the python code that subscribing Float64 msgs gives error and now I Float64 cannot convert to float.. Is there any way to do this? I tried with strings and convert it to float. But it failed.

import roslib; roslib.load_manifest('UWU_Bot')
import rospy
from geometry_msgs.msg  import Twist
from std_msgs.msg       import Float64

def callback(volt):
    Distance = 16.2537*volt**4 - 129.893 * volt**3 + 382.268 * volt**2 - 512.611 * volt + 306.439

def nav():
    rospy.init_node('UWU_Bot')
    pub = rospy.Publisher('cmd_vel', Twist)
    rospy.Subscriber("/IR_volts", Float64 , callback)
    rospy.spin()

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

This is the python code. And I used rosserial IR_ranger example to send the Float64 data.

edit retag flag offensive close merge delete

Comments

This is hard to debug without your code. Can you post your code?

Po-Jen Lai gravatar image Po-Jen Lai  ( 2014-01-24 17:45:36 -0500 )edit

I edited the post and added the python code

Hasitha gravatar image Hasitha  ( 2014-01-24 19:20:08 -0500 )edit

What is the exact error message?

dornhege gravatar image dornhege  ( 2014-01-25 04:44:39 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-01-25 04:44:25 -0500

dornhege gravatar image

The message contains the float64 member data that you need to use, i.e. replace volt with volt.data.

edit flag offensive delete link more

Comments

Thank you. It worked for me.

Hasitha gravatar image Hasitha  ( 2014-01-25 17:03:42 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-01-24 15:26:54 -0500

Seen: 13,555 times

Last updated: Jan 25 '14