Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

very long and high speed message publish #627

Open
rvxfahim opened this issue Dec 12, 2023 · 0 comments
Open

very long and high speed message publish #627

rvxfahim opened this issue Dec 12, 2023 · 0 comments

Comments

@rvxfahim
Copy link

rvxfahim commented Dec 12, 2023

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.
EDIT:
board is OLIMEX ESP32 EVB working with Ethernet connection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant