Skip to content

feat(motor-test): log all firmware status messages to the console - #2181

Open
amilcarlucas wants to merge 1 commit into
masterfrom
STATUSTEXT_in_motor_test
Open

amilcarlucas wants to merge 1 commit into
masterfrom
STATUSTEXT_in_motor_test

Conversation

@amilcarlucas

Copy link
Copy Markdown
Collaborator

Description

Enable STATUSTEXT monitoring while the motor-test plugin is active. Observe messages through pymavlink receive hooks so command ACK, parameter, and battery reads cannot silently filter out firmware feedback.

Log every nonempty payload without requiring a motor-test prefix. Preserve error and warning severity while making informational and debug messages visible at normal console verbosity. Safely decode padded and invalid UTF-8 payloads.

Poll pending telemetry between commands and after Test All dispatch. Include firmware diagnostics received before or shortly after a failed motor-test ACK in the returned error message.

Move the receive hook across reconnects and remove it when the plugin is deactivated or destroyed, preserving unrelated hooks. Bound polling work per refresh and prevent duplicate refresh timers.

Add regression tests for all motor command paths, ACK ordering, severity levels, payload decoding, reconnects, cleanup, and transport failures. Update the motor-test architecture documentation.

Keep existing motor safety checks unchanged.

Checklist

  • Run pre-commit checks locally
  • Verified by a human programmer
  • All commits are signed off (use git commit --signoff)
  • Code follows our coding standards
  • Documentation updated if needed
  • No breaking changes or properly documented

Testing

Describe how you tested these changes:

  • Unit tests pass
  • Integration tests pass
  • Manual testing performed
  • Tested on flight controller hardware

Copilot AI balanced review requested due to automatic review settings October 7, 2026 13:57
@amilcarlucas amilcarlucas added the AIReview Request an automated AI review; picked up by the reviewprs sweep label Oct 7, 2026

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Constructor-time hook acquisition can leak monitoring, and the new translatable messages are missing from locale catalogs.

Review effort: Balanced
Findings: 2 Medium severity · 2 Low severity

Open (4)
What changed in this PR

Adds motor-test firmware STATUSTEXT monitoring across backend, model, and view layers.

Changes:

  • Adds receive-hook logging, bounded polling, and failed-ACK diagnostics.
  • Manages monitoring across plugin lifecycle and reconnects.
  • Adds regression tests and architecture documentation.
File Description
ardupilot_methodic_configurator/​backend_flightcontroller_commands.py Implements monitoring and polling.
ardupilot_methodic_configurator/​backend_flightcontroller.py Exposes facade methods.
ardupilot_methodic_configurator/​backend_flightcontroller_protocols.py Extends the flight-controller protocol.
ardupilot_methodic_configurator/​plugins/​data_model_motor_test.py Delegates monitoring operations.
ardupilot_methodic_configurator/​plugins/​frontend_tkinter_motor_test.py Integrates monitoring with view lifecycle.
tests/​test_backend_flightcontroller.py Tests facade delegation.
tests/​test_backend_flightcontroller_commands.py Tests parsing, logging, polling, and reconnects.
tests/​plugins/​test_data_model_motor_test.py Tests model delegation.
tests/​plugins/​test_frontend_tkinter_motor_test.py Tests view polling and cleanup.
ARCHITECTURE_motor_test.md Documents firmware feedback monitoring.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 134 to +135
self._create_widgets()
self.model.set_status_text_logging(True)
commands.poll_motor_test_status_text()
records = [record for record in caplog.records if "Unrelated sensor diagnostic" in record.getMessage()]
assert len(records) == 1
assert records[0].levelno >= logging.INFO
severity = int(getattr(msg, "severity", 6))
# Keep even firmware DEBUG messages visible at normal console verbosity.
log = logging_error if severity <= 3 else logging_warning if severity == 4 else logging_info
log(_("Flight controller STATUSTEXT (%(severity)d): %(text)s"), {"severity": severity, "text": text})
if master.recv_msg() is None: # pyright: ignore[reportAttributeAccessIssue]
break
except (OSError, ValueError) as exc:
logging_warning(_("Could not read motor-test status messages: %(error)s"), {"error": str(exc)})
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

☂️ Code Coverage

current status: ✅

Overall Coverage

Statements Covered Coverage Threshold Status
27311 25053 92% 89% 🟢

New Files

No new covered files...

Modified Files

No covered modified files...

updated for commit: 53203f8 by action🐍

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

     3 files       3 suites   38m 34s ⏱️
 6 860 tests  6 851 ✅  9 💤 0 ❌
20 461 runs  20 428 ✅ 33 💤 0 ❌

Results for commit 53203f8.

♻️ This comment has been updated with latest results.

@AP-Review

AP-Review commented Oct 8, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-10-08)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: REQUEST CHANGES

Reviewed at head 1b1cfb8bab.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/methodicconfigurator/2181/1.html#prMethodicConfigurator-2181

Thanks for this; logging every STATUSTEXT through a pymavlink message hook is a neat approach, and the reconnect/deactivate handling looks right. One problem needs fixing before merge:

  1. The new once-a-second poll starves the battery display (https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-5bf89ebdc67eb713f5ff51bc3236d106ca22f032998b0446daea02b80348424dR357, called from https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-6dff0ddaef6bc550a0eead1ca254ab2df8e40428029f9695df760b8b71b52033R361). poll_motor_test_status_text() drains the link with recv_msg() just before _update_battery_status(). get_battery_status() reads with non-blocking recv_match(type='BATTERY_STATUS'), which then finds nothing. With a real pymavlink parser and a 2 Hz battery stream, reads go from always succeeding to never succeeding. The voltage label first shows a stale cached value, then 'N/A' once the 3 s cache expires. The battery monitor then re-requests the stream on the Tk thread, sleeping about 1.9 s each time, so the UI freezes periodically and the warning repeats. Could the hook (or the poll) keep the latest BATTERY_STATUS for get_battery_status(), or could the battery read fall back to master.messages? A test that interleaves the poll with get_battery_status() would cover this.

  2. Minor: set_status_text_logging(True) in init (https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-6dff0ddaef6bc550a0eead1ca254ab2df8e40428029f9695df760b8b71b52033R135) runs before code that can raise. If construction fails, the plugin loader catches the error without a stored view, and the hook stays attached until the parent frame is cleaned up. Wrapping the rest of the constructor to release the hook on failure would fix it. Just removing the call would break the standalone MotorTestWindow, which never calls on_activate().

Optional: the severity test at https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-5ab67beea2ef10b83cc1cfbb2d1432811aabb252a08a262242760447c1f1821fR90 could assert the exact ERROR/WARNING/INFO mapping instead of >= INFO. The missing .pot/.po entries are fine, since the translation workflow adds them after merge. Not exercised here: real hardware/SITL timing and the full GUI suite.

@amilcarlucas
amilcarlucas force-pushed the STATUSTEXT_in_motor_test branch from 1b1cfb8 to 282da3e Compare October 8, 2026 14:01
@coveralls

coveralls commented Oct 8, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 38483205280

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Warning

No base build found for commit 9a96139 on master.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 91.773%

Details

  • Patch coverage: No coverable lines changed in this PR.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 27311
Covered Lines: 25064
Line Coverage: 91.77%
Relevant Branches: 8244
Covered Branches: 6991
Branch Coverage: 84.8%
Branches in Coverage %: No
Coverage Strength: 2.74 hits per line

💛 - Coveralls

@AP-Review

AP-Review commented Oct 8, 2026 •

Copy link
Copy Markdown

Deprecated — see below for the updated review.

Previous review (2026-10-08)

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: REQUEST CHANGES

Reviewed at head 282da3e4d6.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/methodicconfigurator/2181/2.html#prMethodicConfigurator-2181

Thanks for the update. This is a rebase of the version reviewed earlier (now 282da3e, same changes as 1b1cfb8), so the earlier points still apply:

  1. Blocking: the 1 s poll in poll_motor_test_status_text() (https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-5bf89ebdc67eb713f5ff51bc3236d106ca22f032998b0446daea02b80348424dR357, called from https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-6dff0ddaef6bc550a0eead1ca254ab2df8e40428029f9695df760b8b71b52033R361) consumes BATTERY_STATUS with recv_msg() right before get_battery_status() does its non-blocking recv_match(). With a real pymavlink parser, battery reads go from 5/5 to 0/5. The voltage goes stale, then shows N/A, and the battery monitor keeps re-requesting the stream with about 1.9 s of sleeps on the Tk thread. master.messages still has the latest BATTERY_STATUS, so a timestamp-checked fallback (or caching it in the hook) plus a test that interleaves the poll with get_battery_status() would fix it.

  2. Minor: set_status_text_logging(True) in init (https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-6dff0ddaef6bc550a0eead1ca254ab2df8e40428029f9695df760b8b71b52033R135) runs before code that can raise. If construction fails, the plugin loader stores no view and the hook stays attached until the parent is cleaned up. Releasing it on failure fixes this; dropping the call would break the standalone window, which never calls on_activate().

  3. Minor: the hook only moves to a new connection on the next command or poll (https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-5bf89ebdc67eb713f5ff51bc3236d106ca22f032998b0446daea02b80348424dR321). After a reset-and-reconnect from the motor-test page, status text that the connection code reads first is not logged.

Optional: the severity test (https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-5ab67beea2ef10b83cc1cfbb2d1432811aabb252a08a262242760447c1f1821fR90) could assert the exact ERROR/WARNING/INFO mapping, since >= INFO also passes if everything is logged as ERROR. Not exercised: hardware/SITL timing and the full GUI suite.

Enable STATUSTEXT monitoring while the motor-test plugin is active.
Observe messages through pymavlink receive hooks so command ACK,
parameter, and battery reads cannot silently filter out firmware feedback.

Log every nonempty payload without requiring a motor-test prefix.
Preserve error and warning severity while making informational and debug
messages visible at normal console verbosity. Safely decode padded and
invalid UTF-8 payloads.

Poll pending telemetry between commands and after Test All dispatch.
Include firmware diagnostics received before or shortly after a failed
motor-test ACK in the returned error message.

Move the receive hook across reconnects and remove it when the plugin
is deactivated or destroyed, preserving unrelated hooks. Bound polling
work per refresh and prevent duplicate refresh timers.

Add regression tests for all motor command paths, ACK ordering, severity
levels, payload decoding, reconnects, cleanup, and transport failures.
Update the motor-test architecture documentation.

Keep existing motor safety checks unchanged.

Signed-off-by: Dr.-Ing. Amilcar do Carmo Lucas <[email protected]>
@amilcarlucas
amilcarlucas force-pushed the STATUSTEXT_in_motor_test branch from 282da3e to 53203f8 Compare October 13, 2026 23:16
@AP-Review

Copy link
Copy Markdown

Automated review note — AI-generated (Claude+Codex), validated against the live diff. Please sanity-check before acting.
Verdict: REQUEST CHANGES

Reviewed at head 53203f8780.
Full report: https://firmware.ardupilot.org/Tools/APReview/DevCallReviews/PRReviews/ardupilot/methodicconfigurator/2181/3.html#prMethodicConfigurator-2181

Thanks for the rebase. 53203f8 carries the same changes as 282da3e, now on a base where the battery and status-text code has changed, so the earlier points were re-run on this head rather than carried over. They still apply:

  1. Blocking: the 1 s refresh calls poll_status_text() (https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-6dff0ddaef6bc550a0eead1ca254ab2df8e40428029f9695df760b8b71b52033R361) before _update_battery_status(). The poll drains the link with recv_msg() (https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-5bf89ebdc67eb713f5ff51bc3236d106ca22f032998b0446daea02b80348424dR419), so the non-blocking BATTERY_STATUS read that follows finds nothing. On ArduCopter 4.7.2 SITL with the real motor-test window left open, two refreshes show the cached voltage, then the third shows 'Voltage: N/A' with a 'Battery status not available from telemetry' warning and the stream re-request sleeps on the Tk thread: 9 of 27 refreshes, each freezing the window for about 2.3 s. The base commit shows 12.60V on every refresh with no freeze. Moving the poll_status_text() call to after _update_battery_status() fixed it in the same test (29 of 29 voltages, no freeze, 'starting motor test' and 'finished motor test' still logged, the existing tests still pass), because the battery read already pumps the link through your hook. A test that interleaves the poll with the battery read would keep it fixed; the view tests use a fake model, so they cannot see this. Motor-test clicks themselves were not refused in these runs (0 of 17).

  2. Minor: set_status_text_logging(True) in init (https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-6dff0ddaef6bc550a0eead1ca254ab2df8e40428029f9695df760b8b71b52033R135) runs before code that can raise. If construction fails, the plugin loader stores no view and the hook stays attached until the parent frame is destroyed. Releasing it on failure fixes this; dropping the call would break the standalone window, which never calls on_activate().

  3. Minor: the hook only moves to a new connection on the next command or poll (https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-5bf89ebdc67eb713f5ff51bc3236d106ca22f032998b0446daea02b80348424dR383). After a reset-and-reconnect from the motor-test page, the boot messages read by the connection code were not logged by this hook (five of five on SITL). The connection manager's own capture hook does keep them, so logging from there, or attaching alongside it, would close the gap.

  4. Minor, new: the hook decodes each packet on its own (https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-5bf89ebdc67eb713f5ff51bc3236d106ca22f032998b0446daea02b80348424dR402), so a status text longer than 50 characters, which ArduPilot sends as MAVLink 2 chunks, is logged as two lines split mid-sentence. StatusTextAssembler, already used in this file for the ACK error text, would join them.

Optional: the severity test (https://github.com/ArduPilot/MethodicConfigurator/pull/2181/files#diff-5ab67beea2ef10b83cc1cfbb2d1432811aabb252a08a262242760447c1f1821fR92) asserts only >= INFO, which still passes if every severity is logged as ERROR; asserting the exact ERROR/WARNING/INFO mapping would pin it. The mapping itself is correct.

Not exercised: real hardware over serial, other firmware versions, Windows and macOS, and the full test suite. CI for this head was still queued when this was written.

This branch has not been deployed

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

Labels

AIReview Request an automated AI review; picked up by the reviewprs sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants