rosserial, publish a ROS topic with uint16_t and strings

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

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:

as7341_0.getChannel(AS7341_CHANNEL_415nm_F1)
as7341_0.getChannel(AS7341_CHANNEL_415nm_F1

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:

result_from_getChannel1,result_from_getChannel2,result_from_getChannel3

Thank you!

edit retag flag offensive close merge delete

Comments

1

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 -0500 )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 -0500 )edit

No suggestions for my problem?

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