Arduino Publisher queue size

asked 2019-07-10 07:51:59 -0500

Shanika gravatar image

Hello,

I have doubts about the queue of a Publisher or a Subscriber. Is a queue required for a publisher on Arduino ?

#include <ros.h>
#include <ros/time.h>
#include <std_msgs/Int16.h>
...

Encoder Encoder1(SLOT1);
Encoder Encoder2(SLOT2);

ros::NodeHandle  nh;

std_msgs::Int16 left_ticks_msg;
std_msgs::Int16 right_ticks_msg;

ros::Publisher pub_left_ticks("/left_ticks",&left_ticks_msg); 
ros::Publisher pub_right_ticks("/right_ticks",&right_ticks_msg);

Here I saw some people add a number like this : ros::Publisher pub("topic", &msg, 10); Does it mean the queue size of this publisher is equal to ten ? Could someone explain to me how it works if I publish these messages every 6 ms like in the following code:

int left_ticks = 0;
int right_ticks = 0;

void update_RTicks(void) { ... }
void update_LTicks(void) { ... }

void setup()
{
  // Interruptions, updating my encoder ticks
  attachInterrupt(Encoder1.getIntNum(), update_RTicks() , RISING);
  attachInterrupt(Encoder2.getIntNum(), update_LTicks() , RISING);

  nh.initNode();
  nh.advertise(pub_left_ticks);
  nh.advertise(pub_right_ticks);
}

void loop()
{
   // Publishing right and left encoder ticks every 6 ms
   if(millis() >= ticks_time){

       left_ticks_msg.data = Encoder2.getLTicks();
       pub_left_ticks.publish(&left_ticks_msg);

       right_ticks_msg.data = -Encoder1.getRTicks();
       pub_right_ticks.publish(&right_ticks_msg);

       ticks_time = millis()+6;
    }

   nh.spinOnce();
   delay(1);
  }

Thank you in advance,

Shanika

edit retag flag offensive close merge delete