Jasper Gerth / controlandadjust

Dependents:   buttoncontrol includeair includeair Oudverslag

controlandadjust.h

Committer:
Gerth
Date:
2015-10-08
Revision:
8:3b077fc3d1ec
Parent:
5:5794dbc42c3d
Child:
10:37bdb3e5f03a

File content as of revision 8:3b077fc3d1ec:

/**
 * @author Jasper Gerth
 *
 * 
 * @section DESCRIPTION
 *
 * This library contains a P-, PI-, and a PID-controller.
 * The controller takes controller consta  
 */

#ifndef _CONTROLANDADJUST_H_
#define _CONTROLANDADJUST_H_
/**
 * Includes
 */
#include "mbed.h"

/** A library with a P-, PI- and PID-controller, useful for the module biorobotics
 * Example
 * @code
 * #include "mbed.h"
 * #include "controlandadjust.h"
 * #include "QEI.h" //This is found at https://developer.mbed.org/users/aberk/code/QEI/
 *
 * QEI encoder1 (D13, D12, NC, 32); //Encoder with X2 encoding and 32 counts per revolution
 * QEI encoder2 (D111, D10, NC, 32); //Encoder with X2 encoding and 32 counts per revolution
 *
 * controlandadjust mycontroller; //NO () AT THE END!!
 * const float kp=0.5;
 * AnalogIn pot(A0);
 *
 * int main(){
 *       while(1){
 *            float error1=(2*PI*pot.read()-counttorad*encoder1.getPulses()); //calculate error motor 1
 *            float error2=(2*PI*pot.read()-counttorad*encoder2.getPulses()); //calculate error motor 2
 *
 *            controller.P(error1,error2,kp); //controll with p controller
 *       };
 *   return 0;
 * } 
 * @endcode
*/

/**
 * Controller for biorobotics
 */
class controlandadjust
{
    
public:

    /**
     * Constructor.
     *
     *Constructs a controller
     */
    controlandadjust(void);
    
    /** P controller
    * @param error1 : float Error from motor 1
    * @param error2 : float Error from motor 2
    * @param Kp : float Desired value of Kp for your controller
    * @return void
    */
    void P(float error1, float error2 ,float Kp );

    /** PI controller
    * @param error1 : float Error from motor 1
    * @param error2 : float Error from motor 2
    * @param Kp : float Desired value of Kp for your controller
    * @param Ki : float Desired value of Ki for your controller
    * @param Ts : float Sampling time of your controller (1/Fs)
    * @param &error1_int : float Error for the integral from motor 1
    * @param &error2_int : float Error for the integral from motor 2
    * @return void
    */
    void PI(float error1, float error2, float Kp, float Ki,float Ts, float &error1_int, float &error2_int);

    /** PID controller
    * @param error1 : float Error from motor 1
    * @param error2 : float Error from motor 2
    * @param Kp : float Desired value of Kp for your controller
    * @param Ki : float Desired value of Ki for your controller
    * @param Kd : float Desired value of Kd for your controller
    * @param Ts : float Sampling time of your controller (1/Fs)
    * @param &error1_int : float Error for the integral from motor 1
    * @param &error2_int : float Error for the integral from motor 2
    * @param &error1_prev : float Previous error from motor 1 for the derivative
    * @param &error2_prev : float Previous error from motor 2 for the derivative
    * @return void
    */
    void PID(float error1, float error2, float Kp, float Ki,float Kd,float Ts,
             float &error1_int, float &error2_int, float &error1_prev, float &error2_prev);

    /** Read the PWM signal to motor 1
    * @return PWM signal to motor 1
    */
    float motor1pwm();

    /** Read the PWM signal to motor 2
      * @return PWM signal to motor 2
      */
    float motor2pwm();
    
    /** STOPS both motors
    * @return void
    */
    void STOP();

private:
    /**
     *Checks the signal and updates the PWM and direction for motor 1 and 2
     */
    void verwerksignaal(float , float );

};

#endif /* CONTROLANDADJUST_H */