Skip to content

MOTOR WIZARD - move driving motor for motor wizard to FW - #12247

Open
error414 wants to merge 6 commits into
iNavFlight:next-10.1from
error414:error414/fix/motor-wizard
Open

error414 wants to merge 6 commits into
iNavFlight:next-10.1from
error414:error414/fix/motor-wizard

Conversation

@error414

@error414 error414 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Current motor wizzard is fully driven by configurator. Configurator sends to FC commands to start motor spinning and stop, like:

motor [index] [throttle]. 

The correct motor timming depends on timming of MSP queue in inav configurator. I would say right aproach to move motor timming to FC, this PR does it, configurator just sends command

motor_wizard_start [index]
motor_wizard_stop [index]
  1. commands works only if FC is disarmed
  2. motor wizard start has security timer for 3s, so it will stop automatically
  3. motor wizard start, stop immediately if FC is armed

See video of diference if motor is driven by configurator (original), and what does this PR (fix)

https://www.youtube.com/watch?v=muuFdlh54_M

Configurator PR: iNavFlight/inav-configurator#2859


Correct memory change

RAM / Flash usage vs. base commit 6cbfc64 — commit 5ac0153

Target Flash Δ RAM Δ
MATEKF405 +528 B (+0.07%) CCM: ±0 B (±0.00%)
RAM: +8 B (+0.01%)
MATEKF722 +372 B (+0.08%) ITCM_RAM: +144 B (+1.24%)
RAM: +12 B (+0.01%)
TCM: ±0 B (±0.00%)
MATEKF765 +388 B (+0.05%) DTCM_RAM: ±0 B (±0.00%)
SRAM1: +12 B (+0.01%)
MATEKH743 -480 B (-0.06%) D2_RAM: ±0 B (±0.00%)
DTCM_RAM: ±0 B (±0.00%)
ITCM_RAM: +192 B (+1.24%)
RAM: +32 B (+0.02%)

@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

qodo-free-for-open-source-projects Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Move motor-wizard twitch timing into flight-controller firmware

🐞 Bug fix ✨ Enhancement 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Move motor-wizard timing from Configurator to firmware, avoiding MSP queue-dependent motor pulses.
• Add disarmed-only start and stop commands, automatic timeout, and cancellation on arming.
• Document the MSP commands and test timing, motor selection, and reversible-motor behavior.
Merge Risk 🟡 Medium

Blast radius 🔴 High 💥 2 capabilities

  • 2 affected capabilities span independent functional scopes: bench motor-output identification and testing, lost-model recovery signaling.
  • The MSP commands, CLI takeover, arming cancellation, mixer timing, and disarmed output changes all implement one bounded bench motor-testing outcome rather than separate technical capabilities.
  • The selected motor is the only output intentionally changed during the pulse sequence.
  • The changed areMotorsRunning result is consumed by the separate DShot beacon path, which suppresses beacon commands while the wizard reports motor activity.
  • This is a distinct recovery-signaling outcome, not another motor-mixer implementation hop.
Behavioral complexity 🔴 High 🧩 Multiple interactions

  • Before, disarmed outputs came directly from motor_disarmed and motor activity reflected armed state or manual motor-test values.
  • After, a timed wizard state overrides those values, changes one output by phase, and reports activity to another consumer.
  • New correctness conditions are that start/stop/arming/motor-test commands agree on ownership, repeated starts extend expiry without changing cycle phase, invalid and SRXL2-not-ready requests do not activate, and expiration clears the runtime state before normal disarmed output resumes.
  • The timing is cooperative with the mixer loop rather than concurrent threads, but ordering between commands and mixer ticks materially affects the result.
Potential damage 🟡 Medium 🩹 Incorrect results

  • Conditionally, a regression could pulse the wrong motor, fail to pulse the requested motor, or leave the identification result ambiguous.
  • The sequence is bounded and does not persist configuration state; reverting code stops new activations, while an already-issued output depends on the runtime stop/expiry path.
  • Reverting restores the prior motor-test behavior.
  • An active sequence normally stops through MSP stop, arming, explicit motor test, or the firmware timer; if runtime servicing or output shutdown is unavailable, manual disarm/output shutdown may be required.
Assessed commit 866476a
Diagram

graph TD
  C["Configurator"] --> P["MSP commands"] --> G{"Valid start?"} -->|yes| M["Wizard mixer"] -->|timed twitch| O["Motor outputs"]
  G -->|no| R["MSP error"]
  P -->|stop| M
  A["Arming"] -->|cancel| M
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Separate scheduled motor-wizard controller
  • ➕ Isolates wizard timing and state from the mixer.
  • ➖ Adds scheduling and motor-output coordination for a small, mixer-specific behavior.

Recommendation: Keep timing in the mixer, where disarmed motor values are produced, and cancel explicitly on both arming paths. A separate controller offers clearer isolation but adds coordination without solving a problem this approach leaves open.

Files changed (8) +274 / -5

Enhancement (3) +23 / -0
fc_msp.cHandle motor-wizard MSP requests +10/-0

Handle motor-wizard MSP requests

• Routes start requests with a safely read motor index to the mixer and returns an MSP error if rejected. Routes stop requests to the mixer.

src/main/fc/fc_msp.c

mixer.hExpose motor-wizard controls and timing constants +10/-0

Expose motor-wizard controls and timing constants

• Declares the start and stop functions and defines the spin, pause, cycle, and duration constants.

src/main/flight/mixer.h

msp_protocol_v2_inav.hAssign MSPv2 motor-wizard command IDs +3/-0

Assign MSPv2 motor-wizard command IDs

• Defines IDs 0x2235 and 0x2236 for the start and stop commands.

src/main/msp/msp_protocol_v2_inav.h

Bug fix (2) +68 / -1
fc_core.cCancel motor-wizard activity before arming +2/-0

Cancel motor-wizard activity before arming

• Stops the sequence before setting the armed flag in both normal and turtle-mode arming paths.

src/main/fc/fc_core.c

mixer.cTime motor-wizard twitches in the disarmed mixer +66/-1

Time motor-wizard twitches in the disarmed mixer

• Adds single-motor twitch state, start validation, stop handling, a 100 ms spin and 500 ms pause cycle, and automatic expiration. Repeated starts extend the limit without resetting the rhythm; reversible motors use a forward throttle range.

src/main/flight/mixer.c

Tests (1) +134 / -3
mixer_battery_profile_throttle_rate_limit_unittest.ccTest motor-wizard safety and timing +134/-3

Test motor-wizard safety and timing

• Extends the mixer test harness with controllable time and features. Tests invalid and armed starts, isolated twitch timing, timeout, stopping and replacement, repeated starts, and reversible-motor output.

src/test/unit/mixer_battery_profile_throttle_rate_limit_unittest.cc

Documentation (2) +49 / -1
README.mdDocument motor-wizard MSP start and stop commands +23/-0

Document motor-wizard MSP start and stop commands

• Adds both commands to the index and documents their payloads, rejection conditions, timing, renewal behavior, and safety guidance.

docs/development/msp/README.md

msp_messages.jsonSpecify motor-wizard MSP messages +26/-1

Specify motor-wizard MSP messages

• Adds the start and stop message definitions and increments the specification patch version to 2.1.4.

docs/development/msp/msp_messages.json

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

qodo-free-for-open-source-projects Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (1) 📜 Skill insights (0)

Grey Divider


Action required

1. Other motors can spin during the wizard ✓ Resolved
Description
motorWizardApply() changes only the selected motor[] entry, leaving the other entries
initialized from motor_disarmed[], while motorWizardStop() only clears the wizard index. If a
prior motor-test command left disarmed outputs above their off value, those motors keep running
during the wizard, and stopping the wizard can restore the selected motor to its prior running
value.


Remediation recommended

2. Newly linked ESCs ignore wizard twitches ✓ Resolved
Description
motorWizardStart() admits a sequence without checking whether an SRXL2 ESC is ready, although the
sequence expires after three seconds. An SRXL2 ESC can ignore throttle for ten seconds after its
link comes up, so a wizard request made during that interval completes without identifying the
motor.

3. Configurator bypasses the safety timer 🔗 Cross-repo conflict ☼ Reliability
Description
The new MSP2_INAV_MOTOR_WIZARD_START handler controls only the firmware-timed path, while
inav-configurator's startMotorPulse() still sends repeated MSP_SET_MOTOR commands. When users
run the pinned configurator's motor wizard, its browser-side interval continues to control
motor_disarmed, so the new three-second shutdown does not protect those twitches.
Code

src/main/fc/fc_msp.c[R2577-2578]

+    case MSP2_INAV_MOTOR_WIZARD_START:
+        if (!sbufReadU8Safe(&tmp_u8, src) || !motorWizardStart(tmp_u8)) {
Evidence
The firmware adds a separate timed start command but retains the legacy motor setter; the
configurator wizard calls that legacy setter on a browser interval, and the firmware copies those
values directly into disarmed motor output.

inav -> inav-configurator
src/main/fc/fc_msp.c[2559-2585]
src/main/flight/mixer.c[732-743]
External repo: iNavFlight/inav-configurator, tabs/mixer.js [648-666]
External repo: iNavFlight/inav-configurator, tabs/mixer.js [718-738]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The configurator still drives motor-wizard pulses through the legacy command, so users do not receive the firmware-timed shutdown.
## Fix Focus Areas
- src/main/fc/fc_msp.c[2559-2585]
- src/main/flight/mixer.c[732-743]
- /cross_repos/inav-configurator/tabs/mixer.js[648-666]
- /cross_repos/inav-configurator/tabs/mixer.js[718-738]
## Recommended Fix
Coordinate a configurator change that sends the new start and stop commands when the connected firmware supports them, including periodic start requests where needed. Keep a version-gated legacy path for older firmware and release the configurator change alongside the firmware feature.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can turn these tips off under Display > Comment parts

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

RAM / Flash usage vs. base commit 01a7aa3 — commit 866476a

Using the nearest available size baseline: this build contains base commit beffa67, which has no stored baseline yet, so the deltas also include what was merged to the base since 01a7aa3.

Target Flash Δ RAM Δ
MATEKF405 ⚠️ -120 B (-0.02%) CCM: +508 B (+1.56%)
RAM: +1692 B (+1.62%)
MATEKF722 ⚠️ -7612 B (-1.58%) ITCM_RAM: -776 B (-6.19%)
RAM: +48 B (+0.06%)
TCM: +512 B (+2.02%)
MATEKF765 +984 B (+0.13%) DTCM_RAM: +512 B (+1.79%)
SRAM1: +100 B (+0.08%)
MATEKH743 ⚠️ +7280 B (+0.91%) D2_RAM: +256 B (+7.84%)
DTCM_RAM: +512 B (+3.95%)
ITCM_RAM: -680 B (-4.15%)
RAM: +1988 B (+1.40%)

See RAM/flash optimization guide for techniques to reduce usage.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Test firmware build ready — commit 866476a

Download firmware for PR #12247

252 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.

Development build for testing only. Use Full Chip Erase when flashing.

@sensei-hacker

Copy link
Copy Markdown
Member

Thanks for this. With the more precise timing, do you think we could further reduce MOTOR_WIZARD_SPIN_MS for safety? My thought is to have the minimum that will reliably twitch the motor, given that we know people WILL run it with props on and the vehicle unsecured, regardless of whether we tell them not to.

@sensei-hacker sensei-hacker added this to the 10.1 milestone Nov 28, 2026
…-wizard

# Conflicts:
#	docs/development/msp/README.md
#	docs/development/msp/msp_messages.json
#	src/main/msp/msp_protocol_v2_inav.h
@error414

Copy link
Copy Markdown
Contributor Author

MOTOR_WIZARD_SPIN_MS

I can test what is minimum value for all ESC FWs, it will not be much less than 100m. I reduced motor spin percent from 10 (in INAV 9) to 8%. Motor with such a lower value has not much power.

And maybe it would help not to start immediately motor to 8%, but make it progresive. 0 - 8% in first 50% of duty cycle.

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