test2017-1-13
Dependencies: AT24C1024 DMX-STM32 mbed
main.cpp@3:dd2305e50390, 2017-03-02 (annotated)
- Committer:
- tomo370
- Date:
- Thu Mar 02 09:03:40 2017 +0000
- Revision:
- 3:dd2305e50390
- Parent:
- 2:198becff12f4
- Child:
- 4:c3f3fdde7eee
???????????????;
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 | 0:d94213e24c2e | 6 | Timer t; |
tomo370 | 1:cf2f5992241c | 7 | DigitalOut dmxEnable(D8); //基本L(レシーブ)に固定します |
tomo370 | 0:d94213e24c2e | 8 | DMX dmx(PA_9, PA_10); |
tomo370 | 0:d94213e24c2e | 9 | |
tomo370 | 1:cf2f5992241c | 10 | I2C i2c(D4, D5); // SDA, SCL |
tomo370 | 1:cf2f5992241c | 11 | AT24C1024 at24c1024(i2c); // Atmel 1Mbit EE-PROM |
tomo370 | 0:d94213e24c2e | 12 | |
tomo370 | 1:cf2f5992241c | 13 | AccelStepper stepper1(1, D9, D6); // step, direction |
tomo370 | 1:cf2f5992241c | 14 | AccelStepper stepper2(1, D10, D7); // step, direction |
tomo370 | 1:cf2f5992241c | 15 | |
tomo370 | 1:cf2f5992241c | 16 | //モーター1 CN0とCN1を使用 |
tomo370 | 0:d94213e24c2e | 17 | DigitalOut stepper1Enable(D2); |
tomo370 | 0:d94213e24c2e | 18 | DigitalOut stepper1MS1(D11); |
tomo370 | 0:d94213e24c2e | 19 | DigitalOut stepper1MS2(D12); |
tomo370 | 0:d94213e24c2e | 20 | DigitalIn stepper1MS3(A4); |
tomo370 | 0:d94213e24c2e | 21 | |
tomo370 | 1:cf2f5992241c | 22 | //モーター2 CN2とCN3を使用 |
tomo370 | 0:d94213e24c2e | 23 | DigitalOut stepper2Enable(D3); |
tomo370 | 0:d94213e24c2e | 24 | DigitalOut stepper2MS1(A5); |
tomo370 | 0:d94213e24c2e | 25 | DigitalOut stepper2MS2(A6); |
tomo370 | 0:d94213e24c2e | 26 | DigitalOut stepper2MS3(A7); |
tomo370 | 0:d94213e24c2e | 27 | |
tomo370 | 1:cf2f5992241c | 28 | DigitalIn EndSW1(A0); //CN4 //3端子エンドスイッチ1 予備 |
tomo370 | 1:cf2f5992241c | 29 | DigitalIn EndSW2(A1); //CN5 //3端子エンドスイッチ2 予備 |
tomo370 | 1:cf2f5992241c | 30 | DigitalIn EndSW3(A2); //CN6 //2端子エンドスイッチ1 モーター1用にする |
tomo370 | 1:cf2f5992241c | 31 | DigitalIn EndSW4(A3); //CN7 //2端子エンドスイッチ2 モーター2用にする |
tomo370 | 1:cf2f5992241c | 32 | |
tomo370 | 1:cf2f5992241c | 33 | DigitalOut myLED(LED3); //動作確認用LED |
tomo370 | 1:cf2f5992241c | 34 | |
tomo370 | 1:cf2f5992241c | 35 | unsigned long position1, position2; //モーター1の設定位置 |
tomo370 | 1:cf2f5992241c | 36 | unsigned long max1, max2; |
tomo370 | 1:cf2f5992241c | 37 | unsigned long speed1, speed2; |
tomo370 | 1:cf2f5992241c | 38 | unsigned long Acceleration1, Acceleration2; |
tomo370 | 1:cf2f5992241c | 39 | unsigned long param1, param2; |
tomo370 | 1:cf2f5992241c | 40 | unsigned long dmxInHighBit, dmxInLowBit; |
tomo370 | 2:198becff12f4 | 41 | unsigned long HighBit, LowBit; |
tomo370 | 1:cf2f5992241c | 42 | |
tomo370 | 1:cf2f5992241c | 43 | bool manipulateMode1 = true; //0:手動 1:自動 |
tomo370 | 1:cf2f5992241c | 44 | bool manipulateMode2 = true; //0:手動 1:自動 |
tomo370 | 1:cf2f5992241c | 45 | |
tomo370 | 1:cf2f5992241c | 46 | |
tomo370 | 1:cf2f5992241c | 47 | //モーター1のパラメーター DMXチャンネルリスト チャンネル数:12個 |
tomo370 | 1:cf2f5992241c | 48 | #define CH_Origin 0 |
tomo370 | 0:d94213e24c2e | 49 | |
tomo370 | 1:cf2f5992241c | 50 | #define DMX_Position1_H CH_Origin //モーター1制御用のDMX信号の始まりの値 |
tomo370 | 1:cf2f5992241c | 51 | #define DMX_Position1_L CH_Origin + 1 |
tomo370 | 1:cf2f5992241c | 52 | #define DMX_Speed1_H CH_Origin + 2 |
tomo370 | 1:cf2f5992241c | 53 | #define DMX_Speed1_L CH_Origin + 3 |
tomo370 | 1:cf2f5992241c | 54 | #define DMX_Acceleration1_H CH_Origin + 4 |
tomo370 | 1:cf2f5992241c | 55 | #define DMX_Acceleration1_L CH_Origin + 5 |
tomo370 | 1:cf2f5992241c | 56 | #define DMX_Max1_H CH_Origin + 6 |
tomo370 | 1:cf2f5992241c | 57 | #define DMX_Max1_L CH_Origin + 7 |
tomo370 | 1:cf2f5992241c | 58 | #define DMX_Offset1_H CH_Origin + 8 |
tomo370 | 1:cf2f5992241c | 59 | #define DMX_Offset1_L CH_Origin + 9 |
tomo370 | 1:cf2f5992241c | 60 | #define DMX_SaveValue1_H CH_Origin + 10 |
tomo370 | 1:cf2f5992241c | 61 | #define DMX_SaveValue1_L CH_Origin + 11 |
tomo370 | 1:cf2f5992241c | 62 | #define DMX_ParmSetMode1_H CH_Origin + 12 |
tomo370 | 1:cf2f5992241c | 63 | #define DMX_ParmSetMode1_L CH_Origin + 13 |
tomo370 | 0:d94213e24c2e | 64 | |
tomo370 | 1:cf2f5992241c | 65 | //モーター2のパラメーター DMXチャンネルリスト チャンネル数:12個 |
tomo370 | 1:cf2f5992241c | 66 | #define DMX_Position2_H CH_Origin + 16 |
tomo370 | 1:cf2f5992241c | 67 | #define DMX_Position2_L CH_Origin + 17 |
tomo370 | 1:cf2f5992241c | 68 | #define DMX_Speed2_H CH_Origin + 18 |
tomo370 | 1:cf2f5992241c | 69 | #define DMX_Speed2_L CH_Origin + 19 |
tomo370 | 1:cf2f5992241c | 70 | #define DMX_Acceleration2_H CH_Origin + 20 |
tomo370 | 1:cf2f5992241c | 71 | #define DMX_Acceleration2_L CH_Origin + 21 |
tomo370 | 1:cf2f5992241c | 72 | #define DMX_Max2_H CH_Origin + 22 |
tomo370 | 1:cf2f5992241c | 73 | #define DMX_Max2_L CH_Origin + 23 |
tomo370 | 1:cf2f5992241c | 74 | #define DMX_Offset2_H CH_Origin + 24 |
tomo370 | 1:cf2f5992241c | 75 | #define DMX_Offset2_L CH_Origin + 25 |
tomo370 | 1:cf2f5992241c | 76 | #define DMX_SaveValue2_H CH_Origin + 26 |
tomo370 | 1:cf2f5992241c | 77 | #define DMX_SaveValue2_L CH_Origin + 27 |
tomo370 | 1:cf2f5992241c | 78 | #define DMX_ParmSetMode2_H CH_Origin + 28 |
tomo370 | 1:cf2f5992241c | 79 | #define DMX_ParmSetMode2_L CH_Origin + 29 |
tomo370 | 1:cf2f5992241c | 80 | |
tomo370 | 1:cf2f5992241c | 81 | //map |
tomo370 | 0:d94213e24c2e | 82 | long map(long x, long in_min, long in_max, long out_min, long out_max) |
tomo370 | 0:d94213e24c2e | 83 | { |
tomo370 | 0:d94213e24c2e | 84 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
tomo370 | 0:d94213e24c2e | 85 | } |
tomo370 | 0:d94213e24c2e | 86 | |
tomo370 | 1:cf2f5992241c | 87 | void blink() |
tomo370 | 1:cf2f5992241c | 88 | { |
tomo370 | 1:cf2f5992241c | 89 | for(int i=0; i<5; i++) { |
tomo370 | 1:cf2f5992241c | 90 | myLED=0; |
tomo370 | 1:cf2f5992241c | 91 | wait_ms(60); |
tomo370 | 1:cf2f5992241c | 92 | myLED=1; |
tomo370 | 1:cf2f5992241c | 93 | wait_ms(60); |
tomo370 | 1:cf2f5992241c | 94 | } |
tomo370 | 1:cf2f5992241c | 95 | } |
tomo370 | 1:cf2f5992241c | 96 | |
tomo370 | 0:d94213e24c2e | 97 | void checkSW() |
tomo370 | 0:d94213e24c2e | 98 | { |
tomo370 | 1:cf2f5992241c | 99 | //モーター1用エンドスイッチのチェック |
tomo370 | 2:198becff12f4 | 100 | if(EndSW3.read() == 1) { |
tomo370 | 0:d94213e24c2e | 101 | stepper1.stop(); |
tomo370 | 0:d94213e24c2e | 102 | stepper1.setCurrentPosition(0); |
tomo370 | 0:d94213e24c2e | 103 | } |
tomo370 | 1:cf2f5992241c | 104 | |
tomo370 | 1:cf2f5992241c | 105 | //モーター2用エンドスイッチのチェック |
tomo370 | 2:198becff12f4 | 106 | if(EndSW4.read() == 1) { |
tomo370 | 1:cf2f5992241c | 107 | stepper2.stop(); |
tomo370 | 1:cf2f5992241c | 108 | stepper2.setCurrentPosition(0); |
tomo370 | 1:cf2f5992241c | 109 | } |
tomo370 | 0:d94213e24c2e | 110 | } |
tomo370 | 0:d94213e24c2e | 111 | |
tomo370 | 0:d94213e24c2e | 112 | void silence() |
tomo370 | 0:d94213e24c2e | 113 | { |
tomo370 | 0:d94213e24c2e | 114 | DigitalIn stepper1MS1(D11); |
tomo370 | 0:d94213e24c2e | 115 | DigitalIn stepper1MS2(D12); |
tomo370 | 1:cf2f5992241c | 116 | |
tomo370 | 1:cf2f5992241c | 117 | DigitalIn stepper2MS1(A5); |
tomo370 | 1:cf2f5992241c | 118 | DigitalIn stepper2MS2(A6); |
tomo370 | 0:d94213e24c2e | 119 | } |
tomo370 | 0:d94213e24c2e | 120 | |
tomo370 | 0:d94213e24c2e | 121 | void run() |
tomo370 | 0:d94213e24c2e | 122 | { |
tomo370 | 0:d94213e24c2e | 123 | DigitalOut stepper1MS1(D11); |
tomo370 | 0:d94213e24c2e | 124 | DigitalOut stepper1MS2(D12); |
tomo370 | 0:d94213e24c2e | 125 | stepper1MS1 = 1; |
tomo370 | 0:d94213e24c2e | 126 | stepper1MS2 = 1; |
tomo370 | 1:cf2f5992241c | 127 | |
tomo370 | 1:cf2f5992241c | 128 | DigitalOut stepper2MS1(A5); |
tomo370 | 1:cf2f5992241c | 129 | DigitalOut stepper2MS2(A6); |
tomo370 | 1:cf2f5992241c | 130 | stepper2MS1 = 1; |
tomo370 | 1:cf2f5992241c | 131 | stepper2MS2 = 1; |
tomo370 | 0:d94213e24c2e | 132 | } |
tomo370 | 0:d94213e24c2e | 133 | |
tomo370 | 3:dd2305e50390 | 134 | |
tomo370 | 3:dd2305e50390 | 135 | void init1() |
tomo370 | 0:d94213e24c2e | 136 | { |
tomo370 | 3:dd2305e50390 | 137 | stepper1.setMaxSpeed(2000); |
tomo370 | 0:d94213e24c2e | 138 | stepper1.setAcceleration(20000); |
tomo370 | 3:dd2305e50390 | 139 | stepper1.moveTo(-30000); |
tomo370 | 0:d94213e24c2e | 140 | |
tomo370 | 0:d94213e24c2e | 141 | while(stepper1.currentPosition() != 0) { |
tomo370 | 0:d94213e24c2e | 142 | stepper1.run(); |
tomo370 | 0:d94213e24c2e | 143 | checkSW(); |
tomo370 | 0:d94213e24c2e | 144 | } |
tomo370 | 0:d94213e24c2e | 145 | stepper1.moveTo(500); |
tomo370 | 0:d94213e24c2e | 146 | while(stepper1.distanceToGo() != 0) { |
tomo370 | 0:d94213e24c2e | 147 | stepper1.run(); |
tomo370 | 0:d94213e24c2e | 148 | } |
tomo370 | 1:cf2f5992241c | 149 | |
tomo370 | 3:dd2305e50390 | 150 | stepper1.setMaxSpeed(4500); |
tomo370 | 3:dd2305e50390 | 151 | |
tomo370 | 3:dd2305e50390 | 152 | while(1) { |
tomo370 | 3:dd2305e50390 | 153 | stepper1.moveTo(20000); |
tomo370 | 3:dd2305e50390 | 154 | while(stepper1.distanceToGo() != 0) { |
tomo370 | 3:dd2305e50390 | 155 | stepper1.run(); |
tomo370 | 3:dd2305e50390 | 156 | |
tomo370 | 3:dd2305e50390 | 157 | } |
tomo370 | 3:dd2305e50390 | 158 | stepper1.moveTo(500); |
tomo370 | 3:dd2305e50390 | 159 | while(stepper1.distanceToGo() != 0) { |
tomo370 | 3:dd2305e50390 | 160 | stepper1.run(); |
tomo370 | 3:dd2305e50390 | 161 | } |
tomo370 | 3:dd2305e50390 | 162 | } |
tomo370 | 3:dd2305e50390 | 163 | |
tomo370 | 3:dd2305e50390 | 164 | } |
tomo370 | 3:dd2305e50390 | 165 | |
tomo370 | 3:dd2305e50390 | 166 | void init2() |
tomo370 | 3:dd2305e50390 | 167 | { |
tomo370 | 3:dd2305e50390 | 168 | |
tomo370 | 2:198becff12f4 | 169 | stepper2.setMaxSpeed(4000); |
tomo370 | 1:cf2f5992241c | 170 | stepper2.setAcceleration(20000); |
tomo370 | 2:198becff12f4 | 171 | stepper2.moveTo(-20000); |
tomo370 | 1:cf2f5992241c | 172 | |
tomo370 | 1:cf2f5992241c | 173 | while(stepper2.currentPosition() != 0) { |
tomo370 | 1:cf2f5992241c | 174 | stepper2.run(); |
tomo370 | 1:cf2f5992241c | 175 | checkSW(); |
tomo370 | 1:cf2f5992241c | 176 | } |
tomo370 | 1:cf2f5992241c | 177 | stepper2.moveTo(500); |
tomo370 | 1:cf2f5992241c | 178 | while(stepper2.distanceToGo() != 0) { |
tomo370 | 1:cf2f5992241c | 179 | stepper2.run(); |
tomo370 | 1:cf2f5992241c | 180 | } |
tomo370 | 1:cf2f5992241c | 181 | } |
tomo370 | 1:cf2f5992241c | 182 | |
tomo370 | 3:dd2305e50390 | 183 | |
tomo370 | 1:cf2f5992241c | 184 | void checkSafeBreak() |
tomo370 | 1:cf2f5992241c | 185 | { |
tomo370 | 2:198becff12f4 | 186 | if(EndSW3.read() == 1) { |
tomo370 | 1:cf2f5992241c | 187 | stepper1.stop(); |
tomo370 | 1:cf2f5992241c | 188 | while(1) { |
tomo370 | 1:cf2f5992241c | 189 | blink(); |
tomo370 | 1:cf2f5992241c | 190 | } |
tomo370 | 1:cf2f5992241c | 191 | } |
tomo370 | 1:cf2f5992241c | 192 | |
tomo370 | 1:cf2f5992241c | 193 | //モーター2用エンドスイッチのチェック |
tomo370 | 2:198becff12f4 | 194 | if(EndSW4.read() == 1) { |
tomo370 | 1:cf2f5992241c | 195 | stepper2.stop(); |
tomo370 | 1:cf2f5992241c | 196 | while(1) { |
tomo370 | 1:cf2f5992241c | 197 | blink(); |
tomo370 | 1:cf2f5992241c | 198 | } |
tomo370 | 1:cf2f5992241c | 199 | } |
tomo370 | 1:cf2f5992241c | 200 | } |
tomo370 | 1:cf2f5992241c | 201 | |
tomo370 | 1:cf2f5992241c | 202 | //モーター1のパラメータ保存 |
tomo370 | 1:cf2f5992241c | 203 | void paramStore1() |
tomo370 | 1:cf2f5992241c | 204 | { |
tomo370 | 1:cf2f5992241c | 205 | //速度 |
tomo370 | 2:198becff12f4 | 206 | uint8_t dt = dmx.get(DMX_Speed1_H); |
tomo370 | 2:198becff12f4 | 207 | at24c1024.write(DMX_Speed1_H, dt); |
tomo370 | 2:198becff12f4 | 208 | wait_ms(2); |
tomo370 | 2:198becff12f4 | 209 | dt = dmx.get(DMX_Speed1_L); |
tomo370 | 2:198becff12f4 | 210 | at24c1024.write(DMX_Speed1_L, dt); |
tomo370 | 1:cf2f5992241c | 211 | wait_ms(2); |
tomo370 | 1:cf2f5992241c | 212 | |
tomo370 | 1:cf2f5992241c | 213 | //加速度 |
tomo370 | 1:cf2f5992241c | 214 | dt = dmx.get(DMX_Acceleration1_H); |
tomo370 | 1:cf2f5992241c | 215 | at24c1024.write(DMX_Acceleration1_H, dt); |
tomo370 | 2:198becff12f4 | 216 | wait_ms(2); |
tomo370 | 1:cf2f5992241c | 217 | dt = dmx.get(DMX_Acceleration1_L); |
tomo370 | 1:cf2f5992241c | 218 | at24c1024.write(DMX_Acceleration1_L, dt); |
tomo370 | 2:198becff12f4 | 219 | wait_ms(2); |
tomo370 | 1:cf2f5992241c | 220 | |
tomo370 | 1:cf2f5992241c | 221 | //最大値 |
tomo370 | 1:cf2f5992241c | 222 | dt = dmx.get(DMX_Max1_H); |
tomo370 | 1:cf2f5992241c | 223 | at24c1024.write(DMX_Max1_H, dt); |
tomo370 | 2:198becff12f4 | 224 | wait_ms(2); |
tomo370 | 1:cf2f5992241c | 225 | dt = dmx.get(DMX_Max1_L); |
tomo370 | 1:cf2f5992241c | 226 | at24c1024.write(DMX_Max1_L, dt); |
tomo370 | 1:cf2f5992241c | 227 | |
tomo370 | 1:cf2f5992241c | 228 | wait_ms(5); |
tomo370 | 1:cf2f5992241c | 229 | } |
tomo370 | 1:cf2f5992241c | 230 | |
tomo370 | 2:198becff12f4 | 231 | //モーター2のパラメータ保存 |
tomo370 | 2:198becff12f4 | 232 | void paramStore2() |
tomo370 | 2:198becff12f4 | 233 | { |
tomo370 | 2:198becff12f4 | 234 | //速度 |
tomo370 | 2:198becff12f4 | 235 | uint8_t dt = dmx.get(DMX_Speed2_H); |
tomo370 | 2:198becff12f4 | 236 | at24c1024.write(DMX_Speed2_H, dt); |
tomo370 | 2:198becff12f4 | 237 | wait_ms(2); |
tomo370 | 2:198becff12f4 | 238 | dt = dmx.get(DMX_Speed2_L); |
tomo370 | 2:198becff12f4 | 239 | at24c1024.write(DMX_Speed2_L, dt); |
tomo370 | 2:198becff12f4 | 240 | wait_ms(2); |
tomo370 | 2:198becff12f4 | 241 | |
tomo370 | 2:198becff12f4 | 242 | //加速度 |
tomo370 | 2:198becff12f4 | 243 | dt = dmx.get(DMX_Acceleration2_H); |
tomo370 | 2:198becff12f4 | 244 | at24c1024.write(DMX_Acceleration2_H, dt); |
tomo370 | 2:198becff12f4 | 245 | wait_ms(2); |
tomo370 | 2:198becff12f4 | 246 | dt = dmx.get(DMX_Acceleration2_L); |
tomo370 | 2:198becff12f4 | 247 | at24c1024.write(DMX_Acceleration2_L, dt); |
tomo370 | 2:198becff12f4 | 248 | wait_ms(2); |
tomo370 | 2:198becff12f4 | 249 | |
tomo370 | 2:198becff12f4 | 250 | //最大値 |
tomo370 | 2:198becff12f4 | 251 | dt = dmx.get(DMX_Max2_H); |
tomo370 | 2:198becff12f4 | 252 | at24c1024.write(DMX_Max2_H, dt); |
tomo370 | 2:198becff12f4 | 253 | wait_ms(2); |
tomo370 | 2:198becff12f4 | 254 | dt = dmx.get(DMX_Max2_L); |
tomo370 | 2:198becff12f4 | 255 | at24c1024.write(DMX_Max2_L, dt); |
tomo370 | 2:198becff12f4 | 256 | |
tomo370 | 2:198becff12f4 | 257 | wait_ms(2); |
tomo370 | 2:198becff12f4 | 258 | } |
tomo370 | 2:198becff12f4 | 259 | |
tomo370 | 2:198becff12f4 | 260 | |
tomo370 | 1:cf2f5992241c | 261 | //速度・加速度・最大値・オフセットの値をスライダーから取得 |
tomo370 | 1:cf2f5992241c | 262 | void captureSliderValue() |
tomo370 | 1:cf2f5992241c | 263 | { |
tomo370 | 1:cf2f5992241c | 264 | dmxInHighBit = dmx.get(DMX_Speed1_H); |
tomo370 | 1:cf2f5992241c | 265 | dmxInLowBit = dmx.get(DMX_Speed1_L); |
tomo370 | 1:cf2f5992241c | 266 | dmxInHighBit = dmxInHighBit << 8; |
tomo370 | 1:cf2f5992241c | 267 | speed1 = (long)(dmxInHighBit + dmxInLowBit); |
tomo370 | 1:cf2f5992241c | 268 | |
tomo370 | 1:cf2f5992241c | 269 | dmxInHighBit = dmx.get(DMX_Speed2_H); |
tomo370 | 1:cf2f5992241c | 270 | dmxInLowBit = dmx.get(DMX_Speed2_L); |
tomo370 | 1:cf2f5992241c | 271 | dmxInHighBit = dmxInHighBit << 8; |
tomo370 | 1:cf2f5992241c | 272 | speed2 = (long)(dmxInHighBit + dmxInLowBit); |
tomo370 | 1:cf2f5992241c | 273 | |
tomo370 | 1:cf2f5992241c | 274 | dmxInHighBit = dmx.get(DMX_Acceleration1_H); |
tomo370 | 1:cf2f5992241c | 275 | dmxInLowBit = dmx.get(DMX_Acceleration1_L); |
tomo370 | 1:cf2f5992241c | 276 | dmxInHighBit = dmxInHighBit << 8; |
tomo370 | 1:cf2f5992241c | 277 | Acceleration1 = (long)(dmxInHighBit + dmxInLowBit); |
tomo370 | 1:cf2f5992241c | 278 | |
tomo370 | 1:cf2f5992241c | 279 | dmxInHighBit = dmx.get(DMX_Acceleration2_H); |
tomo370 | 1:cf2f5992241c | 280 | dmxInLowBit = dmx.get(DMX_Acceleration2_L); |
tomo370 | 1:cf2f5992241c | 281 | dmxInHighBit = dmxInHighBit << 8; |
tomo370 | 1:cf2f5992241c | 282 | Acceleration2 = (long)(dmxInHighBit + dmxInLowBit); |
tomo370 | 1:cf2f5992241c | 283 | |
tomo370 | 1:cf2f5992241c | 284 | dmxInHighBit = dmx.get(DMX_Max1_H); |
tomo370 | 1:cf2f5992241c | 285 | dmxInLowBit = dmx.get(DMX_Max1_L); |
tomo370 | 1:cf2f5992241c | 286 | dmxInHighBit = dmxInHighBit << 8; |
tomo370 | 1:cf2f5992241c | 287 | max1 = (long)(dmxInHighBit + dmxInLowBit); |
tomo370 | 1:cf2f5992241c | 288 | |
tomo370 | 1:cf2f5992241c | 289 | dmxInHighBit = dmx.get(DMX_Max2_H); |
tomo370 | 1:cf2f5992241c | 290 | dmxInLowBit = dmx.get(DMX_Max2_L); |
tomo370 | 1:cf2f5992241c | 291 | dmxInHighBit = dmxInHighBit << 8; |
tomo370 | 1:cf2f5992241c | 292 | max2 = (long)(dmxInHighBit + dmxInLowBit); |
tomo370 | 1:cf2f5992241c | 293 | } |
tomo370 | 0:d94213e24c2e | 294 | |
tomo370 | 0:d94213e24c2e | 295 | |
tomo370 | 1:cf2f5992241c | 296 | //モーター1の 速度・加速度・オフセットの値をEEPROMから取得 |
tomo370 | 1:cf2f5992241c | 297 | void readROMValue1() |
tomo370 | 1:cf2f5992241c | 298 | { |
tomo370 | 1:cf2f5992241c | 299 | //速度 |
tomo370 | 2:198becff12f4 | 300 | HighBit = at24c1024.read(DMX_Speed1_H); |
tomo370 | 2:198becff12f4 | 301 | LowBit = at24c1024.read(DMX_Speed1_L); |
tomo370 | 1:cf2f5992241c | 302 | HighBit = HighBit << 8; |
tomo370 | 2:198becff12f4 | 303 | speed1 = (long)(HighBit + LowBit); |
tomo370 | 1:cf2f5992241c | 304 | |
tomo370 | 1:cf2f5992241c | 305 | //加速度 |
tomo370 | 1:cf2f5992241c | 306 | HighBit = at24c1024.read(DMX_Acceleration1_H); |
tomo370 | 1:cf2f5992241c | 307 | LowBit = at24c1024.read(DMX_Acceleration1_L); |
tomo370 | 1:cf2f5992241c | 308 | HighBit = HighBit << 8; |
tomo370 | 2:198becff12f4 | 309 | Acceleration1 = (long)(HighBit + LowBit); |
tomo370 | 1:cf2f5992241c | 310 | |
tomo370 | 1:cf2f5992241c | 311 | //最大値 |
tomo370 | 1:cf2f5992241c | 312 | HighBit = at24c1024.read(DMX_Max1_H); |
tomo370 | 1:cf2f5992241c | 313 | LowBit = at24c1024.read(DMX_Max1_L); |
tomo370 | 1:cf2f5992241c | 314 | HighBit = HighBit << 8; |
tomo370 | 2:198becff12f4 | 315 | max1 = (long)(HighBit + LowBit); |
tomo370 | 1:cf2f5992241c | 316 | } |
tomo370 | 1:cf2f5992241c | 317 | |
tomo370 | 1:cf2f5992241c | 318 | |
tomo370 | 1:cf2f5992241c | 319 | //モーター2の 速度・加速度・オフセットの値をEEPROMから取得 |
tomo370 | 1:cf2f5992241c | 320 | void readROMValue2() |
tomo370 | 1:cf2f5992241c | 321 | { |
tomo370 | 2:198becff12f4 | 322 | //速度 |
tomo370 | 2:198becff12f4 | 323 | HighBit = at24c1024.read(DMX_Speed2_H); |
tomo370 | 2:198becff12f4 | 324 | LowBit = at24c1024.read(DMX_Speed2_L); |
tomo370 | 2:198becff12f4 | 325 | HighBit = HighBit << 8; |
tomo370 | 2:198becff12f4 | 326 | speed2 = (long)(HighBit + LowBit); |
tomo370 | 2:198becff12f4 | 327 | |
tomo370 | 2:198becff12f4 | 328 | //加速度 |
tomo370 | 2:198becff12f4 | 329 | HighBit = at24c1024.read(DMX_Acceleration2_H); |
tomo370 | 2:198becff12f4 | 330 | LowBit = at24c1024.read(DMX_Acceleration2_L); |
tomo370 | 2:198becff12f4 | 331 | HighBit = HighBit << 8; |
tomo370 | 2:198becff12f4 | 332 | Acceleration2 = (long)(HighBit + LowBit); |
tomo370 | 2:198becff12f4 | 333 | |
tomo370 | 2:198becff12f4 | 334 | //最大値 |
tomo370 | 2:198becff12f4 | 335 | HighBit = at24c1024.read(DMX_Max2_H); |
tomo370 | 2:198becff12f4 | 336 | LowBit = at24c1024.read(DMX_Max2_L); |
tomo370 | 2:198becff12f4 | 337 | HighBit = HighBit << 8; |
tomo370 | 2:198becff12f4 | 338 | max2 = (long)(HighBit + LowBit); |
tomo370 | 0:d94213e24c2e | 339 | } |
tomo370 | 0:d94213e24c2e | 340 | |
tomo370 | 0:d94213e24c2e | 341 | |
tomo370 | 1:cf2f5992241c | 342 | //操作モード切り替えボタンのチェック |
tomo370 | 1:cf2f5992241c | 343 | void checkManipulateButton() |
tomo370 | 1:cf2f5992241c | 344 | { |
tomo370 | 1:cf2f5992241c | 345 | dmxInHighBit = dmx.get(DMX_ParmSetMode1_H); |
tomo370 | 1:cf2f5992241c | 346 | dmxInLowBit = dmx.get(DMX_ParmSetMode1_L); |
tomo370 | 1:cf2f5992241c | 347 | if(dmxInHighBit == 102 && dmxInLowBit == 255) { |
tomo370 | 1:cf2f5992241c | 348 | manipulateMode1 = !manipulateMode1; |
tomo370 | 1:cf2f5992241c | 349 | blink(); |
tomo370 | 1:cf2f5992241c | 350 | } |
tomo370 | 1:cf2f5992241c | 351 | |
tomo370 | 1:cf2f5992241c | 352 | dmxInHighBit = dmx.get(DMX_ParmSetMode2_H); |
tomo370 | 1:cf2f5992241c | 353 | dmxInLowBit = dmx.get(DMX_ParmSetMode2_L); |
tomo370 | 1:cf2f5992241c | 354 | if(dmxInHighBit == 102 && dmxInLowBit == 255) { |
tomo370 | 1:cf2f5992241c | 355 | manipulateMode2 = !manipulateMode2; |
tomo370 | 1:cf2f5992241c | 356 | blink(); |
tomo370 | 1:cf2f5992241c | 357 | } |
tomo370 | 1:cf2f5992241c | 358 | } |
tomo370 | 1:cf2f5992241c | 359 | |
tomo370 | 1:cf2f5992241c | 360 | //書き込みボタンのチェック |
tomo370 | 1:cf2f5992241c | 361 | void checkWriteButton() |
tomo370 | 1:cf2f5992241c | 362 | { |
tomo370 | 1:cf2f5992241c | 363 | dmxInHighBit = dmx.get(DMX_SaveValue1_H); |
tomo370 | 1:cf2f5992241c | 364 | dmxInLowBit = dmx.get(DMX_SaveValue1_L); |
tomo370 | 1:cf2f5992241c | 365 | dmxInHighBit = dmxInHighBit << 8; |
tomo370 | 1:cf2f5992241c | 366 | param1 = (long)(dmxInHighBit + dmxInLowBit); |
tomo370 | 1:cf2f5992241c | 367 | |
tomo370 | 1:cf2f5992241c | 368 | dmxInHighBit = dmx.get(DMX_SaveValue2_H); |
tomo370 | 1:cf2f5992241c | 369 | dmxInLowBit = dmx.get(DMX_SaveValue2_L); |
tomo370 | 1:cf2f5992241c | 370 | dmxInHighBit = dmxInHighBit << 8; |
tomo370 | 1:cf2f5992241c | 371 | param2 = (long)(dmxInHighBit + dmxInLowBit); |
tomo370 | 1:cf2f5992241c | 372 | |
tomo370 | 1:cf2f5992241c | 373 | if(param1 == 24932) { |
tomo370 | 1:cf2f5992241c | 374 | paramStore1(); |
tomo370 | 1:cf2f5992241c | 375 | blink(); |
tomo370 | 1:cf2f5992241c | 376 | } else; |
tomo370 | 1:cf2f5992241c | 377 | |
tomo370 | 1:cf2f5992241c | 378 | if(param2 == 24932) { |
tomo370 | 2:198becff12f4 | 379 | paramStore2(); |
tomo370 | 2:198becff12f4 | 380 | blink(); |
tomo370 | 1:cf2f5992241c | 381 | } else; |
tomo370 | 1:cf2f5992241c | 382 | } |
tomo370 | 1:cf2f5992241c | 383 | |
tomo370 | 1:cf2f5992241c | 384 | |
tomo370 | 0:d94213e24c2e | 385 | int main() |
tomo370 | 0:d94213e24c2e | 386 | { |
tomo370 | 1:cf2f5992241c | 387 | //モーター1と2のコンフィギュレーション |
tomo370 | 0:d94213e24c2e | 388 | stepper1MS1 = 1; |
tomo370 | 0:d94213e24c2e | 389 | stepper1MS2 = 1; |
tomo370 | 0:d94213e24c2e | 390 | stepper1Enable = 0; |
tomo370 | 0:d94213e24c2e | 391 | |
tomo370 | 1:cf2f5992241c | 392 | stepper2MS1 = 1; |
tomo370 | 1:cf2f5992241c | 393 | stepper2MS2 = 1; |
tomo370 | 1:cf2f5992241c | 394 | stepper2Enable = 0; |
tomo370 | 1:cf2f5992241c | 395 | |
tomo370 | 0:d94213e24c2e | 396 | t.start(); |
tomo370 | 0:d94213e24c2e | 397 | |
tomo370 | 0:d94213e24c2e | 398 | dmxEnable = 0; //0:receiver 1:sender |
tomo370 | 0:d94213e24c2e | 399 | |
tomo370 | 0:d94213e24c2e | 400 | stepper1.setCurrentPosition(-1); |
tomo370 | 1:cf2f5992241c | 401 | stepper2.setCurrentPosition(-1); |
tomo370 | 0:d94213e24c2e | 402 | |
tomo370 | 3:dd2305e50390 | 403 | silence(); |
tomo370 | 3:dd2305e50390 | 404 | init1(); |
tomo370 | 3:dd2305e50390 | 405 | // init2(); |
tomo370 | 3:dd2305e50390 | 406 | |
tomo370 | 0:d94213e24c2e | 407 | |
tomo370 | 0:d94213e24c2e | 408 | stepper1.setMaxSpeed(25000); |
tomo370 | 0:d94213e24c2e | 409 | stepper1.setAcceleration(30000); |
tomo370 | 0:d94213e24c2e | 410 | stepper1.setCurrentPosition(0); |
tomo370 | 0:d94213e24c2e | 411 | |
tomo370 | 1:cf2f5992241c | 412 | stepper2.setMaxSpeed(25000); |
tomo370 | 1:cf2f5992241c | 413 | stepper2.setAcceleration(30000); |
tomo370 | 1:cf2f5992241c | 414 | stepper2.setCurrentPosition(0); |
tomo370 | 1:cf2f5992241c | 415 | |
tomo370 | 1:cf2f5992241c | 416 | myLED =1; |
tomo370 | 1:cf2f5992241c | 417 | |
tomo370 | 3:dd2305e50390 | 418 | |
tomo370 | 2:198becff12f4 | 419 | readROMValue1(); |
tomo370 | 2:198becff12f4 | 420 | readROMValue2(); |
tomo370 | 0:d94213e24c2e | 421 | |
tomo370 | 0:d94213e24c2e | 422 | while(1) { |
tomo370 | 0:d94213e24c2e | 423 | |
tomo370 | 1:cf2f5992241c | 424 | //操作モード切り替えボタンのチェック |
tomo370 | 1:cf2f5992241c | 425 | checkManipulateButton(); |
tomo370 | 1:cf2f5992241c | 426 | |
tomo370 | 1:cf2f5992241c | 427 | //書き込みボタンチェック |
tomo370 | 1:cf2f5992241c | 428 | checkWriteButton(); |
tomo370 | 0:d94213e24c2e | 429 | |
tomo370 | 1:cf2f5992241c | 430 | //モーター1の目標位置をスライダーから取得 |
tomo370 | 1:cf2f5992241c | 431 | dmxInHighBit = dmx.get(DMX_Position1_H); |
tomo370 | 1:cf2f5992241c | 432 | dmxInLowBit = dmx.get(DMX_Position1_L); |
tomo370 | 1:cf2f5992241c | 433 | dmxInHighBit = dmxInHighBit << 8; |
tomo370 | 1:cf2f5992241c | 434 | position1 = (long)(dmxInHighBit + dmxInLowBit); |
tomo370 | 0:d94213e24c2e | 435 | |
tomo370 | 1:cf2f5992241c | 436 | //モーター1の目標位置をスライダーから取得 |
tomo370 | 1:cf2f5992241c | 437 | dmxInHighBit = dmx.get(DMX_Position2_H); |
tomo370 | 1:cf2f5992241c | 438 | dmxInLowBit = dmx.get(DMX_Position2_L); |
tomo370 | 1:cf2f5992241c | 439 | dmxInHighBit = dmxInHighBit << 8; |
tomo370 | 1:cf2f5992241c | 440 | position2 = (long)(dmxInHighBit + dmxInLowBit); |
tomo370 | 0:d94213e24c2e | 441 | |
tomo370 | 0:d94213e24c2e | 442 | |
tomo370 | 1:cf2f5992241c | 443 | //手動モードの場合、現在のスライダーの値を取得、パラメーターを設定 |
tomo370 | 2:198becff12f4 | 444 | if(manipulateMode1 == false) { |
tomo370 | 1:cf2f5992241c | 445 | captureSliderValue(); |
tomo370 | 2:198becff12f4 | 446 | myLED = 0; |
tomo370 | 1:cf2f5992241c | 447 | } |
tomo370 | 0:d94213e24c2e | 448 | |
tomo370 | 1:cf2f5992241c | 449 | //自動モードの場合、EEPROMから値を取得、パラメーターを設定 |
tomo370 | 1:cf2f5992241c | 450 | else { |
tomo370 | 2:198becff12f4 | 451 | myLED = 1; |
tomo370 | 2:198becff12f4 | 452 | |
tomo370 | 1:cf2f5992241c | 453 | } |
tomo370 | 0:d94213e24c2e | 454 | |
tomo370 | 2:198becff12f4 | 455 | //手動モードの場合、現在のスライダーの値を取得、パラメーターを設定 |
tomo370 | 2:198becff12f4 | 456 | if(manipulateMode2 == false) { |
tomo370 | 2:198becff12f4 | 457 | captureSliderValue(); |
tomo370 | 2:198becff12f4 | 458 | myLED = 0; |
tomo370 | 2:198becff12f4 | 459 | } |
tomo370 | 2:198becff12f4 | 460 | |
tomo370 | 2:198becff12f4 | 461 | //自動モードの場合、EEPROMから値を取得、パラメータを設定 |
tomo370 | 2:198becff12f4 | 462 | else { |
tomo370 | 2:198becff12f4 | 463 | myLED = 1; |
tomo370 | 2:198becff12f4 | 464 | } |
tomo370 | 1:cf2f5992241c | 465 | |
tomo370 | 1:cf2f5992241c | 466 | position1 = map(position1, 0, 0xFFFF, 0, max1); |
tomo370 | 1:cf2f5992241c | 467 | stepper1.setMaxSpeed(speed1); |
tomo370 | 1:cf2f5992241c | 468 | stepper1.setAcceleration(Acceleration1); |
tomo370 | 1:cf2f5992241c | 469 | |
tomo370 | 2:198becff12f4 | 470 | position2 = map(position2, 0, 0xFFFF, 0, max2); |
tomo370 | 2:198becff12f4 | 471 | stepper2.setMaxSpeed(speed2); |
tomo370 | 2:198becff12f4 | 472 | stepper2.setAcceleration(Acceleration2); |
tomo370 | 1:cf2f5992241c | 473 | |
tomo370 | 1:cf2f5992241c | 474 | stepper1.moveTo(position1); |
tomo370 | 2:198becff12f4 | 475 | stepper2.moveTo(position2); |
tomo370 | 1:cf2f5992241c | 476 | |
tomo370 | 1:cf2f5992241c | 477 | checkSafeBreak(); |
tomo370 | 1:cf2f5992241c | 478 | stepper1.run(); |
tomo370 | 2:198becff12f4 | 479 | stepper2.run(); |
tomo370 | 1:cf2f5992241c | 480 | } |
tomo370 | 1:cf2f5992241c | 481 | } |