hase(kari)
haseMD.cpp@0:24c2a636c6f0, 2020-01-25 (annotated)
- Committer:
- THtakahiro702286
- Date:
- Sat Jan 25 09:11:44 2020 +0000
- Revision:
- 0:24c2a636c6f0
mdpactice;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
THtakahiro702286 | 0:24c2a636c6f0 | 1 | #include "haseMD.h" |
THtakahiro702286 | 0:24c2a636c6f0 | 2 | #include "mbed.h" |
THtakahiro702286 | 0:24c2a636c6f0 | 3 | |
THtakahiro702286 | 0:24c2a636c6f0 | 4 | HaseMD::HaseMD(PinName pwmPin) : pwmMD(pwmPin), |
THtakahiro702286 | 0:24c2a636c6f0 | 5 | mdlpf(1.0/300,0.005) |
THtakahiro702286 | 0:24c2a636c6f0 | 6 | { |
THtakahiro702286 | 0:24c2a636c6f0 | 7 | pwmMD.period(1.0/250000.0); |
THtakahiro702286 | 0:24c2a636c6f0 | 8 | threadMD.start(callback(this, &HaseMD::MDloop)); |
THtakahiro702286 | 0:24c2a636c6f0 | 9 | } |
THtakahiro702286 | 0:24c2a636c6f0 | 10 | |
THtakahiro702286 | 0:24c2a636c6f0 | 11 | void HaseMD::setSpeed(double speed_) |
THtakahiro702286 | 0:24c2a636c6f0 | 12 | { |
THtakahiro702286 | 0:24c2a636c6f0 | 13 | speed = speed_; |
THtakahiro702286 | 0:24c2a636c6f0 | 14 | } |
THtakahiro702286 | 0:24c2a636c6f0 | 15 | |
THtakahiro702286 | 0:24c2a636c6f0 | 16 | void HaseMD::MDloop() |
THtakahiro702286 | 0:24c2a636c6f0 | 17 | { |
THtakahiro702286 | 0:24c2a636c6f0 | 18 | while(true){ |
THtakahiro702286 | 0:24c2a636c6f0 | 19 | _pwmMD = mdlpf.path_value(speed); |
THtakahiro702286 | 0:24c2a636c6f0 | 20 | _pwmMD += ((_pwmMD < 0.1) - (_pwmMD > 0.9)) * 0.1; |
THtakahiro702286 | 0:24c2a636c6f0 | 21 | pwmMD = 0.5 + _pwmMD /2.0; |
THtakahiro702286 | 0:24c2a636c6f0 | 22 | ThisThread::sleep_for(1000.0/400); |
THtakahiro702286 | 0:24c2a636c6f0 | 23 | // threadMD.wait(1000.0/400); |
THtakahiro702286 | 0:24c2a636c6f0 | 24 | } |
THtakahiro702286 | 0:24c2a636c6f0 | 25 | } |