小日向さんのMDライブラリ

Dependents:   00_yotsuba 10_motor-test 00_yotsuba 200_yotsuba_21 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers kohiMD.cpp Source File

kohiMD.cpp

00001 #include "kohiMD.h"
00002 #include "mbed.h"
00003 
00004 KohiMD::KohiMD(PinName pwmPin) : pwmMD(pwmPin),
00005 mdlpf(1.0/300,0.005)//,
00006 //pc(USBTX,USBRX,115200)
00007 {
00008     pwmMD.period(1.0/25000.0);
00009     pwmMD.write(0.5);
00010 //    threadMD.start(callback(this, &HaseMD::MDloop));
00011 //    drive.attach(callback(this,&KohiMD::MDloop),10ms);
00012 }
00013 
00014 void KohiMD::setSpeed(double speed_)
00015 {
00016     speed = speed_;
00017     MDloop();
00018 //    pc.printf("%f \n\r",_pwmMD);
00019 }
00020 
00021 void KohiMD::MDloop()
00022 {
00023 //    while(true){
00024         _pwmMD = mdlpf.path_value(speed);
00025         _pwmMD = 0.5 + _pwmMD /2.0;
00026         if(_pwmMD > 0.9) _pwmMD = 0.9;
00027         if(_pwmMD < 0.1) _pwmMD = 0.1;
00028         pwmMD.write(_pwmMD);
00029 //        pc.printf("%f \n\r",_pwmMD);
00030 //        ThisThread::sleep_for(1000.0/400);
00031 //        threadMD.wait(1000.0/400);
00032 //        }
00033 }