I am receiving multiple CAN bus message every 20ms which is decoded and arranged as a JSON message and sent to the publishing task using FreeRTOS queue. the message is 500 bytes long. I am confused how should I set the setspinTimeout (can't understand what it even does by looking at the code comments in the header files) and how often should i call spinOnce.
#include <ros.h>
#include <std_msgs/String.h>
ros::NodeHandle nh;
std_msgs::String str_msg;
ros::Publisher chatter("CAN_Data", &str_msg);
void messageSenderTask(void *pvParameters)
{
// ... [initialization and other code]
while (true)
{
char message[JSON_BUFFER_SIZE];
if (xQueueReceive(messageQueue, message, (TickType_t)0))
{
if (nh.connected())
{
str_msg.data = message;
chatter.publish(&str_msg);
}
}
vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(10));
}
}
void setup()
{
// ... [initialization and other setup code]
nh.getHardware()->setConnection(server, serverPort);
nh.initNode();
nh.advertise(chatter);
nh.setSpinTimeout(50);
// ... [creation of other tasks]
}
void loop()
{
nh.spinOnce();
taskYIELD();
}
some questions:
does calling publish return immediately and does it write all the 500 bytes to the rosserial server node in one publish call ?
Can i call publish multiple times in a subroutine without calling spinOnce or does each publish call needs spinOnce call ?
looking for advice on any modifications to this code for this purpose.
I am receiving multiple CAN bus message every 20ms which is decoded and arranged as a JSON message and sent to the publishing task using FreeRTOS queue. the message is 500 bytes long. I am confused how should I set the setspinTimeout (can't understand what it even does by looking at the code comments in the header files) and how often should i call spinOnce.
some questions: does calling publish return immediately and does it write all the 500 bytes to the rosserial server node in one publish call ? Can i call publish multiple times in a subroutine without calling spinOnce or does each publish call needs spinOnce call ? looking for advice on any modifications to this code for this purpose.