Effacer les filtres
Effacer les filtres

rossubscriber with callback missing messages

2 vues (au cours des 30 derniers jours)
Daniel Levy
Daniel Levy le 13 Avr 2020
Commenté : Daniel Levy le 14 Avr 2020
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

Réponse acceptée

Daniel Levy
Daniel Levy le 14 Avr 2020
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 commentaires
Daniel Levy
Daniel Levy le 14 Avr 2020
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 le 14 Avr 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!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by