sn7544
Diff: motor.cpp
- Revision:
- 9:b1c5a0cf4a9b
- Parent:
- 8:4fa7fadc583d
--- a/motor.cpp Thu Jul 11 13:29:17 2019 +0000 +++ b/motor.cpp Wed Jul 17 13:01:43 2019 +0000 @@ -1,9 +1,9 @@ #include "motor.h" -MotorCtl::MotorCtl(PinName Pwm, PinName Dir, PinName tachoA, PinName tachoB): +MotorCtl::MotorCtl(PinName Pwm, BusOut &Dir, PinName tachoA, PinName tachoB): _pwm(Pwm), _Dir(Dir), _tachoA(tachoA), _tachoB(tachoB) { - _Dir=1; + _Dir=0; dr = 10; _pwm.period_ms(32); _pwm.write(0); @@ -101,9 +101,9 @@ void MotorCtl::setDirection() { if (dr>5) { - _Dir=1; + _Dir=2; } else { - _Dir=0; + _Dir=1; } } @@ -146,7 +146,7 @@ DeltaCnt = CurrentPosition - PreviousPosition; PreviousPosition = CurrentPosition; CurrentSpeed = (int)CalculateRPM(DeltaCnt); -// printf("DeltaCnt: %d CurrentSpeed: %ld\r\n",DeltaCnt,CurrentSpeed); + printf("DeltaCnt: %d CurrentSpeed: %ld\r\n",DeltaCnt,CurrentSpeed); Error = TargetSpeed - CurrentSpeed; integ += Error; @@ -158,12 +158,12 @@ if(TargetSpeed>0){ vel =(TargetSpeed+control)/200.0; _pwm.write(vel); - _Dir=1; + _Dir=2; // printf("control: %d\r\n",control); }else{ vel =(-TargetSpeed-control)/200.0; _pwm.write(vel); - _Dir=0; + _Dir=1; } // printf("Duty: %d Target:%d control:%d\r\n",duty,TargetSpeed, control);