Revert "feat: Physics-based optimal P estimation with prop-size-aware recommendations"#144
Conversation
… recomme…" This reverts commit 6ab4dd1.
📝 WalkthroughWalkthroughThis PR removes the entire "Optimal P Estimation (Optional, Experimental)" feature from the codebase. It deletes related documentation, public constants and types, the complete ChangesComplete feature removal and pipeline refactoring
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/axis_names.rs (1)
16-24: ⚡ Quick winKeep
axis_name()derived fromAXIS_NAMES.This
matchduplicates both the axis indices and the labels, soaxis_name()can drift fromAXIS_NAMES. Prefer indexing the shared array and keeping the panic path only for invalid input.♻️ Proposed fix
pub fn axis_name(index: usize) -> &'static str { - match index { - 0 => "Roll", - 1 => "Pitch", - 2 => "Yaw", - _ => panic!( - "Invalid axis index: {}. Expected 0 (Roll), 1 (Pitch), or 2 (Yaw)", - index - ), - } + AXIS_NAMES.get(index).copied().unwrap_or_else(|| { + panic!( + "Invalid axis index: {}. Expected 0 (Roll), 1 (Pitch), or 2 (Yaw)", + index + ) + }) }As per coding guidelines, Axis indices (0=Roll, 1=Pitch, 2=Yaw) must use the
src/axis_names.rsmodule withAXIS_COUNT,AXIS_NAMES, andaxis_name()function instead of creating redundant axis index constants.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/axis_names.rs` around lines 16 - 24, Replace the manual match in axis_name() with a direct lookup into the shared AXIS_NAMES array using AXIS_COUNT to validate bounds: check that index < AXIS_COUNT (or use get on AXIS_NAMES) and return AXIS_NAMES[index] for valid indices, and only panic with a clear message for invalid indices; reference AXIS_NAMES, AXIS_COUNT, and axis_name() so the function relies on the single source of truth instead of duplicating labels.src/plot_functions/plot_step_response.rs (1)
18-38: ⚡ Quick winRegroup these step-response annotations into a typed input struct.
This signature now has several adjacent
[Option<_>; 3]parameters with the same shapes, so a future argument swap will still compile and silently mislabel the plot. Wrapping the recommendation/assessment fields into one struct would keep the revert intact while restoring type safety.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/plot_functions/plot_step_response.rs` around lines 18 - 38, The plot_step_response function signature exposes many adjacent similarly-shaped parameters (peak_values, current_pd_ratios, assessments, recommended_pd_conservative, recommended_d_conservative, recommended_d_min_conservative, recommended_d_max_conservative, recommended_pd_aggressive, recommended_d_aggressive, recommended_d_min_aggressive, recommended_d_max_aggressive) which risks silent argument-swaps; define a new typed struct (e.g., StepResponseAnnotation or RecommendationEntry) that groups these related Option fields (retain the existing Option types and array length of 3) and replace those separate parameters with a single &[StepResponseAnnotation; 3] (or slice) parameter in plot_step_response, then update all call sites to construct the struct instances and update any internal uses to access the struct fields instead of the standalone arrays; ensure the new struct derives/implements Copy/Clone/Debug/etc. as needed and keep other parameters (has_nonzero_f_term_data, setpoint_threshold, pid_metadata, sample_rate, show_legend) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/plot_functions/plot_step_response.rs`:
- Around line 440-444: Define a named constant for the Y-range half-padding in
src/constants.rs (e.g., Y_RANGE_HALF_PADDING or Y_RANGE_PADDING_FACTOR_HALF with
value 0.55), export it, and then replace the hardcoded 0.55 in
plot_step_response.rs where half_range is computed (variable half_range) by
importing and using that constant (use crate::constants::Y_RANGE_HALF_PADDING).
This centralizes the magic number, preserves the existing calculation
(half_range = range * <constant>), and keeps the padding rule discoverable and
consistent.
---
Nitpick comments:
In `@src/axis_names.rs`:
- Around line 16-24: Replace the manual match in axis_name() with a direct
lookup into the shared AXIS_NAMES array using AXIS_COUNT to validate bounds:
check that index < AXIS_COUNT (or use get on AXIS_NAMES) and return
AXIS_NAMES[index] for valid indices, and only panic with a clear message for
invalid indices; reference AXIS_NAMES, AXIS_COUNT, and axis_name() so the
function relies on the single source of truth instead of duplicating labels.
In `@src/plot_functions/plot_step_response.rs`:
- Around line 18-38: The plot_step_response function signature exposes many
adjacent similarly-shaped parameters (peak_values, current_pd_ratios,
assessments, recommended_pd_conservative, recommended_d_conservative,
recommended_d_min_conservative, recommended_d_max_conservative,
recommended_pd_aggressive, recommended_d_aggressive,
recommended_d_min_aggressive, recommended_d_max_aggressive) which risks silent
argument-swaps; define a new typed struct (e.g., StepResponseAnnotation or
RecommendationEntry) that groups these related Option fields (retain the
existing Option types and array length of 3) and replace those separate
parameters with a single &[StepResponseAnnotation; 3] (or slice) parameter in
plot_step_response, then update all call sites to construct the struct instances
and update any internal uses to access the struct fields instead of the
standalone arrays; ensure the new struct derives/implements
Copy/Clone/Debug/etc. as needed and keep other parameters
(has_nonzero_f_term_data, setpoint_threshold, pid_metadata, sample_rate,
show_legend) unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a4d1df72-b42f-48e5-9d2e-93e449749daf
📒 Files selected for processing (10)
OVERVIEW.mdREADME.mdsrc/axis_names.rssrc/constants.rssrc/data_analysis/mod.rssrc/data_analysis/optimal_p_estimation.rssrc/data_analysis/spectral_analysis.rssrc/data_analysis/tests_optimal_p.rssrc/main.rssrc/plot_functions/plot_step_response.rs
💤 Files with no reviewable changes (6)
- src/data_analysis/mod.rs
- README.md
- src/data_analysis/tests_optimal_p.rs
- src/data_analysis/optimal_p_estimation.rs
- src/data_analysis/spectral_analysis.rs
- OVERVIEW.md
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Build Release Binaries (windows-latest, binary-windows, target/release/BlackBox_CSV_Render.exe)
- GitHub Check: Build Release Binaries (ubuntu-latest, binary-linux, target/release/BlackBox_CSV_Render)
- GitHub Check: Build Release Binaries (macos-latest, binary-macos, target/release/BlackBox_CSV_Render)
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.rs
📄 CodeRabbit inference engine (AGENTS.md)
src/**/*.rs: All constants go insrc/constants.rs— no hardcoded magic numbers in function code
Axis indices (0=Roll, 1=Pitch, 2=Yaw) must use thesrc/axis_names.rsmodule withAXIS_COUNT,AXIS_NAMES, andaxis_name()function instead of creating redundant axis index constants
ALWAYS useFirmware revisionheader to detect firmware type, NEVER useFirmware type
Firmware revision patterns: Betaflight usesBetaflight 4.x.xorBetaflight YYYY.MM, Emuflight usesEmuFlight 0.x.x, INAV usesINAV x.x.x
Files:
src/axis_names.rssrc/constants.rssrc/plot_functions/plot_step_response.rssrc/main.rs
🔇 Additional comments (1)
src/axis_names.rs (1)
33-34: LGTM!
| // Simple symmetric range expansion with 10% padding | ||
| let range = (global_resp_max - global_resp_min).max(0.1); | ||
| let mid = (global_resp_max + global_resp_min) / 2.0; | ||
| // half_range = range * 0.55 gives a total span of 1.1*range (10% total expansion) | ||
| // which corresponds to ≈5% padding on each side of the center. | ||
| let half_range = range * 0.55; | ||
| let half_range = range * 0.55; // 10% padding = 1.1/2 = 0.55 | ||
| (mid - half_range, mid + half_range) |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Move the Y-range padding factor into src/constants.rs.
0.55 is a newly introduced derived constant in function code. Please centralize it in src/constants.rs and reference it here so the padding rule stays discoverable and consistent.
As per coding guidelines, src/**/*.rs: All constants go in src/constants.rs — no hardcoded magic numbers in function code.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/plot_functions/plot_step_response.rs` around lines 440 - 444, Define a
named constant for the Y-range half-padding in src/constants.rs (e.g.,
Y_RANGE_HALF_PADDING or Y_RANGE_PADDING_FACTOR_HALF with value 0.55), export it,
and then replace the hardcoded 0.55 in plot_step_response.rs where half_range is
computed (variable half_range) by importing and using that constant (use
crate::constants::Y_RANGE_HALF_PADDING). This centralizes the magic number,
preserves the existing calculation (half_range = range * <constant>), and keeps
the padding rule discoverable and consistent.
Reverts #132
Summary by CodeRabbit
Documentation
Refactor
--estimate-optimal-pand--prop-sizeCLI options.Tests