Sylib
A C++ Library For V5
Loading...
Searching...
No Matches
sylib::IntegralController Class Reference

I Controller. More...

#include <math.hpp>

Public Member Functions

 IntegralController (double kI, std::shared_ptr< double > error, double motorGearing=200, bool antiWindupEnabled=false, double antiWindupRange=0)
 Creates an I controller for a V5 motor. More...
 
double update ()
 Calculates controller output based on the current error value. More...
 
double getkI () const
 Gets the kI constant. More...
 
void resetValue ()
 Resets the integral value to 0. More...
 
double getOutput () const
 Gets the current stored output value without calculating a new value. More...
 
double getCurrentTime () const
 Gets the current time the controller is using. More...
 
uint32_t getdT () const
 Gets the most recent time difference between updates. More...
 
void setkI (double gain)
 Sets the kI constant. More...
 
double operator* ()
 Operator overload for getting the current filter ouput. More...
 
void setAntiWindupEnabled (bool enabled)
 Sets whether the antiWindupEnabled flag is on or off. More...
 
void setAntiWindupRange (double range)
 Sets the error range from the target value that is used for anti-windup. More...
 

Detailed Description

I Controller.

Constructor & Destructor Documentation

◆ IntegralController()

sylib::IntegralController::IntegralController ( double  kI,
std::shared_ptr< double >  error,
double  motorGearing = 200,
bool  antiWindupEnabled = false,
double  antiWindupRange = 0 
)

Creates an I controller for a V5 motor.

Parameters
kIIntegral gain
errorA pointer to a double containing the error value to use for calculations
motorGearingThe output speed of the motor, in RPM, if the motor internally is spinning at 3600 RPM. 200 is default for a green motor cartridge
antiWindupEnabledA flag that when true enables anti-windup, setting the output value to 0 when error is more than <antiWindupRange>
antiWindupRangeError range from the target value that is used for anti-windup

Member Function Documentation

◆ getCurrentTime()

double sylib::IntegralController::getCurrentTime ( ) const

Gets the current time the controller is using.

Returns
Time in milliseconds

◆ getdT()

uint32_t sylib::IntegralController::getdT ( ) const

Gets the most recent time difference between updates.

Returns
Time in milliseconds

◆ getkI()

double sylib::IntegralController::getkI ( ) const

Gets the kI constant.

Returns
kI value

◆ getOutput()

double sylib::IntegralController::getOutput ( ) const

Gets the current stored output value without calculating a new value.

Returns
Controller output

◆ operator*()

double sylib::IntegralController::operator* ( )

Operator overload for getting the current filter ouput.

Returns
Controller output

◆ resetValue()

void sylib::IntegralController::resetValue ( )

Resets the integral value to 0.

◆ setAntiWindupEnabled()

void sylib::IntegralController::setAntiWindupEnabled ( bool  enabled)

Sets whether the antiWindupEnabled flag is on or off.

Parameters
enabledFlag value

◆ setAntiWindupRange()

void sylib::IntegralController::setAntiWindupRange ( double  range)

Sets the error range from the target value that is used for anti-windup.

Parameters
rangeMax error value

◆ setkI()

void sylib::IntegralController::setkI ( double  gain)

Sets the kI constant.

Parameters
gainIntegral gain

◆ update()

double sylib::IntegralController::update ( )

Calculates controller output based on the current error value.

Returns
Controller output