teamALI / Mbed 2 deprecated RubyHwTest2

Dependencies:   mbed

Revision:
3:6898c5bd7fef
Parent:
2:ff609fd0c51a
Child:
4:ab3a8a7a0fcf
--- a/motor.cpp	Mon Aug 20 07:58:27 2018 +0000
+++ b/motor.cpp	Mon Aug 20 08:51:01 2018 +0000
@@ -25,7 +25,7 @@
 static  Serial          pc      (USBTX  , USBRX );  
 
         MOTOR_THROTTLE  mt={0,};
-static UCHAR value=0;
+static UCHAR SValue = 0;
 
 //================================================================
 //モーター制御モジュール初期化
@@ -39,6 +39,7 @@
 //----------------------------------------------------------------
 //SPI送信
 //----------------------------------------------------------------
+
 void motorSpiSend
     (UCHAR  ch      //チャンネル番号
     ,UCHAR  val     //モータ設定値0~255
@@ -59,47 +60,66 @@
     pc.printf("ch[%d] %d\r\n" , cmd.bf.ch , cmd.bf.val);
 }
 //================================================================
-//
+//Motor Tests
 //================================================================
-
-void motorUp(){
-    int ch ,i;
-
-    for (i=0; i<10; i++){
-        if (value != 0xFF) { 
-            value++;
+void motorTestUp(){
+    int ch,val;
+        for(ch=1; ch<3; ch++){
+            for(val=0; val<30; val++){
+                motorSpiSend(ch,val);
+                wait(0.01);
+            }
+            wait(1);
         }
-        for(ch=1; ch<3; ch++){
-            motorSpiSend(ch,value);
-            wait(0.01);
-        }
-    }
-        /*
         for(ch=5; ch<9; ch++){
-            for(val=0; val<250; val +=5){
+            for(val=0; val<30; val++){
                 motorSpiSend(ch,val);
                 wait(0.01);
             }
+            wait(1);
         }
-        */
+}
+
+void motorTestDown(){
+    int ch,val;
+        for(ch=5; ch<9; ch++){
+            for(val=30; val>0; val--){
+                motorSpiSend(ch,val);
+                wait(0.01);
+            }
+            wait(1);
+        }
+        for(ch=1; ch<3; ch++){
+            for(val=30; val>0; val--){
+                motorSpiSend(ch,val);
+                wait(0.01);
+            }
+            wait(1);
+        }
+}
+
+void motorUp(){
+    int ch ,v;
+    for (v=0; v<10; v++){ // for each 1 unit of speed v
+        if (SValue < 0xFF) { // check if speed less than max
+            SValue++;
+        } 
+        for(ch=1; ch<3; ch++){ // each channel
+            motorSpiSend(ch,SValue); // increase speed by 1 unit
+            wait(0.01); // 2nd motor increases .01s after 1st motor
+        }
+    }
 }
 
 void motorStop(){
     int ch, v;
-        /*
-        for(ch=5; ch<9; ch++){
-                motorSpiSend(ch,0);
-                wait(0.01);
-            }
+    for (v=SValue; v>0; v--){ // for each 1 unit of speed v
+        for(ch=1; ch<3; ch++){ // each channel
+            motorSpiSend(ch,v); // decrease speed by 1 unit
+            wait(0.01); // 2nd motor decreses .01s after 1st motor
         }
-        */
-        for(ch=1; ch<3; ch++){
-            for (v=value; v>0; v--){
-                motorSpiSend(ch,v);
-                wait(0.01);
-            }
-        }
-        value = 0;
+    }
+    SValue = 0; // after motors have stopped, reset speed value
 }