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