sn7544

Files at this revision

API Documentation at this revision

Comitter:
kangmingyo
Date:
Wed Jul 17 13:01:43 2019 +0000
Parent:
8:4fa7fadc583d
Commit message:
motor;

Changed in this revision

motor.cpp Show annotated file Show diff for this revision Revisions of this file
motor.h Show annotated file Show diff for this revision Revisions of this file
diff -r 4fa7fadc583d -r b1c5a0cf4a9b motor.cpp
--- 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);
     
diff -r 4fa7fadc583d -r b1c5a0cf4a9b motor.h
--- a/motor.h	Thu Jul 11 13:29:17 2019 +0000
+++ b/motor.h	Wed Jul 17 13:01:43 2019 +0000
@@ -10,7 +10,7 @@
 {
     public:
     
-        MotorCtl(PinName Pwm, PinName Dir, PinName tachoA, PinName tachoB);
+        MotorCtl(PinName Pwm, BusOut &Dir, PinName tachoA, PinName tachoB);
         
         ~MotorCtl();
 
@@ -41,7 +41,7 @@
         
     private:
         PwmOut _pwm;
-        DigitalOut _Dir;
+        BusOut _Dir;
         DigitalInOut _tachoA;
         DigitalInOut _tachoB;
         Ticker _tick;