Skip to content

Controller Modes


The dev_motor_controller main controller offers a user selectable closed loop current controller, or open loop voltage controller. The main controller also offers tests for aligning the rotor to the encoder and deriving the motor phase inductances and resistances.

Controller modes

Set the controller mode by writing an enum to controller_mode:

Control mode Description
current_dq Closed loop D/Q axis current controller.
voltage_dq Open loop D/Q axis voltage controller.
test_align Ramp and dwell alignment controller.
test_dq_l D/Q axis inductance test controller.
test_dq_r D/Q axis resistance test controller.

Controller mode: current_dq

The closed loop controller implements field oriented control to control the motor phase currents in the D/Q axis. The control action is provided by two PI controllers - one for each axis.

DQ Current Control

Requirements to start:

  • Aligned rotor.
  • JCS command signals i_q or i_d (either or both) connected.

Configuration parameters

PI Current controllers
Commands Type Required Description
i_d_kp float32 Required D axis current controller proportional gain (A).
i_d_ki float32 Required D axis current controller integral gain (A.s).
i_d_out_lim_h float32 Optional D axis current controller output and integrator upper limit (V).
i_d_out_lim_l float32 Optional D axis current controller output and integrator lower limit (V).
i_q_kp float32 Required Q axis current controller proportional gain (A).
i_q_ki float32 Required Q axis current controller integral gain (A.s).
i_q_out_lim_h float32 Optional Q axis current controller output and integrator upper limit (V).
i_q_out_lim_l float32 Optional Q axis current controller output and integrator lower limit (V).
Current controller decoupling

Performs decoupling of the D and Q axis.

Commands Type Description
using_vdq_decouple boolean True: Enables D/Q axis decoupling.
Default: False

Ensure the following motor parameters are configured: Good estimates of these parameters are required for satisfactory decoupling performance

Command Type Required Description
motor_Rd float32 Optional D axis motor winding resistance (Ohm).
motor_Rq float32 Optional Q axis motor winding resistance (Ohm).
motor_Ld float32 Optional D axis motor winding inductance (Henry).
motor_Lq float32 Optional Q axis motor winding inductance (Henry).
motor_Ym float32 Optional Flux linkage
Cogging torque compensation

The current controller features a motor cogging torque compensation mechanism that applies a feedforward current command to the Q axis current controller. The feedforward current is derived from a table of coefficients that map the rotor position to the current required to overcome cogging torque at that position.

The coefficients are generated by an external tool that rotates the rotor under a stiff position control loop, while recording the Q axis current required to hold that position. The motor should be un-loaded and free to spin when generating the coefficients.

As the absolute motor speed increases, torque due to cogging decreases. An envelope may be applied to reduce the cogging torque compensator contribution based on the rotor speed.

An upper envelope region may be defined that reduces the cogging torque feed forward current from full contribution, linearly down to zero contribution. cogging_compensator_upper_w_m_low defines where the feedforward term begins to reduce its contribution and cogging_compensator_upper_w_m_high defines where the contribution is fully reduced to zero.

Cogging Compensation Map

Commands Type Required Description
cogging_compensator_coeffs float32 Optional Array of 1024 compensation coefficients.
The compensator will be enabled if any value is non-zero.
cogging_compensator_upper_w_m_low float32 Required Start of upper motor speed envelope region, where the cogging torque feedforward contribution starts to be reduced (Rad/s).
cogging_compensator_upper_w_m_high float32 Required End of upper motor speed envelope region, where the cogging torque feedforward contribution is fully reduced to zero (Rad/s).
cogging_compensator_lower_w_m_high float32 Optional End of lower motor speed envelope region, where the cogging torque feedforward contribution is fully enabled (Rad/s).
Set to 0.0f to disable this feature. (default)
Experimental: May cause some hunting of the rotor at zero speed.

Cogging compensation is enabled when any of the cogging_compensator_coeffs are non zero. If cogging compensation is required then cogging_compensator_upper_w_m_low and cogging_compensator_upper_w_m_high must be configured.

NOTE:

Controller commands and limits may be affected by other health limiting processes. See Health.


Controller mode: voltage_dq

Open loop voltage controller that outputs a voltage command in the D/Q axis.

DQ Voltage Control

Requirements to start:

  • Aligned rotor.
  • JCS command signals v_q or v_d (either or both) connected.

NOTE:

Controller commands and limits may be affected by other health limiting processes. See Health.


Controller mode: test_align

This mode runs the rotor/encoder alignment procedure by energising the D axis current. Please see Rotor Position Alignment.


Controller mode: test_dq_l

This controller mode attempts to determine either the D or Q axis inductance (H) via frequency injection.

Test Inductance Waveform

Parameters:

Command Type Required Description
test_ls_dq_test_axis enum Required Selects either the D or Q axis to apply the test voltage. Options are:
measure_test_axis_d
measure_test_axis_q
test_ls_v_dq_bias float32 Required Bias voltage (V). Should be large enough to lock the rotor, but low enough to avoid over current and over temperatures.
test_ls_v_dq_amplitude float32 Required Test square wave amplitude (V), centred around the bias voltage.
test_ls_test_freq_hz float32 Required Test square wave frequency (Hz).
test_ls_test_time_ms uint16 Required Test duration (ms).

Once the parameters are written, set controller_mode to test_dq_l to select the D/Q inductance test, then start the test with a write to controller_start. Poll the status of the test with a boolean read to command controller_is_running. The boolean value will be true if the controller is running (ie, the test is still running) and false if the controller is in any other state. Exit the test early with a write to command controller_stop.

Upon test completion read float32 from command motor_Ld or motor_Lq depending on the axis selected by test_ls_dq_test_axis. The test failed if the return values is 0.0f.

Note: Parameters test_ls_v_dq_bias and test_ls_v_dq_amplitude form the voltage applied to the windings of the motor. Due to the typically low winding resistances of the motors, large currents may develop for seemingly small voltages. Either estimate the winding resistance (or measure with a multimeter) to select a reasonable bias voltage or start with small bias voltages (e.g. 1V) and work up.

Controller mode: test_dq_r

This controller mode attempts to determine the D or Q axis resistance (Ohms) via Ohms law.

Parameters:

Command Type Required Description
test_rs_dq_test_axis enum Required Selects either the D or Q axis to apply the test voltage. Options are:
measure_test_axis_d
measure_test_axis_q
test_rs_v_dq_test_amplitude float32 Required Vd test voltage (V). Should be large enough to lock the rotor, but low enough to avoid over current and over temperatures.
test_rs_test_time_ms uint16 Required Test duration (ms).

Once the parameters are written, set controller_mode to test_dq_r to select the D/Q resistance test, then start the test with a write to controller_start. Poll the status of the test with a boolean read to command controller_is_running. The boolean value will be true if the controller is running (ie, the test is still running) and false if the controller is in any other state. Exit the test early with a write to command controller_stop.

Upon test completion read float32 from command motor_Rd or motor_Rq depending on the axis selected by test_rs_dq_test_axis. The test failed if the return values is 0.0f.

Note: Parameter test_rs_v_dq_test_amplitude is the voltage applied to the windings of the motor. Due to the typically low winding resistances of the motors, large currents may develop for seemingly small voltages. Either estimate the winding resistance (or measure with a multimeter) to select a reasonable bias voltage or start with small bias voltages (e.g. 1V) and work up.


Controller Timing Statistics

The main controller executes within an interrupt routine. The following timing statistics are available to examine the performance of the controller:

Command Type Required Description
ctl_timing_step_max_us uint32 Optional The maximum ISR execution time (us)
ctl_timing_step_ave_us uint32 Optional The average ISR execution time (us)
ctl_timing_interval_us uint32 Optional The time interval between ISR calls (us)
ctl_timing_overrun_count uint32 Optional Number of ISR overruns