Skip to content

Fix: the second gyro is read while the log is paused - #11995

Open
MrScothh wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
MrScothh:fix/secondary-gyro-only-while-running
Open

MrScothh wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
MrScothh:fix/secondary-gyro-only-while-running

Conversation

@MrScothh

Copy link
Copy Markdown
Contributor

Follow-up to #11933, which you merged for RC1. Review raised this after the merge and it is right.

What happens

blackboxSetState() turns the secondary gyro on for every state above BLACKBOX_STATE_STOPPED:

gyroSetSecondaryLogging(newState > BLACKBOX_STATE_STOPPED);

That covers more than logging. The header states, BLACKBOX_STATE_PAUSED, which is where a log goes when the blackbox switch is turned off in flight, and BLACKBOX_STATE_SHUTTING_DOWN all write no main frame. A reading taken in any of them goes nowhere, and it costs a transaction on the sensor bus every gyro cycle while it lasts. A pilot who switches logging off mid-flight keeps paying for a sensor nobody reads.

The change

One condition: the second gyro is read while frames are being written, and not otherwise.

gyroSetSecondaryLogging(newState == BLACKBOX_STATE_RUNNING);

Nothing else changes. The zero calibration does not depend on this flag: gyroUpdateSecondary() also reads while !gyroCalibrationComplete[GYRO_SECONDARY], which is what measures the zero at startup, before arming. Stopping and restarting the reads does not re-initialise the sensor, does not restart a calibration and has no settling time, since the device is never reconfigured. The first frame after a resume can carry a reading one gyro cycle old, which is under a millisecond.

Testing

SITL with a counter on the secondary read, armed throughout, toggling the blackbox switch between running and paused:

before after
before arming, after calibration 0 reads/s 0 reads/s
armed, logging 76 to 103 38 to 93
armed, log paused 76 to 95 0
armed, logging again 74 to 112 58 to 102
disarmed 0 0

The first second of each phase carries the transition, so it sits between the two rates. Both runs produce a log and both resume cleanly. The zero calibration still runs before arming in both, which is the handful of reads visible there.

The condition enabled it for every state above STOPPED, which includes the
header states, a log paused from the switch, and the shutdown. None of those
write a main frame, so each reading taken there goes nowhere while still costing
a transaction on the sensor bus every gyro cycle.

Measured in SITL with a counter on the secondary read, armed throughout and the
blackbox switch toggled: with the log paused the reads went on at 76 to 95 a
second, and now they stop at zero and come back on resume. The zero calibration
is untouched, since it is driven by its own condition and runs before arming.
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can add REVIEW.md to your repo root and Qodo follows it on every PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Stop Secondary Gyro Reads While Blackbox Logging Is Paused

🐞 Bug fix 🕐 Less than 10 minutes

Grey Divider

AI Description

• Enables secondary gyro sampling only while blackbox writes running-state frames.
• Stops wasted sensor-bus transactions during headers, pauses, and shutdown.
• Preserves independent startup calibration reads and clean logging resume.
Diagram

graph TD
    A["State Change"] --> B{"Running State?"}
    B -->|Yes| C["Logging Enabled"] --> D{"Read Needed?"} -->|Yes| G["Read Secondary Gyro"]
    B -->|No| E["Logging Disabled"] --> D
    F["Calibration Pending"] --> D
    D -->|No| H["Skip Bus Read"]
Loading
High-Level Assessment

The exact RUNNING-state check is the best approach because that state directly represents main-frame production. The previous ordinal comparison was overly broad, while coupling sensor control to individual frame-write calls would spread lifecycle responsibility and increase transition risk.

Files changed (1) +5 / -2

Bug fix (1) +5 / -2
blackbox.cRestrict secondary gyro sampling to active frame logging +5/-2

Restrict secondary gyro sampling to active frame logging

• Changes the secondary logging condition from every state above STOPPED to only BLACKBOX_STATE_RUNNING. Expanded comments explain why header, paused, and shutdown states should not spend sensor-bus transactions on unused readings.

src/main/blackbox/blackbox.c

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