Skip to content

feat(position): trapezoidal motion profile with velocity and acceleration feed-forward - #714

Merged
gabrielfrasantos merged 16 commits into
mainfrom
claude/motion-profile
Nov 11, 2026
Merged

gabrielfrasantos merged 16 commits into
mainfrom
claude/motion-profile

Conversation

@gabrielfrasantos

@gabrielfrasantos gabrielfrasantos commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #498.

Summary

In position mode, an optional motion profile replaces the step setpoint with a trapezoid. The trapezoid has limited speed, acceleration and deceleration, plus velocity and acceleration feed-forward. With the profile parameters at their default of 0, position mode behaves exactly as before.

  • Profile: foc::PositionProfile (core/foc/cascade/) runs in the 1 kHz outer loop on the toolbox's TrapezoidalProfileFromState.
    • A new setpoint replans from the current reference position and speed, so the reference stays continuous.
    • The profile restarts from the measured state on Enable, after a jog and after a held current.
    • Without travel limits it takes the shorter way across ±π (REQ-CTL-003); with them it takes the direct way (REQ-CTL-007).
  • Feed-forward: the reference speed is added in every position law, plus an acceleration current J·a/Kt. frictionCurrent is renamed to feedForwardCurrent.
    • Cascade P: K·e + v_ref.
    • PID: v_ref is added outside the clamped state, and the reference weight is 1 while profiled (0.75 left PID and 2-DOF 12 % short of the target).
    • LQR/LQI: speed state (ω − v_ref).
    • 2-DOF: the profile replaces its reference pre-filter.
  • Errors: MotionObservation.positionError is now measured against the profiled reference, for the following-error and encoder-plausibility monitors. A new targetError is measured against the final target, for target reached.
  • Settings: profile velocity, acceleration, deceleration and jerk (0x65–0x68, contract 3.1 from feat(contract): add position motion profile parameters, contract 3.1 e-foc-protocol#6).
  • Requirement: REQ-CTL-010, verified by MIL and SIL.
  • Docs: theory, foc-position.md, position-loop-*.md, service-nvm.md, tool-can-commander.md, fault-supervision.md and the performance README.

Verification

  • Host: build clean; ctest 47/47, including model-in-the-loop.
  • Model-in-the-loop: 5 laws × 2 motors, a 1.5 rad move at 20 rad/s and 400 rad/s².
    • Duration is 125 ms for every law and motor (limit ±1 ms).
    • Cruise error is at most 0.0055 rad (limit 0.02); final target error is at most 2.2e-4.
    • In a mid-move reversal, speed and acceleration stay within their limits.
  • Firmware: the QEMU build and the EK-TM4C1294XL build are clean.
  • SIL: all scenarios pass in three shards. The new @REQ-CTL-010 scenario measures a cruise error of 0.002–0.003 rad and reaches the target in 118 ms.
  • Cycle budget (CI): the outer loop's worst case is 8133 cycles, against 20000 on EK-TM4C1294XL and 28333 on NUCLEO-G474RE. The inner loop is unchanged.
  • Other checks: requirements traceability and clang-format pass.

Dependencies

All are merged:

🤖 Generated with Claude Code

https://claude.ai/code/session_014WUWh7J6XTBVeyaibAtKuE

The FOC motor CAN category's message catalogue, wire contract, server
and client categories and FocMotorCanClient move to the e-foc-protocol
library, together with the unit types, the command limits and the
parameter range checks they use, so a client (a motion controller, a
tool) can depend on the contract without the firmware.

- add infra/e-foc-protocol as a submodule
- remove the moved headers, sources and tests; include them as
  e-foc-protocol/{foc,contract,server,client}/...
- e_foc.can and e_foc.foc.interfaces link the e_foc_protocol targets
- service-can.md keeps the firmware side (Parts D, F-K) and points to
  the library's wire-contract.md for Parts A, B, C and E

The board kind is still reported by the firmware; the contract now
carries it as a byte instead of reading the board registry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WUWh4ve7wn8JxNywWbX5h
Align the two tables this change touched and restore the spacing of the
pointer-to-member parameter in CurrentStreamSteps.cpp, which a newer
clang-format had rewritten.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WUWh4ve7wn8JxNywWbX5h
Four limits, profileVelocity, profileAcceleration, profileDeceleration and
profileJerk (parameters 0x65-0x68), join the configuration record (layout 15)
and the CAN Commander's Motion Profile group. The jerk is reserved for a later
S-curve and is only stored and read back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WUWh7J6XTBVeyaibAtKuE
Position mode plans a trapezoid from the reference state to each setpoint
within the profile velocity and acceleration, replans mid-move without a
jump, and feeds the reference velocity to every position law and J*a/Kt to
the q-axis current. The monitors measure the following error against the
profiled reference and the target-reached check against the final target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WUWh7J6XTBVeyaibAtKuE
The 0.75 reference weight shapes a step the loop is given whole. A profiled
reference is already shaped and its velocity is fed forward, so the weight is 1
while a profile is active; with 0.75 the integral had to supply a quarter of
the move and the rotor ended the profile 8 % short.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WUWh7J6XTBVeyaibAtKuE
Model-in-the-loop sweeps every position law on the nominal and Anaheim plants:
a 1.5 rad move at 20 rad/s and 400 rad/s2 takes 125 ms and follows the cruise
within 20 mrad, a mid-move setpoint stays inside the limits, and a profile
without an acceleration leaves the errors equal. The SIL scenario checks the
rotor against the trapezoid and the target-reached flag, and the stored-limits
scenario reads the four profile settings back after a restart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WUWh7J6XTBVeyaibAtKuE
e-foc-protocol's extraction is merged (embedded-pro/e-foc-protocol#3);
move the submodule from the PR head to the merge commit on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WUWh4ve7wn8JxNywWbX5h
…noether-b931rk

# Conflicts:
#	core/services/mechanical_system_ident/MechanicalParametersIdentificationImpl.cpp
…omState

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WUWh7J6XTBVeyaibAtKuE
…switch

e-foc-protocol now fetches embedded-infra-lib, can-lite and
numerical-toolbox only when their targets do not exist yet
(embedded-pro/e-foc-protocol#5), so a recursive checkout of e-foc no
longer clones a second copy of each under infra/e-foc-protocol/infra.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WUWh4ve7wn8JxNywWbX5h
…/motion-profile

Move the wire contract, server, client, Units, CommandLimits and
ParameterValidation to infra/e-foc-protocol; delete the five files that
were added by the motion-profile CAN commit but now live only in the
library. Point the submodule at claude/motion-profile-parameters
(contract 3.1 with the four profile parameters). service-can.md Part A
now defers to wire-contract.md in the library; infra/numerical-toolbox
stays at 63218e3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WUWh7J6XTBVeyaibAtKuE

Copy link
Copy Markdown
Contributor Author

Verify submodules point to main fails on purpose. infra/e-foc-protocol points at 010567e, the head of embedded-pro/e-foc-protocol#6, because the contract 3.1 parameters exist only there. #713's own pointer fails the same check. Once embedded-pro/e-foc-protocol#6 merges, I'll move the pointer to e-foc-protocol main and the check will pass. Until then, this PR can't fix it.


Generated by Claude Code

@gabrielfrasantos

gabrielfrasantos commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

✅⚠️MegaLinter analysis: Success with warnings

Descriptor Linter Files Fixed Errors Max errors Warnings Elapsed time
✅ ACTION actionlint 9 0 0 0.52s
✅ CPP clang-format 944 0 0 0 25.38s
✅ DOCKERFILE hadolint 1 0 0 0.04s
✅ JSON jsonlint 18 0 0 0.13s
✅ JSON prettier 18 7 0 0 0.7s
⚠️ MARKDOWN markdownlint 95 2 93 0 5.76s
✅ MARKDOWN markdown-table-formatter 95 5 0 0 0.82s
✅ REPOSITORY betterleaks yes no no 1.03s
✅ REPOSITORY checkov yes no no 40.34s
✅ REPOSITORY git_diff yes no no 0.12s
✅ REPOSITORY grype yes no no 104.96s
✅ REPOSITORY ls-lint yes no no 0.03s
⚠️ REPOSITORY osv-scanner yes no 1 0.84s
✅ REPOSITORY secretlint yes no no 2.04s
✅ REPOSITORY syft yes no no 2.38s
✅ REPOSITORY trivy yes no no 13.78s
✅ REPOSITORY trivy-sbom yes no no 0.33s
✅ REPOSITORY trufflehog yes no no 3.79s
⚠️ SPELL lychee 290 2 0 95.76s
✅ XML xmllint 2 0 0 0 0.2s
✅ YAML prettier 23 3 0 0 0.87s
✅ YAML v8r 23 0 0 8.22s
✅ YAML yamllint 23 0 0 0.94s

Detailed Issues

⚠️ SPELL / lychee - 2 errors
📝 Summary
---------------------
🔍 Total..........802
🔗 Unique.........546
✅ Successful.....774
⏳ Timeouts.........0
🔀 Redirected.....196
👻 Excluded........26
❓ Unknown..........0
🚫 Errors...........2
⛔ Unsupported......2

Errors in CHANGELOG.md
[404] https://github.com/embedded-pro/e-foc/compare/v0.0.1...v1.0.0 (at 235:4) | Rejected status code: 404 Not Found
[404] https://github.com/sil-known-defect (at 304:50) | Rejected status code: 404 Not Found

Hint: Followed 196 redirects. You might want to consider replacing redirecting URLs with the resolved URLs. Use verbose mode (`-v`/`-vv`) to see redirection details.
Hint: You can configure accepted/rejected response codes with `-a` or `--accept`
⚠️ MARKDOWN / markdownlint - 93 errors
.claude/agents/reviewer.md:23 error MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
.github/agents/reviewer.agent.md:25 error MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
CHANGELOG.md:62 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Bug Fixes"]
CHANGELOG.md:113 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Continuous Integration"]
CHANGELOG.md:120 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Features"]
CHANGELOG.md:127 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Bug Fixes"]
CHANGELOG.md:132 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Performance Improvements"]
CHANGELOG.md:137 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Continuous Integration"]
CHANGELOG.md:144 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Features"]
CHANGELOG.md:153 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Bug Fixes"]
CHANGELOG.md:165 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Performance Improvements"]
CHANGELOG.md:172 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Documentation"]
CHANGELOG.md:180 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Features"]
CHANGELOG.md:187 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Features"]
CHANGELOG.md:195 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Bug Fixes"]
CHANGELOG.md:200 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Continuous Integration"]
CHANGELOG.md:207 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Features"]
CHANGELOG.md:213 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Continuous Integration"]
CHANGELOG.md:220 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Features"]
CHANGELOG.md:226 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Bug Fixes"]
CHANGELOG.md:231 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Continuous Integration"]
CHANGELOG.md:238 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "⚠ BREAKING CHANGES"]
CHANGELOG.md:245 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Features"]
CHANGELOG.md:284 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Bug Fixes"]
CHANGELOG.md:323:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
CHANGELOG.md:341 error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Performance Improvements"]
documentation/architecture/system.md:507:401 error MD013/line-length Line length [Expected: 400; Actual: 467]
documentation/architecture/system.md:509:401 error MD013/line-length Line length [Expected: 400; Actual: 467]
documentation/architecture/system.md:510:401 error MD013/line-length Line length [Expected: 400; Actual: 467]
documentation/architecture/system.md:511:401 error MD013/line-length Line length [Expected: 400; Actual: 467]
documentation/booklet/README.md:107 error MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
documentation/design/async-callback-lifetime.md:82:401 error MD013/line-length Line length [Expected: 400; Actual: 535]
documentation/design/async-callback-lifetime.md:211:32 error MD060/table-column-style Table column style [Table pipe does not align with header for style "aligned"]
documentation/design/async-callback-lifetime.md:211:151 error MD060/table-column-style Table column style [Table pipe does not align with header for style "aligned"]
documentation/design/async-callback-lifetime.md:211:301 error MD060/table-column-style Table column style [Table pipe does not align with header for style "aligned"]
documentation/design/async-callback-lifetime.md:212:121 error MD060/table-column-style Table column style [Table pipe does not align with header for style "aligned"]
documentation/design/async-callback-lifetime.md:212:265 error MD060/table-column-style Table column style [Table pipe does not align with header for style "aligned"]
documentation/design/bootloader.md:468:401 error MD013/line-length Line length [Expected: 400; Actual: 442]
documentation/design/bootloader.md:470:401 error MD013/line-length Line length [Expected: 400; Actual: 442]
documentation/design/bootloader.md:471:401 error MD013/line-length Line length [Expected: 400; Actual: 442]
documentation/design/bootloader.md:472:401 error MD013/line-length Line length [Expected: 400; Actual: 442]
documentation/design/bootloader.md:473:401 error MD013/line-length Line length [Expected: 400; Actual: 442]
documentation/design/bootloader.md:474:401 error MD013/line-length Line length [Expected: 400; Actual: 442]
documentation/design/bootloader.md:475:401 error MD013/line-length Line length [Expected: 400; Actual: 442]
documentation/design/bootloader.md:476:401 error MD013/line-length Line length [Expected: 400; Actual: 442]
documentation/design/bootloader.md:477:401 error MD013/line-length Line length [Expected: 400; Actual: 442]
documentation/design/bootloader.md:478:401 error MD013/line-length Line length [Expected: 400; Actual: 442]
documentation/design/bootloader.md:479:401 error MD013/line-length Line length [Expected: 400; Actual: 442]
documentation/design/bootloader.md:480:401 error MD013/line-length Line length [Expected: 400; Actual: 442]
documentation/design/error-handling.md:170:401 error MD013/line-length Line length [Expected: 400; Actual: 412]
documentation/design/error-handling.md:172:401 error MD013/line-length Line length [Expected: 400; Actual: 446]
documentation/design/foc-speed.md:199:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:201:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:202:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:203:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:204:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:205:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:206:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:207:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:208:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:209:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:210:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:211:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:212:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:213:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:214:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-speed.md:215:401 error MD013/line-length Line length [Expected: 400; Actual: 508]
documentation/design/foc-transforms.md:102:401 error MD013/line-length Line length [Expected: 400; Actual: 1047]
documentation/design/foc-transforms.md:115:401 error MD013/line-length Line length [Expected: 400; Actual: 503]
documentation/design/integration-testing.md:236 error MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
documentation/design/service-can.md:83:401 error MD013/line-length Line length [Expected: 400; Actual: 1037]
documentation/design/service-firmware-upgrade.md:302:401 error MD013/line-length Line length [Expected: 400; Actual: 422]
documentation/design/service-firmware-upgrade.md:304:401 error MD013/line-length Line length [Expected: 400; Actual: 422]
documentation/design/service-firmware-upgrade.md:305:401 error MD013/line-length Line length [Expected: 400; Actual: 422]
documentation/design/service-firmware-upgrade.md:306:401 error MD013/line-length Line length [Expected: 400; Actual: 422]
documentation/design/service-firmware-upgrade.md:307:401 error MD013/line-length Line length [Expected: 400; Actual: 422]
documentation/design/service-firmware-upgrade.md:308:401 error MD013/line-length Line length [Expected: 400; Actual: 422]
documentation/design/service-firmware-upgrade.md:309:401 error MD013/line-length Line length [Expected: 400; Actual: 422]
documentation/design/service-mechanical-ident.md:450:401 error MD013/line-length Line length [Expected: 400; Actual: 567]
documentation/design/state-machine.md:35:401 error MD013/line-length Line length [Expected: 400; Actual: 470]
documentation/design/state-machine.md:53:401 error MD013/line-length Line length [Expected: 400; Actual: 566]
documentation/design/state-machine.md:55:401 error MD013/line-length Line length [Expected: 400; Actual: 566]
documentation/design/state-machine.md:56:401 error MD013/line-length Line length [Expected: 400; Actual: 566]
documentation/design/state-machine.md:57:401 error MD013/line-length Line length [Expected: 400; Actual: 566]
documentation/design/state-machine.md:58:401 error MD013/line-length Line length [Expected: 400; Actual: 566]
documentation/design/state-machine.md:59:401 error MD013/line-length Line length [Expected: 400; Actual: 566]
documentation/design/state-machine.md:201:401 error MD013/line-length Line length [Expected: 400; Actual: 755]
documentation/design/state-machine.md:320:401 error MD013/line-length Line length [Expected: 400; Actual: 612]
documentation/design/state-machine.md:487:401 error MD013/line-length Line length [Expected: 400; Actual: 728]
documentation/design/state-machine.md:491:401 error MD013/line-length Line length [Expected: 400; Actual: 582]
documentation/design/state-machine.md:495:401 error MD013/line-length Line length [Expected: 400; Actual: 736]
documentation/design/state-machine.md:830:401 error MD013/line-length Line length [Expected: 400; Actual: 606]
documentation/performance-optimization/README.md:373:401 error MD013/line-length Line length [Expected: 400; Actual: 583]
⚠️ REPOSITORY / osv-scanner - 1 warning
Scanning dir .
Starting filesystem walk for root: /
End status: 218 dirs visited, 1599 inodes visited, 0 Extract calls, 33.156038ms elapsed, 33.156318ms wall time
No package sources found, --help for usage information.


[REPOSITORY_OSV_SCANNER_ERROR_NO_PACKAGE_SOURCES] osv-scanner found no lockfiles, manifests, or SBOMs to scan in the repository.
This is a configuration/scope issue, not a vulnerability finding.
Resolutions:
  - Verify the repository actually contains a supported lockfile (package-lock.json, go.sum, Gemfile.lock, Pipfile.lock, etc.) at the scanned path.
  - If this is expected for some sub-projects, disable osv-scanner for the affected paths or mark it non-blocking via `DISABLE_ERRORS_LINTERS`.

Notices

⚠️ Your configuration references items that have been removed from MegaLinter and are ignored: REPOSITORY_GITLEAKS, REPOSITORY_KICS. See Removed linters to find their replacements.

See detailed reports in MegaLinter artifacts

Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@10.2.0 --custom-flavor-setup --custom-flavor-linters ACTION_ACTIONLINT,CPP_CLANG_FORMAT,DOCKERFILE_HADOLINT,JSON_JSONLINT,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_BETTERLEAKS,REPOSITORY_GRYPE,REPOSITORY_LS_LINT,REPOSITORY_OSV_SCANNER,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,SPELL_LYCHEE,XML_XMLLINT,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

MegaLinter is provided by OX Security
Show us your support by starring ⭐ the repository

@github-actions

Copy link
Copy Markdown
Contributor

🏎️ Cycle Estimation — NUCLEO-G474RE

RelWithDebInfo · Cortex-M4 · 170 MHz · percentages are of the loop period

Path Rate Max cycles Budget Status
Inner loop 20 kHz 2955 (34.8%) 6375 (75.0%) ✅ within budget
Outer loop 1 kHz 8133 (4.8%) 28333 (16.7%) ✅ within budget
Identification path 20 kHz 4343 (51.1%) 8500 (100.0%) ✅ within budget
Path breakdowns

Inner loop

ADC ISR -> FOC inner loop (Clarke/Park/current loop/SVM) -> PWM output

Stage Cycles (min–max) Share
ISR Entry (exception overhead) 12–29 1%
Interrupt Vector 26–35 1%
ADC ISR + Callback Dispatch 374–717 24%
Control Mode Dispatch 63–87 3%
Encoder Read 7–86 3%
FOC Inner Loop (Calculate) 553–1275 43%
PWM Output 60–406 14%
PWM Register Update 74–291 10%
ISR Exit (exception return) 12–29 1%
Total 1181–2955

1538 instructions · 6594 bytes · 9 stages

Outer loop

Low-priority interrupt -> position loop -> speed loop -> online estimators

Stage Cycles (min–max) Share
LPI Entry (exception overhead) 12–29 0%
Interrupt Vector 34–49 1%
FOC Outer Loop (LowPriorityHandler) 84–4413 54%
Online Mechanical Estimator (RLS) 403–3172 39%
Online Electrical Estimator (RLS) 31–441 5%
LPI Exit (exception return) 12–29 0%
Total 576–8133

2994 instructions · 9124 bytes · 6 stages

Identification path

ADC ISR -> FOC inner loop -> PWM output -> calibration observer

Stage Cycles (min–max) Share
ISR Entry (exception overhead) 12–29 1%
Interrupt Vector 26–35 1%
ADC ISR + Callback Dispatch 374–717 17%
Control Mode Dispatch 63–87 2%
Encoder Read 7–86 2%
FOC Inner Loop (Calculate) 553–1275 29%
PWM Output 60–406 9%
PWM Register Update 74–291 7%
Observer Hand-over 14–17 0%
Calibration Observer (costliest) 7–1371 32%
ISR Exit (exception return) 12–29 1%
Total 1202–4343

2035 instructions · 8406 bytes · 11 stages

📦 Full reports, annotated disassembly and JSON metrics: the cycle-analysis-NUCLEO-G474RE-* workflow artifacts.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Memory budget (multi-mode)

Unified binary

📦 Memory budget

NUCLEO-G474RE (M4, RelWithDebInfo) — flash 303.36 KiB · static RAM 29.96 KiB · stack 0 B · heap 0 B

Region Used Free Total %
RAM 29.93 KiB 98.07 KiB 128.00 KiB 23.4%
RAM_SHARED 0 B 0 B 0 B 0.0%
FLASH 303.39 KiB 208.61 KiB 512.00 KiB 59.3%

Top symbols

Show top symbols
# Symbol Section Size Source
1 main::logic .bss 18.03 KiB —
2 main::hardware .bss 7.96 KiB —
3 foc::CascadeWithSpeedLoop::CalculateInnerLoop(foc::PhaseCurrents const&, infra::Quantity<infra::BaseUnit<10u>, float> const&) .text 3.05 KiB /__w/e-foc/e-foc/build/NUCLEO-G474RE/../../core/foc/cascade/CascadeWithSpeedLoop.cpp
4 HAL_TIM_ConfigClockSource .text 2.86 KiB /__w/e-foc/e-foc/build/NUCLEO-G474RE/../../infra/hal/st/st/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim.c
5 HAL_ADC_ConfigChannel .text 2.69 KiB /__w/e-foc/e-foc/build/NUCLEO-G474RE/../../infra/hal/st/st/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_adc.c
6 foc::TorqueCascade::Calculate(foc::PhaseCurrents const&, infra::Quantity<infra::BaseUnit<10u>, float>&) .text 2.32 KiB /__w/e-foc/e-foc/build/NUCLEO-G474RE/../../core/foc/cascade/TorqueCascade.cpp
7 can::focParameters .data 2.09 KiB /__w/e-foc/e-foc/build/NUCLEO-G474RE/../../infra/e-foc-protocol/e-foc-protocol/contract/FocMotorWireContract.hpp
8 math::detail::fastSineTable .data 2.00 KiB —
9 _acUpBuffer .bss 2.00 KiB —
10 services::RealTimeFrictionAndInertiaEstimator::Update(foc::MechanicalWindow const&) .text 1.83 KiB /__w/e-foc/e-foc/build/NUCLEO-G474RE/../../core/services/mechanical_system_ident/RealTimeFrictionAndInertiaEstimator.cpp

@github-actions

Copy link
Copy Markdown
Contributor

🏎️ Cycle Estimation — EK-TM4C1294XL

RelWithDebInfo · Cortex-M4 · 120 MHz · percentages are of the loop period

Path Rate Max cycles Budget Status
Inner loop 20 kHz 3131 (52.2%) 4500 (75.0%) ✅ within budget
Outer loop 1 kHz 8133 (6.8%) 20000 (16.7%) ✅ within budget
Identification path 20 kHz 4519 (75.3%) 6000 (100.0%) ✅ within budget
Path breakdowns

Inner loop

ADC ISR -> FOC inner loop (Clarke/Park/current loop/SVM) -> PWM output

Stage Cycles (min–max) Share
ISR Entry (exception overhead) 12–29 1%
Interrupt Vector 26–35 1%
ADC ISR + Callback Dispatch 259–564 18%
Control Mode Dispatch 63–87 3%
Encoder Read 7–89 3%
FOC Inner Loop (Calculate) 553–1275 41%
PWM Output 56–403 13%
PWM Register Update 135–620 20%
ISR Exit (exception return) 12–29 1%
Total 1123–3131

1662 instructions · 6252 bytes · 9 stages

Outer loop

Low-priority interrupt -> position loop -> speed loop -> online estimators

Stage Cycles (min–max) Share
LPI Entry (exception overhead) 12–29 0%
Interrupt Vector 34–49 1%
FOC Outer Loop (LowPriorityHandler) 84–4413 54%
Online Mechanical Estimator (RLS) 403–3172 39%
Online Electrical Estimator (RLS) 31–441 5%
LPI Exit (exception return) 12–29 0%
Total 576–8133

2994 instructions · 9124 bytes · 6 stages

Identification path

ADC ISR -> FOC inner loop -> PWM output -> calibration observer

Stage Cycles (min–max) Share
ISR Entry (exception overhead) 12–29 1%
Interrupt Vector 26–35 1%
ADC ISR + Callback Dispatch 259–564 12%
Control Mode Dispatch 63–87 2%
Encoder Read 7–89 2%
FOC Inner Loop (Calculate) 553–1275 28%
PWM Output 56–403 9%
PWM Register Update 135–620 14%
Observer Hand-over 14–17 0%
Calibration Observer (costliest) 7–1371 30%
ISR Exit (exception return) 12–29 1%
Total 1144–4519

2159 instructions · 8064 bytes · 11 stages

📦 Full reports, annotated disassembly and JSON metrics: the cycle-analysis-EK-TM4C1294XL-* workflow artifacts.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Memory budget (multi-mode)

Unified binary

📦 Memory budget

EK-TM4C1294XL (M4, RelWithDebInfo) — flash 274.27 KiB · static RAM 29.59 KiB · stack 0 B · heap 0 B

Region Used Free Total %
FLASH 274.27 KiB 749.73 KiB 1.00 MiB 26.8%
RAM 29.59 KiB 226.41 KiB 256.00 KiB 11.6%

Top symbols

Show top symbols
# Symbol Section Size Source
1 main::logic .bss 18.03 KiB —
2 main::hardware .bss 6.29 KiB —
3 foc::CascadeWithSpeedLoop::CalculateInnerLoop(foc::PhaseCurrents const&, infra::Quantity<infra::BaseUnit<10u>, float> const&) .text 3.05 KiB /__w/e-foc/e-foc/build/EK-TM4C1294XL/../../core/foc/cascade/CascadeWithSpeedLoop.cpp
4 foc::TorqueCascade::Calculate(foc::PhaseCurrents const&, infra::Quantity<infra::BaseUnit<10u>, float>&) .text 2.32 KiB /__w/e-foc/e-foc/build/EK-TM4C1294XL/../../core/foc/cascade/TorqueCascade.cpp
5 can::focParameters .data 2.09 KiB —
6 math::detail::fastSineTable .data 2.00 KiB —
7 _acUpBuffer .bss 2.00 KiB —
8 services::RealTimeFrictionAndInertiaEstimator::Update(foc::MechanicalWindow const&) .text 1.83 KiB /__w/e-foc/e-foc/build/EK-TM4C1294XL/../../core/services/mechanical_system_ident/RealTimeFrictionAndInertiaEstimator.cpp
9 services::Validated<application::FocLifecycleTable>()::rows .data 1.56 KiB —
10 state_machine::ControlModeStateMachine::Activate(state_machine::ControlMode) .text 1.52 KiB /__w/e-foc/e-foc/build/EK-TM4C1294XL/../../core/state_machine/ControlModeStateMachine.cpp

… runners

The pre-move phase (boot, alignment, the settle wait polled over CAN)
lasts longer in plant time on a slower host, so 600 samples could fill
before the setpoint and leave nothing to measure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014WUWh7J6XTBVeyaibAtKuE
Base automatically changed from claude/compassionate-noether-b931rk to main November 11, 2026 19:36
# Conflicts:
#	documentation/design/service-can.md
#	infra/e-foc-protocol
Copilot AI balanced review requested due to automatic review settings November 11, 2026 19:49

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 was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@sonarqubecloud

Copy link
Copy Markdown

@gabrielfrasantos
gabrielfrasantos merged commit 27b3526 into main Nov 11, 2026
26 checks passed
@gabrielfrasantos
gabrielfrasantos deleted the claude/motion-profile branch November 11, 2026 20:11
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.

feat: jerk-limited motion profile with velocity and acceleration feed-forward

3 participants