mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Change C++ Notifier to allow std::function callback.
Also provide templated varags constructor for backwards compatibility and ease of use. Update PIDController to use new constructor, eliminating static function CallCalculate(). Change-Id: Iaeae95aa5953f294f5debc5fc569ef6d4684f223
This commit is contained in:
@@ -84,7 +84,7 @@ void PIDController::Initialize(float Kp, float Ki, float Kd, float Kf,
|
||||
m_pidOutput = output;
|
||||
m_period = period;
|
||||
|
||||
m_controlLoop = std::make_unique<Notifier>(PIDController::CallCalculate, this);
|
||||
m_controlLoop = std::make_unique<Notifier>(&PIDController::Calculate, this);
|
||||
m_controlLoop->StartPeriodic(m_period);
|
||||
|
||||
static int32_t instances = 0;
|
||||
@@ -98,23 +98,9 @@ PIDController::~PIDController() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the Calculate method as a non-static method. This avoids having to prepend
|
||||
* all local variables in that method with the class pointer. This way the "this"
|
||||
* pointer will be set up and class variables can be called more easily.
|
||||
* This method is static and called by the Notifier class.
|
||||
* @param controller the address of the PID controller object to use in the background loop
|
||||
* Read the input, calculate the output accordingly, and write to the output.
|
||||
* This should only be called by the Notifier.
|
||||
*/
|
||||
void PIDController::CallCalculate(void *controller)
|
||||
{
|
||||
PIDController *control = (PIDController*) controller;
|
||||
control->Calculate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the input, calculate the output accordingly, and write to the output.
|
||||
* This should only be called by the Notifier indirectly through CallCalculate
|
||||
* and is created during initialization.
|
||||
*/
|
||||
void PIDController::Calculate()
|
||||
{
|
||||
bool enabled;
|
||||
|
||||
Reference in New Issue
Block a user