test2017-1-13

Dependencies:   AT24C1024 DMX-STM32 mbed

Files at this revision

API Documentation at this revision

Comitter:
tomo370
Date:
Fri Jul 28 04:44:42 2017 +0000
Parent:
7:813cdaad1200
Commit message:
2017_07_28ver

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 813cdaad1200 -r 2e68b9de685d main.cpp
--- a/main.cpp	Tue Apr 25 12:20:47 2017 +0000
+++ b/main.cpp	Fri Jul 28 04:44:42 2017 +0000
@@ -4,7 +4,12 @@
 #include "DMX.h"
 
 //モータ制御基板の通し番号を設定してください  初期設定は1です 0は使わないでね。
-#define BoardNumber 8
+#define BoardNumber 1 
+
+//ステップ数設定 1:DRV full, 2:DRV 1/2, 3:DRV 1/4, 4:DRV 1/8, 5:DRV 1/16, 6:DRV 1/32, 7:TMC StealthChop µ16
+#define StepSize1 7
+#define StepSize2 7
+
 
 Ticker to;
 
@@ -95,10 +100,6 @@
 float StepAdj1 = 1;
 float StepAdj2 = 1;
 
-//ステップ数設定 1:DRV full, 2:DRV 1/2, 3:DRV 1/4, 4:DRV 1/8, 5:DRV 1/16, 6:DRV 1/32, 7:TMC StealthChop µ16
-#define StepSize1 3
-#define StepSize2 4
-
 
 //未実装
 void sendDataToLPC()
@@ -130,13 +131,13 @@
 void checkSW()
 {
     //モーター1用エンドスイッチのチェック
-    if(EndSW1.read() == 0) {
+    if(EndSW3.read() == 1) {
         stepper1.stop();
         stepper1.setCurrentPosition(0);
     }
 
     //モーター2用エンドスイッチのチェック
-    if(EndSW2.read() == 0) {
+    if(EndSW4.read() == 1) {
         stepper2.stop();
         stepper2.setCurrentPosition(0);
     }
@@ -153,14 +154,14 @@
 
     stepper1.setMaxSpeed(180000);
     while(1) {
-        stepper1.moveTo(3200);
+        stepper1.moveTo(6200);
         //stepper1.moveTo(800 / StepAdj1);
         while(stepper1.distanceToGo() != 0) {
             stepper1.run();
         }
         wait(0.5);
         //stepper1.moveTo(0 / StepAdj1);
-        stepper1.moveTo(0);
+        stepper1.moveTo(200);
         while(stepper1.distanceToGo() != 0) {
             stepper1.run();
         }
@@ -175,7 +176,7 @@
     stepper1.setMaxSpeed(10000 / StepAdj1);
     stepper2.setMaxSpeed(10000 / StepAdj2);
 
-    stepper1.setMaxSpeed(180000);
+    //stepper1.setMaxSpeed(180000);
 
     while(1) {
         stepper1.moveTo(20000 / StepAdj1);
@@ -326,13 +327,16 @@
         if (stepper1.distanceToGo() != 0) stepper1.run();
         if (stepper2.distanceToGo() != 0) stepper2.run();
     }
+    stepper1.setCurrentPosition(-1);
+    stepper2.setCurrentPosition(-1);
+    
 }
 
 
 void checkSafeBreak()
 {
     //モーター1用エンドスイッチのチェック
-    if(EndSW1.read() == 1) {
+    if(EndSW3.read() == 1) {
         stepper1.stop();
         while(1) {
             blink();
@@ -340,7 +344,7 @@
     }
 
     //モーター2用エンドスイッチのチェック
-    if(EndSW2.read() == 1) {
+    if(EndSW4.read() == 1) {
         stepper2.stop();
         while(1) {
             blink();
@@ -416,33 +420,33 @@
     dmxInHighBit = dmxInHighBit << 8;
     speed1 = (long)(dmxInHighBit + dmxInLowBit);
 
-//(停止中)
-//    dmxInHighBit = dmx.get(DMX_Speed2_H);
-//    dmxInLowBit = dmx.get(DMX_Speed2_L);
-//    dmxInHighBit = dmxInHighBit << 8;
-//    speed2 = (long)(dmxInHighBit + dmxInLowBit);
+//(動作)
+    dmxInHighBit = dmx.get(DMX_Speed2_H);
+    dmxInLowBit = dmx.get(DMX_Speed2_L);
+    dmxInHighBit = dmxInHighBit << 8;
+    speed2 = (long)(dmxInHighBit + dmxInLowBit);
 
     dmxInHighBit = dmx.get(DMX_Acceleration1_H);
     dmxInLowBit = dmx.get(DMX_Acceleration1_L);
     dmxInHighBit = dmxInHighBit << 8;
     Acceleration1 = (long)(dmxInHighBit + dmxInLowBit);
 
-//(停止中)
-//    dmxInHighBit = dmx.get(DMX_Acceleration2_H);
-//    dmxInLowBit = dmx.get(DMX_Acceleration2_L);
-//    dmxInHighBit = dmxInHighBit << 8;
-//    Acceleration2 = (long)(dmxInHighBit + dmxInLowBit);
+//(動作)
+    dmxInHighBit = dmx.get(DMX_Acceleration2_H);
+    dmxInLowBit = dmx.get(DMX_Acceleration2_L);
+    dmxInHighBit = dmxInHighBit << 8;
+    Acceleration2 = (long)(dmxInHighBit + dmxInLowBit);
 
     dmxInHighBit = dmx.get(DMX_Max1_H);
     dmxInLowBit = dmx.get(DMX_Max1_L);
     dmxInHighBit = dmxInHighBit << 8;
     max1 = (long)(dmxInHighBit + dmxInLowBit);
 
-//(停止中)
-//    dmxInHighBit = dmx.get(DMX_Max2_H);
-//    dmxInLowBit = dmx.get(DMX_Max2_L);
-//    dmxInHighBit = dmxInHighBit << 8;
-//    max2 = (long)(dmxInHighBit + dmxInLowBit);
+//(動作)
+    dmxInHighBit = dmx.get(DMX_Max2_H);
+    dmxInLowBit = dmx.get(DMX_Max2_L);
+    dmxInHighBit = dmxInHighBit << 8;
+    max2 = (long)(dmxInHighBit + dmxInLowBit);
 }
 
 
@@ -603,8 +607,8 @@
             break;
 
         case 7: //TMC StealthChop µ16 steps
-            DigitalIn stepper1MS1(D11);
-            DigitalIn stepper1MS2(D12);
+            DigitalIn stepper1MS1(A5);
+            DigitalIn stepper1MS2(A6);
             StepAdj1 = 1;
             break;
     }
@@ -683,20 +687,20 @@
     stepper2.setCurrentPosition(-1);
 
 //モーターの初期化シーケンス
-    init1();
+//    init1();
 //    init2();
-//    initBoth();
+    initBoth();
 
 //往復運動を繰り返すテストシーケンス(無限ループ)
-//    testMove1();
+//    testMove2();
 
     myLED =1;
 
     readROMValue1();
-//    readROMValue2();
+    readROMValue2();
 
     stepper1.setMaxSpeed(10000 / StepAdj1);
-//    stepper2.setMaxSpeed(10000 / StepAdj2);
+    stepper2.setMaxSpeed(10000 / StepAdj2);
 
     while(1) {
         //操作モード切り替えボタンのチェック
@@ -712,10 +716,10 @@
         position1 = (long)(dmxInHighBit + dmxInLowBit);
 
         //モーター2の目標位置をスライダーから取得(停止中)
-//        dmxInHighBit = dmx.get(DMX_Position2_H);
-//        dmxInLowBit = dmx.get(DMX_Position2_L);
-//        dmxInHighBit = dmxInHighBit << 8;
-//        position2 = (long)(dmxInHighBit + dmxInLowBit);
+        dmxInHighBit = dmx.get(DMX_Position2_H);
+        dmxInLowBit = dmx.get(DMX_Position2_L);
+        dmxInHighBit = dmxInHighBit << 8;
+        position2 = (long)(dmxInHighBit + dmxInLowBit);
 
         //手動モードの場合、現在のスライダーの値を取得、パラメーターを設定
         if(manipulateMode1 == false) {
@@ -747,16 +751,16 @@
 
 
         //モーター2のパラメーター設定(停止中)
-        //position2 = map(position2, 0, 0xFFFF, 0, max2);
-        //stepper2.setMaxSpeed(speed2);
-        //stepper2.setAcceleration(Acceleration2);
+        position2 = map(position2, 0, 0xFFFF, 0, max2);
+        stepper2.setMaxSpeed(speed2);
+        stepper2.setAcceleration(Acceleration2);
 
 
         //モーター1の目標位置設定
         stepper1.moveTo(position1);
 
-        //モーター2の目標位置設定(停止中)
-        //stepper2.moveTo(position2);
+        //モーター2の目標位置設定()
+        stepper2.moveTo(position2);
 
 
         //安全エンドスイッチの監視(停止中)
@@ -765,15 +769,15 @@
         //モーター1への原点復帰命令のチェック
         checkInitCommand1();
 
-        //モーター2への原点復帰命令のチェック(停止中)
-        //checkInitCommand2();
+        //モーター2への原点復帰命令のチェック()
+        checkInitCommand2();
 
         //モーター1の走行
         if(stepper1.distanceToGo() != 0) {
             //checkInitCommand1();
             stepper1.run();
         }
-        //モーター2の走行(停止中)
-        //if(stepper2.distanceToGo() != 0) stepper2.run();
+        //モーター2の走行
+        if(stepper2.distanceToGo() != 0) stepper2.run();
     }
 }
\ No newline at end of file