[go] Add dynamic segmentation for LiDAR background regions#388
Open
ddol wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds dynamic region segmentation to the LiDAR background grid so background update behaviour can vary by derived region, and exposes a new debug chart endpoint to visualise those regions and their parameters.
Changes:
- Extend
BackgroundGridwith region segmentation state (region index + derived per-region parameters) and apply per-region overrides during background updates after settling. - Add warmup initialisation tracking and trigger one-time region derivation once the grid has settled.
- Add a new
/debug/lidar/background/regionsgo-echarts scatter plot endpoint (with tooltip formatter) and link it from the LiDAR debug dashboard.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| internal/lidar/background.go | Adds region segmentation structures/derivation, warmup initialisation state, and per-region parameter overrides in ProcessFramePolar. |
| internal/lidar/monitor/webserver.go | Adds “Background Regions” debug chart endpoint and dashboard panel, including custom tooltip formatting. |
Comment on lines
+1507
to
+1509
| if g.SettlingComplete && !g.RegionsReady && g.nonzeroCellCount > 0 { | ||
| buildRegionsLocked(g) | ||
| } |
Comment on lines
+851
to
+889
| regionCells := make([][]int, 0) | ||
| for idx := range g.Cells { | ||
| if classes[idx] < 0 || regionIndex[idx] != -1 { | ||
| continue | ||
| } | ||
| targetClass := classes[idx] | ||
| queue := []int{idx} | ||
| regionIndex[idx] = len(regionCells) | ||
| component := []int{idx} | ||
| for q := 0; q < len(queue); q++ { | ||
| cellIdx := queue[q] | ||
| ring := cellIdx / g.AzimuthBins | ||
| az := cellIdx % g.AzimuthBins | ||
| neighbors := [4]int{ | ||
| g.Idx(ring, (az-1+g.AzimuthBins)%g.AzimuthBins), | ||
| g.Idx(ring, (az+1)%g.AzimuthBins), | ||
| -1, | ||
| -1, | ||
| } | ||
| if ring > 0 { | ||
| neighbors[2] = g.Idx(ring-1, az) | ||
| } | ||
| if ring < g.Rings-1 { | ||
| neighbors[3] = g.Idx(ring+1, az) | ||
| } | ||
| for _, nIdx := range neighbors { | ||
| if nIdx < 0 || nIdx >= len(g.Cells) { | ||
| continue | ||
| } | ||
| if classes[nIdx] != targetClass || regionIndex[nIdx] != -1 { | ||
| continue | ||
| } | ||
| regionIndex[nIdx] = len(regionCells) | ||
| queue = append(queue, nIdx) | ||
| component = append(component, nIdx) | ||
| } | ||
| } | ||
| regionCells = append(regionCells, component) | ||
| } |
Comment on lines
+987
to
+1005
| idMap := make(map[int]int, len(finalRegions)) | ||
| regions := make([]BackgroundRegion, 0, len(finalRegions)) | ||
| for _, ri := range finalRegions { | ||
| newID := len(regions) | ||
| idMap[ri.ID] = newID | ||
| meanRange := ri.SumRange / float64(ri.CellCount) | ||
| meanSpread := ri.SumSpread / float64(ri.CellCount) | ||
| meanTimes := ri.SumTimes / float64(ri.CellCount) | ||
| meanNorm := ri.SumNorm / float64(ri.CellCount) | ||
| params := deriveRegionParams(g.Params, meanNorm) | ||
| regions = append(regions, BackgroundRegion{ | ||
| ID: newID, | ||
| CellCount: ri.CellCount, | ||
| MeanRange: float32(meanRange), | ||
| MeanSpread: float32(meanSpread), | ||
| MeanTimesSeen: float32(meanTimes), | ||
| MeanNormSpread: float32(meanNorm), | ||
| Params: params, | ||
| }) |
Comment on lines
+1525
to
+1531
| charts.WithVisualMapOpts(opts.VisualMap{ | ||
| Show: opts.Bool(true), | ||
| Calculable: opts.Bool(true), | ||
| Min: 0, | ||
| Max: float32(maxRegion), | ||
| Dimension: "2", | ||
| InRange: &opts.VisualMapInRange{Color: []string{"#003f5c", "#2f4b7c", "#665191", "#a05195", "#d45087", "#f95d6a", "#ff7c43", "#ffa600", "#62d2a2", "#4f9da6", "#a7c5eb", "#f0a6ca"}}, |
Comment on lines
+1469
to
+1474
| stride := 3 | ||
| if v := r.URL.Query().Get("stride"); v != "" { | ||
| if parsed, err := strconv.Atoi(v); err == nil && parsed > 0 { | ||
| stride = parsed | ||
| } | ||
| } |
Comment on lines
1267
to
1273
| g.mu.Lock() | ||
| if bm.StartTime.IsZero() { | ||
| bm.StartTime = now | ||
| if !g.WarmupInitialized && g.Params.WarmupMinFrames > 0 && !g.SettlingComplete { | ||
| g.WarmupFramesRemaining = g.Params.WarmupMinFrames | ||
| g.WarmupInitialized = true | ||
| } | ||
| if g.WarmupFramesRemaining == 0 && g.Params.WarmupMinFrames > 0 && !g.SettlingComplete { | ||
| g.WarmupFramesRemaining = g.Params.WarmupMinFrames |
Comment on lines
640
to
+649
| g.ChangesSinceSnapshot = 0 | ||
| g.ForegroundCount = 0 | ||
| g.BackgroundCount = 0 | ||
| g.nonzeroCellCount = 0 | ||
| g.WarmupFramesRemaining = 0 | ||
| g.WarmupInitialized = false | ||
| g.SettlingComplete = false | ||
| g.RegionIndex = nil | ||
| g.Regions = nil | ||
| g.RegionsReady = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements dynamic region segmentation for the LiDAR background grid with warmup initialisation and a web chart endpoint.
Changes
internal/lidar/background.go— Add dynamic segmentation logic to BackgroundGrid, including warmup initialisation (+506 lines)internal/lidar/monitor/webserver.go— Add tooltip formatter and chart endpoint for background regions visualisation (+94 lines)Commits
2e4931cAdd lidar background regions9a6ae75Fix tooltip formatter in background regions charta4f3701Add warmup initialisation to BackgroundGrid3 commits, 2 files changed, +593 −7