sparkcan Documentation  1.0
PIDController Class Reference

A class for configuring and controlling PID for SPARK motor controllers. More...

#include <PIDController.hpp>

Public Member Functions

 PIDController (SparkBase &base)
 Construct a PIDController from a SparkBase object. More...
 
void SetReference (float setpoint, CtrlType controlType)
 Set the controller reference value based on the selected control mode. More...
 
void SetFeedbackDevice (uint16_t sensor)
 Set the feedback device for the PID controller. More...
 
void SetP (uint8_t slot, float p)
 Set the Proportional (P) gain. More...
 
void SetI (uint8_t slot, float i)
 Set the Integral (I) gain. More...
 
void SetD (uint8_t slot, float d)
 Set the Derivative (D) gain. More...
 
void SetF (uint8_t slot, float f)
 Set the Feedforward (F) gain. More...
 
void SetIZone (uint8_t slot, float iZone)
 Set the Integral Zone (I-Zone) for the PID controller. More...
 
void SetDFilter (uint8_t slot, float dFilter)
 Set the Derivative Filter for the PID controller. More...
 
void SetOutputMin (uint8_t slot, float min)
 Set the output minimum for the PID controller. More...
 
void SetOutputMax (uint8_t slot, float max)
 Set the output maximum for the PID controller. More...
 
void SetSmartMotionMaxVelocity (uint8_t slot, float maxVel)
 Set the Smart Motion maximum velocity. More...
 
void SetSmartMotionMaxAccel (uint8_t slot, float maxAccel)
 Set the Smart Motion maximum acceleration. More...
 
void SetSmartMotionMinVelOutput (uint8_t slot, float minVel)
 Set the Smart Motion minimum velocity output. More...
 
void SetSmartMotionAllowedClosedLoopError (uint8_t slot, float error)
 Set the allowed closed-loop error for Smart Motion. More...
 
void SetSmartMotionAccelStrategy (uint8_t slot, float strategy)
 Set the acceleration strategy for Smart Motion. More...
 
void SetIMaxAccum (uint8_t slot, float maxAccum)
 Set the maximum accumulated integral for the PID controller. More...
 
void SetSlot3Placeholder1 (uint8_t slot, float value)
 Set the placeholder parameter in slot 3, position 1. More...
 
void SetSlot3Placeholder2 (uint8_t slot, float value)
 Set the placeholder parameter in slot 3, position 2. More...
 
void SetSlot3Placeholder3 (uint8_t slot, float value)
 Set the placeholder parameter in slot 3, position 3. More...
 
void SetPositionPIDWrapEnable (bool enable)
 Enable or disable position PID wrap. More...
 
void SetPositionPIDMinInput (float minInput)
 Set the minimum input for position PID control. More...
 
void SetPositionPIDMaxInput (float maxInput)
 Set the maximum input for position PID control. More...
 
uint16_t GetFeedbackDevice ()
 Get the feedback device ID. More...
 
float GetP (uint8_t slot)
 Get the Proportional (P) gain. More...
 
float GetI (uint8_t slot)
 Get the Integral (I) gain. More...
 
float GetD (uint8_t slot)
 Get the Derivative (D) gain. More...
 
float GetF (uint8_t slot)
 Get the Feedforward (F) gain. More...
 
float GetIZone (uint8_t slot)
 Get the Integral Zone (I-Zone). More...
 
float GetDFilter (uint8_t slot)
 Get the Derivative Filter value. More...
 
float GetOutputMin (uint8_t slot)
 Get the minimum output range. More...
 
float GetOutputMax (uint8_t slot)
 Get the maximum output range. More...
 
float GetSmartMotionMaxVelocity (uint8_t slot)
 Get the Smart Motion maximum velocity. More...
 
float GetSmartMotionMaxAccel (uint8_t slot)
 Get the Smart Motion maximum acceleration. More...
 
float GetSmartMotionMinVelOutput (uint8_t slot)
 Get the Smart Motion minimum velocity output. More...
 
float GetSmartMotionAllowedClosedLoopError (uint8_t slot)
 Get the allowed closed-loop error for Smart Motion. More...
 
float GetSmartMotionAccelStrategy (uint8_t slot)
 Get the Smart Motion acceleration strategy. More...
 
float GetIMaxAccum (uint8_t slot)
 Get the maximum accumulated integral for the PID controller. More...
 
float GetSlot3Placeholder1 (uint8_t slot)
 Get the value of slot 3 placeholder 1. More...
 
float GetSlot3Placeholder2 (uint8_t slot)
 Get the value of slot 3 placeholder 2. More...
 
float GetSlot3Placeholder3 (uint8_t slot)
 Get the value of slot 3 placeholder 3. More...
 
bool GetPositionPIDWrapEnable ()
 Get whether position PID wrap is enabled. More...
 
float GetPositionPIDMinInput ()
 Get the minimum input for position PID control. More...
 
float GetPositionPIDMaxInput ()
 Get the maximum input for position PID control. More...
 

Detailed Description

A class for configuring and controlling PID for SPARK motor controllers.

This class provides methods for setting and getting various PID parameters such as P, I, D, F gains, and other control parameters specific to Smart Motion and position control.

Constructor & Destructor Documentation

◆ PIDController()

PIDController::PIDController ( SparkBase base)
explicit

Construct a PIDController from a SparkBase object.

Constructor that initializes a PIDController with a reference to a SparkBase object.

Parameters
baseThe SparkBase object associated with this PIDController.

Member Function Documentation

◆ GetD()

float PIDController::GetD ( uint8_t  slot)

Get the Derivative (D) gain.

Parameters
slotThe PID slot (0-3).
Returns
The D gain value.

◆ GetDFilter()

float PIDController::GetDFilter ( uint8_t  slot)

Get the Derivative Filter value.

Parameters
slotThe PID slot (0-3).
Returns
The D-Filter value.

◆ GetF()

float PIDController::GetF ( uint8_t  slot)

Get the Feedforward (F) gain.

Parameters
slotThe PID slot (0-3).
Returns
The F gain value.

◆ GetFeedbackDevice()

uint16_t PIDController::GetFeedbackDevice ( )

Get the feedback device ID.

Returns
The feedback device ID.

◆ GetI()

float PIDController::GetI ( uint8_t  slot)

Get the Integral (I) gain.

Parameters
slotThe PID slot (0-3).
Returns
The I gain value.

◆ GetIMaxAccum()

float PIDController::GetIMaxAccum ( uint8_t  slot)

Get the maximum accumulated integral for the PID controller.

Parameters
slotThe PID slot (0-3).
Returns
The maximum accumulated integral value.

◆ GetIZone()

float PIDController::GetIZone ( uint8_t  slot)

Get the Integral Zone (I-Zone).

Parameters
slotThe PID slot (0-3).
Returns
The I-Zone value.

◆ GetOutputMax()

float PIDController::GetOutputMax ( uint8_t  slot)

Get the maximum output range.

Parameters
slotThe PID slot (0-3).
Returns
The maximum output value.

◆ GetOutputMin()

float PIDController::GetOutputMin ( uint8_t  slot)

Get the minimum output range.

Parameters
slotThe PID slot (0-3).
Returns
The minimum output value.

◆ GetP()

float PIDController::GetP ( uint8_t  slot)

Get the Proportional (P) gain.

Parameters
slotThe PID slot (0-3).
Returns
The P gain value.

◆ GetPositionPIDMaxInput()

float PIDController::GetPositionPIDMaxInput ( )

Get the maximum input for position PID control.

Returns
The maximum input value.

◆ GetPositionPIDMinInput()

float PIDController::GetPositionPIDMinInput ( )

Get the minimum input for position PID control.

Returns
The minimum input value.

◆ GetPositionPIDWrapEnable()

bool PIDController::GetPositionPIDWrapEnable ( )

Get whether position PID wrap is enabled.

Returns
True if enabled, false otherwise.

◆ GetSlot3Placeholder1()

float PIDController::GetSlot3Placeholder1 ( uint8_t  slot)

Get the value of slot 3 placeholder 1.

Parameters
slotThe PID slot (0-3).
Returns
The value of slot 3 placeholder 1.

◆ GetSlot3Placeholder2()

float PIDController::GetSlot3Placeholder2 ( uint8_t  slot)

Get the value of slot 3 placeholder 2.

Parameters
slotThe PID slot (0-3).
Returns
The value of slot 3 placeholder 2.

◆ GetSlot3Placeholder3()

float PIDController::GetSlot3Placeholder3 ( uint8_t  slot)

Get the value of slot 3 placeholder 3.

Parameters
slotThe PID slot (0-3).
Returns
The value of slot 3 placeholder 3.

◆ GetSmartMotionAccelStrategy()

float PIDController::GetSmartMotionAccelStrategy ( uint8_t  slot)

Get the Smart Motion acceleration strategy.

Parameters
slotThe Smart Motion slot (0-3).
Returns
The acceleration strategy.

◆ GetSmartMotionAllowedClosedLoopError()

float PIDController::GetSmartMotionAllowedClosedLoopError ( uint8_t  slot)

Get the allowed closed-loop error for Smart Motion.

Parameters
slotThe Smart Motion slot (0-3).
Returns
The allowed closed-loop error.

◆ GetSmartMotionMaxAccel()

float PIDController::GetSmartMotionMaxAccel ( uint8_t  slot)

Get the Smart Motion maximum acceleration.

Parameters
slotThe Smart Motion slot (0-3).
Returns
The maximum acceleration.

◆ GetSmartMotionMaxVelocity()

float PIDController::GetSmartMotionMaxVelocity ( uint8_t  slot)

Get the Smart Motion maximum velocity.

Parameters
slotThe Smart Motion slot (0-3).
Returns
The maximum velocity.

◆ GetSmartMotionMinVelOutput()

float PIDController::GetSmartMotionMinVelOutput ( uint8_t  slot)

Get the Smart Motion minimum velocity output.

Parameters
slotThe Smart Motion slot (0-3).
Returns
The minimum velocity output.

◆ SetD()

void PIDController::SetD ( uint8_t  slot,
float  d 
)

Set the Derivative (D) gain.

Parameters
slotThe PID slot (0-3).
dThe D gain value.

◆ SetDFilter()

void PIDController::SetDFilter ( uint8_t  slot,
float  dFilter 
)

Set the Derivative Filter for the PID controller.

Parameters
slotThe PID slot (0-3).
dFilterThe D-Filter value.

◆ SetF()

void PIDController::SetF ( uint8_t  slot,
float  f 
)

Set the Feedforward (F) gain.

Parameters
slotThe PID slot (0-3).
fThe F gain value.

◆ SetFeedbackDevice()

void PIDController::SetFeedbackDevice ( uint16_t  sensor)

Set the feedback device for the PID controller.

Parameters
sensorThe feedback sensor device.

◆ SetI()

void PIDController::SetI ( uint8_t  slot,
float  i 
)

Set the Integral (I) gain.

Parameters
slotThe PID slot (0-3).
iThe I gain value.

◆ SetIMaxAccum()

void PIDController::SetIMaxAccum ( uint8_t  slot,
float  maxAccum 
)

Set the maximum accumulated integral for the PID controller.

Parameters
slotThe PID slot (0-3).
maxAccumThe maximum accumulated integral value.

◆ SetIZone()

void PIDController::SetIZone ( uint8_t  slot,
float  iZone 
)

Set the Integral Zone (I-Zone) for the PID controller.

Parameters
slotThe PID slot (0-3).
iZoneThe I-Zone value.

◆ SetOutputMax()

void PIDController::SetOutputMax ( uint8_t  slot,
float  max 
)

Set the output maximum for the PID controller.

Parameters
slotThe PID slot (0-3).
maxThe maximum output value.

◆ SetOutputMin()

void PIDController::SetOutputMin ( uint8_t  slot,
float  min 
)

Set the output minimum for the PID controller.

Parameters
slotThe PID slot (0-3).
minThe minimum output value.

◆ SetP()

void PIDController::SetP ( uint8_t  slot,
float  p 
)

Set the Proportional (P) gain.

Parameters
slotThe PID slot (0-3).
pThe P gain value.

◆ SetPositionPIDMaxInput()

void PIDController::SetPositionPIDMaxInput ( float  maxInput)

Set the maximum input for position PID control.

Parameters
maxInputThe maximum input value.

◆ SetPositionPIDMinInput()

void PIDController::SetPositionPIDMinInput ( float  minInput)

Set the minimum input for position PID control.

Parameters
minInputThe minimum input value.

◆ SetPositionPIDWrapEnable()

void PIDController::SetPositionPIDWrapEnable ( bool  enable)

Enable or disable position PID wrap.

Parameters
enableTrue to enable, false to disable.

◆ SetReference()

void PIDController::SetReference ( float  setpoint,
CtrlType  controlType 
)

Set the controller reference value based on the selected control mode.

Parameters
controlTypeCtrlType::kDutyCycle for Duty Cycle, CtrlType::kVelocity for Velocity, CtrlType::kVoltage for Voltage, CtrlType::kPosition for Position

◆ SetSlot3Placeholder1()

void PIDController::SetSlot3Placeholder1 ( uint8_t  slot,
float  value 
)

Set the placeholder parameter in slot 3, position 1.

Parameters
slotThe PID slot (0-3).
valueThe value for the placeholder.

◆ SetSlot3Placeholder2()

void PIDController::SetSlot3Placeholder2 ( uint8_t  slot,
float  value 
)

Set the placeholder parameter in slot 3, position 2.

Parameters
slotThe PID slot (0-3).
valueThe value for the placeholder.

◆ SetSlot3Placeholder3()

void PIDController::SetSlot3Placeholder3 ( uint8_t  slot,
float  value 
)

Set the placeholder parameter in slot 3, position 3.

Parameters
slotThe PID slot (0-3).
valueThe value for the placeholder.

◆ SetSmartMotionAccelStrategy()

void PIDController::SetSmartMotionAccelStrategy ( uint8_t  slot,
float  strategy 
)

Set the acceleration strategy for Smart Motion.

Parameters
slotThe Smart Motion slot (0-3).
strategyThe acceleration strategy.

◆ SetSmartMotionAllowedClosedLoopError()

void PIDController::SetSmartMotionAllowedClosedLoopError ( uint8_t  slot,
float  error 
)

Set the allowed closed-loop error for Smart Motion.

Parameters
slotThe Smart Motion slot (0-3).
errorThe allowed closed-loop error.

◆ SetSmartMotionMaxAccel()

void PIDController::SetSmartMotionMaxAccel ( uint8_t  slot,
float  maxAccel 
)

Set the Smart Motion maximum acceleration.

Parameters
slotThe Smart Motion slot (0-3).
maxAccelThe maximum acceleration.

◆ SetSmartMotionMaxVelocity()

void PIDController::SetSmartMotionMaxVelocity ( uint8_t  slot,
float  maxVel 
)

Set the Smart Motion maximum velocity.

Parameters
slotThe Smart Motion slot (0-3).
maxVelThe maximum velocity.

◆ SetSmartMotionMinVelOutput()

void PIDController::SetSmartMotionMinVelOutput ( uint8_t  slot,
float  minVel 
)

Set the Smart Motion minimum velocity output.

Parameters
slotThe Smart Motion slot (0-3).
minVelThe minimum velocity output.

The documentation for this class was generated from the following files: