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

TypeError: cannot marshal <type 'numpy.float64'> objects

asked 2015-01-29 09:44:17 -0500

carrello gravatar image

I have a script that doesn't let me write on the parameter server . This is the script

  #!/usr/bin/env python

import rospy
from rospy.numpy_msg import numpy_msg
from rospy_tutorials.msg import Floats

import numpy as np
from scipy import integrate
from matplotlib.pylab import *

def diffDrive(t, y, u):
    # Assign some variables for convenience of notation
    X = y[0]
    Y = y[1]
    T = y[2]
    V = u[0]
    W = u[1]

    # Output from ODE function must be a COLUMN vector, with n rows
    n = len(y)      # 3: implies we have three ODEs
    dydt = np.zeros((n,1))
    dydt[0] = V * cos(T)
    dydt[1] = V * sin(T)
    dydt[2] = W
    return dydt
def callback(data):
    # Start by specifying the integrator:
    # use ``vode`` with "backward differentiation formula"
    r = integrate.ode(diffDrive).set_integrator('vode', method='bdf')

    # Set the time range
    t_start = 0.0
    delta_t = 0.01

    # Set initial condition(s): for integrating variable and time!
    X_t_zero = float(rospy.get_param('/x', '0.0'))
    Y_t_zero = float(rospy.get_param('/y', '0.0'))
    T_t_zero = float(rospy.get_param('/theta', '0.0'))

    r.set_initial_value([X_t_zero, Y_t_zero, T_t_zero], t_start)

    # Integrate the ODE
    r.integrate(r.t + delta_t)

    # results
    t = r.t
    X = r.y[0]
    Y = r.y[1]
    T = r.y[2]

    # Publish on topic
    pub = rospy.Publisher('x_y_theta', numpy_msg(Floats) ,queue_size=10)

    # Publish on parameter server
    rospy.set_param('x', X)
    rospy.set_param('y', Y)
    rospy.set_param('theta', T)

def sim():
    rospy.init_node('sim', anonymous=True)
    rospy.Subscriber("v_omega", numpy_msg(Floats), callback)

if __name__ == '__main__':

and this is the error

[ERROR] [WallTime: 1422545577.129270] bad callback: <function callback at 0x7f0be6c8f6e0>
Traceback (most recent call last):
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/", line 702, in _invoke_callback
  File "/home/viki/catkin_ws/src/wheelchair/scripts/", line 58, in callback
    rospy.set_param('x', X)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/", line 502, in set_param
    _param_server[param_name] = param_value #MasterProxy does all the magic for us
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/", line 148, in __setitem__, rospy.names.resolve_name(key), val)
  File "/usr/lib/python2.7/", line 1224, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/", line 1572, in __request
  File "/usr/lib/python2.7/", line 1085, in dumps
    data = m.dumps(params)
  File "/usr/lib/python2.7/", line 632, in dumps
    dump(v, write)
  File "/usr/lib/python2.7/", line 646, in __dump
    raise TypeError, "cannot marshal %s objects" % type(value)
TypeError: cannot marshal <type 'numpy.float64'> objects

The params are initialised with a .launch or loading a .yaml . The result is the same. I use ROS indigo on a virtual box machine running on a mac osx. Does someone know how to help me ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-01-29 09:58:18 -0500

dornhege gravatar image

set_param only accepts python's building floats. You are passing a numpy float, which is a different data type. Converting that to float should help.

edit flag offensive delete link more


it works! thank you!

carrello gravatar image carrello  ( 2015-01-29 10:12:40 -0500 )edit

Question Tools

1 follower


Asked: 2015-01-29 09:44:17 -0500

Seen: 3,289 times

Last updated: Jan 29 '15