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

P Controller. More...

#include <math.hpp>

Public Member Functions

 ProportionalController (double kP, std::shared_ptr< double > error, double motorGearing=200, bool maxRangeEnabled=false, double kP2=0, double maxRange=0)
 Creates a P controller for a V5 motor. More...
 
double update ()
 Calculates controller output based on the current error value. More...
 
double getkP () const
 Gets the kP constant. More...
 
double getOutput () const
 Gets the current stored output value without calculating a new value. More...
 
void setkP (double gain)
 Sets the kP constant. More...
 
double operator* ()
 Operator overload for getting the current filter ouput. More...
 
void setMaxRangeEnabled (bool enabled)
 Sets whether the maxRangeEnabled flag is on or off. More...
 
void setMaxRange (double range)
 Sets the error range from the target value that is used for switching between kP and kP2. More...
 
void setkP2 (double gain)
 Sets the secondary kP constant. More...
 

Detailed Description

P Controller.

Constructor & Destructor Documentation

◆ ProportionalController()

sylib::ProportionalController::ProportionalController ( double  kP,
std::shared_ptr< double >  error,
double  motorGearing = 200,
bool  maxRangeEnabled = false,
double  kP2 = 0,
double  maxRange = 0 
)

Creates a P controller for a V5 motor.

Parameters
kPProportional 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
maxRangeEnabledA flag that when true shifts the P controller to using kP2 as the kP constant when error is less than <maxRange>
kP2The secondary kP value that is used when maxRangeEnabled is on and the error is within maxRange
maxRangeError range from the target value that is used for switching between kP and kP2

Member Function Documentation

◆ getkP()

double sylib::ProportionalController::getkP ( ) const

Gets the kP constant.

Returns
kP value

◆ getOutput()

double sylib::ProportionalController::getOutput ( ) const

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

Returns
Controller output

◆ operator*()

double sylib::ProportionalController::operator* ( )

Operator overload for getting the current filter ouput.

Returns
Controller output

◆ setkP()

void sylib::ProportionalController::setkP ( double  gain)

Sets the kP constant.

Parameters
gainProportional gain

◆ setkP2()

void sylib::ProportionalController::setkP2 ( double  gain)

Sets the secondary kP constant.

Parameters
gainProportional gain

◆ setMaxRange()

void sylib::ProportionalController::setMaxRange ( double  range)

Sets the error range from the target value that is used for switching between kP and kP2.

Parameters
rangeMax error value

◆ setMaxRangeEnabled()

void sylib::ProportionalController::setMaxRangeEnabled ( bool  enabled)

Sets whether the maxRangeEnabled flag is on or off.

Parameters
enabledFlag value

◆ update()

double sylib::ProportionalController::update ( )

Calculates controller output based on the current error value.

Returns
Controller output