Skip to content

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

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

error414 wants to merge 7 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 29983e8

Target Flash Δ RAM Δ
MATEKF405 +240 B (+0.03%) CCM: ±0 B (±0.00%)
RAM: +8 B (+0.01%)
MATEKF722 +424 B (+0.09%) ITCM_RAM: +152 B (+1.31%)
RAM: +8 B (+0.01%)
TCM: ±0 B (±0.00%)
MATEKF765 +468 B (+0.06%) DTCM_RAM: ±0 B (±0.00%)
SRAM1: +12 B (+0.01%)
MATEKH743 -264 B (-0.03%) D2_RAM: ±0 B (±0.00%)
DTCM_RAM: ±0 B (±0.00%)
ITCM_RAM: +208 B (+1.34%)
RAM: +40 B (+0.03%)

@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 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed MSP, CLI, arming, mixer, and protocol paths implement one bounded end-to-end bench operation: selecting, driving, stopping, and identifying a motor output.
  • They share the same motor-output state and safety transitions rather than representing independent functional behaviors.
Behavioral complexity 🔴 High 🧩 Multiple interactions

  • Before, disarmed output values were static or manually assigned.
  • After, a selected motor owns a timed active/paused/expired sequence, repeated starts preserve cycle phase while extending expiry, another motor replaces the active selection, and stop/arming/manual tests must cancel it.
  • New correctness conditions are that only the selected motor moves, all other disarmed values remain at motor-zero, expiration is bounded, cancellation prevents later output, reversible motors use forward-range settings, and SRXL2 starts respect readiness.
  • These are newly interacting state and output invariants, not merely reuse of existing mixer or protocol helpers.
Sources

src/main/fc/fc_msp.c[2586-2593]

    case MSP2_INAV_MOTOR_WIZARD_START:
        if (!sbufReadU8Safe(&tmp_u8, src) || !motorWizardStart(tmp_u8)) {
            return MSP_RESULT_ERROR;
        }
        break;

    case MSP2_INAV_MOTOR_WIZARD_STOP:
        motorWizardStop();
Potential damage 🟡 Medium 🩹 Incorrect results

  • If the changed behavior regresses, the wizard could fail to identify the requested output, use incorrect timing, or leave the user testing the wrong motor.
  • The affected operation has no persistent data mutation beyond volatile disarmed motor values, and the source explicitly stops it on arming and manual motor-test takeover.
  • This assessment assumes the normal bench use described by the protocol; no evidence supports broader flight-control or persistent-state consequences.
  • Revert or rerun the bench identification operation restores the capability.
  • A failed or misleading twitch may require repeating the test and checking wiring manually; no database repair or external compensation is indicated.
Sources

src/main/fc/fc_msp.c[2586-2593]

    case MSP2_INAV_MOTOR_WIZARD_START:
        if (!sbufReadU8Safe(&tmp_u8, src) || !motorWizardStart(tmp_u8)) {
            return MSP_RESULT_ERROR;
        }
        break;

    case MSP2_INAV_MOTOR_WIZARD_STOP:
        motorWizardStop();
Assessed commit 1839ea3
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 switch off images and animations for a plain-text comment

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 1839ea3

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

Target Flash Δ RAM Δ
MATEKF405 ⚠️ +7460 B (+1.03%) CCM: +12836 B (+39.42%)
RAM: -1692 B (-1.62%)
MATEKF722 ⚠️ -4884 B (-1.02%) ITCM_RAM: -680 B (-5.42%)
RAM: +9068 B (+10.45%)
TCM: +516 B (+2.04%)
MATEKF765 ⚠️ +8176 B (+1.08%) DTCM_RAM: +512 B (+1.79%)
SRAM1: +9228 B (+7.36%)
MATEKH743 ⚠️ +11124 B (+1.39%) D2_RAM: +256 B (+7.84%)
DTCM_RAM: +512 B (+3.95%)
ITCM_RAM: -656 B (-4.00%)
RAM: +14788 B (+10.39%)

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 1839ea3

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.

@sensei-hacker

Copy link
Copy Markdown
Member

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.

Thanks! My idea is the safest (minimum) amount to be able to reliably identify which motor is twitching, across a variety of ESCs. Even if the motor doesn't spin smoothly at all, as long as it's clear WHICH motor is being activated. I have a set that doesn't move until about 10% throttle or so.

@error414

Copy link
Copy Markdown
Contributor Author

probably my OCD would not accept not smootly turn :D. I made it progressive, start spinning from 0 to 8%.

On the video all motors are 2300kv, 2206 or 2205 + 3s battery, all settings in ESC FWs is default, smees that AM32 has biger "start power" than other ESCs.

I tested all main FWs. Motor is easy to stop by hand, so I believe even with propeler, it can't cut skin. It's really weak.
https://www.youtube.com/watch?v=JeOTUuC6GrQ

For example bluejay is on limit to start turn, maybe we will need a little bit increase max value. But still I think it's save even with proppeler.

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