rossubscriber with callback missing messages

조회 수: 2 (최근 30일)
Daniel Levy
Daniel Levy 2020년 4월 13일
댓글: Daniel Levy 2020년 4월 14일
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

채택된 답변

Daniel Levy
Daniel Levy 2020년 4월 14일
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
Daniel Levy
Daniel Levy 2020년 4월 14일
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 2020년 4월 14일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Specialized Messages에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by