Skip to content

Testing for PCU 4/23/26#47

Closed
rahilpasha wants to merge 1 commit into
mainfrom
rp/update_PCU
Closed

Testing for PCU 4/23/26#47
rahilpasha wants to merge 1 commit into
mainfrom
rp/update_PCU

Conversation

@rahilpasha

@rahilpasha rahilpasha commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Updates
    • Modified accelerator pedal sensor default configuration for dual-sensor operation
    • Updated brake pressure validation processing during normal operation
    • Adjusted torque control safety logic and drivetrain mode selection behavior

@coderabbitai

coderabbitai Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Three sensor and safety validation systems are modified: default accelerator pedal mode is disabled, brake pressure plausibility validation between dual sensors is deactivated, and torque control safety gating bypasses drive-state checks while forcing overall sensor plausibility true.

Changes

Cohort / File(s) Summary
Accelerator Pedal Configuration
PCU/Core/User/Inc/FEB_PINOUT.h
Compile-time macro SINGLE_APPS_MODE changed from 1 to 0, disabling single-sensor accelerator pedal mode by default.
Brake System Plausibility
PCU/Core/User/Src/FEB_ADC.c
Inter-sensor pressure difference validation between pressure1_percent and pressure2_percent removed; tolerance-based plausibility logic disabled while other brake data computation (pressure mapping, constrain, switches, BOTS) remains intact.
Torque Control Safety Gating
PCU/Core/User/Src/FEB_RMS.c
Brake plausibility no longer force-set after sensor reads; sensors_plausible now forcibly set true, bypassing BMS/DRIVE-state plausibility checks while mode selection proceeds based on brake position thresholds.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hop speeds quicken, sensors take their ease,
Brakes and drive-states yield with gentle squeeze,
One pedal, trust the flow, no double-check,
Zip through safety gates without a speck!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Testing for PCU 4/23/26' is vague and does not meaningfully describe the actual changes: disabling SINGLE_APPS_MODE, removing brake plausibility enforcement, and bypassing torque control safety gating. Replace with a specific title describing the primary change, such as 'Disable brake plausibility checks and safety gating in PCU' or 'Update PCU accelerator and brake sensor modes for testing'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 rp/update_PCU

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.

@coderabbitai coderabbitai Bot left a comment

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
PCU/Core/User/Src/FEB_ADC.c (1)

582-593: ⚠️ Potential issue | 🟠 Major

Major: brake_data->plausible is now never written in FEB_ADC_GetBrakeData().

With the plausibility block commented out, this function no longer sets brake_data->plausible in any branch — the field is left holding whatever stale value the caller's struct had on entry. Two concrete downstream consequences:

  1. FEB_CAN_Diagnostics.c packs Brake_Data.plausible into the brake status CAN frame (bit 0). Since Brake_Data is the zero-initialized global in FEB_RMS.c, the diagnostic will report plausible=false from boot until FEB_RMS_Torque() reaches the "pedals released" branch (Line 228) and flips it true — giving vehicle observers an incorrect safety status.
  2. Any future consumer that reads brake_data->plausible from a local (stack-allocated) Brake_DataTypeDef will observe indeterminate data.

Even while the inter-sensor check is disabled for bench testing, the function should still affirmatively initialize the flag (e.g., to true) at entry so the contract of "this function fully populates the struct" is preserved.

🛠️ Suggested minimal fix
 ADC_StatusTypeDef FEB_ADC_GetBrakeData(Brake_DataTypeDef *brake_data)
 {
   if (!brake_data)
     return ADC_STATUS_ERROR;
 
+  /* Default to plausible; re-enable inter-sensor check below once sensor 2 is wired. */
+  brake_data->plausible = true;
+
   /* Get brake pressure readings */

Separately, when you re-enable the check, note the original expression compares a percent-scale diff (pressure1_percent - pressure2_percent, range 0–100) against BRAKE_PRESSURE_MAX_PHYSICAL_BAR * 0.2f = 40.0f bar — mixed units. If the intent was "20% tolerance", the threshold should simply be 20.0f (percent), or the diff should be computed from bar values. Worth fixing before it gets re-enabled.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@PCU/Core/User/Src/FEB_ADC.c` around lines 582 - 593, FEB_ADC_GetBrakeData
currently never sets brake_data->plausible because the plausibility block was
commented out; restore the function's contract by explicitly initializing
brake_data->plausible (e.g., set to true) at the top of FEB_ADC_GetBrakeData or
before any early return so callers never see stale/indeterminate data, and when
you later re-enable the inter-sensor check update the commented comparison to
use consistent units (either compare percent vs percent like
pressure1_percent/pressure2_percent against 20.0f, or compute diffs in bar
before comparing to BRAKE_PRESSURE_MAX_PHYSICAL_BAR * 0.2f).
PCU/Core/User/Src/FEB_RMS.c (1)

196-218: ⚠️ Potential issue | 🔴 Critical

Critical: committed TEMP OVERRIDE bypasses torque-gating safety checks.

Line 198 unconditionally sets sensors_plausible = true before it is used as the gate for both REGEN (Line 232) and ACCELERATION (Line 241) modes. Concrete impact on the signed-off code path:

  • BMS drive state is no longer a gate for torque. FEB_RMS_Process() guards enable, but with this override the torque calculation in Lines 232‑246 will still execute regardless of bms_in_drive / DRIVE_STATE, so RMS_CONTROL_MESSAGE.torque gets computed from APPS and pushed to FEB_CAN_RMS_Transmit_UpdateTorque on Line 254 alongside whatever enabled happens to be. Any future change that holds enabled high across a BMS drive-state drop would command torque unexpectedly.
  • The safety-violation log block (Lines 200‑218) becomes unreachable. During the very testing this override is intended to support, you lose the diagnostic signal that would tell you the vehicle would otherwise have cut torque.
  • Semantic confusion. The identifier sensors_plausible suggests a check on APPS_Data.plausible / Brake_Data.plausible, but Line 197 computes it purely from BMS/drive state, and Line 198 then discards even that. The !APPS_Data.plausible and !Brake_Data.plausible branches in the log block were never actually enforced against torque by this variable to begin with — worth fixing that gap too.

Strongly recommend gating the override behind a compile-time flag (matching the SINGLE_APPS_MODE pattern already in FEB_PINOUT.h) so it cannot accidentally ship, and make the variable actually reflect sensor plausibility before using it.

🔒 Suggested compile-time-gated refactor
   // Check plausibility and safety conditions (require BMS in drive state)
   bool bms_in_drive = FEB_CAN_BMS_InDriveState();
-  bool sensors_plausible = bms_in_drive && DRIVE_STATE;
-  sensors_plausible = true; /* TEMP OVERRIDE - ignore BMS state for testing */
+  bool sensors_plausible = bms_in_drive && DRIVE_STATE &&
+                           APPS_Data.plausible && Brake_Data.plausible;
+#ifdef RMS_BYPASS_SAFETY_FOR_BENCH_TEST
+#warning "RMS safety gating is bypassed — DO NOT FLASH TO VEHICLE"
+  sensors_plausible = true;
+#endif

At minimum, please add a #warning / #error guard, a tracking issue, and a target date for removal so this doesn't silently reach a car.

Happy to open a follow-up issue to track removal of the override and re-enable the gating, if that helps.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@PCU/Core/User/Src/FEB_RMS.c` around lines 196 - 218, Remove the unconditional
test override that sets sensors_plausible = true; instead compute
sensors_plausible from the actual checks (bms_in_drive =
FEB_CAN_BMS_InDriveState(), DRIVE_STATE, APPS_Data.plausible,
Brake_Data.plausible and optionally brake position vs BRAKE_POSITION_THRESHOLD)
so the existing safety-log block and torque gating in FEB_RMS_Process() and
RMS_CONTROL_MESSAGE.torque -> FEB_CAN_RMS_Transmit_UpdateTorque are honored; if
a test override is required, wrap it in a compile-time flag (like
SINGLE_APPS_MODE) and add a `#warning` or `#error` so it cannot be compiled into
production, and add a short tracking comment/issue ID and target removal date
adjacent to the flag.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@PCU/Core/User/Src/FEB_ADC.c`:
- Around line 582-593: FEB_ADC_GetBrakeData currently never sets
brake_data->plausible because the plausibility block was commented out; restore
the function's contract by explicitly initializing brake_data->plausible (e.g.,
set to true) at the top of FEB_ADC_GetBrakeData or before any early return so
callers never see stale/indeterminate data, and when you later re-enable the
inter-sensor check update the commented comparison to use consistent units
(either compare percent vs percent like pressure1_percent/pressure2_percent
against 20.0f, or compute diffs in bar before comparing to
BRAKE_PRESSURE_MAX_PHYSICAL_BAR * 0.2f).

In `@PCU/Core/User/Src/FEB_RMS.c`:
- Around line 196-218: Remove the unconditional test override that sets
sensors_plausible = true; instead compute sensors_plausible from the actual
checks (bms_in_drive = FEB_CAN_BMS_InDriveState(), DRIVE_STATE,
APPS_Data.plausible, Brake_Data.plausible and optionally brake position vs
BRAKE_POSITION_THRESHOLD) so the existing safety-log block and torque gating in
FEB_RMS_Process() and RMS_CONTROL_MESSAGE.torque ->
FEB_CAN_RMS_Transmit_UpdateTorque are honored; if a test override is required,
wrap it in a compile-time flag (like SINGLE_APPS_MODE) and add a `#warning` or
`#error` so it cannot be compiled into production, and add a short tracking
comment/issue ID and target removal date adjacent to the flag.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e2b0b70b-a823-45f9-8a93-eb52727fa5f0

📥 Commits

Reviewing files that changed from the base of the PR and between b4b94eb and cd27ce7.

📒 Files selected for processing (3)
  • PCU/Core/User/Inc/FEB_PINOUT.h
  • PCU/Core/User/Src/FEB_ADC.c
  • PCU/Core/User/Src/FEB_RMS.c

@ZacharyBer ZacharyBer closed this Jun 6, 2026
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.

2 participants