MotorPositionController
Utility that uses a PID controller to control the position of a motor similarly to a servo.
The default PID controller can be overridden using the setPid function.
Using the scale variable motor positions can be set in units other than radians. For example, the position of a lift could be set in mm of movement rather than radians of motor rotation. Whenever the term "position" is used in this context it refers to the value with this scale applied. Raw angle with be referred to as "angle".
Positions are set relative to a "home" position. This home position can be set using the setHome function.
Parameters
Initial goal
Motor to be controller
Motor encoder
Whether velocity should be obtained directly from the encoder
Properties
If lowerLimitEnabled is set to true the position will not be set lower than this value. This is applied post scaling meaning that if position is in mm this will also be in mm. IMPORTANT: THIS WILL NOT BE APPLIED IF lowerLimitEnabled IS SET TO FALSE.
If set to true position will be clamped at minimum value of lowerLimit
If upperLimitEnabled is set to true the position will not be set higher than this value. This is applied post scaling meaning that if position is in mm this will also be in mm. IMPORTANT: THIS WILL NOT BE APPLIED IF upperLimitEnabled IS SET TO FALSE.
If set to true position will be clamped at maximum value of upperLimit
Functions
Get position of the encoder relative to the home position.
Get the home position of the motor
Get the position of the arm (not angle)
Offset the home position of the motor
Set the motor target position. The scale variable can be used to set the units of position.