Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: buttoncontrol includeair includeair Oudverslag
controlandadjust.h
- Committer:
- Gerth
- Date:
- 2015-10-26
- Revision:
- 17:666505754e3f
- Parent:
- 15:a1a29db96f4f
- Child:
- 19:e3585d3c5a85
File content as of revision 17:666505754e3f:
/**
* @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 no don't put () after your controller
*@param errorband : float Width of the band at of allowable error
*@param controlfrequency : float Frequency of the controller in Hz
*/
controlandadjust(float errorband, float controlfrequency);
/** 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);
/** 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 );
/** PID controller with low pass
* @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
* @param tau_p : float Value of tau p (for the low pass filter)
* @return void
*/
void PIDLowPass(float error1, float error2, float Kp, float Ki,float Kd, float tau_p);
/** 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();
/** set safety cutoff value for the pwm signal to the motors
* @return void
*/
void cutoff(float maxvalue);
private:
/**
*Checks the signal and updates the PWM and direction for motor 1 and 2
*/
void verwerksignaal(float , float );
};
#endif /* CONTROLANDADJUST_H */