Ask Your Question
0

Publishing arrays unsuccessful

asked 2013-04-29 10:23:20 -0500

whiterose gravatar image

updated 2013-04-29 22:29:50 -0500

Hi all,

I have been following this http://answers.ros.org/question/9471/how-to-recieve-an-array-over-publisher-and-subscriber-python/ (question) very closely.

This is how mine looks like:

def talker(armj_acc) :

    pub10 = rospy.Publisher('/armj_acc', obs_arm_JointAccelerations)

    msg2send10 = obs_arm_JointAccelerations()
    msg2send10.header.stamp.secs = time_now
    msg2send10.accelerations = armj_acc
    pub10.publish(msg2send10)

I have my own custom message, by the name obs_arm_JointAccelerations which contains

Header header 
float64[] accelerations

The variable armj_acc is actually a list whose values have been successfully calculated and passed into the function, which I print them on the screen. The calculation for the armj_acc is done via subscribing velocities from the /joint_states topic, every 4 seconds ((current velocity - previous velocity) /4).

The problem is, whenever I try to echo the topic, it gives me the following error:

(1) In the terminal where the topic is being echo-ed

WARNING: no messages received and simulated time is active. Is /clock being published?

(2) In the terminal where the code is run:

[ERROR] [WallTime: 1367266510.640556] [5269.097000] bad callback: <function callback="" at="" 0x2f6e1b8>="" traceback="" (most="" recent="" call="" last):="" file="" "="" opt="" ros="" fuerte="" lib="" python2.7="" dist-packages="" rospy="" topics.py",="" line="" 678,="" in="" _invoke_callback="" cb(msg)="" file="" "="" home="" path="" to="" my="" package="" script="" obs_armj_all.py",="" line="" 47,="" in="" callback="" talker(armj_names,="" armj_act_positions,="" armj_act_velocities,="" armj_effort_act,="" armj_effort_diff,="" armj_pos_rel_diff)#,="" armj_acc)#,="" armj_jerk)="" file="" "="" home="" path="" to="" my="" package="" script="" obs_armj_all.py",="" line="" 185,="" in="" talker="" pub10.publish(msg2send10)="" file="" "="" opt="" ros="" fuerte="" lib="" python2.7="" dist-packages="" rospy="" topics.py",="" line="" 796,="" in="" publish="" raise="" rosserializationexception(str(e))="" rosserializationexception:="" cannot="" convert="" argument="" to="" integer<="" p="">

Any ideas?

Thanks.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-04-29 15:53:12 -0500

If your posted code matches what you're running, it looks like you're publishing the wrong variable. You're trying to publish the armj_acc array directly, rather than the msg2send10 message. I'm also not sure that you're allowed to assign a time directly to the header field like you've shown.

Try this:

def talker(armj_acc) :
    pub10 = rospy.Publisher('/armj_acc', obs_arm_JointAccelerations)

    msg2send10 = obs_arm_JointAccelerations()
    msg2send10.header.stamp = rospy.Time.now()
    msg2send10.accelerations = armj_acc
    pub10.publish(msg2send10)
edit flag offensive delete link more

Comments

I edited that one, it is now: msg2send10.header.stamp.secs = time_now, where time_now = rospy.Time.now(), which is actually wrong. It is supposed to be: msg2send10.header.stamp.secs = time_now.secs... Thanks!

whiterose gravatar image whiterose  ( 2013-04-29 22:30:38 -0500 )edit
1

answered 2013-04-29 12:15:20 -0500

Publishers take a little while to register themselves with the master. By creating a publisher and then publishing a message immediately, the publisher has likely not finished registering, so the message will be lost. Try sleeping a little bit before before publishing, or (if appropriate) publishing inside a loop.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-04-29 10:23:20 -0500

Seen: 220 times

Last updated: Apr 29 '13