rossubscriber with callback missing messages

I'm using a rossubscriber to interface a C++ simulator with an algorithm written in Matlab. At each time step of the simulations I'm publishing a custom navigation message from ten different entities to one topic which I would like Matlab to parse for a separate navigation algorithm. Despite a very large buffer size or running the simulator very slowly, the ros subscriber will miss many of the messages from some entities while not missing others.
For example, in 23 messages from ten entities, my subscriber and call back recorded; 23, 14, 18, 15, 16, 18, 18, 19, 18, 23 messages. Is there something I'm missing to get the subscriber to read and parse all of the messages?
rosinit('XX.XX.XX.XX')
global Messages;
Messages = [];
global splineFits;
num_entitiez = 10;
splineFits = [];
for ii = 1:num_entitiez
splineFit.ID = ii;
splineFit.Time = [];
splineFit.ECEF = [];
splineFit.Vel = [];
splineFit.Quat = [];
splineFit.RotVel = [];
splineFits = [splineFits; splineFit];
end
sub = rossubscriber('/Sim_State_msg','navigation_msgs/StateECEFWithCovariance',@navigationMessageReader,"BufferSize",1000000);
function navigationMessageReader(~,message,~)
global splineFits;
global Messages;
Messages = [Messages; message];
Time = message.Header.Stamp.Sec + message.Header.Stamp.Nsec/1000000000;
X = message.Pose.Pose.Position.X;
Y = message.Pose.Pose.Position.Y;
Z = message.Pose.Pose.Position.Z;
vX = message.Twist.Twist.Linear.X;
vY = message.Twist.Twist.Linear.Y;
vZ = message.Twist.Twist.Linear.Z;
qX = message.Pose.Pose.Orientation.X;
qY = message.Pose.Pose.Orientation.Y;
qZ = message.Pose.Pose.Orientation.Z;
qW = message.Pose.Pose.Orientation.W;
vR = message.Twist.Twist.Angular.X;
vP = message.Twist.Twist.Angular.Y;
vY = message.Twist.Twist.Angular.Z;
ID = str2double(message.Header.FrameId);
splineFits(ID).Time = [splineFits(ID).Time;Time];
splineFits(ID).ECEF = [splineFits(ID).ECEF;X Y Z];
splineFits(ID).Vel = [splineFits(ID).Vel;vX vY vZ];
splineFits(ID).Quat = [splineFits(ID).Quat;qX qY qZ qW];
splineFits(ID).RotVel = [splineFits(ID).RotVel;vR vP vY];
end

 Respuesta aceptada

Daniel Levy
Daniel Levy el 14 de Abr. de 2020

0 votos

It looks like you wrote your subscriber right. It may be a problem with your publisher. Can you post the code of your C++ publisher?

3 comentarios

Sure,
I create the publisher with
nh_ = std::make_shared<ros::NodeHandle>();
pose_scan_pub_ = nh_->advertise<navigation_msgs:StateECEFWithCovariance>("Sim_State_msg",1)
pub_ = advertise("LocalNetwork", "NoisyState");
and then publish I the message with
navigation_msgs:StateECEFWithCovariance ROSmsg;
pose_scan_pub_.publish(ROSmsg);
Try changing your advertise to
pose_scan_pub_ = nh_->advertise<navigation_msgs:StateECEFWithCovariance>("Sim_State_msg",100)
The second number is the queu size for your publisher and may be talking over itself.
Daniel Levy
Daniel Levy el 14 de Abr. de 2020
Wow, that fixed it. I'm receiving all of my messages now, I feel like a real idiot not checking to see if my publisher queu size was long enough!
Thanks for the help Dan!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Preguntada:

el 13 de Abr. de 2020

Comentada:

el 14 de Abr. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by