components/PID/PID_v1.h

Mon, 21 Jun 2021 19:04:10 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 21 Jun 2021 19:04:10 +0200
changeset 102
96e30a3a3980
parent 82
7d17e2cb31a8
permissions
-rw-r--r--

Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.

/**
 * @file
 * @brief Interface definitions for the PID controller.
 *
 * Loger description
 */

#ifndef	_PID_V1_H
#define	_PID_V1_H

/**
 * @brief PID mode codes.
 */
typedef enum
{
    PID_MANUAL    = 0,		///< PID mode manual.
    PID_AUTOMATIC = 1,		///< PID mode is automatic.
} PID_MODE;

/**
 * @brief PID direction codes.
 */
typedef enum
{
    PID_DIRECT  = 0,		///< PID direction normal.
    PID_REVERSE = 1,		///< PID direction reverse.
} PID_DIRECTION;

/**
 * @brief Setup the PID controller and initialize.
 * @param[in] Input The measured value.
 * @param[in,out] Output The computed result.
 * @param[in] Setpoint The setpoint to regulate to.
 * @param[in] Kp The Proportional value.
 * @param[in] Ki The Intergral value.
 * @param[in] Kd The Derivate value.
 * @param[in] Direction Direct or Reverse action.
 */
void PID(double* Input, double* Output, double* Setpoint, double Kp, double Ki, double Kd, PID_DIRECTION Direction);

/**
 * @brief sets PID to either Manual or Automatic.
 * @param Mode Manual (0) or Automatic (1).
 */
void PID_SetMode(PID_MODE Mode);

/**
 * @brief This, as they say, is where the magic happens.  this function should be called
 *        every time "void loop()" executes.  the function will decide for itself whether a new
 *        pid Output needs to be computed.
 * @return Returns true when the output is computed, false when nothing has been done.
 */
bool PID_Compute(void);

/**
 * @brief Clamps the output to a specific range. 0-255 by default, but it's likely the user
 *        will want to change this depending on the application.
 * @param[in] Min The minimal value that Output can be.
 * @param[in] Max The maximum value that Output can be.
 */
void PID_SetOutputLimits(double Min, double Max);

/**
 * @brief While most users will set the tunings once in the constructor, this function gives
 *        the user the option of changing tunings during runtime for Adaptive control.
 * @param[in] Kp The Proportional value.
 * @param[in] Ki The Intergral value.
 * @param[in] Kd The Derivate value.
 */
void PID_SetTunings(double Kp, double Ki, double Kd);

/**
 * @brief The PID will either be connected to a DIRECT acting process (+Output leads
 *        to +Input) or a REVERSE acting process(+Output leads to -Input.)  we need to
 *        know which one, because otherwise we may increase the output when we should
 *        be decreasing.
 * @param[in] Direction Direct or Reverse action.
 */
void PID_SetControllerDirection(PID_DIRECTION Direction);

/**
 * @brief Sets the frequency, in Milliseconds, with which the PID calculation is performed.
 *        default is 100
 * @param[in] NewSampleTime The new time in Milliseconds.
 */
void PID_SetSampleTime(int NewSampleTime);

/**
 * @brief This function queries the internal state of the PID.  It's here for display
 *        purposes.  this are the functions the PID Front-end uses for example.
 * @return The Kp setting.
 */
double PID_GetKp();

/**
 * @brief This function queries the internal state of the PID.  It's here for display
 *        purposes.  this are the functions the PID Front-end uses for example.
 * @return The Ki setting.
 */
double PID_GetKi();

/**
 * @brief This function queries the internal state of the PID.  It's here for display
 *        purposes.  this are the functions the PID Front-end uses for example.
 * @return The Kp setting.
 */
double PID_GetKd();

/**
 * @brief This function queries the internal state of the PID.  It's here for display
 *        purposes.  this are the functions the PID Front-end uses for example.
 * @return Returns PID_AUTOMATIC or PID_MANUAL.
 */
PID_MODE PID_GetMode();

/**
 * @brief This function queries the internal state of the PID.  It's here for display
 *        purposes.  this are the functions the PID Front-end uses for example.
 * @return Returns PID_DIRECT or PID_REVERSE.
 */
PID_DIRECTION PID_GetDirection();


#endif

mercurial