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

how to pub array msg?

asked 2020-07-29 02:12:51 -0500

lester gravatar image

updated 2020-07-29 02:19:11 -0500

mgruhler gravatar image

i have 2 msg, battery.msg and battery_array.msg, i want to send battery_array.msg, contain two battery.msg (two battery) how could i use command line to send it? i just can send one array with command line, could you please tell me how to send two array....

here is a sample with one battery array in command line:

rostopic pub -1 /bms_info_array drone_msg/BatteryStateArray "battery_number: 2 battery_state_array: - {temperature: 40.0,  state: 80, voltage: 17.0}" 
---------------------------------------------------------

1.
battery.msg
(below is msg content)
-----------------
float32 temperature
int8    state
float32 voltage
-----------------

2.
battery_array.msg
(below is msg content)
-----------------
int8 battery_number
battery[] battery_state_array
-----------------

thank you very much

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-07-29 02:28:00 -0500

mgruhler gravatar image

updated 2020-07-29 02:29:01 -0500

you can simply add a new line with the next values of the array. I.e.

rostopic pub -1 /bms_info_array drone_msg/BatteryStateArray "battery_number: 2
battery_state_array:
- {temperature: 40.0,  state: 80, voltage: 17.0}
- {temperature: 41.0,  state: 81, voltage: 17.1}"

Note that hitting TAB right after the message type (don't type the opening apostrophe or anything else) will already provide you with a somewhat more nicely formatted message field.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-07-29 02:05:46 -0500

Seen: 335 times

Last updated: Jul 29 '20