0x03. Application

SRAM Stack

Motor Controller

Encoder encoder

The struct that holds the Encoder object.

PowerStage powerstage

The struct that holds the PowerStage object.

Motor motor

The struct that holds the Motor object.

CurrentController current_controller

The struct that holds the CurrentController object.

PositionController position_controller

The struct that holds the PositionController object.

Mode mode

Mode of the motor controller. See Mode of Operation.

ErrorCode error

Error code, if any.

uint8_t device_id

CAN ID of this device. The possible range is 1-63

uint32_t firmware_version

The version of the firmware. The 32 bit number is segmented as MMMM.mm.pp, where M is major version, m is minor version, and p is patch version.

Encoder

I2C_HandleTypeDef *hi2c

This is the pointer to the i2c handler that connects to the I2C encoder.

uint8_t i2c_buffer[2]

This buffer stores the raw byte data read from the encoder

uint8_t i2c_update_counter

int32_t cpr

float position_offset

in range (-inf, inf)

float filter_alpha

float flux_offset

float flux_offset_table[128]

int16_t position_raw

in range [-cpr/2, cpr/2)

int32_t n_rotations

float position

in range (-inf, inf), with offset

float velocity

Mode of operation

ModeMode Id

DISABLED

0x00

IDLE

0x01

DAMPING

0x02

CALIBRATION

0x05

CURRENT

0x10

TORQUE

0x11

VELOCITY

0x12

POSITION

0x13

VABC_OVERRIDE

0x20

VALPHABETA_OVERRIDE

0x21

VQD_OVERRIDE

0x22

DEBUG

0x80

DISABLED Mode

In this mode, the gate driver is not activated. The motor is disabled with three phase wires floating. The motor is free to rotate.

Any error in other mode will trigger the state machine to enter DISABLED mode. The error code can be seen in the error_code register.

Switching from DISABLED mode to any other mode than IDLE is prohibited and will result in an error state.

IDLE Mode

The gate driver is activated and outputs zero or balanced output. Motor is in free spinning mode.

Upon entering this mode, all the error status is cleared.

DAMPING Mode

The gate driver is activated and outputs zero. Motor is in damping mode.

CALIBRATION Mode

The motor controller will execute the calibration sequence in the main loop.

After calibration, the motor controller will set itself in IDLE mode.

CURRENT Mode

Current closed-loop mode.

User sets i_q_target and i_d_target to control the motor.

TORQUE Mode

Torque closed-loop mode.

User sets torque_target to control the motor.

VELOCITY Mode

Velocity closed-loop mode.

User sets velocity_target to control the motor.

POSITION Mode

Position closed-loop mode.

User sets position_target to control the motor.

VABC_OVERRIDE Mode

Open loop controlled V_a, V_b, V_c.

User sets v_a_setpoint, v_b_setpoint, and v_c_setpoint to control the motor.

VALPHABETA_OVERRIDE Mode

Open loop controlled V_alpha and V_beta.

User sets v_alpha_setpoint and v_beta_setpoint to control the motor.

VQD_OVERRIDE Mode

Open loop controlled V_d and V_q.

User sets v_d_target and v_q_target to control the motor.

DEBUG Mode

Last updated