Add clang-tidy config and CI job from cymon - #9
Merged
Conversation
Copilot created this pull request from a session on behalf of
Tecnologic
May 27, 2026 05:33
View session
Tecnologic
marked this pull request as ready for review
May 27, 2026 05:33
Tecnologic
approved these changes
Jun 26, 2026
Tecnologic
added a commit
that referenced
this pull request
Aug 4, 2026
* updated modm to current release
* added small not on python version
* ignore py cache files
* fix the build after modm update
* feat: add SVM, dead-time compensation, MTPA, field weakening, back-EMF observer, HFI
- lib/control/Svm.hpp: centered SVPWM with duty clamped to 5-95%
- lib/control/DeadTimeCompensation.hpp: per-phase dead-time correction in α/β
- lib/control/Mtpa.hpp: closed-form MTPA for IPMSM
- lib/control/FieldWeakening.hpp: PI field weakening via i_d control
- lib/observer/MechanicalObserver.hpp: full-order back-EMF Luenberger observer
+ PLL; supports flying start; inject_angle_error() for HFI/hall feedback
- lib/observer/Hfi.hpp: VESC-style 4-step HFI with angle error injection
- lib/CMakeLists.txt: expose control/ and observer/ include paths
- Fix pre-existing bugs: sin_cos<T> template arg in park/inverse_park,
missing <cmath> in StatorReference/ThreePhase, SinCos abstract class,
SinCos this.length() → this->length(), wrong sinCos2 test values
* feat: add MotorType enum, ASM flux observer, and ASM flux controller
- lib/system/MotorType.hpp: enum class MotorType { PMSM, ASM }
- lib/observer/AsmFluxObserver.hpp: full-order Luenberger rotor-flux observer
for induction motors; corrects stator current and rotor flux estimates from
the current prediction error; injects flux angle into MechanicalObserver PLL
via inject_angle_error() so both share the same speed/angle estimates
- lib/control/AsmFluxController.hpp: PI flux controller (psi_r* -> i_d*) with
integrator anti-windup and slip-frequency feedforward omega_slip
* feat: add EESM rotor excitation control and absolute position control with homing
- Add EESM to MotorType enum with full doc comment
- Add ExcitationController: PI loop for rotor I_f or flux ψ_f (CurrentMode / FluxMode)
- Add ExcitationObserver: first-order LPF on rotor current → psi_f estimate
- Add PositionTracker: multi-turn absolute position (±4096+ rev), homing support
- Add PositionController: cascaded P+PI position/speed loops, homing state machine
- Add ControlMode enum (TORQUE / SPEED / POSITION)
- Fix pre-existing SinCos.hpp Wshadow build error
- Fix CMakeLists.txt unconditional target_link_libraries for test builds
- Add 34 new unit tests (47 total, all passing)
* Add comprehensive README with CI badge, Cyphal register table, NVM and architecture docs
* ci: add BatteryCase Controller firmware build job
* fix: address PR review feedback on homing identity build setup
* Add UDRAL servo control mode selection helper
* Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* fix(SinCos): update class doc to reflect plain-value-type API
* fix: make SinCos::normToOne non-throwing for -fno-exceptions firmware
* feat: add smessmer/gitversion submodule and Cyphal heartbeat with version VSSC
- Add lib/gitversion as a git submodule (smessmer/gitversion)
- Replace manual git-describe version detection in CMakeLists.txt with
TARGET_GIT_VERSION_INIT from gitversion's cmake.cmake
- Add src/cyphal/heartbeat.hpp: header-only uavcan.node.Heartbeat.1.0
serializer that reads SW_VERSION_MAJOR/MINOR from gitversion's
VERSION_STRING at compile time and encodes them in the 19-bit VSSC field
* Add current control ISR, SlowUpdate, double-buffer, and register map updates (#6)
* Add Kalman mechanical observer, PMSM flux observer, and hardware limits
* Add current control ISR, SlowUpdate, double-buffer, and register map updates
* chore: remove duplicate NvmSettings heading block
* fix: flip double buffer before slow-update snapshot
* fix: use real CCR values in ISR boundary guard
* Fix ISR settings mapping to use single motor parameter set
* fix: express CurrentController voltage limit in volts via v_dc parameter
Add `v_dc` parameter to `CurrentController::update()` so the voltage limit
is computed as `v_max * v_dc` [V] instead of comparing against the raw
fractional `v_max` value. This fixes the bug where `v_max=0.9` was being
compared against raw rotor-frame voltage demands in volts, causing immediate
saturation on any real bus.
- `v_max` remains a dimensionless fraction (0, 1] (e.g. 0.9 for SVM headroom)
- `update()` now takes `v_dc` [V] and computes `v_limit = v_max * v_dc`
- Call site in `CurrentControlIsr.cpp` passes the ADC-read `v_dc` value
* fix: resolve CI duplicate runs and build errors
- ci.yml: change push trigger from branches ["**"] to ["main"] to
eliminate the duplicate push+pull_request run on every PR push
- ci.yml: add submodules: true to batterycase checkout so the
lib/gitversion submodule is initialized before configure
- ci.yml: install python-is-python3 in batterycase job so cmake.cmake's
`python -m gitversionbuilder` call resolves correctly on Ubuntu
- CMakeLists.txt: move INCLUDE(lib/gitversion/cmake.cmake) and
TARGET_GIT_VERSION_INIT inside the if(HARDWARE_DIRECTORY) block so
the hosted/test build never needs the submodule
* fix: replace freeze anti-windup with back-calculation in CurrentController
The previous integrator freeze strategy halted integration whenever the
total output (PI + feedforward) was saturated, including cases where the
feedforward terms alone pushed the output over the limit. This caused
the integrator to freeze even with correct PI behaviour, producing
steady-state current error at high speed.
Replace with back-calculation anti-windup:
integrator += (ki * e + kb * (u_limited - u_raw)) * dt
- When unsaturated: `u_limited == u_raw`, correction term is zero,
integrator advances normally.
- When saturated: `(u_limited - u_raw) < 0`, so the integrator is
wound back proportionally to the saturation error.
- The total output (PI + feedforward) is still always hard-clamped to
the voltage circle regardless of what drives saturation.
Add `kb_d` / `kb_q` back-calculation gain parameters (default 100.0,
equal to ki/kp with default gains, giving tracking time-constant equal
to the integral time Ti = kp/ki). Update class docstring and usage
example accordingly.
* fix: resolve ARM target build errors in RotorReference, StatorReference, ThreePhase
- Fix -Werror=shadow: rename constructor parameters (d->d_in, q->q_in,
alpha->alpha_in, beta->beta_in, a->a_in, b->b_in, c->c_in) to avoid
shadowing member variables
- Replace undefined sin_cos<T> with SinCos<T> in park() and inverse_park()
signatures; add #include "SinCos.hpp" to RotorReference.hpp and
StatorReference.hpp; remove stale sin_cos forward declarations
- Replace C++20 designated initializers (non-aggregate type errors) with
positional constructor calls in park(), inverse_park(), and clark()
* fix: use arm-none-eabi-gcc as ASM compiler to support C-preprocessed assembly
* fix: install pyelftools for system Python in batterycase CI step
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
* Add Cyphal ExecuteCommand interface for motor identification and telemetry (#7)
* feat: add cyphal execute command codes for all available measurements
* feat: add motor identification measurement commands and phase balance NVM fields
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
* Hardware startup aid FSM for new UNIMOC boards (#8)
* feat: add hardware startup aid FSM (HwStartup)
* docs: add Hardware Bring-Up Guide to README
* fix: align NUM_STARTUP_STEPS comment with actual value
* fix: address all startup FSM review comments
- Update is_active() to return false for DONE and FAULT states so
SlowUpdate resumes after the startup sequence completes or aborts
- Fix request_abort() to no-op when FSM is IDLE or DONE
- Gate ADC_OFFSET_CAL sampling with step_done_ to prevent log spam
and accumulator drift after N_CAL samples are reached
- Gate ADC_NOISE_FLOOR sampling with step_done_ for the same reason
- Add step_done_ guard at the start of run_gate_driver_enable_check()
to prevent gate_phase_disabled_ being reset and baseline re-collection
on subsequent calls after the step is complete
- Fix DC_LINK_VOLTAGE_CHECK to accumulate raw_vdc directly (not via
collect_sample() which accumulates raw_ia/raw_ib) and average N_CAL
samples for measured_vdc instead of using a single last sample
- Fix PHASE_ADC_ALIGNMENT signed→uint32_t cast by keeping the
intermediate value as int32_t and clamping to 0 before casting,
preventing underflow for negative tick offsets
- Initialize base_trigger_offset_ from cc_.state.adc_trigger_offset
at PHASE_ADC_ALIGNMENT sweep start so the sweep step-size is correct
for any timer clock, not just 168 MHz
- Fix STARTUP_RESULTS Cyphal register type comment: uint8[<=14]
(14 FSM states, not 13)
* fix: resolve double-promotion build errors in variance computations
* fix: remove hard-coded 168u default for base_trigger_offset_
* fix: DC_LINK_VOLTAGE_CHECK — use N_CAL average and compute gain_vdc when ext_vdc_V_ arrives late
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
* Add clang-tidy config and CI job from cymon (#9)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
* fixed builds
* added host limits
* Fix hosted merge configuration
Co-authored-by: Tecnologic <1442404+Tecnologic@users.noreply.github.com>
---------
Co-authored-by: Alex Evers <tecnologic86@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Tecnologic <1442404+Tecnologic@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the clang-tidy configuration from
Tecnologic/cymoninto this repo and wires it into CI as a dedicated analysis job.Changes
.clang-tidy— enablesclang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,performance-*,readability-*with suppressions for magic-numbers, reinterpret-cast, pointer-arithmetic, and union-access; enforcesCamelCasefor classes/functions/constants (k-prefixed),lower_casewith_suffix for members.github/workflows/ci.yml— newclang-tidyjob installsclang-tidy, configures the hosted build with-DENABLE_CLANG_TIDY=ON(hooked via the existingcmake/StaticAnalyzers.cmake), and builds thesystem_testtarget to run analysis across all compiled sources