Documentation ¶
Overview ¶
Package pid provides PID controllers for Go.
Index ¶
- type AntiWindupController
- type AntiWindupControllerConfig
- type AntiWindupControllerInput
- type AntiWindupControllerState
- type Controller
- type ControllerConfig
- type ControllerInput
- type ControllerState
- type TrackingController
- type TrackingControllerConfig
- type TrackingControllerInput
- type TrackingControllerState
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AntiWindupController ¶
type AntiWindupController struct { // Config for the AntiWindupController. Config AntiWindupControllerConfig // State of the AntiWindupController. State AntiWindupControllerState }
AntiWindupController implements a PID-controller with low-pass filter of the derivative term, feed forward term, a saturated control output and anti-windup.
The anti-windup mechanism uses an actuator saturation model as defined in Chapter 6 of Åström and Murray, Feedback Systems: An Introduction to Scientists and Engineers, 2008 (http://www.cds.caltech.edu/~murray/amwiki)
The ControlError, ControlErrorIntegrand, ControlErrorIntegral and ControlErrorDerivative are prevented from reaching +/- inf by clamping them to [-math.MaxFloat64, math.MaxFloat64].
func (*AntiWindupController) DischargeIntegral ¶
func (c *AntiWindupController) DischargeIntegral(dt time.Duration)
DischargeIntegral provides the ability to discharge the controller integral state over a configurable period of time.
func (*AntiWindupController) Reset ¶
func (c *AntiWindupController) Reset()
Reset the controller state.
func (*AntiWindupController) Update ¶
func (c *AntiWindupController) Update(input AntiWindupControllerInput)
Update the controller state.
type AntiWindupControllerConfig ¶
type AntiWindupControllerConfig struct { // ProportionalGain is the P part gain. ProportionalGain float64 // IntegralGain is the I part gain. IntegralGain float64 // DerivativeGain is the D part gain. DerivativeGain float64 // AntiWindUpGain is the anti-windup tracking gain. AntiWindUpGain float64 // IntegralDischargeTimeConstant is the time constant to discharge the integral state of the PID controller (s) IntegralDischargeTimeConstant float64 // LowPassTimeConstant is the D part low-pass filter time constant => cut-off frequency 1/LowPassTimeConstant. LowPassTimeConstant time.Duration // MaxOutput is the max output from the PID. MaxOutput float64 // MinOutput is the min output from the PID. MinOutput float64 }
AntiWindupControllerConfig contains config parameters for a AntiWindupController.
type AntiWindupControllerInput ¶
type AntiWindupControllerInput struct { // ReferenceSignal is the reference value for the signal to control. ReferenceSignal float64 // ActualSignal is the actual value of the signal to control. ActualSignal float64 // FeedForwardSignal is the contribution of the feed-forward control loop in the controller output. FeedForwardSignal float64 // SamplingInterval is the time interval elapsed since the previous call of the controller Update method. SamplingInterval time.Duration }
AntiWindupControllerInput holds the input parameters to an AntiWindupController.
type AntiWindupControllerState ¶
type AntiWindupControllerState struct { // ControlError is the difference between reference and current value. ControlError float64 // ControlErrorIntegrand is the control error integrand, which includes the anti-windup correction. ControlErrorIntegrand float64 // ControlErrorIntegral is the control error integrand integrated over time. ControlErrorIntegral float64 // ControlErrorDerivative is the low-pass filtered time-derivative of the control error. ControlErrorDerivative float64 // ControlSignal is the current control signal output of the controller. ControlSignal float64 // UnsaturatedControlSignal is the control signal before saturation. UnsaturatedControlSignal float64 }
AntiWindupControllerState holds mutable state for a AntiWindupController.
type Controller ¶
type Controller struct { // Config for the Controller. Config ControllerConfig // State of the Controller. State ControllerState }
Controller implements a basic PID controller.
Example ¶
package main import ( "fmt" "time" "go.einride.tech/pid" ) func main() { // Create a PID controller. c := pid.Controller{ Config: pid.ControllerConfig{ ProportionalGain: 2.0, IntegralGain: 1.0, DerivativeGain: 1.0, }, } // Update the PID controller. c.Update(pid.ControllerInput{ ReferenceSignal: 10, ActualSignal: 0, SamplingInterval: 100 * time.Millisecond, }) fmt.Printf("%+v\n", c.State) // Reset the PID controller. c.Reset() fmt.Printf("%+v\n", c.State) }
Output: {ControlError:10 ControlErrorIntegral:1 ControlErrorDerivative:100 ControlSignal:121} {ControlError:0 ControlErrorIntegral:0 ControlErrorDerivative:0 ControlSignal:0}
func (*Controller) Update ¶
func (c *Controller) Update(input ControllerInput)
Update the controller state.
type ControllerConfig ¶
type ControllerConfig struct { // ProportionalGain determines ratio of output response to error signal. ProportionalGain float64 // IntegralGain determines previous error's affect on output. IntegralGain float64 // DerivativeGain decreases the sensitivity to large reference changes. DerivativeGain float64 }
ControllerConfig contains configurable parameters for a Controller.
type ControllerInput ¶
type ControllerInput struct { // ReferenceSignal is the reference value for the signal to control. ReferenceSignal float64 // ActualSignal is the actual value of the signal to control. ActualSignal float64 // SamplingInterval is the time interval elapsed since the previous call of the controller Update method. SamplingInterval time.Duration }
ControllerInput holds the input parameters to a Controller.
type ControllerState ¶
type ControllerState struct { // ControlError is the difference between reference and current value. ControlError float64 // ControlErrorIntegral is the integrated control error over time. ControlErrorIntegral float64 // ControlErrorDerivative is the rate of change of the control error. ControlErrorDerivative float64 // ControlSignal is the current control signal output of the controller. ControlSignal float64 }
ControllerState holds mutable state for a Controller.
type TrackingController ¶
type TrackingController struct { // Config for the TrackingController. Config TrackingControllerConfig // State of the TrackingController. State TrackingControllerState }
TrackingController implements a PID-controller with low-pass filter of the derivative term, feed forward term, anti-windup and bumpless transfer using tracking mode control.
The anti-windup and bumpless transfer mechanisms use a tracking mode as defined in Chapter 6 of Åström and Murray, Feedback Systems: An Introduction to Scientists and Engineers, 2008 (http://www.cds.caltech.edu/~murray/amwiki)
The ControlError, ControlErrorIntegrand, ControlErrorIntegral and ControlErrorDerivative are prevented from reaching +/- inf by clamping them to [-math.MaxFloat64, math.MaxFloat64].
func (*TrackingController) DischargeIntegral ¶
func (c *TrackingController) DischargeIntegral(dt time.Duration)
DischargeIntegral provides the ability to discharge the controller integral state over a configurable period of time.
func (*TrackingController) Update ¶
func (c *TrackingController) Update(input TrackingControllerInput)
Update the controller state.
type TrackingControllerConfig ¶
type TrackingControllerConfig struct { // ProportionalGain is the P part gain. ProportionalGain float64 // IntegralGain is the I part gain. IntegralGain float64 // DerivativeGain is the D part gain. DerivativeGain float64 // AntiWindUpGain is the anti-windup tracking gain. AntiWindUpGain float64 // IntegralDischargeTimeConstant is the time constant to discharge the integral state of the PID controller (s) IntegralDischargeTimeConstant float64 // LowPassTimeConstant is the D part low-pass filter time constant => cut-off frequency 1/LowPassTimeConstant. LowPassTimeConstant time.Duration // MaxOutput is the max output from the PID. MaxOutput float64 // MinOutput is the min output from the PID. MinOutput float64 }
TrackingControllerConfig contains configurable parameters for a TrackingController.
type TrackingControllerInput ¶
type TrackingControllerInput struct { // ReferenceSignal is the reference value for the signal to control. ReferenceSignal float64 // ActualSignal is the actual value of the signal to control. ActualSignal float64 // FeedForwardSignal is the contribution of the feed-forward control loop in the controller output. FeedForwardSignal float64 // AppliedControlSignal is the actual control command applied by the actuator. AppliedControlSignal float64 // SamplingInterval is the time interval elapsed since the previous call of the controller Update method. SamplingInterval time.Duration }
TrackingControllerInput holds the input parameters to a TrackingController.
type TrackingControllerState ¶
type TrackingControllerState struct { // ControlError is the difference between reference and current value. ControlError float64 // ControlErrorIntegrand is the integrated control error over time. ControlErrorIntegrand float64 // ControlErrorIntegral is the control error integrand integrated over time. ControlErrorIntegral float64 // ControlErrorDerivative is the low-pass filtered time-derivative of the control error. ControlErrorDerivative float64 // ControlSignal is the current control signal output of the controller. ControlSignal float64 // UnsaturatedControlSignal is the control signal before saturation used for tracking the // actual control signal for bumpless transfer or compensation of un-modeled saturations. UnsaturatedControlSignal float64 }
TrackingControllerState holds the mutable state a TrackingController.