Skip to main content

PID

Constructorsโ€‹

PID()โ€‹

Build PID object given constants and the sample_time.

  PID(const float _kp, const float _ki, const float _kd,unsigned int _sample_time, const float _scale);
Parameters
_kpThe proportional constant.
_ki The integral constant.
_kd The integral constant.
_sample_timeThe derivative constant.
_scaleA scaling factor that limits the output of the PID controller. For example, a value of 0.5 limits the output to 50% of its maximum value.

PID Copy constructor

  PID(const PID& other);
Parameters
otherother PID object.

Functionsโ€‹

update()โ€‹

Updates the PID controller.

note

You should put this function inside of while loop to update the PID input.

With this function you will update the proportional, integral, derivative and output value.

   virtual void update(const float error);
Parameters
errorThe error of PID controller (target - actual reading).

target_arrived()โ€‹

Checks if the target was reached.

   bool target_arrived() const;

Returns: True if the target was reached, False if the target wasnยดt reached.


initialization()โ€‹

Initialize the controller.

note

This function is neccesary to start in any procces or function where the controller is involve.

   void initialization();

Settersโ€‹

set_stop_time()โ€‹

Sets the stop time limit for the PID controller.

This function allows the user to set the maximum time limit after which the PID controller output will be set to zero.

   void set_stop_time(const float _stop_time_msec);  
Parameters
_stop_time_msecThe stop time limit in milliseconds. If more than this time elapses,the PID controller output will be forced to zero

set_error_tolerance()โ€‹

Sets the error tolerance.

note

For example: In a distance controller maybe the error tolerance would be .02 inches

    void set_error_tolerance(const float _error_tolerance);  
Parameters
_error_toleranceThe error tolerance for the controller.

set_derivative_tolerance()โ€‹

Sets derivative tolerance.

     void set_derivative_tolerance(const float _derivative_tolerance);
Parameters
_derivative_toleranceThe derivative tolerance.

set_integral_zone()โ€‹

Sets integral zone.

note

The integral zone is the zone where the intregal will not act.

void set_integral_zone(const float _integral_zone);
Parameters
_integral_zoneThe integral zone.

set_integral_power_limitโ€‹

Sets integral power limit.

note

The integral power limit would be the highest value of the integral.

void set_integral_power_limit(const float _integral_power_limit);

Parameters
_integral_power_limitThe integral power limit.

set_jump_time()โ€‹

Sets the jump time limit for the PID controller.

note

When the PID controller is approaching the target, a timer starts. If the timer reaches the jump time limit, the PID controller operation is halted.

void set_jump_time(const float _jump_time);

Parameters
_jump_timeThe jump time limit in milliseconds.

set_max()โ€‹

Sets the maximum output for the PID output.

    void set_max(const float _max);
Parameters
_maxThe max value of the PID output.

set_scale()โ€‹

Set the scale for the PID controller.

    void set_scale(const float _scale);
Parameters
_scalescaling factor that limits the output of the PID controller.For example, a value of 0.5 limits the output to 50% of its maximum value.

set_kp()โ€‹

Sets the proportional constant (kp) of the PID controller.

    void set_kp(const float _kp);

Parameters
_kpThe new value for the proportional constant.

set_ki()โ€‹

Sets the integral constant (ki) of the PID controller.

void set_ki(const float _ki);

Parameters
_kiThe new value for the integral constant.

set_kdโ€‹

Sets the derivative constant (kd) of the PID controller.

void set_kd(const float _kd);

Parameters
_kdThe new value for the derivative constant.

set_sample_timeโ€‹

Sets the sample time of the PID controller.

void set_sample_time(const  unsigned int time_msec); 

Parameters
time_msecThe new sample time in milliseconds.

Gettersโ€‹

get_error()โ€‹

Gets the current error.

float get_error() const;

Returns: The current error.


get_kp()โ€‹

Gets proportional constant [Kp].

float get_kp() const;

Returns: The kp constant.


get_ki()โ€‹

Gets proportional constant [Ki].

float get_ki() const;

Returns: The ki constant.


get_kd()โ€‹

Gets proportional constant [Kd].

float get_kd() const;

Returns: The kd constant.


get_proportion()โ€‹

Gets the proportion part of the output.

double get_proportion() const;

Returns: The proportion value.


get_integral()โ€‹

Gets the proportion part of the output.

double get_integral() const;

Returns: The integral value.


get_derivative()โ€‹

Gets the proportion part of the output.

double get_derivative() const;

Returns: The derivative value.


get_sample_time()โ€‹

Gets the sample time.

unsigned int get_sample_time() const;

Returns: The sample time.

get_output()โ€‹

Gets the current output from controller.

double get_output() const;

Returns: The current output from controller.

get_error_tolerance()โ€‹

Retrieves the error tolerance of the PID controller.

float get_error_tolerance() const;

Returns: The current error tolerance value.

get_derivative_tolerance()โ€‹

float get_derivative_tolerance() const;

Returns: The current derivative tolerance value.

get_integral_zone()โ€‹

Retrieves the integral zone of the PID controller.

float get_integral_zone() const;

Returns: The current integral zone value.


get_integral_power_limit()โ€‹

Retrieves the integral power limit of the PID controller.

float get_integral_power_limit() const;

Returns: The current integral power limit value.

get_max()โ€‹

Retrieves the maximum value allowed for the PID controller output.

float get_max() const;

Returns: The maximum values allowed.