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

replay of the finished message through foreach

asked 2019-02-07 00:38:51 -0500

D0l0RES gravatar image

updated 2019-02-07 00:39:28 -0500

I have a msg message containing 45 variables, and I’m actually able to fill in the message variables through a loop or should I write each variable manually? I use ros2, I write on C++, assembly ament_cmake

edit retag flag offensive close merge delete

Comments

This question doesn't make much sense? What do these 45 variables represent?

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-02-07 03:20:37 -0500 )edit

@PeteBlackerThe3rd float32 voltage float32 charge_level float32 block_n_voltage float32 block_n_amperage float32 akb_voltage float32 akb_amperage float32 temperature_akb400v bool availability_of_coolant_duct_akb400v

D0l0RES gravatar image D0l0RES  ( 2019-02-07 05:23:47 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2019-02-07 16:23:36 -0500

tfoote gravatar image

There's not a generic way to loop over differently named elements. You will need to specifically address them individually.

If you want to loop across elements you can store them in an array. But as these elements appear to be quite specific and different. Aka they're not representing multiple instances of a type the separate variables makes more sense. The temperature and amperage are not interchangeable. And some elements are even of different types which makes iterating even less likely. If you have those 45 things to assign specifically you're going to need to actually assign them individually. This way the compiler will know exactly what you want to do and anyone reading the code will also know what you're doing. Trying to save lines of code to avoid this sort of thing is likely not worth it. If you're assigning into it from a similar data struct in several different places a helper function is the best way to do this.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-02-07 00:38:51 -0500

Seen: 240 times

Last updated: Feb 07 '19