Getting Started - Software🔗

This guide should get you from 0 to 1 for getting a motor to spin assuming all of the hardware is setup per Getting Started - Hardware.

In addition to setting up the hardware, before proceeding through this guide, it is recommended to understand the fundamentals of how the software works. Consider skimming through these chapters to get a high-level understanding of the system.

Validate Interfaces🔗

First, apply LV power to the motor controller through the LV Connector Pinout. After a short (<=5 second) delay, the unit will start emitting telemetry packets over the CAN bus. Before attempting to spin under HV power, it is prudent to ensure that all sensors are operational

Validate Internal Sensors🔗

Read the data from the 0x016 (State ID). Both cangaroo and wireshark are excellent tools to use for this purpose on Linux. When the motor controller first turns on, it will be in the Init state (learn more here: State Machine). It should then quickly and automatically progress to the ReadyToSwitch state if the temperature, current, and resolver sensors are healthy. Additionally, none of the fault bits should be active.

If one or more fault bits are set, it could indicate that the resolver’s external signals are not properly connected, or that there is an issue internal to the unit.

Write Initial EEPROM values🔗

For proper commutation, there are a few EEPROM values for which the default value is unlikely to be appropriate for your usecase. You will almost certainly need to update these values from the default See EEPROM Configuration for details on how to set configuration values.

EEPROM Fields🔗

Field Name

Default

Description

What will happen if it is incorrect?

ResolverOffsetDegrees

\(0.0\)

This value should be the electrical angle read by the resolver when the rotor is aligned to phase A of the motor.

Motor may not spin, or if it does, commutation efficiency may be severely degraded

LoopIqPGain

\(0.0\)

See below

Improper commutation, or poor performance under high speeds/torques

LoopIqIGain

\(0.005\)

See below

Improper commutation, or poor performance under high speeds/torques

LoopIdPGain

\(0.0\)

See below

Improper commutation, or poor performance under high speeds/torques

LoopIdIGain

\(0.005\)

See below

Improper commutation, or poor performance under high speeds/torques

MotorPolesPerResolverPole

\(1.0\)

This value should be the motor pole count / resolver pole count. For example, with a 10 pole motor and a 5 pole resolver, this value should be 2.0. The sign of this value indicates whether the resolver is expected to read forwards or backwards relative to the motor.

Motor will not spin, reported \(i_d\)/\(i_q\)/torque values will be incorrect

TorqueConstant

\(1.0 \, \frac{\text{Nm}}{\text{A}_\text{peak}}\)

This value should be the torque constant from the motor’s datasheet (rescaled to \( \frac{\text{Nm}}{\text{A}_\text{peak}}\))

Torque values to/from the motor will be incorrect

MaxTorqueSlewRate

\(65.0 \, \frac{\text{Nm}}{\text{sec}}\)

Maximum allowable change in torque per second

Aggressive motoring/regen action may sag/boost HV DC bus beyond system limits.

Calculating initial \(i_d\) & \(i_q\) PI gains🔗

We have found these to be a good initial guess for PI gains when manually tuning:

\[ K_p = 2 \pi f_b \cdot L \qquad K_i = 2 \pi f_b \cdot R \]

where

  • \(L\) is the motor’s inductance on that axis (in Henries)

  • \(R\) is the motor’s phase-to-neutral resistance (in Ohms)

  • \(f_b\) is the desired loop bandwidth (in Hz)

Note that \(f_b\) must be less than the CurrentFbLpfHz parameter in the EEPROM Configuration for stable and reliable performance.

The quality of your chosen gains can be evaluated by using the Torque Control mode in the 0x019 (Command Packet).

Note

Autotuning, plug and play operation of the motor controller units is coming via a firmware update.

Tune velocity PI gains🔗

The ideal velocity gains of the system depends on the rotational inertia/damping of the rest of the system. The following EEPROM Configuration parameters can be used to tune the velocity response.

EEPROM Fields🔗

Field Name

Default

Description

Unit

LoopVelPGain

0.006

P (proportional) gain in the velocity control loop.

\(\mathrm{Nm \cdot s / E\degree}\)

LoopVelIGain

0.001

I (integral) gain in the velocity control loop.

\(\mathrm{Nm / E\degree}\)

LoopVelDGain

0.0

D (derivative) gain in the velocity control loop.

\(\mathrm{Nm \cdot s^2 / E\degree}\)

The velocity controller is best tuned by setting LoopVelIGain to 0 initially and adjusting LoopVelPGain by a small increment (e.g by 0.001) until a sufficiently fast response is achieved between the reported electrical velocity (in 0x025 (Electrical Angle)) and the desired electrical velocity (in 0x019 (Command Packet)). A small increment is required as \(E\degree / \mathrm{s}\) is a small unit – e.g on a 10 pole pair motor, 10,000 \(E\degree / \mathrm{s}\) is equivalent to ~166 mechanical RPM.

Once an appropriate response speed has been achieved, LoopVelIGain can be slowly increased to reduce the steady-state error.

Note that, while the current control loop currently runs at 10kHz, the velocity control loop runs at 1kHz.

Note

Autotuning, plug and play operation of the motor controller units is coming via a firmware update.

Validate Position Sensing🔗

Read back the data from 0x012 (Resolver) and 0x025 (Electrical Angle). Validate that in 0x012 (Resolver) there are no fault bits (FAULT should equal 0x00).

Manually spin the motor by hand to complete 1 mechanical rotation. The position reported in 0x025 (Electrical Angle) should increment or decrement depending on the direction of rotation. Ensure that the angle returns to it’s initial angle N times, where N is the number of pole pairs in the resolver.

Tune Resolver Offset🔗

Note

Autotuning, plug and play operation of the motor controller units is coming via a firmware update.

The resolver offset can be tuned manually by guessing and checking ResolverOffsetDegrees. To do so,

  1. Select a guess for ResolverOffsetDegrees

  2. Send a small, positive torque command via 0x019 (Command Packet)

  3. Observe both the electrical velocity (in 0x025 (Electrical Angle)) and the d/q axis integrals (in 0x022 (DQ PID Integral + DC Current estimate))

You can adjust the guess using the following rules:

  • If the motor does not spin at all, try increasing ResolverOffsetDegrees by 60 degrees

  • If the electrical velocity is negative (for a positive torque command), increase ResolverOffsetDegrees by 180 degrees.

  • If the motor is spinning freely in the correct direction at low velocity, adjust ResolverOffsetDegrees by a few degrees such that D_INTEGRAL is near-zero

    • If D_INTEGRAL grows positive, reduce ResolverOffsetDegrees

    • If D_INTEGRAL grows negative, increase ResolverOffsetDegrees

  • If no value of ResolverOffsetDegrees allows the motor to spin, try negating MotorPolesPerResolverPole. This may indicate that the resolver is reading in the opposite direction from the motor.

When ResolverOffsetDegrees is properly tuned, the motor should freely spin forwards with a positive torque command, and the D_INTEGRAL should be near zero at low load.

Complete!

Once you’re spinning with reasonable PI gains and a working resolver offset, you’re off to the races!