PIDBase¶
- class commands1.PIDBase(*args, **kwargs)¶
Bases:
commands1._impl._commands_v1.command.PIDInterface
,commands1._impl._commands_v1.command.PIDOutput
,wpiutil._wpiutil.Sendable
Class implements a PID Control Loop.
Creates a separate thread which reads the given PIDSource and takes care of the integral calculations, as well as writing the given PIDOutput.
This feedback controller runs in discrete time, so time deltas are not used in the integral and derivative calculations. Therefore, the sample rate affects the controller’s behavior for a given set of PID constants.
This class is provided by the OldCommands VendorDep
- Deprecated
All APIs which use this have been deprecated.
Overloaded function.
__init__(self: commands1._impl._commands_v1.command.PIDBase, p: float, i: float, d: float, source: commands1._impl._commands_v1.command.PIDSource, output: commands1._impl._commands_v1.command.PIDOutput) -> None
__init__(self: commands1._impl._commands_v1.command.PIDBase, p: float, i: float, d: float, f: float, source: commands1._impl._commands_v1.command.PIDSource, output: commands1._impl._commands_v1.command.PIDOutput) -> None
- get() float ¶
Return the current PID result.
This is always centered on zero and constrained the the max and min outs.
- Returns
the latest calculated output
- getAvgError() float ¶
- getD() float ¶
Get the Differential coefficient.
- Returns
differential coefficient
- getDeltaSetpoint() float ¶
Returns the change in setpoint over time of the PIDBase.
- Returns
the change in setpoint over time
- getError() float ¶
Returns the current difference of the input from the setpoint.
- Returns
the current error
- getF() float ¶
Get the Feed forward coefficient.
- Returns
Feed forward coefficient
- getI() float ¶
Get the Integral coefficient.
- Returns
integral coefficient
- getP() float ¶
Get the Proportional coefficient.
- Returns
proportional coefficient
- getPIDSourceType() commands1._impl._commands_v1.PIDSourceType ¶
Returns the type of input the PID controller is using.
- Returns
the PID controller input type
- getSetpoint() float ¶
Returns the current setpoint of the PIDBase.
- Returns
the current setpoint
- initSendable(builder: wpiutil._wpiutil.SendableBuilder) None ¶
- onTarget() bool ¶
Return true if the error is within the percentage of the total input range, determined by SetTolerance. This asssumes that the maximum and minimum input were set using SetInput.
Currently this just reports on target as the actual value passes through the setpoint. Ideally it should be based on being within the tolerance for some period of time.
This will return false until at least one input value has been computed.
- pidWrite(output: float) None ¶
Passes the output directly to SetSetpoint().
PIDControllers can be nested by passing a PIDController as another PIDController’s output. In that case, the output of the parent controller becomes the input (i.e., the reference) of the child.
It is the caller’s responsibility to put the data into a valid form for SetSetpoint().
- reset() None ¶
Reset the previous error, the integral term, and disable the controller.
- setAbsoluteTolerance(absTolerance: float) None ¶
Set the absolute error which is considered tolerable for use with OnTarget.
- Parameters
absTolerance – error which is tolerable
- setContinuous(continuous: bool = True) None ¶
Set the PID controller to consider the input to be continuous,
Rather then using the max and min input range as constraints, it considers them to be the same point and automatically calculates the shortest route to the setpoint.
- Parameters
continuous – true turns on continuous, false turns off continuous
- setD(d: float) None ¶
Set the Differential coefficient of the PID controller gain.
- Parameters
d – differential coefficient
- setF(f: float) None ¶
Get the Feed forward coefficient of the PID controller gain.
- Parameters
f – Feed forward coefficient
- setI(i: float) None ¶
Set the Integral coefficient of the PID controller gain.
- Parameters
i – integral coefficient
- setInputRange(minimumInput: float, maximumInput: float) None ¶
Sets the maximum and minimum values expected from the input.
- Parameters
minimumInput – the minimum value expected from the input
maximumInput – the maximum value expected from the output
- setOutputRange(minimumOutput: float, maximumOutput: float) None ¶
Sets the minimum and maximum values to write.
- Parameters
minimumOutput – the minimum value to write to the output
maximumOutput – the maximum value to write to the output
- setP(p: float) None ¶
Set the Proportional coefficient of the PID controller gain.
- Parameters
p – proportional coefficient
- setPID(*args, **kwargs)¶
Overloaded function.
setPID(self: commands1._impl._commands_v1.command.PIDBase, p: float, i: float, d: float) -> None
Set the PID Controller gain parameters.
Set the proportional, integral, and differential coefficients.
- Parameters
p – Proportional coefficient
i – Integral coefficient
d – Differential coefficient
setPID(self: commands1._impl._commands_v1.command.PIDBase, p: float, i: float, d: float, f: float) -> None
Set the PID Controller gain parameters.
Set the proportional, integral, and differential coefficients.
- Parameters
p – Proportional coefficient
i – Integral coefficient
d – Differential coefficient
f – Feed forward coefficient
- setPIDSourceType(pidSource: commands1._impl._commands_v1.PIDSourceType) None ¶
Sets what type of input the PID controller will use.
- setPercentTolerance(percent: float) None ¶
Set the percentage error which is considered tolerable for use with OnTarget.
- Parameters
percent – error which is tolerable
- setSetpoint(setpoint: float) None ¶
Set the setpoint for the PIDBase.
- Parameters
setpoint – the desired setpoint
- setTolerance(percent: float) None ¶
- setToleranceBuffer(bufLength: int = 1) None ¶