ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Loop through unbounded tracks array in radar_msgs/RadarTrackArray

asked 2019-04-19 09:26:37 -0500

roskinetic gravatar image

updated 2019-04-19 10:18:15 -0500

gvdhoorn gravatar image

Hi,

I am having this programming problem:

void msgCallback(const radar_msgs::RadarTrackArray::ConstPtr& msg)
{
  for (int i=0; i < msg->tracks.size(); i++)
   {
      a.push_back(msg->tracks[i].track_id);
   }
}

int main(int argc, char** argv)
{
  ...
  ros::Subscriber radar_sub = nh.subscribe("/radarTrack",1000,msgCallback);
  ros::spin();
  return 0;
}

the topic "/radarTrack" publishes messages every 20ms and the tracks array is an unbounded array, that is, it gives different length of array at each frame. For example, msg->tracks.size() can be 420, 28, 128 and so on.. When the length of tracks array is large, the calculation time of for-loop could be larger than 20ms. In this case, Does the messages that are published by "/radarTrack" wait until the for-loop calculation is complete although its calculation time is larger than 20ms?

Any help will be much appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-04-19 10:19:17 -0500

gvdhoorn gravatar image

updated 2019-04-19 10:19:59 -0500

the topic "/radarTrack" publishes messages every 20ms, [..] When the length of tracks array is large, the calculation time of for-loop could be larger than 20ms. In this case, Does the messages that are published by "/radarTrack" wait until the for-loop calculation is complete although its calculation time is larger than 20ms?

callbacks are not pre-empted, interrupted or run in parallel (with a standard single-threaded spinner as you are using), so if callback(..) takes longer than 20 ms to process all the tracks, processing of other messages will be delayed.

edit flag offensive delete link more

Comments

Thank you very much! :)

roskinetic gravatar image roskinetic  ( 2019-04-19 10:57:38 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-04-19 09:26:37 -0500

Seen: 220 times

Last updated: Apr 19 '19