feat(bldc): Refactor bldc some to create new bldc_types component; add bldc_current_sense (untested); Improve motorgo APIs; Update BLDC examples to support running on Motorgo boards#658
Merged
Conversation
…add `bldc_current_sense` (untested); Improve motorgo APIs; Update BLDC examples to support running on Motorgo boards
|
✅Static analysis result - no issues found! ✅ |
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.
Description
This PR is a set of related improvements to the BLDC motor stack. It factors the shared types and
concepts into a small dependency-light component, adds an (experimental) FOC
current-sense component and the driver hook it needs, makes the
bldc_motor/bldc_hapticsexamples runnable on the MotorGo Mini and Axis boards via Kconfig,and gives the two MotorGo BSPs a symmetric API. Everything is additive /
backwards compatible.
1. New
bldc_typescomponent (shared types + concepts)Moved the FOC value types (
DqCurrent,DqVoltage,PhaseCurrent,foc_utils.hpp), the control enums (bldc_types.hpp), andsensor_direction.hppout of
bldc_motorinto a new, dependency-lightbldc_typescomponent, andadded a new
bldc_concepts.hppthat now holds the interface concepts(
DriverConcept,SensorConcept,CurrentSensorConcept,MotorConcept) plusDummyCurrentSense.bldc_motor,bldc_haptics, andbldc_current_sensenowdepend on
bldc_types, which decouples them from each other (notably,bldc_current_senseno longer depends onbldc_motor). Header moves are trackedas git renames;
bldc_motor.hppstill includes the same headers, so externalcode that includes
bldc_motor.hppis unaffected.2. Torque-control groundwork
TorqueControlType::VOLTAGEis fully supported (no currentsense required), while
DC_CURRENT/FOC_CURRENTare experimental and need aCurrentSensorConceptimplementation + PWM-synchronized sampling + per-boardtuning.
BldcDriver::register_pwm_sample_callback(): registers a callback fired atthe MCPWM timer "empty" (TEZ) event — the instant the low-side FETs conduct in
this center-aligned configuration — so callers can trigger a PWM-synchronized
current-sense ADC read.
CurrentSensorConcept::driver_align()is now non-const (a real current sensormust capture calibration state);
DummyCurrentSenseupdated to match.3. New
bldc_current_sensecomponent (experimental)Adds
espp::CurrentSense<Driver>, a generic FOC current sensor implementing theCurrentSensorConcept. It is decoupled from any specific ADC via aread_phase_currentscallback, and handles zero-current offset calibration(
driver_align()), per-phase gain-sign correction, two-phase reconstruction(
Ia + Ib + Ic = 0), and the Clarke + Park transforms (get_foc_currents()/get_dc_current()). Includes a hardware-free example that statically assertsconcept conformance and exercises the calibration + transform pipeline, plus
docs. Marked EXPERIMENTAL: automatic phase-ordering / gain-sign discovery is not
implemented, and current-mode torque control must be validated on hardware.
4. Examples runnable on MotorGo boards via Kconfig
The
bldc_motorandbldc_hapticsexamples gained Kconfig hardware options forMotorGo Mini and MotorGo Axis (alongside the existing Test Stand /
Custom), plus a Motor 1 / Motor 2 channel choice. The examples build a
std::shared_ptr<BldcMotor>+std::shared_ptr<BldcDriver>from the selectedboard.
5. Symmetric MotorGo Mini / Axis API
Both
espp::MotorGoMiniandespp::MotorGoAxisnow expose the same zero-based,index-based API (
num_motor_channels(),initialize_encoders(),initialize_motors(),encoder(i),motor_driver(i),motor(i),reset_encoder_accumulator(i), the driver enable/disable helpers,default_motor_config(i), andinitialize_motor(i, config)), with sharedEncoder/MotorDriver/BldcMotortype aliases. Axis now owns theBldcMotorobjects (it previously exposed only drivers + encoders). All existingmethods on both boards are unchanged. With this, the example board branches
collapse to a single
using Board = espp::MotorGoMini;(orMotorGoAxis;) andidentical setup code.
Motivation and Context
living inside
bldc_motor);bldc_typescleanly factors them out.bldc_current_sense+ the driver PWM hook provide the missing pieces (stillexperimental, pending hardware validation).
awkward; the symmetric API makes switching boards a one-line change.
How has this been tested?
esp32s3(plusesp32p4/esp32s3forunrelated BSP sanity where applicable).
bldc_motor,bldc_haptics,bldc_current_sense,motorgo-mini,and
motorgo-axisexamples — all clean.bldc_motorandbldc_hapticsexamples in the default / MotorGoMini / MotorGo Axis configurations (including the Motor 2 channel) — all clean.
bldc_current_senseexample validatesCurrentSenseConceptconformance via acompile-time
static_assertand exercises the offset-removal + Clarke/Park +reconstruction pipeline in software (no hardware required).
existing MotorGo Axis API, and external includes of
bldc_motor.hpp.NOTE: the FOC current-feedback torque modes have not been validated on physical hardware in this PR.
Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):
N/A
Types of changes
Checklist:
Software
.github/workflows/build.ymlfile to add my new test to the automated cloud build github acti