test2017-1-13

Dependencies:   AT24C1024 DMX-STM32 mbed

Committer:
tomo370
Date:
Tue Apr 25 12:20:47 2017 +0000
Revision:
7:813cdaad1200
Parent:
6:2a9e0228f81d
Child:
8:2e68b9de685d
???????2017_04_25

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tomo370 0:d94213e24c2e 1 #include "mbed.h"
tomo370 0:d94213e24c2e 2 #include "AT24C1024.h"
tomo370 0:d94213e24c2e 3 #include "AccelStepper.h"
tomo370 0:d94213e24c2e 4 #include "DMX.h"
tomo370 0:d94213e24c2e 5
tomo370 7:813cdaad1200 6 //モータ制御基板の通し番号を設定してください  初期設定は1です 0は使わないでね。
tomo370 7:813cdaad1200 7 #define BoardNumber 8
tomo370 5:fd097a259856 8
tomo370 7:813cdaad1200 9 Ticker to;
tomo370 4:c3f3fdde7eee 10
tomo370 0:d94213e24c2e 11 Timer t;
tomo370 1:cf2f5992241c 12 DigitalOut dmxEnable(D8); //基本L(レシーブ)に固定します
tomo370 0:d94213e24c2e 13 DMX dmx(PA_9, PA_10);
tomo370 0:d94213e24c2e 14
tomo370 1:cf2f5992241c 15 I2C i2c(D4, D5); // SDA, SCL
tomo370 1:cf2f5992241c 16 AT24C1024 at24c1024(i2c); // Atmel 1Mbit EE-PROM
tomo370 7:813cdaad1200 17 const int addr = 0x70;
tomo370 0:d94213e24c2e 18
tomo370 1:cf2f5992241c 19 AccelStepper stepper1(1, D9, D6); // step, direction
tomo370 1:cf2f5992241c 20 AccelStepper stepper2(1, D10, D7); // step, direction
tomo370 1:cf2f5992241c 21
tomo370 1:cf2f5992241c 22 //モーター1 CN0とCN1を使用
tomo370 0:d94213e24c2e 23 DigitalOut stepper1Enable(D2);
tomo370 0:d94213e24c2e 24 DigitalOut stepper1MS1(D11);
tomo370 0:d94213e24c2e 25 DigitalOut stepper1MS2(D12);
tomo370 4:c3f3fdde7eee 26 DigitalOut stepper1MS3(A4);
tomo370 0:d94213e24c2e 27
tomo370 1:cf2f5992241c 28 //モーター2 CN2とCN3を使用
tomo370 0:d94213e24c2e 29 DigitalOut stepper2Enable(D3);
tomo370 0:d94213e24c2e 30 DigitalOut stepper2MS1(A5);
tomo370 0:d94213e24c2e 31 DigitalOut stepper2MS2(A6);
tomo370 0:d94213e24c2e 32 DigitalOut stepper2MS3(A7);
tomo370 0:d94213e24c2e 33
tomo370 1:cf2f5992241c 34 DigitalIn EndSW1(A0); //CN4 //3端子エンドスイッチ1 予備
tomo370 1:cf2f5992241c 35 DigitalIn EndSW2(A1); //CN5 //3端子エンドスイッチ2 予備
tomo370 1:cf2f5992241c 36 DigitalIn EndSW3(A2); //CN6 //2端子エンドスイッチ1 モーター1用にする
tomo370 1:cf2f5992241c 37 DigitalIn EndSW4(A3); //CN7 //2端子エンドスイッチ2 モーター2用にする
tomo370 1:cf2f5992241c 38
tomo370 1:cf2f5992241c 39 DigitalOut myLED(LED3); //動作確認用LED
tomo370 1:cf2f5992241c 40
tomo370 1:cf2f5992241c 41 unsigned long position1, position2; //モーター1の設定位置
tomo370 1:cf2f5992241c 42 unsigned long max1, max2;
tomo370 1:cf2f5992241c 43 unsigned long speed1, speed2;
tomo370 1:cf2f5992241c 44 unsigned long Acceleration1, Acceleration2;
tomo370 1:cf2f5992241c 45 unsigned long param1, param2;
tomo370 1:cf2f5992241c 46 unsigned long dmxInHighBit, dmxInLowBit;
tomo370 2:198becff12f4 47 unsigned long HighBit, LowBit;
tomo370 1:cf2f5992241c 48
tomo370 4:c3f3fdde7eee 49 bool manipulateMode1 = false; //0:手動 1:自動
tomo370 4:c3f3fdde7eee 50 bool manipulateMode2 = false; //0:手動 1:自動
tomo370 1:cf2f5992241c 51
tomo370 1:cf2f5992241c 52
tomo370 5:fd097a259856 53 //モーター1のパラメーター DMXチャンネルリスト チャンネル数:16個
tomo370 5:fd097a259856 54 #define CH_Origin BoardNumber * 32 - 32
tomo370 0:d94213e24c2e 55
tomo370 1:cf2f5992241c 56 #define DMX_Position1_H CH_Origin //モーター1制御用のDMX信号の始まりの値
tomo370 1:cf2f5992241c 57 #define DMX_Position1_L CH_Origin + 1
tomo370 1:cf2f5992241c 58 #define DMX_Speed1_H CH_Origin + 2
tomo370 1:cf2f5992241c 59 #define DMX_Speed1_L CH_Origin + 3
tomo370 1:cf2f5992241c 60 #define DMX_Acceleration1_H CH_Origin + 4
tomo370 1:cf2f5992241c 61 #define DMX_Acceleration1_L CH_Origin + 5
tomo370 1:cf2f5992241c 62 #define DMX_Max1_H CH_Origin + 6
tomo370 1:cf2f5992241c 63 #define DMX_Max1_L CH_Origin + 7
tomo370 1:cf2f5992241c 64 #define DMX_Offset1_H CH_Origin + 8
tomo370 1:cf2f5992241c 65 #define DMX_Offset1_L CH_Origin + 9
tomo370 1:cf2f5992241c 66 #define DMX_SaveValue1_H CH_Origin + 10
tomo370 1:cf2f5992241c 67 #define DMX_SaveValue1_L CH_Origin + 11
tomo370 1:cf2f5992241c 68 #define DMX_ParmSetMode1_H CH_Origin + 12
tomo370 1:cf2f5992241c 69 #define DMX_ParmSetMode1_L CH_Origin + 13
tomo370 5:fd097a259856 70 #define DMX_Initialize1_H CH_Origin + 14
tomo370 5:fd097a259856 71 #define DMX_Initialize1_L CH_Origin + 15
tomo370 0:d94213e24c2e 72
tomo370 5:fd097a259856 73 //モーター2のパラメーター DMXチャンネルリスト チャンネル数:16個
tomo370 1:cf2f5992241c 74 #define DMX_Position2_H CH_Origin + 16
tomo370 1:cf2f5992241c 75 #define DMX_Position2_L CH_Origin + 17
tomo370 1:cf2f5992241c 76 #define DMX_Speed2_H CH_Origin + 18
tomo370 1:cf2f5992241c 77 #define DMX_Speed2_L CH_Origin + 19
tomo370 1:cf2f5992241c 78 #define DMX_Acceleration2_H CH_Origin + 20
tomo370 1:cf2f5992241c 79 #define DMX_Acceleration2_L CH_Origin + 21
tomo370 1:cf2f5992241c 80 #define DMX_Max2_H CH_Origin + 22
tomo370 1:cf2f5992241c 81 #define DMX_Max2_L CH_Origin + 23
tomo370 1:cf2f5992241c 82 #define DMX_Offset2_H CH_Origin + 24
tomo370 1:cf2f5992241c 83 #define DMX_Offset2_L CH_Origin + 25
tomo370 1:cf2f5992241c 84 #define DMX_SaveValue2_H CH_Origin + 26
tomo370 1:cf2f5992241c 85 #define DMX_SaveValue2_L CH_Origin + 27
tomo370 1:cf2f5992241c 86 #define DMX_ParmSetMode2_H CH_Origin + 28
tomo370 1:cf2f5992241c 87 #define DMX_ParmSetMode2_L CH_Origin + 29
tomo370 5:fd097a259856 88 #define DMX_Initialize2_H CH_Origin + 30
tomo370 5:fd097a259856 89 #define DMX_Initialize2_L CH_Origin + 31
tomo370 1:cf2f5992241c 90
tomo370 4:c3f3fdde7eee 91 //モーターの回転方向 TMCは1 DRVは-1に設定すること
tomo370 4:c3f3fdde7eee 92 //未実装(実装予定)
tomo370 4:c3f3fdde7eee 93
tomo370 4:c3f3fdde7eee 94 //ステップ数の調整用の係数
tomo370 4:c3f3fdde7eee 95 float StepAdj1 = 1;
tomo370 4:c3f3fdde7eee 96 float StepAdj2 = 1;
tomo370 4:c3f3fdde7eee 97
tomo370 4:c3f3fdde7eee 98 //ステップ数設定 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
tomo370 4:c3f3fdde7eee 99 #define StepSize1 3
tomo370 4:c3f3fdde7eee 100 #define StepSize2 4
tomo370 4:c3f3fdde7eee 101
tomo370 4:c3f3fdde7eee 102
tomo370 5:fd097a259856 103 //未実装
tomo370 7:813cdaad1200 104 void sendDataToLPC()
tomo370 4:c3f3fdde7eee 105 {
tomo370 7:813cdaad1200 106 char cmd[2];
tomo370 7:813cdaad1200 107 cmd[0] = 0x51;
tomo370 7:813cdaad1200 108 cmd[1] = 0x51;
tomo370 7:813cdaad1200 109 i2c.write(addr, cmd, 2);
tomo370 7:813cdaad1200 110
tomo370 7:813cdaad1200 111 //stepper1.newSpeed();
tomo370 4:c3f3fdde7eee 112 }
tomo370 4:c3f3fdde7eee 113
tomo370 1:cf2f5992241c 114 //map
tomo370 0:d94213e24c2e 115 long map(long x, long in_min, long in_max, long out_min, long out_max)
tomo370 0:d94213e24c2e 116 {
tomo370 0:d94213e24c2e 117 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
tomo370 0:d94213e24c2e 118 }
tomo370 0:d94213e24c2e 119
tomo370 1:cf2f5992241c 120 void blink()
tomo370 1:cf2f5992241c 121 {
tomo370 1:cf2f5992241c 122 for(int i=0; i<5; i++) {
tomo370 1:cf2f5992241c 123 myLED=0;
tomo370 1:cf2f5992241c 124 wait_ms(60);
tomo370 1:cf2f5992241c 125 myLED=1;
tomo370 1:cf2f5992241c 126 wait_ms(60);
tomo370 1:cf2f5992241c 127 }
tomo370 1:cf2f5992241c 128 }
tomo370 1:cf2f5992241c 129
tomo370 0:d94213e24c2e 130 void checkSW()
tomo370 0:d94213e24c2e 131 {
tomo370 1:cf2f5992241c 132 //モーター1用エンドスイッチのチェック
tomo370 5:fd097a259856 133 if(EndSW1.read() == 0) {
tomo370 0:d94213e24c2e 134 stepper1.stop();
tomo370 0:d94213e24c2e 135 stepper1.setCurrentPosition(0);
tomo370 0:d94213e24c2e 136 }
tomo370 1:cf2f5992241c 137
tomo370 1:cf2f5992241c 138 //モーター2用エンドスイッチのチェック
tomo370 5:fd097a259856 139 if(EndSW2.read() == 0) {
tomo370 1:cf2f5992241c 140 stepper2.stop();
tomo370 1:cf2f5992241c 141 stepper2.setCurrentPosition(0);
tomo370 1:cf2f5992241c 142 }
tomo370 0:d94213e24c2e 143 }
tomo370 0:d94213e24c2e 144
tomo370 4:c3f3fdde7eee 145
tomo370 4:c3f3fdde7eee 146 //モーター1のみの往復テスト
tomo370 4:c3f3fdde7eee 147 void testMove1()
tomo370 0:d94213e24c2e 148 {
tomo370 4:c3f3fdde7eee 149 //initなしの場合
tomo370 4:c3f3fdde7eee 150 stepper1.setCurrentPosition(0);
tomo370 4:c3f3fdde7eee 151 stepper1.setMaxSpeed(4000 / StepAdj1);
tomo370 4:c3f3fdde7eee 152 stepper1.setAcceleration(20000 / StepAdj1);
tomo370 0:d94213e24c2e 153
tomo370 4:c3f3fdde7eee 154 stepper1.setMaxSpeed(180000);
tomo370 4:c3f3fdde7eee 155 while(1) {
tomo370 4:c3f3fdde7eee 156 stepper1.moveTo(3200);
tomo370 4:c3f3fdde7eee 157 //stepper1.moveTo(800 / StepAdj1);
tomo370 4:c3f3fdde7eee 158 while(stepper1.distanceToGo() != 0) {
tomo370 4:c3f3fdde7eee 159 stepper1.run();
tomo370 4:c3f3fdde7eee 160 }
tomo370 4:c3f3fdde7eee 161 wait(0.5);
tomo370 4:c3f3fdde7eee 162 //stepper1.moveTo(0 / StepAdj1);
tomo370 4:c3f3fdde7eee 163 stepper1.moveTo(0);
tomo370 4:c3f3fdde7eee 164 while(stepper1.distanceToGo() != 0) {
tomo370 4:c3f3fdde7eee 165 stepper1.run();
tomo370 4:c3f3fdde7eee 166 }
tomo370 4:c3f3fdde7eee 167 wait(0.5);
tomo370 4:c3f3fdde7eee 168 }
tomo370 0:d94213e24c2e 169 }
tomo370 0:d94213e24c2e 170
tomo370 3:dd2305e50390 171
tomo370 5:fd097a259856 172 //モーター2個同時の往復テスト
tomo370 4:c3f3fdde7eee 173 void testMove2()
tomo370 4:c3f3fdde7eee 174 {
tomo370 4:c3f3fdde7eee 175 stepper1.setMaxSpeed(10000 / StepAdj1);
tomo370 4:c3f3fdde7eee 176 stepper2.setMaxSpeed(10000 / StepAdj2);
tomo370 4:c3f3fdde7eee 177
tomo370 4:c3f3fdde7eee 178 stepper1.setMaxSpeed(180000);
tomo370 4:c3f3fdde7eee 179
tomo370 4:c3f3fdde7eee 180 while(1) {
tomo370 4:c3f3fdde7eee 181 stepper1.moveTo(20000 / StepAdj1);
tomo370 4:c3f3fdde7eee 182 stepper2.moveTo(20000 / StepAdj2);
tomo370 4:c3f3fdde7eee 183 while(stepper1.distanceToGo() != 0) {
tomo370 4:c3f3fdde7eee 184 stepper1.run();
tomo370 5:fd097a259856 185 stepper2.run();
tomo370 4:c3f3fdde7eee 186 }
tomo370 5:fd097a259856 187 while(stepper2.distanceToGo() != 0) {
tomo370 5:fd097a259856 188 stepper1.run();
tomo370 5:fd097a259856 189 stepper2.run();
tomo370 5:fd097a259856 190 }
tomo370 4:c3f3fdde7eee 191
tomo370 4:c3f3fdde7eee 192 stepper1.moveTo(500 / StepAdj1);
tomo370 5:fd097a259856 193 stepper2.moveTo(500 / StepAdj2);
tomo370 4:c3f3fdde7eee 194 while(stepper1.distanceToGo() != 0) {
tomo370 4:c3f3fdde7eee 195 stepper1.run();
tomo370 5:fd097a259856 196 stepper2.run();
tomo370 4:c3f3fdde7eee 197 }
tomo370 4:c3f3fdde7eee 198 while(stepper2.distanceToGo() != 0) {
tomo370 5:fd097a259856 199 stepper2.run();
tomo370 4:c3f3fdde7eee 200 stepper1.run();
tomo370 4:c3f3fdde7eee 201 }
tomo370 4:c3f3fdde7eee 202 }
tomo370 4:c3f3fdde7eee 203 }
tomo370 4:c3f3fdde7eee 204
tomo370 6:2a9e0228f81d 205
tomo370 5:fd097a259856 206 void interuptInit1()
tomo370 5:fd097a259856 207 {
tomo370 7:813cdaad1200 208 //stepper1.setMaxSpeed(1000);
tomo370 7:813cdaad1200 209 //stepper1.setAcceleration(5000);
tomo370 7:813cdaad1200 210
tomo370 5:fd097a259856 211
tomo370 7:813cdaad1200 212 //まずとにかく原点を目指す
tomo370 7:813cdaad1200 213 stepper1.moveTo(1);
tomo370 6:2a9e0228f81d 214 while(stepper1.distanceToGo() != 0) {
tomo370 6:2a9e0228f81d 215 stepper1.run();
tomo370 6:2a9e0228f81d 216 }
tomo370 6:2a9e0228f81d 217
tomo370 7:813cdaad1200 218 //15度程度の時計回り動作
tomo370 7:813cdaad1200 219 stepper1.moveTo(200);
tomo370 7:813cdaad1200 220 while(stepper1.distanceToGo() != 0) {
tomo370 7:813cdaad1200 221 stepper1.run();
tomo370 7:813cdaad1200 222 }
tomo370 7:813cdaad1200 223
tomo370 7:813cdaad1200 224 //原点復帰動作、反時計回り
tomo370 6:2a9e0228f81d 225 stepper1.setCurrentPosition(-1);
tomo370 5:fd097a259856 226 stepper1.moveTo(-30000 / StepAdj1);
tomo370 5:fd097a259856 227 while(stepper1.currentPosition() != 0) {
tomo370 5:fd097a259856 228 stepper1.run();
tomo370 5:fd097a259856 229 checkSW();
tomo370 5:fd097a259856 230 }
tomo370 5:fd097a259856 231 //初期位置へ移動
tomo370 5:fd097a259856 232 //something
tomo370 5:fd097a259856 233 }
tomo370 5:fd097a259856 234
tomo370 5:fd097a259856 235 void interuptInit2()
tomo370 5:fd097a259856 236 {
tomo370 5:fd097a259856 237 stepper2.setMaxSpeed(4000 / StepAdj2);
tomo370 5:fd097a259856 238 stepper2.setAcceleration(20000 / StepAdj2);
tomo370 5:fd097a259856 239
tomo370 7:813cdaad1200 240 //まず原点を目指す
tomo370 7:813cdaad1200 241
tomo370 7:813cdaad1200 242
tomo370 6:2a9e0228f81d 243 //15度程度の後退動作
tomo370 7:813cdaad1200 244 stepper2.setCurrentPosition(1);
tomo370 6:2a9e0228f81d 245 stepper2.moveTo(100);
tomo370 6:2a9e0228f81d 246 while(stepper2.distanceToGo() != 0) {
tomo370 6:2a9e0228f81d 247 stepper2.run();
tomo370 6:2a9e0228f81d 248 }
tomo370 6:2a9e0228f81d 249
tomo370 5:fd097a259856 250 //原点復帰動作
tomo370 6:2a9e0228f81d 251 stepper2.setCurrentPosition(-1);
tomo370 5:fd097a259856 252 stepper2.moveTo(-30000 / StepAdj2);
tomo370 5:fd097a259856 253 while(stepper2.currentPosition() != 0) {
tomo370 5:fd097a259856 254 stepper2.run();
tomo370 5:fd097a259856 255 checkSW();
tomo370 5:fd097a259856 256 }
tomo370 5:fd097a259856 257 //初期位置へ移動
tomo370 5:fd097a259856 258 //something
tomo370 5:fd097a259856 259 }
tomo370 5:fd097a259856 260
tomo370 5:fd097a259856 261
tomo370 3:dd2305e50390 262 void init1()
tomo370 0:d94213e24c2e 263 {
tomo370 4:c3f3fdde7eee 264 stepper1.setMaxSpeed(4000 / StepAdj1);
tomo370 4:c3f3fdde7eee 265 stepper1.setAcceleration(20000 / StepAdj1);
tomo370 6:2a9e0228f81d 266
tomo370 6:2a9e0228f81d 267 //30度程度の後退動作
tomo370 6:2a9e0228f81d 268 stepper1.moveTo(200);
tomo370 6:2a9e0228f81d 269 while(stepper1.distanceToGo() != 0) {
tomo370 6:2a9e0228f81d 270 stepper1.run();
tomo370 6:2a9e0228f81d 271 }
tomo370 6:2a9e0228f81d 272 stepper1.setCurrentPosition(-1);
tomo370 6:2a9e0228f81d 273
tomo370 6:2a9e0228f81d 274 //反時計回りに回転、エンドスイッチで停止
tomo370 4:c3f3fdde7eee 275 stepper1.moveTo(-30000 / StepAdj1);
tomo370 0:d94213e24c2e 276 while(stepper1.currentPosition() != 0) {
tomo370 0:d94213e24c2e 277 stepper1.run();
tomo370 0:d94213e24c2e 278 checkSW();
tomo370 0:d94213e24c2e 279 }
tomo370 5:fd097a259856 280 // stepper1.moveTo(500 / StepAdj1);
tomo370 5:fd097a259856 281 // while(stepper1.distanceToGo() != 0) stepper1.run();
tomo370 3:dd2305e50390 282 }
tomo370 3:dd2305e50390 283
tomo370 3:dd2305e50390 284 void init2()
tomo370 3:dd2305e50390 285 {
tomo370 6:2a9e0228f81d 286
tomo370 4:c3f3fdde7eee 287 stepper2.setMaxSpeed(4000 / StepAdj2);
tomo370 4:c3f3fdde7eee 288 stepper2.setAcceleration(20000 / StepAdj2);
tomo370 6:2a9e0228f81d 289
tomo370 6:2a9e0228f81d 290 //30度程度時計回りに回転動作
tomo370 6:2a9e0228f81d 291 stepper2.moveTo(200);
tomo370 6:2a9e0228f81d 292 while(stepper2.distanceToGo() != 0) {
tomo370 6:2a9e0228f81d 293 stepper2.run();
tomo370 6:2a9e0228f81d 294 }
tomo370 6:2a9e0228f81d 295
tomo370 6:2a9e0228f81d 296 stepper2.setCurrentPosition(-1);
tomo370 6:2a9e0228f81d 297
tomo370 6:2a9e0228f81d 298 //反時計回りに回転、エンドスイッチで停止
tomo370 4:c3f3fdde7eee 299 stepper2.moveTo(-30000 / StepAdj2);
tomo370 1:cf2f5992241c 300 while(stepper2.currentPosition() != 0) {
tomo370 1:cf2f5992241c 301 stepper2.run();
tomo370 1:cf2f5992241c 302 checkSW();
tomo370 1:cf2f5992241c 303 }
tomo370 4:c3f3fdde7eee 304 }
tomo370 4:c3f3fdde7eee 305
tomo370 4:c3f3fdde7eee 306 void initBoth()
tomo370 4:c3f3fdde7eee 307 {
tomo370 4:c3f3fdde7eee 308 stepper1.setCurrentPosition(-1);
tomo370 4:c3f3fdde7eee 309 stepper1.setMaxSpeed(4000 / StepAdj1);
tomo370 4:c3f3fdde7eee 310 stepper1.setAcceleration(20000 / StepAdj1);
tomo370 4:c3f3fdde7eee 311 stepper1.moveTo(-30000 / StepAdj1);
tomo370 4:c3f3fdde7eee 312
tomo370 4:c3f3fdde7eee 313 stepper2.setCurrentPosition(-1);
tomo370 4:c3f3fdde7eee 314 stepper2.setMaxSpeed(4000 / StepAdj2);
tomo370 4:c3f3fdde7eee 315 stepper2.setAcceleration(20000 / StepAdj2);
tomo370 4:c3f3fdde7eee 316 stepper2.moveTo(-30000 / StepAdj2);
tomo370 4:c3f3fdde7eee 317
tomo370 4:c3f3fdde7eee 318 while((stepper1.distanceToGo() != 0)||(stepper2.distanceToGo() != 0)) {
tomo370 4:c3f3fdde7eee 319 if (stepper1.distanceToGo() != 0) stepper1.run();
tomo370 4:c3f3fdde7eee 320 if (stepper2.distanceToGo() != 0) stepper2.run();
tomo370 4:c3f3fdde7eee 321 checkSW();
tomo370 4:c3f3fdde7eee 322 }
tomo370 4:c3f3fdde7eee 323 stepper1.moveTo(500 / StepAdj1);
tomo370 4:c3f3fdde7eee 324 stepper2.moveTo(500 / StepAdj2);
tomo370 4:c3f3fdde7eee 325 while((stepper1.distanceToGo() != 0)||(stepper2.distanceToGo() != 0)) {
tomo370 4:c3f3fdde7eee 326 if (stepper1.distanceToGo() != 0) stepper1.run();
tomo370 4:c3f3fdde7eee 327 if (stepper2.distanceToGo() != 0) stepper2.run();
tomo370 1:cf2f5992241c 328 }
tomo370 1:cf2f5992241c 329 }
tomo370 1:cf2f5992241c 330
tomo370 3:dd2305e50390 331
tomo370 1:cf2f5992241c 332 void checkSafeBreak()
tomo370 1:cf2f5992241c 333 {
tomo370 5:fd097a259856 334 //モーター1用エンドスイッチのチェック
tomo370 5:fd097a259856 335 if(EndSW1.read() == 1) {
tomo370 1:cf2f5992241c 336 stepper1.stop();
tomo370 1:cf2f5992241c 337 while(1) {
tomo370 1:cf2f5992241c 338 blink();
tomo370 1:cf2f5992241c 339 }
tomo370 1:cf2f5992241c 340 }
tomo370 1:cf2f5992241c 341
tomo370 1:cf2f5992241c 342 //モーター2用エンドスイッチのチェック
tomo370 5:fd097a259856 343 if(EndSW2.read() == 1) {
tomo370 1:cf2f5992241c 344 stepper2.stop();
tomo370 1:cf2f5992241c 345 while(1) {
tomo370 1:cf2f5992241c 346 blink();
tomo370 1:cf2f5992241c 347 }
tomo370 1:cf2f5992241c 348 }
tomo370 1:cf2f5992241c 349 }
tomo370 1:cf2f5992241c 350
tomo370 5:fd097a259856 351
tomo370 1:cf2f5992241c 352 //モーター1のパラメータ保存
tomo370 1:cf2f5992241c 353 void paramStore1()
tomo370 1:cf2f5992241c 354 {
tomo370 1:cf2f5992241c 355 //速度
tomo370 2:198becff12f4 356 uint8_t dt = dmx.get(DMX_Speed1_H);
tomo370 2:198becff12f4 357 at24c1024.write(DMX_Speed1_H, dt);
tomo370 2:198becff12f4 358 wait_ms(2);
tomo370 2:198becff12f4 359 dt = dmx.get(DMX_Speed1_L);
tomo370 2:198becff12f4 360 at24c1024.write(DMX_Speed1_L, dt);
tomo370 1:cf2f5992241c 361 wait_ms(2);
tomo370 1:cf2f5992241c 362
tomo370 1:cf2f5992241c 363 //加速度
tomo370 1:cf2f5992241c 364 dt = dmx.get(DMX_Acceleration1_H);
tomo370 1:cf2f5992241c 365 at24c1024.write(DMX_Acceleration1_H, dt);
tomo370 2:198becff12f4 366 wait_ms(2);
tomo370 1:cf2f5992241c 367 dt = dmx.get(DMX_Acceleration1_L);
tomo370 1:cf2f5992241c 368 at24c1024.write(DMX_Acceleration1_L, dt);
tomo370 2:198becff12f4 369 wait_ms(2);
tomo370 1:cf2f5992241c 370
tomo370 1:cf2f5992241c 371 //最大値
tomo370 1:cf2f5992241c 372 dt = dmx.get(DMX_Max1_H);
tomo370 1:cf2f5992241c 373 at24c1024.write(DMX_Max1_H, dt);
tomo370 2:198becff12f4 374 wait_ms(2);
tomo370 1:cf2f5992241c 375 dt = dmx.get(DMX_Max1_L);
tomo370 1:cf2f5992241c 376 at24c1024.write(DMX_Max1_L, dt);
tomo370 1:cf2f5992241c 377
tomo370 1:cf2f5992241c 378 wait_ms(5);
tomo370 1:cf2f5992241c 379 }
tomo370 1:cf2f5992241c 380
tomo370 2:198becff12f4 381 //モーター2のパラメータ保存
tomo370 2:198becff12f4 382 void paramStore2()
tomo370 2:198becff12f4 383 {
tomo370 2:198becff12f4 384 //速度
tomo370 2:198becff12f4 385 uint8_t dt = dmx.get(DMX_Speed2_H);
tomo370 2:198becff12f4 386 at24c1024.write(DMX_Speed2_H, dt);
tomo370 2:198becff12f4 387 wait_ms(2);
tomo370 2:198becff12f4 388 dt = dmx.get(DMX_Speed2_L);
tomo370 2:198becff12f4 389 at24c1024.write(DMX_Speed2_L, dt);
tomo370 2:198becff12f4 390 wait_ms(2);
tomo370 2:198becff12f4 391
tomo370 2:198becff12f4 392 //加速度
tomo370 2:198becff12f4 393 dt = dmx.get(DMX_Acceleration2_H);
tomo370 2:198becff12f4 394 at24c1024.write(DMX_Acceleration2_H, dt);
tomo370 2:198becff12f4 395 wait_ms(2);
tomo370 2:198becff12f4 396 dt = dmx.get(DMX_Acceleration2_L);
tomo370 2:198becff12f4 397 at24c1024.write(DMX_Acceleration2_L, dt);
tomo370 2:198becff12f4 398 wait_ms(2);
tomo370 2:198becff12f4 399
tomo370 2:198becff12f4 400 //最大値
tomo370 2:198becff12f4 401 dt = dmx.get(DMX_Max2_H);
tomo370 2:198becff12f4 402 at24c1024.write(DMX_Max2_H, dt);
tomo370 2:198becff12f4 403 wait_ms(2);
tomo370 2:198becff12f4 404 dt = dmx.get(DMX_Max2_L);
tomo370 2:198becff12f4 405 at24c1024.write(DMX_Max2_L, dt);
tomo370 2:198becff12f4 406
tomo370 2:198becff12f4 407 wait_ms(2);
tomo370 2:198becff12f4 408 }
tomo370 2:198becff12f4 409
tomo370 2:198becff12f4 410
tomo370 1:cf2f5992241c 411 //速度・加速度・最大値・オフセットの値をスライダーから取得
tomo370 1:cf2f5992241c 412 void captureSliderValue()
tomo370 1:cf2f5992241c 413 {
tomo370 1:cf2f5992241c 414 dmxInHighBit = dmx.get(DMX_Speed1_H);
tomo370 1:cf2f5992241c 415 dmxInLowBit = dmx.get(DMX_Speed1_L);
tomo370 1:cf2f5992241c 416 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 417 speed1 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 418
tomo370 6:2a9e0228f81d 419 //(停止中)
tomo370 6:2a9e0228f81d 420 // dmxInHighBit = dmx.get(DMX_Speed2_H);
tomo370 6:2a9e0228f81d 421 // dmxInLowBit = dmx.get(DMX_Speed2_L);
tomo370 6:2a9e0228f81d 422 // dmxInHighBit = dmxInHighBit << 8;
tomo370 6:2a9e0228f81d 423 // speed2 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 424
tomo370 1:cf2f5992241c 425 dmxInHighBit = dmx.get(DMX_Acceleration1_H);
tomo370 1:cf2f5992241c 426 dmxInLowBit = dmx.get(DMX_Acceleration1_L);
tomo370 1:cf2f5992241c 427 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 428 Acceleration1 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 429
tomo370 6:2a9e0228f81d 430 //(停止中)
tomo370 6:2a9e0228f81d 431 // dmxInHighBit = dmx.get(DMX_Acceleration2_H);
tomo370 6:2a9e0228f81d 432 // dmxInLowBit = dmx.get(DMX_Acceleration2_L);
tomo370 6:2a9e0228f81d 433 // dmxInHighBit = dmxInHighBit << 8;
tomo370 6:2a9e0228f81d 434 // Acceleration2 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 435
tomo370 1:cf2f5992241c 436 dmxInHighBit = dmx.get(DMX_Max1_H);
tomo370 1:cf2f5992241c 437 dmxInLowBit = dmx.get(DMX_Max1_L);
tomo370 1:cf2f5992241c 438 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 439 max1 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 440
tomo370 6:2a9e0228f81d 441 //(停止中)
tomo370 6:2a9e0228f81d 442 // dmxInHighBit = dmx.get(DMX_Max2_H);
tomo370 6:2a9e0228f81d 443 // dmxInLowBit = dmx.get(DMX_Max2_L);
tomo370 6:2a9e0228f81d 444 // dmxInHighBit = dmxInHighBit << 8;
tomo370 6:2a9e0228f81d 445 // max2 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 446 }
tomo370 0:d94213e24c2e 447
tomo370 0:d94213e24c2e 448
tomo370 1:cf2f5992241c 449 //モーター1の 速度・加速度・オフセットの値をEEPROMから取得
tomo370 1:cf2f5992241c 450 void readROMValue1()
tomo370 1:cf2f5992241c 451 {
tomo370 1:cf2f5992241c 452 //速度
tomo370 2:198becff12f4 453 HighBit = at24c1024.read(DMX_Speed1_H);
tomo370 2:198becff12f4 454 LowBit = at24c1024.read(DMX_Speed1_L);
tomo370 1:cf2f5992241c 455 HighBit = HighBit << 8;
tomo370 2:198becff12f4 456 speed1 = (long)(HighBit + LowBit);
tomo370 1:cf2f5992241c 457
tomo370 1:cf2f5992241c 458 //加速度
tomo370 1:cf2f5992241c 459 HighBit = at24c1024.read(DMX_Acceleration1_H);
tomo370 1:cf2f5992241c 460 LowBit = at24c1024.read(DMX_Acceleration1_L);
tomo370 1:cf2f5992241c 461 HighBit = HighBit << 8;
tomo370 2:198becff12f4 462 Acceleration1 = (long)(HighBit + LowBit);
tomo370 1:cf2f5992241c 463
tomo370 1:cf2f5992241c 464 //最大値
tomo370 1:cf2f5992241c 465 HighBit = at24c1024.read(DMX_Max1_H);
tomo370 1:cf2f5992241c 466 LowBit = at24c1024.read(DMX_Max1_L);
tomo370 1:cf2f5992241c 467 HighBit = HighBit << 8;
tomo370 2:198becff12f4 468 max1 = (long)(HighBit + LowBit);
tomo370 1:cf2f5992241c 469 }
tomo370 1:cf2f5992241c 470
tomo370 1:cf2f5992241c 471
tomo370 1:cf2f5992241c 472 //モーター2の 速度・加速度・オフセットの値をEEPROMから取得
tomo370 1:cf2f5992241c 473 void readROMValue2()
tomo370 1:cf2f5992241c 474 {
tomo370 2:198becff12f4 475 //速度
tomo370 2:198becff12f4 476 HighBit = at24c1024.read(DMX_Speed2_H);
tomo370 2:198becff12f4 477 LowBit = at24c1024.read(DMX_Speed2_L);
tomo370 2:198becff12f4 478 HighBit = HighBit << 8;
tomo370 2:198becff12f4 479 speed2 = (long)(HighBit + LowBit);
tomo370 2:198becff12f4 480
tomo370 2:198becff12f4 481 //加速度
tomo370 2:198becff12f4 482 HighBit = at24c1024.read(DMX_Acceleration2_H);
tomo370 2:198becff12f4 483 LowBit = at24c1024.read(DMX_Acceleration2_L);
tomo370 2:198becff12f4 484 HighBit = HighBit << 8;
tomo370 2:198becff12f4 485 Acceleration2 = (long)(HighBit + LowBit);
tomo370 2:198becff12f4 486
tomo370 2:198becff12f4 487 //最大値
tomo370 2:198becff12f4 488 HighBit = at24c1024.read(DMX_Max2_H);
tomo370 2:198becff12f4 489 LowBit = at24c1024.read(DMX_Max2_L);
tomo370 2:198becff12f4 490 HighBit = HighBit << 8;
tomo370 2:198becff12f4 491 max2 = (long)(HighBit + LowBit);
tomo370 0:d94213e24c2e 492 }
tomo370 0:d94213e24c2e 493
tomo370 0:d94213e24c2e 494
tomo370 1:cf2f5992241c 495 //操作モード切り替えボタンのチェック
tomo370 1:cf2f5992241c 496 void checkManipulateButton()
tomo370 1:cf2f5992241c 497 {
tomo370 1:cf2f5992241c 498 dmxInHighBit = dmx.get(DMX_ParmSetMode1_H);
tomo370 1:cf2f5992241c 499 dmxInLowBit = dmx.get(DMX_ParmSetMode1_L);
tomo370 1:cf2f5992241c 500 if(dmxInHighBit == 102 && dmxInLowBit == 255) {
tomo370 1:cf2f5992241c 501 manipulateMode1 = !manipulateMode1;
tomo370 1:cf2f5992241c 502 blink();
tomo370 1:cf2f5992241c 503 }
tomo370 1:cf2f5992241c 504
tomo370 1:cf2f5992241c 505 dmxInHighBit = dmx.get(DMX_ParmSetMode2_H);
tomo370 1:cf2f5992241c 506 dmxInLowBit = dmx.get(DMX_ParmSetMode2_L);
tomo370 1:cf2f5992241c 507 if(dmxInHighBit == 102 && dmxInLowBit == 255) {
tomo370 1:cf2f5992241c 508 manipulateMode2 = !manipulateMode2;
tomo370 1:cf2f5992241c 509 blink();
tomo370 1:cf2f5992241c 510 }
tomo370 1:cf2f5992241c 511 }
tomo370 1:cf2f5992241c 512
tomo370 1:cf2f5992241c 513 //書き込みボタンのチェック
tomo370 1:cf2f5992241c 514 void checkWriteButton()
tomo370 1:cf2f5992241c 515 {
tomo370 1:cf2f5992241c 516 dmxInHighBit = dmx.get(DMX_SaveValue1_H);
tomo370 1:cf2f5992241c 517 dmxInLowBit = dmx.get(DMX_SaveValue1_L);
tomo370 1:cf2f5992241c 518 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 519 param1 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 520
tomo370 1:cf2f5992241c 521 dmxInHighBit = dmx.get(DMX_SaveValue2_H);
tomo370 1:cf2f5992241c 522 dmxInLowBit = dmx.get(DMX_SaveValue2_L);
tomo370 1:cf2f5992241c 523 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 524 param2 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 1:cf2f5992241c 525
tomo370 1:cf2f5992241c 526 if(param1 == 24932) {
tomo370 1:cf2f5992241c 527 paramStore1();
tomo370 1:cf2f5992241c 528 blink();
tomo370 1:cf2f5992241c 529 } else;
tomo370 1:cf2f5992241c 530
tomo370 1:cf2f5992241c 531 if(param2 == 24932) {
tomo370 2:198becff12f4 532 paramStore2();
tomo370 2:198becff12f4 533 blink();
tomo370 1:cf2f5992241c 534 } else;
tomo370 1:cf2f5992241c 535 }
tomo370 1:cf2f5992241c 536
tomo370 5:fd097a259856 537 //原点復帰命令のチェック
tomo370 5:fd097a259856 538 void checkInitCommand1()
tomo370 5:fd097a259856 539 {
tomo370 5:fd097a259856 540 dmxInHighBit = dmx.get(DMX_Initialize1_H);
tomo370 5:fd097a259856 541 dmxInLowBit = dmx.get(DMX_Initialize1_L);
tomo370 5:fd097a259856 542
tomo370 5:fd097a259856 543 if(dmxInHighBit == 75 && dmxInLowBit == 255) {
tomo370 5:fd097a259856 544 interuptInit1();
tomo370 5:fd097a259856 545 }
tomo370 5:fd097a259856 546 }
tomo370 5:fd097a259856 547
tomo370 5:fd097a259856 548 void checkInitCommand2()
tomo370 5:fd097a259856 549 {
tomo370 5:fd097a259856 550 dmxInHighBit = dmx.get(DMX_Initialize2_H);
tomo370 5:fd097a259856 551 dmxInLowBit = dmx.get(DMX_Initialize2_L);
tomo370 5:fd097a259856 552
tomo370 5:fd097a259856 553 if(dmxInHighBit == 75 && dmxInLowBit == 255) {
tomo370 5:fd097a259856 554 interuptInit2();
tomo370 5:fd097a259856 555 }
tomo370 5:fd097a259856 556 }
tomo370 5:fd097a259856 557
tomo370 5:fd097a259856 558
tomo370 4:c3f3fdde7eee 559 //モータードライバの設定
tomo370 4:c3f3fdde7eee 560 void conf1()
tomo370 4:c3f3fdde7eee 561 {
tomo370 4:c3f3fdde7eee 562 switch (StepSize1) {
tomo370 4:c3f3fdde7eee 563 case 1: //DRV8825 full steps
tomo370 4:c3f3fdde7eee 564 stepper1MS1 = 0;
tomo370 4:c3f3fdde7eee 565 stepper1MS2 = 0;
tomo370 4:c3f3fdde7eee 566 stepper1MS3 = 0;
tomo370 4:c3f3fdde7eee 567 StepAdj1 = 16;
tomo370 4:c3f3fdde7eee 568 break;
tomo370 4:c3f3fdde7eee 569
tomo370 4:c3f3fdde7eee 570 case 2: //DRV8825 1/2 steps
tomo370 4:c3f3fdde7eee 571 stepper1MS1 = 1;
tomo370 4:c3f3fdde7eee 572 stepper1MS2 = 0;
tomo370 4:c3f3fdde7eee 573 stepper1MS3 = 0;
tomo370 4:c3f3fdde7eee 574 StepAdj1 = 8;
tomo370 4:c3f3fdde7eee 575 break;
tomo370 4:c3f3fdde7eee 576
tomo370 4:c3f3fdde7eee 577 case 3: //DRV8825 1/4 steps
tomo370 4:c3f3fdde7eee 578 stepper1MS1 = 0;
tomo370 4:c3f3fdde7eee 579 stepper1MS2 = 1;
tomo370 4:c3f3fdde7eee 580 stepper1MS3 = 0;
tomo370 4:c3f3fdde7eee 581 StepAdj1 = 4;
tomo370 4:c3f3fdde7eee 582 break;
tomo370 4:c3f3fdde7eee 583
tomo370 4:c3f3fdde7eee 584 case 4: //DRV8825 1/8 steps
tomo370 4:c3f3fdde7eee 585 stepper1MS1 = 1;
tomo370 4:c3f3fdde7eee 586 stepper1MS2 = 1;
tomo370 4:c3f3fdde7eee 587 stepper1MS3 = 0;
tomo370 4:c3f3fdde7eee 588 StepAdj1 = 2;
tomo370 4:c3f3fdde7eee 589 break;
tomo370 4:c3f3fdde7eee 590
tomo370 4:c3f3fdde7eee 591 case 5: //DRV8825 1/16 steps
tomo370 4:c3f3fdde7eee 592 stepper1MS1 = 0;
tomo370 4:c3f3fdde7eee 593 stepper1MS2 = 0;
tomo370 4:c3f3fdde7eee 594 stepper1MS3 = 1;
tomo370 4:c3f3fdde7eee 595 StepAdj1 = 1;
tomo370 4:c3f3fdde7eee 596 break;
tomo370 4:c3f3fdde7eee 597
tomo370 4:c3f3fdde7eee 598 case 6: //DRV8825 1/32 steps
tomo370 4:c3f3fdde7eee 599 stepper1MS1 = 1;
tomo370 4:c3f3fdde7eee 600 stepper1MS2 = 1;
tomo370 4:c3f3fdde7eee 601 stepper1MS3 = 1;
tomo370 4:c3f3fdde7eee 602 StepAdj1 = 0.5;
tomo370 4:c3f3fdde7eee 603 break;
tomo370 4:c3f3fdde7eee 604
tomo370 4:c3f3fdde7eee 605 case 7: //TMC StealthChop µ16 steps
tomo370 4:c3f3fdde7eee 606 DigitalIn stepper1MS1(D11);
tomo370 4:c3f3fdde7eee 607 DigitalIn stepper1MS2(D12);
tomo370 4:c3f3fdde7eee 608 StepAdj1 = 1;
tomo370 4:c3f3fdde7eee 609 break;
tomo370 4:c3f3fdde7eee 610 }
tomo370 4:c3f3fdde7eee 611 stepper1Enable = 0;
tomo370 4:c3f3fdde7eee 612 }
tomo370 4:c3f3fdde7eee 613
tomo370 4:c3f3fdde7eee 614 void conf2()
tomo370 4:c3f3fdde7eee 615 {
tomo370 4:c3f3fdde7eee 616 switch (StepSize2) {
tomo370 4:c3f3fdde7eee 617 case 1: //DRV8825 full steps
tomo370 4:c3f3fdde7eee 618 stepper2MS1 = 0;
tomo370 4:c3f3fdde7eee 619 stepper2MS2 = 0;
tomo370 4:c3f3fdde7eee 620 stepper2MS3 = 0;
tomo370 4:c3f3fdde7eee 621 StepAdj2 = 16;
tomo370 4:c3f3fdde7eee 622 break;
tomo370 4:c3f3fdde7eee 623
tomo370 4:c3f3fdde7eee 624 case 2: //DRV8825 1/2 steps
tomo370 4:c3f3fdde7eee 625 stepper2MS1 = 1;
tomo370 4:c3f3fdde7eee 626 stepper2MS2 = 0;
tomo370 4:c3f3fdde7eee 627 stepper2MS3 = 0;
tomo370 4:c3f3fdde7eee 628 StepAdj2 = 8;
tomo370 4:c3f3fdde7eee 629 break;
tomo370 4:c3f3fdde7eee 630
tomo370 4:c3f3fdde7eee 631 case 3: //DRV8825 1/4 steps
tomo370 4:c3f3fdde7eee 632 stepper2MS1 = 0;
tomo370 4:c3f3fdde7eee 633 stepper2MS2 = 1;
tomo370 4:c3f3fdde7eee 634 stepper2MS3 = 0;
tomo370 4:c3f3fdde7eee 635 StepAdj2 = 4;
tomo370 4:c3f3fdde7eee 636 break;
tomo370 4:c3f3fdde7eee 637
tomo370 4:c3f3fdde7eee 638 case 4: //DRV8825 1/8 steps
tomo370 4:c3f3fdde7eee 639 stepper2MS1 = 1;
tomo370 4:c3f3fdde7eee 640 stepper2MS2 = 1;
tomo370 4:c3f3fdde7eee 641 stepper2MS3 = 0;
tomo370 4:c3f3fdde7eee 642 StepAdj2 = 2;
tomo370 4:c3f3fdde7eee 643 break;
tomo370 4:c3f3fdde7eee 644
tomo370 4:c3f3fdde7eee 645 case 5: //DRV8825 1/16 steps
tomo370 4:c3f3fdde7eee 646 stepper2MS1 = 0;
tomo370 4:c3f3fdde7eee 647 stepper2MS2 = 0;
tomo370 4:c3f3fdde7eee 648 stepper2MS3 = 1;
tomo370 4:c3f3fdde7eee 649 StepAdj2 = 1;
tomo370 4:c3f3fdde7eee 650 break;
tomo370 4:c3f3fdde7eee 651
tomo370 4:c3f3fdde7eee 652 case 6: //DRV8825 1/32 steps
tomo370 4:c3f3fdde7eee 653 stepper2MS1 = 1;
tomo370 4:c3f3fdde7eee 654 stepper2MS2 = 1;
tomo370 4:c3f3fdde7eee 655 stepper2MS3 = 1;
tomo370 4:c3f3fdde7eee 656 StepAdj2 = 0.5;
tomo370 4:c3f3fdde7eee 657 break;
tomo370 4:c3f3fdde7eee 658
tomo370 4:c3f3fdde7eee 659 case 7: //TMC StealthChop µ16 steps
tomo370 4:c3f3fdde7eee 660 DigitalIn stepper2MS1(D11);
tomo370 4:c3f3fdde7eee 661 DigitalIn stepper2MS2(D12);
tomo370 4:c3f3fdde7eee 662 StepAdj2 = 1;
tomo370 4:c3f3fdde7eee 663 break;
tomo370 4:c3f3fdde7eee 664 }
tomo370 4:c3f3fdde7eee 665 stepper2Enable = 0;
tomo370 4:c3f3fdde7eee 666 }
tomo370 4:c3f3fdde7eee 667
tomo370 1:cf2f5992241c 668
tomo370 0:d94213e24c2e 669 int main()
tomo370 0:d94213e24c2e 670 {
tomo370 5:fd097a259856 671 wait(1);
tomo370 4:c3f3fdde7eee 672
tomo370 7:813cdaad1200 673 //DMXの機能をレシーブに固定 (ハードウェア的に固定するため停止中)
tomo370 7:813cdaad1200 674 // dmxEnable = 0; //0:receiver 1:sender
tomo370 0:d94213e24c2e 675
tomo370 4:c3f3fdde7eee 676 conf1(); //motor1 config ドライバの設定
tomo370 4:c3f3fdde7eee 677 conf2(); //motor2 config
tomo370 1:cf2f5992241c 678
tomo370 0:d94213e24c2e 679 t.start();
tomo370 7:813cdaad1200 680 //to.attach(&sendDataToLPC, 1);
tomo370 0:d94213e24c2e 681
tomo370 0:d94213e24c2e 682 stepper1.setCurrentPosition(-1);
tomo370 1:cf2f5992241c 683 stepper2.setCurrentPosition(-1);
tomo370 0:d94213e24c2e 684
tomo370 4:c3f3fdde7eee 685 //モーターの初期化シーケンス
tomo370 5:fd097a259856 686 init1();
tomo370 3:dd2305e50390 687 // init2();
tomo370 4:c3f3fdde7eee 688 // initBoth();
tomo370 0:d94213e24c2e 689
tomo370 4:c3f3fdde7eee 690 //往復運動を繰り返すテストシーケンス(無限ループ)
tomo370 5:fd097a259856 691 // testMove1();
tomo370 1:cf2f5992241c 692
tomo370 1:cf2f5992241c 693 myLED =1;
tomo370 1:cf2f5992241c 694
tomo370 2:198becff12f4 695 readROMValue1();
tomo370 5:fd097a259856 696 // readROMValue2();
tomo370 0:d94213e24c2e 697
tomo370 4:c3f3fdde7eee 698 stepper1.setMaxSpeed(10000 / StepAdj1);
tomo370 5:fd097a259856 699 // stepper2.setMaxSpeed(10000 / StepAdj2);
tomo370 4:c3f3fdde7eee 700
tomo370 0:d94213e24c2e 701 while(1) {
tomo370 1:cf2f5992241c 702 //操作モード切り替えボタンのチェック
tomo370 1:cf2f5992241c 703 checkManipulateButton();
tomo370 1:cf2f5992241c 704
tomo370 1:cf2f5992241c 705 //書き込みボタンチェック
tomo370 1:cf2f5992241c 706 checkWriteButton();
tomo370 0:d94213e24c2e 707
tomo370 6:2a9e0228f81d 708 //モーター1の目標位置をDMXから取得
tomo370 1:cf2f5992241c 709 dmxInHighBit = dmx.get(DMX_Position1_H);
tomo370 1:cf2f5992241c 710 dmxInLowBit = dmx.get(DMX_Position1_L);
tomo370 1:cf2f5992241c 711 dmxInHighBit = dmxInHighBit << 8;
tomo370 1:cf2f5992241c 712 position1 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 0:d94213e24c2e 713
tomo370 5:fd097a259856 714 //モーター2の目標位置をスライダーから取得(停止中)
tomo370 5:fd097a259856 715 // dmxInHighBit = dmx.get(DMX_Position2_H);
tomo370 5:fd097a259856 716 // dmxInLowBit = dmx.get(DMX_Position2_L);
tomo370 5:fd097a259856 717 // dmxInHighBit = dmxInHighBit << 8;
tomo370 5:fd097a259856 718 // position2 = (long)(dmxInHighBit + dmxInLowBit);
tomo370 0:d94213e24c2e 719
tomo370 1:cf2f5992241c 720 //手動モードの場合、現在のスライダーの値を取得、パラメーターを設定
tomo370 2:198becff12f4 721 if(manipulateMode1 == false) {
tomo370 1:cf2f5992241c 722 captureSliderValue();
tomo370 2:198becff12f4 723 myLED = 0;
tomo370 1:cf2f5992241c 724 }
tomo370 0:d94213e24c2e 725
tomo370 1:cf2f5992241c 726 //自動モードの場合、EEPROMから値を取得、パラメーターを設定
tomo370 1:cf2f5992241c 727 else {
tomo370 2:198becff12f4 728 myLED = 1;
tomo370 1:cf2f5992241c 729 }
tomo370 0:d94213e24c2e 730
tomo370 6:2a9e0228f81d 731 //手動モードの場合、現在のスライダーの値を取得、パラメーターを設定(停止中)
tomo370 6:2a9e0228f81d 732 // if(manipulateMode2 == false) {
tomo370 6:2a9e0228f81d 733 // captureSliderValue();
tomo370 6:2a9e0228f81d 734 // myLED = 0;
tomo370 6:2a9e0228f81d 735 // }
tomo370 2:198becff12f4 736
tomo370 6:2a9e0228f81d 737 //自動モードの場合、EEPROMから値を取得、パラメータを設定(停止中)
tomo370 6:2a9e0228f81d 738 // else {
tomo370 6:2a9e0228f81d 739 // myLED = 1;
tomo370 6:2a9e0228f81d 740 // }
tomo370 1:cf2f5992241c 741
tomo370 5:fd097a259856 742
tomo370 5:fd097a259856 743 //モーター1のパラメーター設定
tomo370 1:cf2f5992241c 744 position1 = map(position1, 0, 0xFFFF, 0, max1);
tomo370 1:cf2f5992241c 745 stepper1.setMaxSpeed(speed1);
tomo370 1:cf2f5992241c 746 stepper1.setAcceleration(Acceleration1);
tomo370 1:cf2f5992241c 747
tomo370 5:fd097a259856 748
tomo370 5:fd097a259856 749 //モーター2のパラメーター設定(停止中)
tomo370 5:fd097a259856 750 //position2 = map(position2, 0, 0xFFFF, 0, max2);
tomo370 5:fd097a259856 751 //stepper2.setMaxSpeed(speed2);
tomo370 5:fd097a259856 752 //stepper2.setAcceleration(Acceleration2);
tomo370 1:cf2f5992241c 753
tomo370 5:fd097a259856 754
tomo370 5:fd097a259856 755 //モーター1の目標位置設定
tomo370 1:cf2f5992241c 756 stepper1.moveTo(position1);
tomo370 5:fd097a259856 757
tomo370 5:fd097a259856 758 //モーター2の目標位置設定(停止中)
tomo370 5:fd097a259856 759 //stepper2.moveTo(position2);
tomo370 1:cf2f5992241c 760
tomo370 4:c3f3fdde7eee 761
tomo370 5:fd097a259856 762 //安全エンドスイッチの監視(停止中)
tomo370 5:fd097a259856 763 //checkSafeBreak();
tomo370 5:fd097a259856 764
tomo370 5:fd097a259856 765 //モーター1への原点復帰命令のチェック
tomo370 5:fd097a259856 766 checkInitCommand1();
tomo370 4:c3f3fdde7eee 767
tomo370 5:fd097a259856 768 //モーター2への原点復帰命令のチェック(停止中)
tomo370 5:fd097a259856 769 //checkInitCommand2();
tomo370 5:fd097a259856 770
tomo370 5:fd097a259856 771 //モーター1の走行
tomo370 7:813cdaad1200 772 if(stepper1.distanceToGo() != 0) {
tomo370 7:813cdaad1200 773 //checkInitCommand1();
tomo370 7:813cdaad1200 774 stepper1.run();
tomo370 7:813cdaad1200 775 }
tomo370 5:fd097a259856 776 //モーター2の走行(停止中)
tomo370 5:fd097a259856 777 //if(stepper2.distanceToGo() != 0) stepper2.run();
tomo370 1:cf2f5992241c 778 }
tomo370 1:cf2f5992241c 779 }