MCPcopy Create free account
hub / github.com/RoboMaster/RoboRTS / MapUpdateLoop

Method MapUpdateLoop

roborts_costmap/src/costmap_interface.cpp:206–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204}
205
206void CostmapInterface::MapUpdateLoop(double frequency) {
207 if (frequency <= 0.0) {
208 ROS_ERROR("Frequency must be positive in MapUpdateLoop.");
209 }
210 ros::NodeHandle nh;
211 ros::Rate r(frequency);
212 while (nh.ok() && !map_update_thread_shutdown_) {
213 struct timeval start, end;
214 gettimeofday(&start, NULL);
215 UpdateMap();
216 gettimeofday(&end, NULL);
217 r.sleep();
218 if (r.cycleTime() > ros::Duration(1 / frequency)) {
219 if (is_debug_) {
220 ROS_WARN("Map update loop missed its desired rate of %.4fHz... the loop actually took %.4f seconds",\
221 frequency, r.cycleTime().toSec());
222 }
223 }
224 double x, y;
225 Costmap2D *temp_costmap = layered_costmap_->GetCostMap();
226 unsigned char *data = temp_costmap->GetCharMap();
227 temp_costmap->Map2World(0, 0, x, y);
228 grid_.header.frame_id = global_frame_;
229 grid_.header.stamp = ros::Time::now();
230 if (is_rolling_window_) {
231 grid_.info.resolution = map_resolution_;
232 grid_.info.width = map_width_ / map_resolution_;
233 grid_.info.height = map_height_ / map_resolution_;
234 grid_.info.origin.position.x = x - map_resolution_ * 0.5;
235 grid_.info.origin.position.y = y - map_resolution_ * 0.5;
236 grid_.info.origin.position.z = 0;
237 grid_.info.origin.orientation.w = 1.0;
238 grid_.data.resize(grid_.info.width * grid_.info.height);
239 } else {
240 auto resolution = temp_costmap->GetResolution();
241 auto map_width = temp_costmap->GetSizeXCell();
242 auto map_height = temp_costmap->GetSizeYCell();
243 grid_.info.resolution = resolution;
244 grid_.info.width = map_width;
245 grid_.info.height = map_height;
246 grid_.info.origin.position.x = temp_costmap->GetOriginX();
247 grid_.info.origin.position.y = temp_costmap->GetOriginY();
248 grid_.info.origin.position.z = 0;
249 grid_.info.origin.orientation.w = 1.0;
250 grid_.data.resize(map_width * map_height);
251 }
252 for (size_t i = 0; i < grid_.data.size(); i++) {
253 grid_.data[i] = cost_translation_table_[data[i]];
254 }
255 costmap_pub_.publish(grid_);
256 }
257}
258
259void CostmapInterface::UpdateMap() {
260 if (!stop_updates_) {

Callers

nothing calls this directly

Calls 9

Map2WorldMethod · 0.80
resizeMethod · 0.80
GetResolutionMethod · 0.80
GetSizeXCellMethod · 0.80
GetSizeYCellMethod · 0.80
GetOriginXMethod · 0.80
GetOriginYMethod · 0.80
GetCostMapMethod · 0.45
GetCharMapMethod · 0.45

Tested by

no test coverage detected