PositionAndVelocityControl¶
- class PositionAndVelocityControl(encoder: AbsoluteRotaryEncoder, tachometer: Tachometer, powertrain: Powertrain, position_PID: PIDController, velocity_PID: PIDController, trajectory: SCurveTrajectory)¶
Bases:
RuleBaseAdded in version 1.3.0.
PositionAndVelocityControlobject.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
pwmto apply to thepowertrain’s motor in order to stick to position and velocity set by thetrajectorythrough the two nestedposition_PIDandvelocity_PID.
Raises
TypeErrorIf
encoderis not an instance ofAbsoluteRotaryEncoder,if
tachometeris not an instance ofTachometer,if
powertrainis not an instance ofDCMotor,if
position_PIDis not an instance ofPIDController,if
velocity_PIDis not an instance ofPIDController,if
trajectoryis not an instance ofSCurveTrajectory.
- apply() None | float | int¶
It computes the
pwmto apply to thepowertrain’s motor in order to stick to position and velocity set by thetrajectorythrough the two nestedposition_PIDandvelocity_PID.Returns¶
floatorintorNonePWM 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_PIDas:\[\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_PIDas:\[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.