PositionAndVelocityControl

class PositionAndVelocityControl(encoder: AbsoluteRotaryEncoder, tachometer: Tachometer, powertrain: Powertrain, position_PID: PIDController, velocity_PID: PIDController, trajectory: SCurveTrajectory)

Bases: RuleBase

Added in version 1.3.0.

PositionAndVelocityControl object.

It can be used to force the angular position of a rotating object, tracked by the encoder, to follow an S curve trajectory from a starting to a stopping position.

Methods

apply()

It computes the pwm to apply to the powertrain’s motor in order to stick to position and velocity set by the trajectory through the two nested position_PID and velocity_PID.

Raises

TypeError
apply() None | float | int

It computes the pwm to apply to the powertrain’s motor in order to stick to position and velocity set by the trajectory through the two nested position_PID and velocity_PID.

Returns

float or int or None

PWM value to apply to the powertrain’s motor in order to stick to the S curve trajectory.

Notes

It computes a velocity reference through the position_PID as:

\[\dot{\theta}_{ref} = PID_{pos}(\theta - \theta_{ref})\]

where:

  • \(\dot{\theta}_{ref}\) is the velocity reference,

  • \(\theta\) is the current angular position, tracked by the encoder,

  • \(\theta_{ref}\) is the reference angular position, get by the S curve trajectory.

Then, it computes a PWM through the velocity_PID as:

\[PWM_{ref} = PID_{vel}(\dot{\theta} - \dot{\theta}_{ref})\]

where:

  • \(PWM_{ref}\) is the reference PWM,

  • \(\dot{\theta}\) is the current angular speed, tracked by the tachometer.