rosserial, publish a ROS topic with uint16_t and strings

asked 2022-05-04 13:32:47 -0600

Marcus Barnet gravatar image

I'm using a Arduino MEGA 2560 to read from different spectrometers and then I need to publish a ROS topic for each sensor. I'm on ROS Melodic.

The problem is that I read each sensor channel with:


and so on, and getChannel is defined in this way

uint16_t Adafruit_AS7341::getChannel    (   as7341_color_channel_t  channel )

I publish the ROS topic by using this string:

std_msgs::String str_msg;

How can I concatenate all the getChannel values and copy them to str_msg? Is it possible?

I would like to publish something like this with commas:


Thank you!

edit retag flag offensive close merge delete



Do you have any particular reason to use a string instead of a message with proper fields per channel?

gvdhoorn gravatar image gvdhoorn  ( 2022-05-04 14:14:32 -0600 )edit

Thank you for your answer. I haven't used a message with a proper fields template because I do not have how to do that in Arduino.

Marcus Barnet gravatar image Marcus Barnet  ( 2022-05-05 01:47:03 -0600 )edit

No suggestions for my problem?

Marcus Barnet gravatar image Marcus Barnet  ( 2022-05-05 14:26:33 -0600 )edit