apply

ReachAngularPosition.apply() None | float | int

It computes the pwm to apply to the powertrain’s DC motor in order to reach a target_angular_position by the target rotating object of the encoder, within a specific braking_angle.

Returns

float or int or None

PWM value to apply to the motor in order to reach the target angular position.

Notes

The braking angle is the angle within which the motor’s pwm is controlled in order to brake and reach the target_angular_position.

The rule is applied only if the difference between target_angular_position and the encoder’s target angular_position is lower than or equal to the braking_angle.

The lower the braking_angle the higher the deceleration of the system, thus the higher the vibrations produced.

First of all, the rule computes the powertrain’s static error according to the following formula:

\[\theta_{err} \left( T_l \right) = \frac{T_l}{T_{max}} \, \frac{\theta_b}{\eta_t}\]

where:

  • \(\theta_{err}\) is the powertrain static error,

  • \(T_l\) is the load torque on the powertrain DC motor (DCMotor.load_torque),

  • \(T_{max}\) is the maximum torque developed by the powertrain DC motor (DCMotor.maximum_torque),

  • \(\theta_b\) is the braking_angle parameter,

  • \(\eta_t\) is the powertrain overall efficiency, computed as:

\[\eta_t = \prod_{i = 1}^N \eta_i\]

where:

Then it checks the applicability condition, defined as:

\[\theta \ge \theta_s = \theta_t - \theta_b + \theta_{err}\]

where:

  • \(\theta\) is the encoder’s target angular_position,

  • \(\theta_s\) is the braking starting angle,

  • \(\theta_t\) is the target_angular_position parameter.

If the applicability condition is not met, then it returns None, otherwise it computes the pwm as:

\[D \left( \theta \right) = 1 - \frac{\theta - \theta_s}{\theta_b}\]

where \(D\) is the supply voltage PWM duty cycle pwm to apply to the DC motor in order to reach the target_angular_position by the encoder’s target rotating object.