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