RIT VEXU Core API
Loading...
Searching...
No Matches
PID Class Reference

#include <pid.h>

Inheritance diagram for PID:
Feedback

Classes

struct  pid_config_t
 

Public Types

enum  ERROR_TYPE
 

Public Member Functions

 PID (pid_config_t &config)
 
void init (double start_pt, double set_pt) override
 
double update (double sensor_val) override
 
double update (double sensor_val, double v_setpt)
 
double get_sensor_val () const
 gets the sensor value that we were last updated with
 
double get () override
 
void set_limits (double lower, double upper) override
 
bool is_on_target () override
 
void reset ()
 
double get_error ()
 
double get_target () const
 
void set_target (double target)
 

Public Attributes

pid_config_tconfig
 

Detailed Description

PID Class

Defines a standard feedback loop using the constants kP, kI, kD, deadband, and on_target_time. The formula is:

out = kP*error + kI*integral(d Error) + kD*(dError/dt)

The PID object will determine it is "on target" when the error is within the deadband, for a duration of on_target_time

Author
Ryan McGee
Date
4/3/2020

Member Enumeration Documentation

◆ ERROR_TYPE

An enum to distinguish between a linear and angular caluclation of PID error.

Constructor & Destructor Documentation

◆ PID()

PID::PID ( pid_config_t & config)

Create the PID object

Parameters
configthe configuration data for this controller

Create the PID object

Member Function Documentation

◆ get()

double PID::get ( )
overridevirtual

Gets the current PID out value, from when update() was last run

Returns
the Out value of the controller (voltage, RPM, whatever the PID controller is controlling)

Gets the current PID out value, from when update() was last run

Implements Feedback.

◆ get_error()

double PID::get_error ( )

Get the delta between the current sensor data and the target

Returns
the error calculated. how it is calculated depends on error_method specified in pid_config_t

Get the delta between the current sensor data and the target

◆ get_sensor_val()

double PID::get_sensor_val ( ) const

gets the sensor value that we were last updated with

Returns
sensor_val

◆ get_target()

double PID::get_target ( ) const

Get the PID's target

Returns
the target the PID controller is trying to achieve

◆ init()

void PID::init ( double start_pt,
double set_pt )
overridevirtual

Inherited from Feedback for interoperability. Update the setpoint and reset integral accumulation

start_pt can be safely ignored in this feedback controller

Parameters
start_ptcommpletely ignored for PID. necessary to satisfy Feedback base
set_ptsets the target of the PID controller
start_velcompletely ignored for PID. necessary to satisfy Feedback base
end_velsets the target end velocity of the PID controller

Implements Feedback.

◆ is_on_target()

bool PID::is_on_target ( )
overridevirtual

Checks if the PID controller is on target.

Returns
true if the loop is within [deadband] for [on_target_time] seconds

Returns true if the loop is within [deadband] for [on_target_time] seconds

Implements Feedback.

◆ reset()

void PID::reset ( )

Reset the PID loop by resetting time since 0 and accumulated error.

◆ set_limits()

void PID::set_limits ( double lower,
double upper )
overridevirtual

Set the limits on the PID out. The PID out will "clip" itself to be between the limits.

Parameters
lowerthe lower limit. the PID controller will never command the output go below lower
upperthe upper limit. the PID controller will never command the output go higher than upper

Set the limits on the PID out. The PID out will "clip" itself to be between the limits.

Implements Feedback.

◆ set_target()

void PID::set_target ( double target)

Set the target for the PID loop, where the robot is trying to end up

Parameters
targetthe sensor reading we would like to achieve

Set the target for the PID loop, where the robot is trying to end up

◆ update() [1/2]

double PID::update ( double sensor_val)
overridevirtual

Update the PID loop by taking the time difference from last update, and running the PID formula with the new sensor data

Parameters
sensor_valthe distance, angle, encoder position or whatever it is we are measuring
Returns
the new output. What would be returned by PID::get()

Implements Feedback.

◆ update() [2/2]

double PID::update ( double sensor_val,
double v_setpt )

Update the PID loop by taking the time difference from last update, and running the PID formula with the new sensor data

Parameters
sensor_valthe distance, angle, encoder position or whatever it is we are measuring
v_setptExpected velocity setpoint, to subtract from the D term (for velocity control)
Returns
the new output. What would be returned by PID::get()

Member Data Documentation

◆ config

pid_config_t& PID::config

configuration struct for this controller. see pid_config_t for information about what this contains


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