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.
Dependencies: QEI mbed-rtos mbed
Revision 6:16bee943a9fa, committed 2012-11-17
- Comitter:
- kosaka
- Date:
- Sat Nov 17 03:14:59 2012 +0000
- Parent:
- 5:2e53814aae4c
- Child:
- 7:613febb8f028
- Commit message:
- if CONTROL_MODE=3, u=Rand to identify G(s)
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Nov 17 00:07:04 2012 +0000
+++ b/main.cpp Sat Nov 17 03:14:59 2012 +0000
@@ -1,5 +1,5 @@
// DC motor control program using H-bridge driver (ex. TA7291P) and 360 resolution rotary encoder with A, B phase.
-// ver. 121116a by Kosaka lab.
+// ver. 121117a by Kosaka lab.
#include "mbed.h"
#include "rtos.h"
#include "QEI.h"
@@ -7,9 +7,9 @@
/*********** User setting for control parameters (begin) ***************/
//#define SIMULATION // Comment this line if not simulation
#define USE_PWM // H bridge PWM mode: Vref=Vcc, FIN,2 = PWM or 0. Comment if use Vref=analog mode
-#define CONTROL_MODE 0 // 0:PID control, 1:Frequency response, 2:Step response
+#define CONTROL_MODE 3 // 0:PID control, 1:Frequency response, 2:Step response, 3. u=Rand to identify G(s)
#define GOOD_DATA // Comment this line if the length of data TMAX/TS2 > 1000
-//#define R_SIN // Comment this line if not r = sin
+//#define R_SIN // Comment this line if r=step, not r = sin
float _freq_u = 0.3; // [Hz], freq. of Frequency response, or Step response
float _rmax=100./180.*PI; // [rad], max. of reference signal
float _Kp=20; // P gain for PID ... Kp=1, Ki=0, Kd=0 is good.
@@ -174,7 +174,7 @@
_f_umax = 0;
}
//#define CONTROL_MODE 2 // 0:PID control, 1:Frequency response, 2:Step response
-#if CONTROL_MODE>=1 // frequency response, or Step response
+#if CONTROL_MODE==1||CONTROL_MODE==2 // frequency response, or Step response
wt = _freq_u *2.0*PI*_time;
if(wt>2*PI) wt -= 2*PI*(float)((int)(wt/2.0*PI));
u = sin(wt ) * (UMAX-UMIN)/2.0 + (UMAX+UMIN)/2.0;
@@ -183,6 +183,13 @@
if( u>=0 ) u = UMAX;
else u = UMIN;
#endif
+#if CONTROL_MODE==3 // u=rand() to identify motor transfer function G(s) from V to angle
+ if(count2==(int)(TS2/TS)){
+ u = ((float)rand()/RAND_MAX*2.0-1.0) * (UMAX-1.5)/2.0 + (UMAX+1.5)/2.0;
+ }else{
+ u = _u;
+ }
+#endif
//debug[0]=u;//minus
u2Hbridge(u); // input u to TA7291 driver