小日向さんのMDライブラリ
Dependents: 00_yotsuba 10_motor-test 00_yotsuba 200_yotsuba_21 ... more
kohiMD.cpp@6:d4d97efd8881, 2021-03-04 (annotated)
- Committer:
- piroro4560
- Date:
- Thu Mar 04 11:57:50 2021 +0000
- Revision:
- 6:d4d97efd8881
- Parent:
- 3:1d075a1750ee
- Child:
- 7:d7e8402e6869
kohi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
THtakahiro702286 | 1:87d96da7a474 | 1 | #include "kohiMD.h" |
THtakahiro702286 | 1:87d96da7a474 | 2 | #include "mbed.h" |
THtakahiro702286 | 1:87d96da7a474 | 3 | |
THtakahiro702286 | 1:87d96da7a474 | 4 | KohiMD::KohiMD(PinName pwmPin) : pwmMD(pwmPin), |
piroro4560 | 6:d4d97efd8881 | 5 | mdlpf(1.0/300,0.005) |
THtakahiro702286 | 1:87d96da7a474 | 6 | { |
THtakahiro702286 | 1:87d96da7a474 | 7 | pwmMD.period(1.0/25000.0); |
THtakahiro702286 | 1:87d96da7a474 | 8 | pwmMD.write(0.5); |
piroro4560 | 6:d4d97efd8881 | 9 | // drive.attach(callback(this,&KohiMD::MDloop),10ms); |
THtakahiro702286 | 1:87d96da7a474 | 10 | } |
THtakahiro702286 | 1:87d96da7a474 | 11 | |
THtakahiro702286 | 1:87d96da7a474 | 12 | void KohiMD::setSpeed(double speed_) |
THtakahiro702286 | 1:87d96da7a474 | 13 | { |
THtakahiro702286 | 1:87d96da7a474 | 14 | speed = speed_; |
piroro4560 | 6:d4d97efd8881 | 15 | printf("%d\r\n",(int)(speed*10)); |
piroro4560 | 6:d4d97efd8881 | 16 | MDloop(); |
THtakahiro702286 | 1:87d96da7a474 | 17 | } |
THtakahiro702286 | 1:87d96da7a474 | 18 | |
THtakahiro702286 | 1:87d96da7a474 | 19 | void KohiMD::MDloop() |
THtakahiro702286 | 1:87d96da7a474 | 20 | { |
THtakahiro702286 | 1:87d96da7a474 | 21 | _pwmMD = mdlpf.path_value(speed); |
THtakahiro702286 | 1:87d96da7a474 | 22 | _pwmMD = 0.5 + _pwmMD /2.0; |
piroro4560 | 3:1d075a1750ee | 23 | if(_pwmMD > 0.9) _pwmMD = 0.9; |
piroro4560 | 3:1d075a1750ee | 24 | if(_pwmMD < 0.1) _pwmMD = 0.1; |
piroro4560 | 6:d4d97efd8881 | 25 | pwmMD.write(0.0); |
THtakahiro702286 | 1:87d96da7a474 | 26 | } |