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

how can I make a custom msg struct to publish?

asked 2020-10-19 07:57:08 -0500

MisticFury gravatar image

i have a script that publishes a lot of system information like battery voltage/current, sysstem status, and isready all in all i have 13 different parameters im publishing. what i want is to tie all that data into a single sturct and only publish once.

for example something live geometry msgs odom msg, you know how it has like msg.pose.pose.x i want something similar like msg.data1.data

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-10-19 09:36:24 -0500

mgruhler gravatar image

What you want is to create multiple custom msgs (for how to create custom msgs, see @JackB answer).

Then, you need to nest the messages the way you want. Something along the line of the following msg definitions:

BatteryStatus.msg:

float32 current
float32 voltage

SystemStatus.msg:

int32 error_code
string error_msg

FullSystemInformation.msg

BatteryStatus battery
SystemStatus system

And then you can access the fields like, e.g. msg.battery.current or msg.system.error_code.

edit flag offensive delete link more

Comments

gvdhoorn gravatar image gvdhoorn  ( 2020-10-19 09:50:55 -0500 )edit
0

answered 2020-10-19 08:44:28 -0500

JackB gravatar image

Look here about creating a custom message.

edit flag offensive delete link more

Comments

this doesn't make sense still don't understand how to build what i want

MisticFury gravatar image MisticFury  ( 2020-10-19 09:18:40 -0500 )edit
1

Maybe explain what you don't understand. What have you tried and what do you actually want to have? And why is the above suggestion "not making sense"?

Also, note that melodic is still using python 2, not python 3, so I'm not sure that the tags you set up are correct. Which ROS distro are you using?

mgruhler gravatar image mgruhler  ( 2020-10-19 09:25:11 -0500 )edit

im using ros melodic with python3 what i still don't understand is how should to msg file be built so i can get something ordered the same way the standard odometry msg is and such.

MisticFury gravatar image MisticFury  ( 2020-10-19 09:29:35 -0500 )edit

About using ROS melodic with python3, I recommend to read #q348093 and the linked #q237613 about how you would need to set that up and what drawbacks exist. I suggest to either upgrade to noetic, which uses python3, or stay at python 2...

mgruhler gravatar image mgruhler  ( 2020-10-19 09:42:12 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-10-19 07:57:08 -0500

Seen: 652 times

Last updated: Oct 19 '20