Bring main up to the dev_cam_intel line
main had not moved since 11 July, while the depth-camera work continued on
dev_cam_intel for six weeks. The two branches did not diverge by accident: they
ended up holding two different clearing designs for the same layer.
main carried frustum clearing as VoxelLayer members - frustum_clearing_enabled_,
a pixel step and a min/max range - driven from costmap_2d_robot. dev_cam_intel
replaced that with a full-column clearing pass whose configuration lives per
observation, so the layer keeps no frustum state of its own.
This commit takes the dev_cam_intel tree whole. It is the line running on the
robot, the one rb_ws points at, and the one the NUC measurements were taken
against; the frustum design is superseded rather than merged, and stays in
history at 45c8227 if it is ever wanted back.
Squashed deliberately: the nineteen commits behind it are a working diary -
metrics that were added and removed, test toggles, an optimal-run series - and
none of that is worth carrying onto a branch other trees track.
This commit is contained in:
@@ -69,6 +69,119 @@ namespace robot_costmap_2d
|
||||
costmap_.setDefaultValue(NO_INFORMATION);
|
||||
else
|
||||
costmap_.setDefaultValue(FREE_SPACE);
|
||||
performance_window_start_ = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
void LayeredCostmap::setPerformanceMetrics(bool enabled, double reporting_period_seconds)
|
||||
{
|
||||
performance_metrics_enabled_ = enabled;
|
||||
performance_metrics_period_seconds_ = reporting_period_seconds > 0.0 ? reporting_period_seconds : 5.0;
|
||||
resetPerformanceMetrics();
|
||||
}
|
||||
|
||||
void LayeredCostmap::setDebugLevel(int level)
|
||||
{
|
||||
debug_level_ = std::max(0, std::min(level, 2));
|
||||
}
|
||||
|
||||
void LayeredCostmap::resetPerformanceMetrics()
|
||||
{
|
||||
performance_window_start_ = std::chrono::steady_clock::now();
|
||||
performance_cycle_nanoseconds_ = 0;
|
||||
performance_reset_nanoseconds_ = 0;
|
||||
performance_cycles_ = 0;
|
||||
performance_cycle_samples_.clear();
|
||||
performance_cycle_samples_.reserve(128);
|
||||
layer_performance_.assign(plugins_.size(), LayerPerformance());
|
||||
lock_wait_nanoseconds_ = 0;
|
||||
lock_wait_max_nanoseconds_ = 0;
|
||||
lock_hold_nanoseconds_ = 0;
|
||||
window_cells_sum_ = 0;
|
||||
window_cells_max_ = 0;
|
||||
performance_empty_cycles_ = 0;
|
||||
}
|
||||
|
||||
void LayeredCostmap::maybeReportPerformance()
|
||||
{
|
||||
// debug_level >= 1 also reports windows with only empty cycles, so an idle
|
||||
// costmap (e.g. the global one with obstacle updates disabled) stays visible.
|
||||
const bool has_activity = performance_cycles_ > 0 ||
|
||||
(debug_level_ >= 1 && performance_empty_cycles_ > 0);
|
||||
if (!performance_metrics_enabled_ || !has_activity)
|
||||
return;
|
||||
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
const double elapsed = std::chrono::duration<double>(now - performance_window_start_).count();
|
||||
if (elapsed < performance_metrics_period_seconds_)
|
||||
return;
|
||||
|
||||
if (performance_cycles_ > 0)
|
||||
{
|
||||
const double average_cycle_ms =
|
||||
static_cast<double>(performance_cycle_nanoseconds_) / performance_cycles_ / 1.0e6;
|
||||
const double average_reset_ms =
|
||||
static_cast<double>(performance_reset_nanoseconds_) / performance_cycles_ / 1.0e6;
|
||||
std::sort(performance_cycle_samples_.begin(), performance_cycle_samples_.end());
|
||||
const auto percentile_ms = [this](double percentile) {
|
||||
if (performance_cycle_samples_.empty())
|
||||
return 0.0;
|
||||
const std::size_t index = static_cast<std::size_t>(
|
||||
percentile * static_cast<double>(performance_cycle_samples_.size() - 1));
|
||||
return static_cast<double>(performance_cycle_samples_[index]) / 1.0e6;
|
||||
};
|
||||
robot::log_info(
|
||||
"Costmap performance: cycles=%llu avg_cycle_ms=%.3f p95_cycle_ms=%.3f "
|
||||
"p99_cycle_ms=%.3f avg_reset_ms=%.3f\n",
|
||||
static_cast<unsigned long long>(performance_cycles_), average_cycle_ms,
|
||||
percentile_ms(0.95), percentile_ms(0.99), average_reset_ms);
|
||||
|
||||
for (std::size_t i = 0; i < plugins_.size() && i < layer_performance_.size(); ++i)
|
||||
{
|
||||
const LayerPerformance& stats = layer_performance_[i];
|
||||
const double average_bounds_ms = stats.bounds_calls == 0 ? 0.0 :
|
||||
static_cast<double>(stats.bounds_nanoseconds) / stats.bounds_calls / 1.0e6;
|
||||
const double average_costs_ms = stats.costs_calls == 0 ? 0.0 :
|
||||
static_cast<double>(stats.costs_nanoseconds) / stats.costs_calls / 1.0e6;
|
||||
robot::log_info(
|
||||
"Costmap layer [%s]: avg_bounds_ms=%.3f avg_costs_ms=%.3f\n",
|
||||
plugins_[i]->getName().c_str(), average_bounds_ms, average_costs_ms);
|
||||
}
|
||||
}
|
||||
|
||||
if (debug_level_ >= 1)
|
||||
{
|
||||
const std::uint64_t lock_samples = performance_cycles_ + performance_empty_cycles_;
|
||||
const double average_lock_wait_ms = lock_samples == 0 ? 0.0 :
|
||||
static_cast<double>(lock_wait_nanoseconds_) / lock_samples / 1.0e6;
|
||||
const double max_lock_wait_ms = static_cast<double>(lock_wait_max_nanoseconds_) / 1.0e6;
|
||||
const double average_lock_hold_ms = performance_cycles_ == 0 ? 0.0 :
|
||||
static_cast<double>(lock_hold_nanoseconds_) / performance_cycles_ / 1.0e6;
|
||||
const std::uint64_t average_window_cells = performance_cycles_ == 0 ? 0 :
|
||||
window_cells_sum_ / performance_cycles_;
|
||||
robot::log_info(
|
||||
"Costmap debug: lock_wait avg=%.3f max=%.3f [ms], lock_hold avg=%.3f [ms], "
|
||||
"window avg=%llu max=%llu [cells], empty_cycles=%llu\n",
|
||||
average_lock_wait_ms, max_lock_wait_ms, average_lock_hold_ms,
|
||||
static_cast<unsigned long long>(average_window_cells),
|
||||
static_cast<unsigned long long>(window_cells_max_),
|
||||
static_cast<unsigned long long>(performance_empty_cycles_));
|
||||
}
|
||||
|
||||
if (debug_level_ >= 2 && performance_cycles_ > 0)
|
||||
{
|
||||
for (std::size_t i = 0; i < plugins_.size() && i < layer_performance_.size(); ++i)
|
||||
{
|
||||
const LayerPerformance& stats = layer_performance_[i];
|
||||
if (stats.bounds_calls == 0)
|
||||
continue;
|
||||
const double average_grow = stats.bounds_grow_m2_sum / stats.bounds_calls;
|
||||
robot::log_info(
|
||||
"Costmap debug layer [%s]: bounds_grow avg=%.2f max=%.2f [m^2]\n",
|
||||
plugins_[i]->getName().c_str(), average_grow, stats.bounds_grow_m2_max);
|
||||
}
|
||||
}
|
||||
|
||||
resetPerformanceMetrics();
|
||||
}
|
||||
|
||||
LayeredCostmap::~LayeredCostmap()
|
||||
@@ -94,9 +207,23 @@ namespace robot_costmap_2d
|
||||
|
||||
void LayeredCostmap::updateMap(double robot_x, double robot_y, double robot_yaw)
|
||||
{
|
||||
const auto cycle_start = performance_metrics_enabled_ ? std::chrono::steady_clock::now() :
|
||||
std::chrono::steady_clock::time_point();
|
||||
// Lock for the remainder of this function, some plugins (e.g. VoxelLayer)
|
||||
// implement thread unsafe updateBounds() functions.
|
||||
boost::unique_lock<Costmap2D::mutex_t> lock(*(costmap_.getMutex()));
|
||||
// Time spent acquiring the master mutex is the contention with planner
|
||||
// reads — measured separately from our own work (hold time) so the two
|
||||
// show up as distinct numbers in the debug report.
|
||||
const auto lock_acquired = performance_metrics_enabled_ ? std::chrono::steady_clock::now() :
|
||||
std::chrono::steady_clock::time_point();
|
||||
if (performance_metrics_enabled_)
|
||||
{
|
||||
const std::uint64_t wait_ns = static_cast<std::uint64_t>(
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(lock_acquired - cycle_start).count());
|
||||
lock_wait_nanoseconds_ += wait_ns;
|
||||
lock_wait_max_nanoseconds_ = std::max(lock_wait_max_nanoseconds_, wait_ns);
|
||||
}
|
||||
|
||||
// if we're using a rolling buffer costmap... we need to update the origin using the robot's position
|
||||
if (rolling_window_)
|
||||
@@ -111,23 +238,57 @@ namespace robot_costmap_2d
|
||||
|
||||
minx_ = miny_ = 1e30;
|
||||
maxx_ = maxy_ = -1e30;
|
||||
for (vector<boost::shared_ptr<Layer>>::iterator plugin = plugins_.begin(); plugin != plugins_.end();
|
||||
++plugin)
|
||||
if (performance_metrics_enabled_ && layer_performance_.size() != plugins_.size())
|
||||
layer_performance_.assign(plugins_.size(), LayerPerformance());
|
||||
|
||||
for (std::size_t plugin_index = 0; plugin_index < plugins_.size(); ++plugin_index)
|
||||
{
|
||||
if (!(*plugin)->isEnabled())
|
||||
const boost::shared_ptr<Layer>& plugin = plugins_[plugin_index];
|
||||
if (!plugin->isEnabled())
|
||||
continue;
|
||||
double prev_minx = minx_;
|
||||
double prev_miny = miny_;
|
||||
double prev_maxx = maxx_;
|
||||
double prev_maxy = maxy_;
|
||||
(*plugin)->updateBounds(robot_x, robot_y, robot_yaw, &minx_, &miny_, &maxx_, &maxy_);
|
||||
const auto bounds_start = performance_metrics_enabled_ ? std::chrono::steady_clock::now() :
|
||||
std::chrono::steady_clock::time_point();
|
||||
plugin->updateBounds(robot_x, robot_y, robot_yaw, &minx_, &miny_, &maxx_, &maxy_);
|
||||
if (performance_metrics_enabled_)
|
||||
{
|
||||
layer_performance_[plugin_index].bounds_nanoseconds +=
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now() - bounds_start).count();
|
||||
++layer_performance_[plugin_index].bounds_calls;
|
||||
if (debug_level_ >= 2 && plugin_index < layer_performance_.size())
|
||||
{
|
||||
// Rect area clamped to the map extent, so the inflation layer's
|
||||
// "reinflate everything" request (+/-FLT_MAX) stays finite.
|
||||
const auto clamped_area = [this](double mnx, double mny, double mxx, double mxy) {
|
||||
const double ox = costmap_.getOriginX();
|
||||
const double oy = costmap_.getOriginY();
|
||||
const double ex = ox + costmap_.getSizeInMetersX();
|
||||
const double ey = oy + costmap_.getSizeInMetersY();
|
||||
const double cx0 = std::max(mnx, ox), cy0 = std::max(mny, oy);
|
||||
const double cx1 = std::min(mxx, ex), cy1 = std::min(mxy, ey);
|
||||
return (cx1 > cx0 && cy1 > cy0) ? (cx1 - cx0) * (cy1 - cy0) : 0.0;
|
||||
};
|
||||
const double grow = clamped_area(minx_, miny_, maxx_, maxy_) -
|
||||
clamped_area(prev_minx, prev_miny, prev_maxx, prev_maxy);
|
||||
if (grow > 0.0)
|
||||
{
|
||||
layer_performance_[plugin_index].bounds_grow_m2_sum += grow;
|
||||
layer_performance_[plugin_index].bounds_grow_m2_max =
|
||||
std::max(layer_performance_[plugin_index].bounds_grow_m2_max, grow);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (minx_ > prev_minx || miny_ > prev_miny || maxx_ < prev_maxx || maxy_ < prev_maxy)
|
||||
{
|
||||
robot::log_error("Illegal bounds change, was [tl: (%f, %f), br: (%f, %f)], but "
|
||||
"is now [tl: (%f, %f), br: (%f, %f)]. The offending layer is %s\n",
|
||||
prev_minx, prev_miny, prev_maxx, prev_maxy,
|
||||
minx_, miny_, maxx_, maxy_,
|
||||
(*plugin)->getName().c_str());
|
||||
plugin->getName().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,15 +302,43 @@ namespace robot_costmap_2d
|
||||
yn = std::min(int(costmap_.getSizeInCellsY()), yn + 1);
|
||||
|
||||
if (xn < x0 || yn < y0)
|
||||
return;
|
||||
|
||||
costmap_.resetMap(x0, y0, xn, yn);
|
||||
|
||||
for (vector<boost::shared_ptr<Layer>>::iterator plugin = plugins_.begin(); plugin != plugins_.end();
|
||||
++plugin)
|
||||
{
|
||||
if ((*plugin)->isEnabled())
|
||||
(*plugin)->updateCosts(costmap_, x0, y0, xn, yn);
|
||||
// No dirty region this cycle (idle costmap): count it so the debug
|
||||
// report still fires and the idle costmap stays visible in the log.
|
||||
if (performance_metrics_enabled_)
|
||||
{
|
||||
++performance_empty_cycles_;
|
||||
maybeReportPerformance();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const auto reset_start = performance_metrics_enabled_ ? std::chrono::steady_clock::now() :
|
||||
std::chrono::steady_clock::time_point();
|
||||
costmap_.resetMap(x0, y0, xn, yn);
|
||||
if (performance_metrics_enabled_)
|
||||
{
|
||||
performance_reset_nanoseconds_ +=
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now() - reset_start).count();
|
||||
}
|
||||
|
||||
for (std::size_t plugin_index = 0; plugin_index < plugins_.size(); ++plugin_index)
|
||||
{
|
||||
const boost::shared_ptr<Layer>& plugin = plugins_[plugin_index];
|
||||
if (!plugin->isEnabled())
|
||||
continue;
|
||||
|
||||
const auto costs_start = performance_metrics_enabled_ ? std::chrono::steady_clock::now() :
|
||||
std::chrono::steady_clock::time_point();
|
||||
plugin->updateCosts(costmap_, x0, y0, xn, yn);
|
||||
if (performance_metrics_enabled_)
|
||||
{
|
||||
layer_performance_[plugin_index].costs_nanoseconds +=
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now() - costs_start).count();
|
||||
++layer_performance_[plugin_index].costs_calls;
|
||||
}
|
||||
}
|
||||
|
||||
bx0_ = x0;
|
||||
@@ -158,6 +347,23 @@ namespace robot_costmap_2d
|
||||
byn_ = yn;
|
||||
|
||||
initialized_ = true;
|
||||
|
||||
if (performance_metrics_enabled_)
|
||||
{
|
||||
const auto cycle_end = std::chrono::steady_clock::now();
|
||||
const std::uint64_t cycle_nanoseconds = static_cast<std::uint64_t>(
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(cycle_end - cycle_start).count());
|
||||
performance_cycle_nanoseconds_ += cycle_nanoseconds;
|
||||
performance_cycle_samples_.push_back(cycle_nanoseconds);
|
||||
++performance_cycles_;
|
||||
lock_hold_nanoseconds_ += static_cast<std::uint64_t>(
|
||||
std::chrono::duration_cast<std::chrono::nanoseconds>(cycle_end - lock_acquired).count());
|
||||
const std::uint64_t window_cells =
|
||||
static_cast<std::uint64_t>(xn - x0) * static_cast<std::uint64_t>(yn - y0);
|
||||
window_cells_sum_ += window_cells;
|
||||
window_cells_max_ = std::max(window_cells_max_, window_cells);
|
||||
maybeReportPerformance();
|
||||
}
|
||||
}
|
||||
|
||||
bool LayeredCostmap::isCurrent()
|
||||
|
||||
Reference in New Issue
Block a user