test2017-1-13

Dependencies:   AT24C1024 DMX-STM32 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "AT24C1024.h"
00003 #include "AccelStepper.h"
00004 #include "DMX.h"
00005 
00006 //モータ制御基板の通し番号を設定してください  初期設定は1です 0は使わないでね。
00007 #define BoardNumber 1 
00008 
00009 //ステップ数設定 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
00010 #define StepSize1 7
00011 #define StepSize2 7
00012 
00013 
00014 Ticker to;
00015 
00016 Timer t;
00017 DigitalOut dmxEnable(D8);   //基本L(レシーブ)に固定します
00018 DMX dmx(PA_9, PA_10);
00019 
00020 I2C         i2c(D4, D5);      // SDA, SCL
00021 AT24C1024   at24c1024(i2c);     // Atmel 1Mbit EE-PROM
00022 const int addr = 0x70;
00023 
00024 AccelStepper stepper1(1, D9, D6);   // step, direction
00025 AccelStepper stepper2(1, D10, D7);  // step, direction
00026 
00027 //モーター1 CN0とCN1を使用
00028 DigitalOut stepper1Enable(D2);
00029 DigitalOut stepper1MS1(D11);
00030 DigitalOut stepper1MS2(D12);
00031 DigitalOut stepper1MS3(A4);
00032 
00033 //モーター2 CN2とCN3を使用
00034 DigitalOut stepper2Enable(D3);
00035 DigitalOut stepper2MS1(A5);
00036 DigitalOut stepper2MS2(A6);
00037 DigitalOut stepper2MS3(A7);
00038 
00039 DigitalIn EndSW1(A0); //CN4 //3端子エンドスイッチ1  予備
00040 DigitalIn EndSW2(A1); //CN5 //3端子エンドスイッチ2  予備
00041 DigitalIn EndSW3(A2); //CN6 //2端子エンドスイッチ1 モーター1用にする
00042 DigitalIn EndSW4(A3); //CN7 //2端子エンドスイッチ2 モーター2用にする
00043 
00044 DigitalOut myLED(LED3);     //動作確認用LED
00045 
00046 unsigned long position1, position2; //モーター1の設定位置
00047 unsigned long max1, max2;
00048 unsigned long speed1, speed2;
00049 unsigned long Acceleration1, Acceleration2;
00050 unsigned long param1, param2;
00051 unsigned long dmxInHighBit, dmxInLowBit;
00052 unsigned long HighBit, LowBit;
00053 
00054 bool manipulateMode1 = false; //0:手動 1:自動
00055 bool manipulateMode2 = false; //0:手動 1:自動
00056 
00057 
00058 //モーター1のパラメーター DMXチャンネルリスト チャンネル数:16個
00059 #define CH_Origin BoardNumber * 32 - 32
00060 
00061 #define DMX_Position1_H CH_Origin  //モーター1制御用のDMX信号の始まりの値
00062 #define DMX_Position1_L CH_Origin + 1
00063 #define DMX_Speed1_H CH_Origin + 2
00064 #define DMX_Speed1_L CH_Origin + 3
00065 #define DMX_Acceleration1_H CH_Origin + 4
00066 #define DMX_Acceleration1_L CH_Origin + 5
00067 #define DMX_Max1_H CH_Origin + 6
00068 #define DMX_Max1_L CH_Origin + 7
00069 #define DMX_Offset1_H CH_Origin + 8
00070 #define DMX_Offset1_L CH_Origin + 9
00071 #define DMX_SaveValue1_H CH_Origin + 10
00072 #define DMX_SaveValue1_L CH_Origin + 11
00073 #define DMX_ParmSetMode1_H CH_Origin + 12
00074 #define DMX_ParmSetMode1_L CH_Origin + 13
00075 #define DMX_Initialize1_H CH_Origin + 14
00076 #define DMX_Initialize1_L CH_Origin + 15
00077 
00078 //モーター2のパラメーター DMXチャンネルリスト チャンネル数:16個
00079 #define DMX_Position2_H CH_Origin + 16
00080 #define DMX_Position2_L CH_Origin + 17
00081 #define DMX_Speed2_H CH_Origin + 18
00082 #define DMX_Speed2_L CH_Origin + 19
00083 #define DMX_Acceleration2_H CH_Origin + 20
00084 #define DMX_Acceleration2_L CH_Origin + 21
00085 #define DMX_Max2_H CH_Origin + 22
00086 #define DMX_Max2_L CH_Origin + 23
00087 #define DMX_Offset2_H CH_Origin + 24
00088 #define DMX_Offset2_L CH_Origin + 25
00089 #define DMX_SaveValue2_H CH_Origin + 26
00090 #define DMX_SaveValue2_L CH_Origin + 27
00091 #define DMX_ParmSetMode2_H CH_Origin + 28
00092 #define DMX_ParmSetMode2_L CH_Origin + 29
00093 #define DMX_Initialize2_H CH_Origin + 30
00094 #define DMX_Initialize2_L CH_Origin + 31
00095 
00096 //モーターの回転方向 TMCは1  DRVは-1に設定すること
00097 //未実装(実装予定)
00098 
00099 //ステップ数の調整用の係数
00100 float StepAdj1 = 1;
00101 float StepAdj2 = 1;
00102 
00103 
00104 //未実装
00105 void sendDataToLPC()
00106 {
00107     char cmd[2];
00108     cmd[0] = 0x51;  
00109     cmd[1] = 0x51;  
00110     i2c.write(addr, cmd, 2);
00111     
00112     //stepper1.newSpeed();
00113 }
00114 
00115 //map
00116 long map(long x, long in_min, long in_max, long out_min, long out_max)
00117 {
00118     return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
00119 }
00120 
00121 void blink()
00122 {
00123     for(int i=0; i<5; i++) {
00124         myLED=0;
00125         wait_ms(60);
00126         myLED=1;
00127         wait_ms(60);
00128     }
00129 }
00130 
00131 void checkSW()
00132 {
00133     //モーター1用エンドスイッチのチェック
00134     if(EndSW3.read() == 1) {
00135         stepper1.stop();
00136         stepper1.setCurrentPosition(0);
00137     }
00138 
00139     //モーター2用エンドスイッチのチェック
00140     if(EndSW4.read() == 1) {
00141         stepper2.stop();
00142         stepper2.setCurrentPosition(0);
00143     }
00144 }
00145 
00146 
00147 //モーター1のみの往復テスト
00148 void testMove1()
00149 {
00150     //initなしの場合
00151     stepper1.setCurrentPosition(0);
00152     stepper1.setMaxSpeed(4000 / StepAdj1);
00153     stepper1.setAcceleration(20000 / StepAdj1);
00154 
00155     stepper1.setMaxSpeed(180000);
00156     while(1) {
00157         stepper1.moveTo(6200);
00158         //stepper1.moveTo(800 / StepAdj1);
00159         while(stepper1.distanceToGo() != 0) {
00160             stepper1.run();
00161         }
00162         wait(0.5);
00163         //stepper1.moveTo(0 / StepAdj1);
00164         stepper1.moveTo(200);
00165         while(stepper1.distanceToGo() != 0) {
00166             stepper1.run();
00167         }
00168         wait(0.5);
00169     }
00170 }
00171 
00172 
00173 //モーター2個同時の往復テスト
00174 void testMove2()
00175 {
00176     stepper1.setMaxSpeed(10000 / StepAdj1);
00177     stepper2.setMaxSpeed(10000 / StepAdj2);
00178 
00179     //stepper1.setMaxSpeed(180000);
00180 
00181     while(1) {
00182         stepper1.moveTo(20000 / StepAdj1);
00183         stepper2.moveTo(20000 / StepAdj2);
00184         while(stepper1.distanceToGo() != 0) {
00185             stepper1.run();
00186             stepper2.run();
00187         }
00188         while(stepper2.distanceToGo() != 0) {
00189             stepper1.run();
00190             stepper2.run();
00191         }
00192 
00193         stepper1.moveTo(500 / StepAdj1);
00194         stepper2.moveTo(500 / StepAdj2);
00195         while(stepper1.distanceToGo() != 0) {
00196             stepper1.run();
00197             stepper2.run();
00198         }
00199         while(stepper2.distanceToGo() != 0) {
00200             stepper2.run();
00201             stepper1.run();
00202         }
00203     }
00204 }
00205 
00206 
00207 void interuptInit1()
00208 {
00209     //stepper1.setMaxSpeed(1000);
00210     //stepper1.setAcceleration(5000);
00211     
00212 
00213     //まずとにかく原点を目指す
00214     stepper1.moveTo(1);
00215     while(stepper1.distanceToGo() != 0) {
00216         stepper1.run();
00217     }
00218 
00219     //15度程度の時計回り動作
00220     stepper1.moveTo(200);
00221     while(stepper1.distanceToGo() != 0) {
00222         stepper1.run();
00223     }
00224 
00225     //原点復帰動作、反時計回り
00226     stepper1.setCurrentPosition(-1);
00227     stepper1.moveTo(-30000 / StepAdj1);
00228     while(stepper1.currentPosition() != 0) {
00229         stepper1.run();
00230         checkSW();
00231     }
00232     //初期位置へ移動
00233     //something
00234 }
00235 
00236 void interuptInit2()
00237 {
00238     stepper2.setMaxSpeed(4000 / StepAdj2);
00239     stepper2.setAcceleration(20000 / StepAdj2);
00240 
00241     //まず原点を目指す
00242 
00243 
00244     //15度程度の後退動作
00245     stepper2.setCurrentPosition(1);
00246     stepper2.moveTo(100);
00247     while(stepper2.distanceToGo() != 0) {
00248         stepper2.run();
00249     }
00250 
00251     //原点復帰動作
00252     stepper2.setCurrentPosition(-1);
00253     stepper2.moveTo(-30000 / StepAdj2);
00254     while(stepper2.currentPosition() != 0) {
00255         stepper2.run();
00256         checkSW();
00257     }
00258     //初期位置へ移動
00259     //something
00260 }
00261 
00262 
00263 void init1()
00264 {
00265     stepper1.setMaxSpeed(4000 / StepAdj1);
00266     stepper1.setAcceleration(20000 / StepAdj1);
00267 
00268     //30度程度の後退動作
00269     stepper1.moveTo(200);
00270     while(stepper1.distanceToGo() != 0) {
00271         stepper1.run();
00272     }
00273     stepper1.setCurrentPosition(-1);
00274 
00275     //反時計回りに回転、エンドスイッチで停止
00276     stepper1.moveTo(-30000 / StepAdj1);
00277     while(stepper1.currentPosition() != 0) {
00278         stepper1.run();
00279         checkSW();
00280     }
00281 //    stepper1.moveTo(500 / StepAdj1);
00282 //    while(stepper1.distanceToGo() != 0) stepper1.run();
00283 }
00284 
00285 void init2()
00286 {
00287 
00288     stepper2.setMaxSpeed(4000 / StepAdj2);
00289     stepper2.setAcceleration(20000 / StepAdj2);
00290 
00291     //30度程度時計回りに回転動作
00292     stepper2.moveTo(200);
00293     while(stepper2.distanceToGo() != 0) {
00294         stepper2.run();
00295     }
00296 
00297     stepper2.setCurrentPosition(-1);
00298 
00299     //反時計回りに回転、エンドスイッチで停止
00300     stepper2.moveTo(-30000 / StepAdj2);
00301     while(stepper2.currentPosition() != 0) {
00302         stepper2.run();
00303         checkSW();
00304     }
00305 }
00306 
00307 void initBoth()
00308 {
00309     stepper1.setCurrentPosition(-1);
00310     stepper1.setMaxSpeed(4000 / StepAdj1);
00311     stepper1.setAcceleration(20000 / StepAdj1);
00312     stepper1.moveTo(-30000 / StepAdj1);
00313 
00314     stepper2.setCurrentPosition(-1);
00315     stepper2.setMaxSpeed(4000 / StepAdj2);
00316     stepper2.setAcceleration(20000 / StepAdj2);
00317     stepper2.moveTo(-30000 / StepAdj2);
00318 
00319     while((stepper1.distanceToGo() != 0)||(stepper2.distanceToGo() != 0)) {
00320         if (stepper1.distanceToGo() != 0) stepper1.run();
00321         if (stepper2.distanceToGo() != 0) stepper2.run();
00322         checkSW();
00323     }
00324     stepper1.moveTo(500 / StepAdj1);
00325     stepper2.moveTo(500 / StepAdj2);
00326     while((stepper1.distanceToGo() != 0)||(stepper2.distanceToGo() != 0)) {
00327         if (stepper1.distanceToGo() != 0) stepper1.run();
00328         if (stepper2.distanceToGo() != 0) stepper2.run();
00329     }
00330     stepper1.setCurrentPosition(-1);
00331     stepper2.setCurrentPosition(-1);
00332     
00333 }
00334 
00335 
00336 void checkSafeBreak()
00337 {
00338     //モーター1用エンドスイッチのチェック
00339     if(EndSW3.read() == 1) {
00340         stepper1.stop();
00341         while(1) {
00342             blink();
00343         }
00344     }
00345 
00346     //モーター2用エンドスイッチのチェック
00347     if(EndSW4.read() == 1) {
00348         stepper2.stop();
00349         while(1) {
00350             blink();
00351         }
00352     }
00353 }
00354 
00355 
00356 //モーター1のパラメータ保存
00357 void paramStore1()
00358 {
00359     //速度
00360     uint8_t dt = dmx.get(DMX_Speed1_H);
00361     at24c1024.write(DMX_Speed1_H, dt);
00362     wait_ms(2);
00363     dt = dmx.get(DMX_Speed1_L);
00364     at24c1024.write(DMX_Speed1_L, dt);
00365     wait_ms(2);
00366 
00367     //加速度
00368     dt = dmx.get(DMX_Acceleration1_H);
00369     at24c1024.write(DMX_Acceleration1_H, dt);
00370     wait_ms(2);
00371     dt = dmx.get(DMX_Acceleration1_L);
00372     at24c1024.write(DMX_Acceleration1_L, dt);
00373     wait_ms(2);
00374 
00375     //最大値
00376     dt = dmx.get(DMX_Max1_H);
00377     at24c1024.write(DMX_Max1_H, dt);
00378     wait_ms(2);
00379     dt = dmx.get(DMX_Max1_L);
00380     at24c1024.write(DMX_Max1_L, dt);
00381 
00382     wait_ms(5);
00383 }
00384 
00385 //モーター2のパラメータ保存
00386 void paramStore2()
00387 {
00388     //速度
00389     uint8_t dt = dmx.get(DMX_Speed2_H);
00390     at24c1024.write(DMX_Speed2_H, dt);
00391     wait_ms(2);
00392     dt = dmx.get(DMX_Speed2_L);
00393     at24c1024.write(DMX_Speed2_L, dt);
00394     wait_ms(2);
00395 
00396     //加速度
00397     dt = dmx.get(DMX_Acceleration2_H);
00398     at24c1024.write(DMX_Acceleration2_H, dt);
00399     wait_ms(2);
00400     dt = dmx.get(DMX_Acceleration2_L);
00401     at24c1024.write(DMX_Acceleration2_L, dt);
00402     wait_ms(2);
00403 
00404     //最大値
00405     dt = dmx.get(DMX_Max2_H);
00406     at24c1024.write(DMX_Max2_H, dt);
00407     wait_ms(2);
00408     dt = dmx.get(DMX_Max2_L);
00409     at24c1024.write(DMX_Max2_L, dt);
00410 
00411     wait_ms(2);
00412 }
00413 
00414 
00415 //速度・加速度・最大値・オフセットの値をスライダーから取得
00416 void captureSliderValue()
00417 {
00418     dmxInHighBit = dmx.get(DMX_Speed1_H);
00419     dmxInLowBit = dmx.get(DMX_Speed1_L);
00420     dmxInHighBit = dmxInHighBit << 8;
00421     speed1 = (long)(dmxInHighBit + dmxInLowBit);
00422 
00423 //(動作)
00424     dmxInHighBit = dmx.get(DMX_Speed2_H);
00425     dmxInLowBit = dmx.get(DMX_Speed2_L);
00426     dmxInHighBit = dmxInHighBit << 8;
00427     speed2 = (long)(dmxInHighBit + dmxInLowBit);
00428 
00429     dmxInHighBit = dmx.get(DMX_Acceleration1_H);
00430     dmxInLowBit = dmx.get(DMX_Acceleration1_L);
00431     dmxInHighBit = dmxInHighBit << 8;
00432     Acceleration1 = (long)(dmxInHighBit + dmxInLowBit);
00433 
00434 //(動作)
00435     dmxInHighBit = dmx.get(DMX_Acceleration2_H);
00436     dmxInLowBit = dmx.get(DMX_Acceleration2_L);
00437     dmxInHighBit = dmxInHighBit << 8;
00438     Acceleration2 = (long)(dmxInHighBit + dmxInLowBit);
00439 
00440     dmxInHighBit = dmx.get(DMX_Max1_H);
00441     dmxInLowBit = dmx.get(DMX_Max1_L);
00442     dmxInHighBit = dmxInHighBit << 8;
00443     max1 = (long)(dmxInHighBit + dmxInLowBit);
00444 
00445 //(動作)
00446     dmxInHighBit = dmx.get(DMX_Max2_H);
00447     dmxInLowBit = dmx.get(DMX_Max2_L);
00448     dmxInHighBit = dmxInHighBit << 8;
00449     max2 = (long)(dmxInHighBit + dmxInLowBit);
00450 }
00451 
00452 
00453 //モーター1の 速度・加速度・オフセットの値をEEPROMから取得
00454 void readROMValue1()
00455 {
00456     //速度
00457     HighBit = at24c1024.read(DMX_Speed1_H);
00458     LowBit = at24c1024.read(DMX_Speed1_L);
00459     HighBit = HighBit << 8;
00460     speed1 = (long)(HighBit + LowBit);
00461 
00462     //加速度
00463     HighBit = at24c1024.read(DMX_Acceleration1_H);
00464     LowBit = at24c1024.read(DMX_Acceleration1_L);
00465     HighBit = HighBit << 8;
00466     Acceleration1 = (long)(HighBit + LowBit);
00467 
00468     //最大値
00469     HighBit = at24c1024.read(DMX_Max1_H);
00470     LowBit = at24c1024.read(DMX_Max1_L);
00471     HighBit = HighBit << 8;
00472     max1 = (long)(HighBit + LowBit);
00473 }
00474 
00475 
00476 //モーター2の 速度・加速度・オフセットの値をEEPROMから取得
00477 void readROMValue2()
00478 {
00479     //速度
00480     HighBit = at24c1024.read(DMX_Speed2_H);
00481     LowBit = at24c1024.read(DMX_Speed2_L);
00482     HighBit = HighBit << 8;
00483     speed2 = (long)(HighBit + LowBit);
00484 
00485     //加速度
00486     HighBit = at24c1024.read(DMX_Acceleration2_H);
00487     LowBit = at24c1024.read(DMX_Acceleration2_L);
00488     HighBit = HighBit << 8;
00489     Acceleration2 = (long)(HighBit + LowBit);
00490 
00491     //最大値
00492     HighBit = at24c1024.read(DMX_Max2_H);
00493     LowBit = at24c1024.read(DMX_Max2_L);
00494     HighBit = HighBit << 8;
00495     max2 = (long)(HighBit + LowBit);
00496 }
00497 
00498 
00499 //操作モード切り替えボタンのチェック
00500 void checkManipulateButton()
00501 {
00502     dmxInHighBit = dmx.get(DMX_ParmSetMode1_H);
00503     dmxInLowBit = dmx.get(DMX_ParmSetMode1_L);
00504     if(dmxInHighBit == 102 && dmxInLowBit == 255) {
00505         manipulateMode1 = !manipulateMode1;
00506         blink();
00507     }
00508 
00509     dmxInHighBit = dmx.get(DMX_ParmSetMode2_H);
00510     dmxInLowBit = dmx.get(DMX_ParmSetMode2_L);
00511     if(dmxInHighBit == 102 && dmxInLowBit == 255) {
00512         manipulateMode2 = !manipulateMode2;
00513         blink();
00514     }
00515 }
00516 
00517 //書き込みボタンのチェック
00518 void checkWriteButton()
00519 {
00520     dmxInHighBit = dmx.get(DMX_SaveValue1_H);
00521     dmxInLowBit = dmx.get(DMX_SaveValue1_L);
00522     dmxInHighBit = dmxInHighBit << 8;
00523     param1 = (long)(dmxInHighBit + dmxInLowBit);
00524 
00525     dmxInHighBit = dmx.get(DMX_SaveValue2_H);
00526     dmxInLowBit = dmx.get(DMX_SaveValue2_L);
00527     dmxInHighBit = dmxInHighBit << 8;
00528     param2 = (long)(dmxInHighBit + dmxInLowBit);
00529 
00530     if(param1 == 24932) {
00531         paramStore1();
00532         blink();
00533     } else;
00534 
00535     if(param2 == 24932) {
00536         paramStore2();
00537         blink();
00538     } else;
00539 }
00540 
00541 //原点復帰命令のチェック
00542 void checkInitCommand1()
00543 {
00544     dmxInHighBit = dmx.get(DMX_Initialize1_H);
00545     dmxInLowBit = dmx.get(DMX_Initialize1_L);
00546 
00547     if(dmxInHighBit == 75 && dmxInLowBit == 255) {
00548         interuptInit1();
00549     }
00550 }
00551 
00552 void checkInitCommand2()
00553 {
00554     dmxInHighBit = dmx.get(DMX_Initialize2_H);
00555     dmxInLowBit = dmx.get(DMX_Initialize2_L);
00556 
00557     if(dmxInHighBit == 75 && dmxInLowBit == 255) {
00558         interuptInit2();
00559     }
00560 }
00561 
00562 
00563 //モータードライバの設定
00564 void conf1()
00565 {
00566     switch (StepSize1) {
00567         case 1: //DRV8825 full steps
00568             stepper1MS1 = 0;
00569             stepper1MS2 = 0;
00570             stepper1MS3 = 0;
00571             StepAdj1 = 16;
00572             break;
00573 
00574         case 2: //DRV8825 1/2 steps
00575             stepper1MS1 = 1;
00576             stepper1MS2 = 0;
00577             stepper1MS3 = 0;
00578             StepAdj1 = 8;
00579             break;
00580 
00581         case 3: //DRV8825 1/4 steps
00582             stepper1MS1 = 0;
00583             stepper1MS2 = 1;
00584             stepper1MS3 = 0;
00585             StepAdj1 = 4;
00586             break;
00587 
00588         case 4: //DRV8825 1/8 steps
00589             stepper1MS1 = 1;
00590             stepper1MS2 = 1;
00591             stepper1MS3 = 0;
00592             StepAdj1 = 2;
00593             break;
00594 
00595         case 5: //DRV8825 1/16 steps
00596             stepper1MS1 = 0;
00597             stepper1MS2 = 0;
00598             stepper1MS3 = 1;
00599             StepAdj1 = 1;
00600             break;
00601 
00602         case 6: //DRV8825 1/32 steps
00603             stepper1MS1 = 1;
00604             stepper1MS2 = 1;
00605             stepper1MS3 = 1;
00606             StepAdj1 = 0.5;
00607             break;
00608 
00609         case 7: //TMC StealthChop µ16 steps
00610             DigitalIn stepper1MS1(A5);
00611             DigitalIn stepper1MS2(A6);
00612             StepAdj1 = 1;
00613             break;
00614     }
00615     stepper1Enable = 0;
00616 }
00617 
00618 void conf2()
00619 {
00620     switch (StepSize2) {
00621         case 1: //DRV8825 full steps
00622             stepper2MS1 = 0;
00623             stepper2MS2 = 0;
00624             stepper2MS3 = 0;
00625             StepAdj2 = 16;
00626             break;
00627 
00628         case 2: //DRV8825 1/2 steps
00629             stepper2MS1 = 1;
00630             stepper2MS2 = 0;
00631             stepper2MS3 = 0;
00632             StepAdj2 = 8;
00633             break;
00634 
00635         case 3: //DRV8825 1/4 steps
00636             stepper2MS1 = 0;
00637             stepper2MS2 = 1;
00638             stepper2MS3 = 0;
00639             StepAdj2 = 4;
00640             break;
00641 
00642         case 4: //DRV8825 1/8 steps
00643             stepper2MS1 = 1;
00644             stepper2MS2 = 1;
00645             stepper2MS3 = 0;
00646             StepAdj2 = 2;
00647             break;
00648 
00649         case 5: //DRV8825 1/16 steps
00650             stepper2MS1 = 0;
00651             stepper2MS2 = 0;
00652             stepper2MS3 = 1;
00653             StepAdj2 = 1;
00654             break;
00655 
00656         case 6: //DRV8825 1/32 steps
00657             stepper2MS1 = 1;
00658             stepper2MS2 = 1;
00659             stepper2MS3 = 1;
00660             StepAdj2 = 0.5;
00661             break;
00662 
00663         case 7: //TMC StealthChop µ16 steps
00664             DigitalIn stepper2MS1(D11);
00665             DigitalIn stepper2MS2(D12);
00666             StepAdj2 = 1;
00667             break;
00668     }
00669     stepper2Enable = 0;
00670 }
00671 
00672 
00673 int main()
00674 {
00675     wait(1);
00676 
00677 //DMXの機能をレシーブに固定 (ハードウェア的に固定するため停止中)
00678 //    dmxEnable = 0;  //0:receiver 1:sender
00679 
00680     conf1();    //motor1 config     ドライバの設定
00681     conf2();    //motor2 config
00682 
00683     t.start();
00684     //to.attach(&sendDataToLPC, 1);
00685 
00686     stepper1.setCurrentPosition(-1);
00687     stepper2.setCurrentPosition(-1);
00688 
00689 //モーターの初期化シーケンス
00690 //    init1();
00691 //    init2();
00692     initBoth();
00693 
00694 //往復運動を繰り返すテストシーケンス(無限ループ)
00695 //    testMove2();
00696 
00697     myLED =1;
00698 
00699     readROMValue1();
00700     readROMValue2();
00701 
00702     stepper1.setMaxSpeed(10000 / StepAdj1);
00703     stepper2.setMaxSpeed(10000 / StepAdj2);
00704 
00705     while(1) {
00706         //操作モード切り替えボタンのチェック
00707         checkManipulateButton();
00708 
00709         //書き込みボタンチェック
00710         checkWriteButton();
00711 
00712         //モーター1の目標位置をDMXから取得
00713         dmxInHighBit = dmx.get(DMX_Position1_H);
00714         dmxInLowBit = dmx.get(DMX_Position1_L);
00715         dmxInHighBit = dmxInHighBit << 8;
00716         position1 = (long)(dmxInHighBit + dmxInLowBit);
00717 
00718         //モーター2の目標位置をスライダーから取得(停止中)
00719         dmxInHighBit = dmx.get(DMX_Position2_H);
00720         dmxInLowBit = dmx.get(DMX_Position2_L);
00721         dmxInHighBit = dmxInHighBit << 8;
00722         position2 = (long)(dmxInHighBit + dmxInLowBit);
00723 
00724         //手動モードの場合、現在のスライダーの値を取得、パラメーターを設定
00725         if(manipulateMode1 == false) {
00726             captureSliderValue();
00727             myLED = 0;
00728         }
00729 
00730         //自動モードの場合、EEPROMから値を取得、パラメーターを設定
00731         else {
00732             myLED = 1;
00733         }
00734 
00735         //手動モードの場合、現在のスライダーの値を取得、パラメーターを設定(停止中)
00736 //        if(manipulateMode2 == false) {
00737 //            captureSliderValue();
00738 //            myLED = 0;
00739 //        }
00740 
00741         //自動モードの場合、EEPROMから値を取得、パラメータを設定(停止中)
00742 //        else {
00743 //            myLED = 1;
00744 //        }
00745 
00746 
00747         //モーター1のパラメーター設定
00748         position1 = map(position1, 0, 0xFFFF, 0, max1);
00749         stepper1.setMaxSpeed(speed1);
00750         stepper1.setAcceleration(Acceleration1);
00751 
00752 
00753         //モーター2のパラメーター設定(停止中)
00754         position2 = map(position2, 0, 0xFFFF, 0, max2);
00755         stepper2.setMaxSpeed(speed2);
00756         stepper2.setAcceleration(Acceleration2);
00757 
00758 
00759         //モーター1の目標位置設定
00760         stepper1.moveTo(position1);
00761 
00762         //モーター2の目標位置設定()
00763         stepper2.moveTo(position2);
00764 
00765 
00766         //安全エンドスイッチの監視(停止中)
00767         //checkSafeBreak();
00768 
00769         //モーター1への原点復帰命令のチェック
00770         checkInitCommand1();
00771 
00772         //モーター2への原点復帰命令のチェック()
00773         checkInitCommand2();
00774 
00775         //モーター1の走行
00776         if(stepper1.distanceToGo() != 0) {
00777             //checkInitCommand1();
00778             stepper1.run();
00779         }
00780         //モーター2の走行
00781         if(stepper2.distanceToGo() != 0) stepper2.run();
00782     }
00783 }