PID
PID is a way to control motors to a certain position or velocity.
PID Config
To create PID loop, you need to create a PIDConfig
object.
To create one you can use the following constructor:
The constructor is contained inside of a struct holding all of the configuration values.
To create a PIDConfig
object you can use the following code:
Parameters
Type | Name | Description | See Also |
---|---|---|---|
std::string | path | The path in the networktables | |
wom::PIDConfig::kp_t | kp | The proportional gain | |
wom::PIDConfig::ki_t | ki | The integral gain | |
wom::PIDConfig::kd_t | kd | The derivative gain | |
wom::PIDConfig::error_t | stableThresh | The error threshold for the PID loop to be considered stable | |
wom::PIDConfig::deriv_t | stableDerivThresh | The derivative threshold for the PID loop to be considered stable | |
in_t | izone | The integral zone |
PID Loop
Then you can create a PID loop using the following code:
where IN
is the input type and OUT
is the output type.
Methods
SetSetpoint
Sets the setpoint of the PID loop.
setpoint
is the setpoint of the PID loop (must always be the same type asIN
in the constructor)
GetSetpoint
Gets the setpoint of the PID loop.
GetError
Gets the error value of the PID loop.
SetWrap
Sets the range of the input. If the input is outside of the range, it will wrap around to the other side of the range.
Example
Reset
Resets the integral value
Calculate
Calculates the output of the PID loop.
input
is the input of the PID loop (must always be the same type asIN
in the constructor)dt
is the time deltafeedforward
is the feedforward value (must always be the same type asOUT
in the constructor)
Example
IsStable
Checks if the PID loop is stable.