rosserial, publish a ROS topic with uint16_t and strings
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!
Do you have any particular reason to use a string instead of a message with proper fields per channel?
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.
No suggestions for my problem?