小日向さんのMDライブラリ
Dependents: 00_yotsuba 10_motor-test 00_yotsuba 200_yotsuba_21 ... more
kohiMD.cpp
- Committer:
- piroro4560
- Date:
- 2021-03-04
- Revision:
- 6:d4d97efd8881
- Parent:
- 3:1d075a1750ee
- Child:
- 7:d7e8402e6869
File content as of revision 6:d4d97efd8881:
#include "kohiMD.h" #include "mbed.h" KohiMD::KohiMD(PinName pwmPin) : pwmMD(pwmPin), mdlpf(1.0/300,0.005) { pwmMD.period(1.0/25000.0); pwmMD.write(0.5); // drive.attach(callback(this,&KohiMD::MDloop),10ms); } void KohiMD::setSpeed(double speed_) { speed = speed_; printf("%d\r\n",(int)(speed*10)); MDloop(); } void KohiMD::MDloop() { _pwmMD = mdlpf.path_value(speed); _pwmMD = 0.5 + _pwmMD /2.0; if(_pwmMD > 0.9) _pwmMD = 0.9; if(_pwmMD < 0.1) _pwmMD = 0.1; pwmMD.write(0.0); }