Skip to content

Revert "feat: Physics-based optimal P estimation with prop-size-aware recommendations"#144

Merged
nerdCopter merged 1 commit into
masterfrom
revert-132-feature/optimal-p-estimation
May 20, 2026
Merged

Revert "feat: Physics-based optimal P estimation with prop-size-aware recommendations"#144
nerdCopter merged 1 commit into
masterfrom
revert-132-feature/optimal-p-estimation

Conversation

@nerdCopter
Copy link
Copy Markdown
Owner

@nerdCopter nerdCopter commented May 20, 2026

Reverts #132

Summary by CodeRabbit

  • Documentation

    • Removed documentation for the optimal P estimation feature and related CLI options from README and OVERVIEW.
  • Refactor

    • Removed --estimate-optimal-p and --prop-size CLI options.
    • Refactored internal code structures and function signatures to simplify analysis processing.
    • Removed unused code paths and related constants.
  • Tests

    • Removed tests for the optimal P estimation feature.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

📝 Walkthrough

Walkthrough

This PR removes the entire "Optimal P Estimation (Optional, Experimental)" feature from the codebase. It deletes related documentation, public constants and types, the complete optimal_p_estimation.rs module, CLI options, and adjusts downstream function signatures to pass primitive arrays and parameters directly instead of bundled configuration structs.

Changes

Complete feature removal and pipeline refactoring

Layer / File(s) Summary
Documentation cleanup
OVERVIEW.md, README.md
Removes --estimate-optimal-p and --prop-size from Table of Contents, feature description section, CLI help text, and example command.
Backend constants and types removal
src/constants.rs, src/data_analysis/mod.rs, src/data_analysis/spectral_analysis.rs
Deletes the entire "Optimal P Estimation Constants" block from constants.rs (including TdTargetSpec, TD_TARGETS, and 15+ related constants), unregisters the optimal_p_estimation submodule, and removes the calculate_hf_energy_ratio function that depended on deleted constants.
Axis naming simplification
src/axis_names.rs
Refactors axis_name to use explicit match instead of array lookup, removes ROLL_PITCH_AXIS_COUNT, and simplifies compile-time invariant to a single array-length check.
Main entry point and CLI refactoring
src/main.rs
Removes CLI option parsing for --estimate-optimal-p and --prop-size, deletes AnalysisOptions struct, refactors process_file signature to accept setpoint_threshold, show_legend, debug_mode, show_butterworth directly, removes optimal-P analysis execution block, adjusts console recommendation output formatting, and rewires plot invocations to pass debug/Butterworth flags directly.
Step-response plotting refactoring
src/plot_functions/plot_step_response.rs
Refactors public function signature to accept primitive arrays (peak_values, current_pd_ratios, recommended_pd_*, recommended_d_*) and parameters (show_legend, setpoint_threshold) instead of bundled structs (CurrentPeakAndRatios, PlotDisplayConfig, ConservativeRecommendations, ModerateRecommendations, OptimalPConfig), removes optimal-P legend section, updates series label construction and combined-response computation to use new array inputs and thresholds, and removes 6 public helper struct declarations.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • nerdCopter/BlackBox_CSV_Render#45: Both PRs modify src/axis_names.rs with overlapping axis naming and constant infrastructure changes.
  • nerdCopter/BlackBox_CSV_Render#69: Both PRs modify step-response recommendation plumbing in plot_step_response.rs, with this PR removing optimal-P legend inputs while preserving conservative/moderate/aggressive arrays.
  • nerdCopter/BlackBox_CSV_Render#118: Both PRs refactor spectral-analysis API in src/data_analysis/spectral_analysis.rs to align with downstream Welch PSD/CPSD/coherence usage.

Suggested labels

DO NOT MERGE

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and accurately describes the main change: reverting a feature commit. The title is specific, concise, and directly matches the changeset content.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch revert-132-feature/optimal-p-estimation

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nerdCopter nerdCopter merged commit 4cd5d3f into master May 20, 2026
1 of 2 checks passed
@nerdCopter nerdCopter deleted the revert-132-feature/optimal-p-estimation branch May 20, 2026 18:43
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/axis_names.rs (1)

16-24: ⚡ Quick win

Keep axis_name() derived from AXIS_NAMES.

This match duplicates both the axis indices and the labels, so axis_name() can drift from AXIS_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.rs module with AXIS_COUNT, AXIS_NAMES, and axis_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 win

Regroup 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6ab4dd1 and 94b3442.

📒 Files selected for processing (10)
  • OVERVIEW.md
  • README.md
  • src/axis_names.rs
  • src/constants.rs
  • src/data_analysis/mod.rs
  • src/data_analysis/optimal_p_estimation.rs
  • src/data_analysis/spectral_analysis.rs
  • src/data_analysis/tests_optimal_p.rs
  • src/main.rs
  • src/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 in src/constants.rs — no hardcoded magic numbers in function code
Axis indices (0=Roll, 1=Pitch, 2=Yaw) must use the src/axis_names.rs module with AXIS_COUNT, AXIS_NAMES, and axis_name() function instead of creating redundant axis index constants
ALWAYS use Firmware revision header to detect firmware type, NEVER use Firmware type
Firmware revision patterns: Betaflight uses Betaflight 4.x.x or Betaflight YYYY.MM, Emuflight uses EmuFlight 0.x.x, INAV uses INAV x.x.x

Files:

  • src/axis_names.rs
  • src/constants.rs
  • src/plot_functions/plot_step_response.rs
  • src/main.rs
🔇 Additional comments (1)
src/axis_names.rs (1)

33-34: LGTM!

Comment on lines +440 to 444
// 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant