Skip to content

Mc encoders

Rotor Position Alignment

Rotor and Encoder Relationship

Before dev_motor_controller can startup and run, the relationship between the encoder's zero position and the motor's D axis must be established.

Two methods of encoder/rotor alignment are supported by dev_motor_controller:

  1. Ramping the D axis current and zeroing the position via a call to encoder_X_position_zero once the rotor has locked to the D axis. Typically used with incremental encoders, or first time commissioning of absolute encoders.
  2. Writing the encoder position to the D-Axis zero position offset to encoder_X_position_offset. Typically used with absolute encoders.

The rotor is considered aligned when either a write to encoder_X_position_zero is performed to zero the encoder or an encoder offset is written to encoder_X_position_offset. Controllers that rely on rotor position to operate will not enter a run state until the rotor is aligned.

(1) D-Axis alignment and encoder zero procedure

This procedure ramps the D axis current such that the rotor 'locks' to the D axis. When the rotor has settled the encoder is zeroed and and the offset between the encoder zero position (arbitrary at startup for incremental encoders) and the motor D axis is stored.

The typical process is:

  • Configure the current controller gains and limits.
  • Start the motor controller with command start.
  • Snooze for 100ms to let dev_motor_controller run calibration routines.
  • Configure controller_mode with test_align to select the alignment controller.
  • Enter into alignment mode by starting the controller with controller_start.
  • Poll align_in_dwell to wait until the controller is in the dwell period.
  • Snooze for a bit to let the rotor settle.
  • Zero the encoder with command encoder_X_position_zero.
  • Exit controller alignment mode with command controller_stop.

NOTE:

  • This procedure requires that the rotor is able to turn. If a load is connected to the motor output, the alignment current must be set such that it can cause the motor to turn.

  • The alignment current must be large enough to over come any motor friction, cogging torque etc. The result of a motor that is not aligned correctly may be an uncontrollable motor.

INFO:

For motors with high cogging torque, increasing the ramp time and alignment current can help with alignment. For challenging motors such as this it is recommended to use an absolute encoder and perform the alignment process once so that correct motor operation can be validated in a controlled manner, rather than aligning an incremental encoder every startup.

The following commands are available to configure the alignment controller and monitor the progress of the rotor D axis to an encoder:

Command Type Required Description
is_aligned boolean Optional Returns true if the rotor is aligned.
align_in_dwell boolean Optional Returns true if the alignment process is in the dwell section.
i_d_alignment float32 Optional Sets the alignment current. This is motor dependent.
i_d_alignment_ramp_time_ms float32 Optional Sets the alignment ramp up time.
Default value: 2 seconds.
encoder_X_position_zero command Optional Records the encoder position as the zero offset.
encoder_X_position_offset float32 Optional Sets or returns the rotor position offset.
controller_mode enum Required Set the controller mode to test_align to choose the alignment controller.
controller_start command/
boolean
Required Write as a command to start the controller and start the alignment process.
Read as a boolean to poll the controller status. Returns:
true if the controller is running.
false if the controller is in any other state.
controller_stop command Optional Stops the controller and aborts the alignment process.

(2) Writing an encoder zero offset

An absolute encoder can recover it's own position at power up and in turn the position of the rotor, assuming the rotor / encoder position relationship has not changed.

If this relationship is known then it can be written to dev_motor_controller via command encoder_X_position_offset, which is typically written as a configuration value in each dev_motor_controller YAML configuration file. Once it is written to the device then dev_motor_controller is considered aligned.

Initial absolute encoder offset recovery

When first commissioning an encoder and motor it is required to find the offset that will be written to each dev_motor_controller at startup. This process is simple and uses the same D axis alignment and encoder zero procedure outlined above, except the newly written offset is fetched at the end of the procedure by reading command encoder_X_position_offset.

The offset is then stored in the dev_motor_controller.yaml configuration.

WARNING:

Any time the positional relationship between the motor and the encoder changes the offset becomes invalid and the offset recovery procedure must be ran again.

Failure to do so can result in erratic motor behaviour.

Checking for a working encoder

Before starting motor control it is recommended to ensure the encoder is working first. Configure a basic JCS system. Configure the motor controller and encoder for the expected operation. Configure dev_HOST.yaml such that it does not start any motor controllers (e.g. remove/comment references to controller_start for the motor controllers). Start the JCS system and examine the signal th_m. Rotate the motor by hand. th_m should complete one cycle for one mechanical revolution.

Troubleshooting encoders

  • SPI encoders

    • At high data rates the propagation delay of the drivers and receivers can effect the transmission.
      • 3MHz - 6MHz is a practical upper limit to SPI data transfer rates.
  • The encoder works but continually shows warnings

    • From experience:
      • Differential encoder had one connector with DI+ and DI- pins swapped.