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

Unsupported Operand *

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

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
[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/", line 702, in _invoke_callback
  File "/home/pi/catkin_ws/src/servo/", line 13, in set
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


def set(angle):
        pi.set_servo_pulsewidth(servos, pulswidth)

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

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


if __name__ == '__main__':

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

1 Answer

Sort by ยป oldest newest most voted

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

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


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

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

Leave the subscriber as it is, you are subscribing to a Float32 message, just change the function to access 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 -0600 )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 -0600 )edit

Question Tools

1 follower


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

Seen: 1,825 times

Last updated: Feb 11 '15