HF-TMC9660 Driver 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC9660
Loading...
Searching...
No Matches
tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig Struct Reference

Configuration structure for torque/flux control auto-configuration. More...

#include <tmc9660.hpp>

Public Attributes

std::optional< uint16_ttorqueP
 Direct PI gain configuration (optional).
 
std::optional< uint16_ttorqueI
 Torque I gain [0-32767] (optional, defaults to 100 if not provided)
 
bool separateTorqueFluxLoops
 Use separate PI parameters for torque and flux loops.
 
std::optional< uint16_tfluxP
 Flux PI gains (only used if separateTorqueFluxLoops = true).
 
std::optional< uint16_tfluxI
 Flux I gain [0-32767] (optional, only used if separateTorqueFluxLoops = true)
 
std::optional< tmc9660::tmcl::CurrentPiNormalizationpNormalization
 PI normalization format (optional).
 
std::optional< tmc9660::tmcl::CurrentPiNormalizationiNormalization
 I-term normalization format (optional, defaults to SHIFT_16_BIT)
 
bool enableFieldWeakening = false
 Enable field weakening for high-speed operation.
 
float fieldWeakeningVoltageThresholdPercent
 Field weakening voltage threshold as percentage of OUTPUT_VOLTAGE_LIMIT.
 
uint16_t fieldWeakeningI = 100
 Field weakening I-controller gain.
 
int16_t torqueOffset_mA = 0
 Current offset compensation.
 
int16_t fluxOffset_mA = 0
 Flux offset in m_a [-4700 to 4700] (default: 0)
 
bool enableTorqueBiquadFilter
 Enable biquad filter on target torque command.
 
std::optional< int32_tbiquadACoeff1
 Biquad filter coefficients (optional, only used if enableTorqueBiquadFilter = true).
 
std::optional< int32_tbiquadACoeff2
 
std::optional< int32_tbiquadBCoeff0
 
std::optional< int32_tbiquadBCoeff1
 
std::optional< int32_tbiquadBCoeff2
 

Detailed Description

template<typename CommType>
struct tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig

Configuration structure for torque/flux control auto-configuration.

This structure provides high-level, user-friendly parameters for configuring the torque and flux current control loops. Complex low-level parameters are automatically derived from these intuitive settings.

Member Data Documentation

◆ biquadACoeff1

template<typename CommType >
std::optional<int32_t> tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::biquadACoeff1

Biquad filter coefficients (optional, only used if enableTorqueBiquadFilter = true).

These coefficients define the biquad filter difference equation: Y(n) = X(n)*b0 + X(n-1)*b1 + X(n-2)*b2 - Y(n-1)*a1 - Y(n-2)*a2

Or in z-domain transfer function form: H(z) = (B0 + B1*z^-1 + B2*z^-2) / (1 + A1*z^-1 + A2*z^-2)

Coefficient Format: All coefficients are 24-bit values in Q4.20 fixed-point format:

  • 4 integer bits (range: -8 to +7)
  • 20 fractional bits (resolution: 1/1048576)
  • To convert a floating-point value to Q4.20: coeff = (float_value * 1048576.0f)
  • Example: 1.0 → 1048576, 0.5 → 524288, -0.25 → -262144

Default Values: If not provided, the filter uses default coefficients:

  • BCOEFF_0 = 1048576 (1.0 in Q4.20, unity gain)
  • All other coefficients = 0 (no filtering, passes signal through)

Typical Use Cases:

  • Low-pass filter: Smooth high-frequency noise from velocity/position controllers
  • Notch filter: Remove specific oscillation frequencies
  • Custom filtering: Based on motor/system characteristics

Note: For most applications, leave these unset unless you have specific filtering requirements. The default values provide a simple pass-through filter. Biquad A coefficient 1 (a1) in Q4.20 format [-2147483648 to 2147483647] (optional, default: 0)

◆ biquadACoeff2

template<typename CommType >
std::optional<int32_t> tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::biquadACoeff2

Biquad A coefficient 2 (a2) in Q4.20 format [-2147483648 to 2147483647] (optional, default: 0)

◆ biquadBCoeff0

template<typename CommType >
std::optional<int32_t> tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::biquadBCoeff0

Biquad B coefficient 0 (b0) in Q4.20 format [-2147483648 to 2147483647] (optional, default: 1048576 = 1.0)

◆ biquadBCoeff1

template<typename CommType >
std::optional<int32_t> tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::biquadBCoeff1

Biquad B coefficient 1 (b1) in Q4.20 format [-2147483648 to 2147483647] (optional, default: 0)

◆ biquadBCoeff2

template<typename CommType >
std::optional<int32_t> tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::biquadBCoeff2

Biquad B coefficient 2 (b2) in Q4.20 format [-2147483648 to 2147483647] (optional, default: 0)

◆ enableFieldWeakening

template<typename CommType >
bool tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::enableFieldWeakening = false

Enable field weakening for high-speed operation.

Field weakening allows the motor to operate beyond its base speed by reducing the back-EMF through negative flux current. This is essential for high-speed BLDC/stepper motors.

When enabled, field weakening activates automatically when the motor voltage exceeds field_weakening_voltage_threshold_percent. Enable field weakening (default: false)

◆ enableTorqueBiquadFilter

template<typename CommType >
bool tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::enableTorqueBiquadFilter
Initial value:
=
false

Enable biquad filter on target torque command.

The biquad filter can be used to smooth the torque command, reducing high-frequency noise or oscillations. This is particularly useful when using velocity or position control, where the velocity/position controller output is used as the target torque.

When enabled, you can optionally provide filter coefficients below. If coefficients are not provided, the filter is enabled but uses default coefficient values (BCOEFF_0 = 1048576, others = 0).

Default: Disabled (filter is off by default). Most users should leave this disabled unless experiencing torque command oscillations or need to smooth controller outputs. Enable biquad filter on target torque (default: false)

◆ fieldWeakeningI

template<typename CommType >
uint16_t tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::fieldWeakeningI = 100

Field weakening I-controller gain.

Higher values = more aggressive field weakening (faster response to voltage limit, but may cause instability). Lower values = gentler field weakening (slower response, more stable).

Typical values:

  • 50-200: Standard field weakening
  • 100: Recommended starting point
  • >200: Aggressive (may cause oscillations) Field weakening I gain [0-32767] (default: 100, only used if enableFieldWeakening = true)

◆ fieldWeakeningVoltageThresholdPercent

template<typename CommType >
float tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::fieldWeakeningVoltageThresholdPercent
Initial value:
=
0.85f

Field weakening voltage threshold as percentage of OUTPUT_VOLTAGE_LIMIT.

Field weakening activates when motor voltage exceeds this threshold. Expressed as a fraction (0.0 to 1.0) of the OUTPUT_VOLTAGE_LIMIT.

Typical values:

  • 0.80-0.90: Standard field weakening (activates at 80-90% of voltage limit)
  • 0.85: Recommended starting point

Example: If OUTPUT_VOLTAGE_LIMIT = 8000 and threshold = 0.85, field weakening activates at 6800 (85% of 8000). Voltage threshold for field weakening [0.0-1.0] as fraction of OUTPUT_VOLTAGE_LIMIT (default: 0.85 = 85%)

◆ fluxI

template<typename CommType >
std::optional<uint16_t> tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::fluxI

Flux I gain [0-32767] (optional, only used if separateTorqueFluxLoops = true)

◆ fluxOffset_mA

template<typename CommType >
int16_t tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::fluxOffset_mA = 0

Flux offset in m_a [-4700 to 4700] (default: 0)

◆ fluxP

template<typename CommType >
std::optional<uint16_t> tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::fluxP

Flux PI gains (only used if separateTorqueFluxLoops = true).

If separate_torque_flux_loops is true and these are not provided, they default to the same values as torqueP/torqueI. Flux P gain [0-32767] (optional, only used if separateTorqueFluxLoops = true)

◆ iNormalization

template<typename CommType >
std::optional<tmc9660::tmcl::CurrentPiNormalization> tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::iNormalization

I-term normalization format (optional, defaults to SHIFT_16_BIT)

◆ pNormalization

template<typename CommType >
std::optional<tmc9660::tmcl::CurrentPiNormalization> tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::pNormalization

PI normalization format (optional).

These control how the PI gains are normalized internally. If not provided, defaults are used (SHIFT_8_BIT for P, SHIFT_16_BIT for I) which match the datasheet defaults and work well for most applications.

  • SHIFT_8_BIT: Standard normalization, good balance
  • SHIFT_16_BIT: Higher precision, better for fine control

Typically, P uses 8-bit (faster, standard) and I uses 16-bit (better precision). Only override if you have specific requirements. P-term normalization format (optional, defaults to SHIFT_8_BIT)

◆ separateTorqueFluxLoops

template<typename CommType >
bool tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::separateTorqueFluxLoops
Initial value:
=
false

Use separate PI parameters for torque and flux loops.

When false (default): Torque and flux share the same PI gains. When true: Torque and flux have independent PI gains (flux_p, flux_i).

Separate loops are useful when torque and flux have different response requirements, but most applications work fine with combined loops. Use separate PI parameters for torque and flux (default: false, combined)

◆ torqueI

template<typename CommType >
std::optional<uint16_t> tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::torqueI

Torque I gain [0-32767] (optional, defaults to 100 if not provided)

◆ torqueOffset_mA

template<typename CommType >
int16_t tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::torqueOffset_mA = 0

Current offset compensation.

These offsets are added to the torque/flux commands to compensate for measurement errors or motor asymmetries. Usually set to 0 unless calibration reveals systematic offsets. Torque offset in m_a [-4700 to 4700] (default: 0)

◆ torqueP

template<typename CommType >
std::optional<uint16_t> tmc9660::TMC9660< CommType >::TorqueFluxControl::TorqueFluxConfig::torqueP

Direct PI gain configuration (optional).

If provided, these values are used directly. If not provided, default values are used (P=50, I=100). Use this for fine-tuning or when you know the exact gains you need.

Typical values:

  • P: 30-100 (higher = faster response)
  • I: 50-200 (higher = better steady-state accuracy) Torque P gain [0-32767] (optional, defaults to 50 if not provided)

The documentation for this struct was generated from the following file: