FRC Paradigm Shift #1259
Documentation for the 2021 Robot
PIDLoaderFalcon Class Reference

Public Member Functions

 PIDLoaderFalcon (string name, bool adjustable, double p, double i, double d, double ff)
 
 PIDLoaderFalcon (string name, bool adjustable, double p, double i, double d, double ff, double max, double min)
 
void Load (TalonFX &driveMotor)
 
void LoadFromNetworkTable (TalonFX &driveMotor)
 

Private Attributes

string m_name
 
bool m_adjustable
 
double m_p
 
double m_i
 
double m_d
 
double m_ff
 
double m_max
 
double m_min
 

Detailed Description

Definition at line 13 of file PIDLoaderFalcon.h.

Constructor & Destructor Documentation

PIDLoaderFalcon::PIDLoaderFalcon ( string  name,
bool  adjustable,
double  p,
double  i,
double  d,
double  ff 
)

Definition at line 4 of file PIDLoaderFalcon.cpp.

5  : m_name(name)
6  , m_adjustable(adjustable)
7  , m_p(p)
8  , m_i(i)
9  , m_d(d)
10  , m_ff(ff) {}
PIDLoaderFalcon::PIDLoaderFalcon ( string  name,
bool  adjustable,
double  p,
double  i,
double  d,
double  ff,
double  max,
double  min 
)

Definition at line 12 of file PIDLoaderFalcon.cpp.

13  : m_name(name)
14  , m_adjustable(adjustable)
15  , m_p(p)
16  , m_i(i)
17  , m_d(d)
18  , m_ff(ff)
19  , m_max(max)
20  , m_min(min) {}

Member Function Documentation

void PIDLoaderFalcon::Load ( TalonFX &  driveMotor)

Loads drive PID controller with values, also sends default PID values to SmartDashboard

Parameters
driveMotorThe TalonFX responsible for driving

Definition at line 22 of file PIDLoaderFalcon.cpp.

References m_adjustable, m_d, m_ff, m_i, m_max, m_min, m_name, and m_p.

23 {
24  driveMotor.Config_kP(0, m_p);
25  driveMotor.Config_kD(0, m_d);
26  driveMotor.Config_kF(0, m_ff);
27  driveMotor.ConfigPeakOutputForward(m_max);
28  driveMotor.ConfigPeakOutputReverse(m_min);
29 
30  if (m_adjustable)
31  {
32  SmartDashboard::PutNumber("T_" + m_name + "_DP", m_p);
33  SmartDashboard::PutNumber("T_" + m_name + "_DI", m_i);
34  SmartDashboard::PutNumber("T_" + m_name + "_DD", m_d);
35  SmartDashboard::PutNumber("T_" + m_name + "_DFF", m_ff);
36  SmartDashboard::PutNumber("T_" + m_name + "_DMax", m_max);
37  SmartDashboard::PutNumber("T_" + m_name + "_DMin", m_min);
38  }
39 }
void PIDLoaderFalcon::LoadFromNetworkTable ( TalonFX &  driveMotor)

Loads drive PID controller with on the fly values from SmartDashboard

Parameters
driveMotorThe TalonFX responsible for driving

if PID coefficients on SmartDashboard have changed, write new values to controller

Definition at line 41 of file PIDLoaderFalcon.cpp.

References m_adjustable, m_d, m_ff, m_i, m_max, m_min, m_name, and m_p.

42 {
43  if (!m_adjustable)
44  return;
45 
46  double p = SmartDashboard::GetNumber("T_" + m_name + "_DP", m_p);
47  double i = SmartDashboard::GetNumber("T_" + m_name + "_DI", m_i);
48  double d = SmartDashboard::GetNumber("T_" + m_name + "_DD", m_d);
49  double ff = SmartDashboard::GetNumber("T_" + m_name + "_DFF", m_ff);
50  double max = SmartDashboard::GetNumber("T_" + m_name + "_DMax", m_max);
51  double min = SmartDashboard::GetNumber("T_" + m_name + "_DMin", m_min);
52 
54  if ((p != m_p)) { driveMotor.Config_kP(0, p); m_p = p; }
55  if ((i != m_i)) { driveMotor.Config_kI(0, i); m_i = i; }
56  if ((d != m_d)) { driveMotor.Config_kD(0, d); m_d = d; }
57  if ((ff != m_ff)) { driveMotor.Config_kF(0, ff); m_ff = ff; }
58 
59  if ((max != m_max) || (min != m_min))
60  {
61  driveMotor.ConfigPeakOutputForward(m_max);
62  driveMotor.ConfigPeakOutputReverse(m_min);
63  m_min = min;
64  m_max = max;
65  }

Member Data Documentation

string PIDLoaderFalcon::m_name
private

Definition at line 28 of file PIDLoaderFalcon.h.

bool PIDLoaderFalcon::m_adjustable
private

Definition at line 29 of file PIDLoaderFalcon.h.

double PIDLoaderFalcon::m_p
private

Definition at line 31 of file PIDLoaderFalcon.h.

double PIDLoaderFalcon::m_i
private

Definition at line 32 of file PIDLoaderFalcon.h.

double PIDLoaderFalcon::m_d
private

Definition at line 33 of file PIDLoaderFalcon.h.

double PIDLoaderFalcon::m_ff
private

Definition at line 34 of file PIDLoaderFalcon.h.

double PIDLoaderFalcon::m_max
private

Definition at line 35 of file PIDLoaderFalcon.h.

double PIDLoaderFalcon::m_min
private

Definition at line 36 of file PIDLoaderFalcon.h.


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