Ask Your Question

How to publish messages with specific data types for arguments?

asked 2014-08-14 16:13:51 -0500

mysteriousmonkey29 gravatar image

Hello, I've adapted some C++ control code for a smart motor I have attached to a laser scanner (it rotates the laser scanner back and forth) into a node to do the same thing upon receiving a custom message. The message includes start/end angle, speed, and duration, which are the inputs the original control code uses:

  float32 start
  float32 end
  float32 speed
  float32 duration

The node compiles and runs (the code as is can be found here: ). Now I am trying to complete a simple back and forth sweep for 3 seconds, by publishing a custom Sweep message to the /sweep topic from the command line. I run the command:

  rostopic pub -1 /sweep toro/Sweep -- -3.14159/2 3.14159/2 3.14159/2 3

but get the following response (repeated many times):

 [WARN] [WallTime: 1408045951.800915] Inbound TCP/IP connection failed: <class 'struct.error'>: 'required argument is not  a float' when writing 'start: -3.14159/2
 end: 3.14159/2
 speed: 3.14159/2
 duration: 3'

Is there any kind of way I can specify the data type of the arguments while publishing the message? I guess they might be doubles by default, but ros custom messages don't support doubles (or at least I couldn't get them to work), so I don't think I can fix the problem on that end.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-08-14 16:29:07 -0500

ahendrix gravatar image

The trouble here is that rostopic pub is not a calculator - it's expecting numbers, and instead you're giving it an equation (effectively a string).

Instead, try:

  rostopic pub -1 /sweep toro/Sweep -- -1.57 1.57 1.57 3

P.S. - The ROS message type for doubles is float64 (since most doubles are 64-bit floating-precision numbers)

edit flag offensive delete link more


Great, that completely solved the problem! Thanks for such a helpful answer, and the information on the doubles.

mysteriousmonkey29 gravatar image mysteriousmonkey29  ( 2014-08-14 16:53:53 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2014-08-14 16:13:51 -0500

Seen: 2,754 times

Last updated: Aug 14 '14