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
Diff: controlandadjust.h
- Revision:
- 3:8e6dacabe898
- Parent:
- 2:a1b6930947a9
- Child:
- 4:e732794d8e7f
diff -r a1b6930947a9 -r 8e6dacabe898 controlandadjust.h
--- a/controlandadjust.h Tue Oct 06 12:44:50 2015 +0000
+++ b/controlandadjust.h Tue Oct 06 13:21:20 2015 +0000
@@ -1,36 +1,89 @@
#ifndef MBED_CONTROLANDADJUST_H
#define MBED_CONTROLANDADJUST_H
-
+/**
+ * Includes
+ */
#include "mbed.h"
#include <string>
/** 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 Encoder (D13, D12, NC, 32); //Encoder with X2 encoding and 32 counts per revolution
-*Ticker controlticker;
-*controlandadjust mycontroller; //NO () AT THE END!!
-*AnalogIn pot1(A0);
-*
+ * 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:
///Instantiate the controller
controlandadjust(void);
- /**P controller
- *@param error1 : Error from motor 1
- *@param error2 : Error from motor 2
- *@param Kp : Desired value of Kp for your controller*/
+ /** 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();
private: