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.
main.cpp@1:9732c03b0de4, 2019-11-14 (annotated)
- Committer:
- maxnagazumi
- Date:
- Thu Nov 14 07:22:16 2019 +0000
- Revision:
- 1:9732c03b0de4
- Parent:
- 0:ef259ff25554
- Child:
- 2:d213999ee436
new
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| maxnagazumi | 0:ef259ff25554 | 1 | #include "mbed.h" | 
| maxnagazumi | 0:ef259ff25554 | 2 | #include "EC.h" //Encoderライブラリをインクルード | 
| maxnagazumi | 0:ef259ff25554 | 3 | #include "SpeedController.h" //SpeedControlライブラリをインクルード | 
| maxnagazumi | 0:ef259ff25554 | 4 | #define RESOLUTION 500 | 
| maxnagazumi | 0:ef259ff25554 | 5 | |
| maxnagazumi | 1:9732c03b0de4 | 6 | //PwmOut f(PA_9); | 
| maxnagazumi | 1:9732c03b0de4 | 7 | //PwmOut b(PA_10); | 
| maxnagazumi | 0:ef259ff25554 | 8 | DigitalIn s(PB_7,PullUp); | 
| maxnagazumi | 1:9732c03b0de4 | 9 | DigitalOut out1(PA_8); | 
| maxnagazumi | 1:9732c03b0de4 | 10 | Ticker ticker; | 
| maxnagazumi | 1:9732c03b0de4 | 11 | Ec4multi EC(PA_6,PA_7,RESOLUTION); | 
| maxnagazumi | 1:9732c03b0de4 | 12 | InterruptIn X(PA_4); | 
| maxnagazumi | 1:9732c03b0de4 | 13 | SpeedControl motor(PA_10,PA_9,50,EC); | 
| maxnagazumi | 0:ef259ff25554 | 14 | |
| maxnagazumi | 1:9732c03b0de4 | 15 | void calOmega() | 
| maxnagazumi | 1:9732c03b0de4 | 16 | { | 
| maxnagazumi | 1:9732c03b0de4 | 17 | EC.calOmega(); | 
| maxnagazumi | 1:9732c03b0de4 | 18 | } | 
| maxnagazumi | 1:9732c03b0de4 | 19 | |
| maxnagazumi | 1:9732c03b0de4 | 20 | int X_count=0; | 
| maxnagazumi | 1:9732c03b0de4 | 21 | |
| maxnagazumi | 1:9732c03b0de4 | 22 | void Xcount() | 
| maxnagazumi | 1:9732c03b0de4 | 23 | { | 
| maxnagazumi | 1:9732c03b0de4 | 24 | X_count++; | 
| maxnagazumi | 1:9732c03b0de4 | 25 | } | 
| maxnagazumi | 1:9732c03b0de4 | 26 | /*void shot() | 
| maxnagazumi | 1:9732c03b0de4 | 27 | { | 
| maxnagazumi | 1:9732c03b0de4 | 28 | out1 = 1; | 
| maxnagazumi | 1:9732c03b0de4 | 29 | } | 
| maxnagazumi | 1:9732c03b0de4 | 30 | */ | 
| maxnagazumi | 0:ef259ff25554 | 31 | int main() | 
| maxnagazumi | 0:ef259ff25554 | 32 | { | 
| maxnagazumi | 1:9732c03b0de4 | 33 | out1 =0; | 
| maxnagazumi | 1:9732c03b0de4 | 34 | motor.setPDparam(0.01,0.01); | 
| maxnagazumi | 1:9732c03b0de4 | 35 | motor.setEquation(0.005,0.01,0.023,0.0); | 
| maxnagazumi | 1:9732c03b0de4 | 36 | /* | 
| maxnagazumi | 1:9732c03b0de4 | 37 | b.setPDparam(double kp,double kd); | 
| maxnagazumi | 1:9732c03b0de4 | 38 | b.setEquation(double cf,double df,double cb,double db); | 
| maxnagazumi | 1:9732c03b0de4 | 39 | */ | 
| maxnagazumi | 1:9732c03b0de4 | 40 | //int i=0; | 
| maxnagazumi | 1:9732c03b0de4 | 41 | double a=0,r=0.4,v=0;//rで半径指定 a*r=v | 
| maxnagazumi | 1:9732c03b0de4 | 42 | X.rise(&Xcount); | 
| maxnagazumi | 1:9732c03b0de4 | 43 | ticker.attach(&calOmega,0.05); | 
| maxnagazumi | 1:9732c03b0de4 | 44 | printf("%d\n",s.read()); | 
| maxnagazumi | 1:9732c03b0de4 | 45 | motor.setDutyLimit(0.6); | 
| maxnagazumi | 1:9732c03b0de4 | 46 | printf("Omega V(m/s)"); | 
| maxnagazumi | 0:ef259ff25554 | 47 | while(1) { | 
| maxnagazumi | 1:9732c03b0de4 | 48 | if(s.read()==1) { | 
| maxnagazumi | 1:9732c03b0de4 | 49 | while(1) { | 
| maxnagazumi | 1:9732c03b0de4 | 50 | a=EC.getOmega(); | 
| maxnagazumi | 1:9732c03b0de4 | 51 | v=a*r; | 
| maxnagazumi | 1:9732c03b0de4 | 52 | printf("%f %f %d\r\n",a,v,X_count); | 
| maxnagazumi | 1:9732c03b0de4 | 53 | motor.Sc(10.5); | 
| maxnagazumi | 1:9732c03b0de4 | 54 | motor.setDutyLimit(0.4); | 
| maxnagazumi | 1:9732c03b0de4 | 55 | /*if(a>16.9||a<17.1) { | 
| maxnagazumi | 1:9732c03b0de4 | 56 | i++; | 
| maxnagazumi | 1:9732c03b0de4 | 57 | }*/ | 
| maxnagazumi | 1:9732c03b0de4 | 58 | /*if(X_count==6) { | 
| maxnagazumi | 1:9732c03b0de4 | 59 | out1 =1; | 
| maxnagazumi | 1:9732c03b0de4 | 60 | printf("shot\n");break; | 
| maxnagazumi | 1:9732c03b0de4 | 61 | } | 
| maxnagazumi | 1:9732c03b0de4 | 62 | */ | 
| maxnagazumi | 1:9732c03b0de4 | 63 | |
| maxnagazumi | 1:9732c03b0de4 | 64 | if(s.read()==0)break; | 
| maxnagazumi | 1:9732c03b0de4 | 65 | } | 
| maxnagazumi | 1:9732c03b0de4 | 66 | } | 
| maxnagazumi | 1:9732c03b0de4 | 67 | motor.stop(); | 
| maxnagazumi | 1:9732c03b0de4 | 68 | motor.reset(); | 
| maxnagazumi | 0:ef259ff25554 | 69 | if(s.read() ==0)break; | 
| maxnagazumi | 1:9732c03b0de4 | 70 | |
| maxnagazumi | 0:ef259ff25554 | 71 | } | 
| maxnagazumi | 0:ef259ff25554 | 72 | return 0; | 
| maxnagazumi | 0:ef259ff25554 | 73 | } |