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

Unsupported Operand *

asked 2015-02-11 10:25:42 -0500

dshimano gravatar image

Hi, I'm using Indigo on a RPi,

I'm running a code and am getting the error

pi@raspberrypi ~/catkin_ws/src/servo $ rosrun servo pigpio_listner.py
[ERROR] [WallTime: 1423671413.743414] bad callback: <function set at 0x1f12670>
Traceback (most recent call last):
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py", line 702, in _invoke_callback
    cb(msg)
  File "/home/pi/catkin_ws/src/servo/pigpio_listner.py", line 13, in set
    pulswidth=1000+angle*5.5556
TypeError: unsupported operand type(s) for *: 'Float32' and 'float'

Unhandled exception in thread started by 
sys.excepthook is missing
lost sys.stderr

I'm not sure what this means, doesn't * mean multiply? Can't you multiply floats? I'll include the code:

#!/usr/bin/env python
import rospy
from std_msgs.msg import Float32
import time
import pigpio

servos = 4 #GPIO number

pi=pigpio.pi()


def set(angle):
        pulswidth=1000+angle*5.5556
        pi.set_servo_pulsewidth(servos, pulswidth)

def listener():
        rospy.init_node('servo', anonymous=True)

        rospy.Subscriber("angle", Float32, set)

        rospy.spin

if __name__ == '__main__':
        try:
                listener()


# switch all servos off
        except KeyboardInterrupt:
                pigpio.set_servo_pulsewidth(servos, 0);
                pigpio.stop()
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-02-11 10:33:44 -0500

dornhege gravatar image

Float32 is not a float, it's a type that has a .data member, which is a float.

edit flag offensive delete link more

Comments

Okay, how do I address this problem. Do I change the subscriber to Float32.data, or to float?

dshimano gravatar image dshimano  ( 2015-02-13 09:46:58 -0500 )edit

Leave the subscriber as it is, you are subscribing to a Float32 message, just change the function to access angle.data instead. It might help to think of std_msgs/Float32 as a std_msgs/Float32DataMessage.

dornhege gravatar image dornhege  ( 2015-02-16 03:43:58 -0500 )edit

Thanks, that helped. I'm getting a new error now, so I'm posting a new question for that.

dshimano gravatar image dshimano  ( 2015-02-16 08:32:31 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2015-02-11 10:25:42 -0500

Seen: 1,857 times

Last updated: Feb 11 '15