More about Motors

The Control Class

The Motor class uses PID control to accurately track your commanded target angles. Similarly, the DriveBase class uses two of such controllers: one to control the heading and one to control the traveled distance.

You can change the control settings through the following attributes, which are instances of the Control class given below.:

  • Motor.control

  • DriveBase.heading_control

  • DriveBase.distance_control

You can only change the settings while the controller is stopped. For example, you can set the settings at the beginning of your program. Alternatively, first call stop() to make your Motor or DriveBase stop, and then change the settings.

class Control

Class to interact with PID controller and settings.

scale

Scaling factor between the controlled integer variable and the physical output. For example, for a single motor this is the number of encoder pulses per degree of rotation.

Status

done()

Checks if an ongoing command or maneuver is done.

Returns

True if the command is done, False if not.

Return type

bool

stalled()

Checks if the controller is currently stalled.

A controller is stalled when it cannot reach the target speed or position, even with the maximum actuation signal.

Returns

True if the controller is stalled, False if not.

Return type

bool

load()

Gets the load acting on the Motor or DriveBase.

This value is determined from the feedback torque that is needed to track the speed or position command given by the user.

When coasting, braking, or controlling the duty cycle manually, the load cannot be estimated in this way. Then this method returns zero.

Returns

The load torque. It returns 0 if control is not active.

Return type

torque: mNm

Settings

limits(speed, acceleration, duty, torque)

Configures the maximum speed, acceleration, duty, and torque.

If no arguments are given, this will return the current values.

Parameters
pid(kp, ki, kd, integral_range, integral_rate, feed_forward)

Gets or sets the PID values for position and speed control.

If no arguments are given, this will return the current values.

Parameters
  • kp (int) – Proportional position control constant. It is the feedback torque per degree of error: µNm/deg.

  • ki (int) – Integral position control constant. It is the feedback torque per accumulated degree of error: µNm/(deg s).

  • kd (int) – Derivative position (or proportional speed) control constant. It is the feedback torque per unit of speed: µNm/(deg/s).

  • integral_range (angle: deg or distance: mm) – Region around the target angle or distance, in which integral control errors are accumulated.

  • integral_rate (rotational speed: deg/s or speed: mm/s) – Maximum rate at which the error integral is allowed to grow.

  • feed_forward (percentage: %) – This adds a feed forward signal to the PID feedback signal, in the direction of the speed reference. This value is expressed as a percentage of the absolute maximum duty cycle.

target_tolerances(speed, position)

Gets or sets the tolerances that say when a maneuver is done.

If no arguments are given, this will return the current values.

Parameters
stall_tolerances(speed, time)

Gets or sets stalling tolerances.

If no arguments are given, this will return the current values.

Parameters
  • speed (rotational speed: deg/s or speed: mm/s) – If the controller cannot reach this speed for some time even with maximum actuation, it is stalled.

  • time (time: ms) – How long the controller has to be below this minimum speed before we say it is stalled.