質問編集履歴
2
全スケッチを記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,12 +48,248 @@
|
|
48
48
|
|
49
49
|
|
50
50
|
|
51
|
+
#include <SPI.h>
|
52
|
+
|
53
|
+
#include <MsTimer2.h>
|
54
|
+
|
55
|
+
#include <stdio.h>
|
56
|
+
|
57
|
+
#include <SoftwareSerial.h>
|
58
|
+
|
59
|
+
#include <Wire.h>
|
60
|
+
|
61
|
+
#include <DFRobot_QMC5883.h>
|
62
|
+
|
63
|
+
#include <A4988.h>
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
//RunMotor PIN-difinitions
|
68
|
+
|
69
|
+
#define PIN_SPI_MOSI 51
|
70
|
+
|
71
|
+
#define PIN_SPI_MISO 50
|
72
|
+
|
73
|
+
#define PIN_SPI_SCK 52
|
74
|
+
|
75
|
+
#define PIN_SPI_SS 53
|
76
|
+
|
77
|
+
#define PIN_BUSY 44
|
78
|
+
|
79
|
+
#define PIN_BUSY2 46
|
80
|
+
|
81
|
+
#define PIN_BUSY3 45
|
82
|
+
|
83
|
+
#define PIN_BUSY4 47
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
//Joystick difinitions
|
88
|
+
|
89
|
+
const int analogInPinUD = A0; // UDアナログ入力ピン(定数)
|
90
|
+
|
91
|
+
const int analogInPinLR = A1; // LRアナログ入力ピン(定数)
|
92
|
+
|
93
|
+
int UD = 0; // Up-DownのAD値(変数)
|
94
|
+
|
95
|
+
int LR = 0; // Left-RightのAD値(変数)
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
//MODE switch difinitions
|
100
|
+
|
101
|
+
const int DIN_PIN_run_auto = 2;
|
102
|
+
|
103
|
+
const int DIN_PIN_beforeLift = 3;
|
104
|
+
|
105
|
+
const int DIN_PIN_AfterLift = 22;
|
106
|
+
|
107
|
+
const int DIN_PIN_run_manual = 4;
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
//LinearActuator difinitions
|
112
|
+
|
113
|
+
#define PIN_LinearA_1 10
|
114
|
+
|
115
|
+
#define PIN_LinearA_2 11
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
//LiftMotor difinitions
|
120
|
+
|
121
|
+
const int MOTOR_STEPS = 400;
|
122
|
+
|
123
|
+
const int DIR = 8;
|
124
|
+
|
125
|
+
const int STEP = 9;
|
126
|
+
|
127
|
+
float rpm = 135; //0.88sm/sec 140以上は微脱調
|
128
|
+
|
129
|
+
int microsteps = 1;
|
130
|
+
|
131
|
+
#define MOTOR_ACCEL 400
|
132
|
+
|
133
|
+
#define MOTOR_DECEL 400
|
134
|
+
|
135
|
+
A4988 stepper(MOTOR_STEPS, DIR, STEP);
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
void setup(){
|
142
|
+
|
143
|
+
Serial.begin(115200);
|
144
|
+
|
145
|
+
// MODE switch setting
|
146
|
+
|
147
|
+
pinMode( DIN_PIN_run_auto, INPUT_PULLUP );
|
148
|
+
|
149
|
+
pinMode( DIN_PIN_beforeLift, INPUT_PULLUP );
|
150
|
+
|
151
|
+
pinMode( DIN_PIN_AfterLift, INPUT_PULLUP );
|
152
|
+
|
153
|
+
pinMode( DIN_PIN_run_manual, INPUT_PULLUP );
|
154
|
+
|
155
|
+
// RunMotor setting
|
156
|
+
|
157
|
+
pinMode( PIN_SPI_MOSI, OUTPUT);
|
158
|
+
|
159
|
+
pinMode( PIN_SPI_MISO, INPUT);
|
160
|
+
|
161
|
+
pinMode( PIN_SPI_SCK, OUTPUT);
|
162
|
+
|
163
|
+
pinMode( PIN_SPI_SS, OUTPUT);
|
164
|
+
|
165
|
+
pinMode( PIN_BUSY, INPUT_PULLUP);
|
166
|
+
|
167
|
+
pinMode( PIN_BUSY2, INPUT_PULLUP);
|
168
|
+
|
169
|
+
pinMode( PIN_BUSY3, INPUT_PULLUP);
|
170
|
+
|
171
|
+
pinMode( PIN_BUSY4, INPUT_PULLUP);
|
172
|
+
|
173
|
+
SPI.begin();
|
174
|
+
|
175
|
+
SPI.setDataMode(SPI_MODE3);
|
176
|
+
|
177
|
+
SPI.setBitOrder(MSBFIRST);
|
178
|
+
|
179
|
+
digitalWrite(PIN_SPI_SS, HIGH);
|
180
|
+
|
181
|
+
// LinearActuator setting
|
182
|
+
|
183
|
+
pinMode( PIN_LinearA_1, OUTPUT);
|
184
|
+
|
185
|
+
pinMode( PIN_LinearA_2, OUTPUT);
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
// Serial setting
|
190
|
+
|
191
|
+
// EspSerial2.begin(9600);
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
// RunMotor setting
|
196
|
+
|
197
|
+
L6470_resetdevice(); //1台目のL6470リセット
|
198
|
+
|
51
|
-
L6470
|
199
|
+
L6470_resetdevice2(); //2台目のL6470リセット
|
200
|
+
|
201
|
+
L6470_resetdevice3(); //3台目のL6470リセット
|
202
|
+
|
203
|
+
L6470_resetdevice4(); //4台目のL6470リセット
|
204
|
+
|
205
|
+
L6470_setup(); //1台目のL6470を設定
|
206
|
+
|
207
|
+
L6470_setup2(); //2台目のL6470を設定
|
208
|
+
|
209
|
+
L6470_setup3(); //3台目のL6470を設定
|
210
|
+
|
211
|
+
L6470_setup4(); //4台目のL6470を設定
|
212
|
+
|
213
|
+
L6470_getstatus(); //1台目のフラグ解放
|
214
|
+
|
215
|
+
L6470_getstatus2();//2台目のフラグ解放
|
216
|
+
|
217
|
+
L6470_getstatus3();//3台目のフラグ解放
|
218
|
+
|
219
|
+
L6470_getstatus4();//4台目のフラグ解放
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
MsTimer2::set(25, fulash);//シリアルモニター用のタイマー割り込み
|
224
|
+
|
225
|
+
MsTimer2::start();
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
void loop(){
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
int runspeed = 10000;
|
238
|
+
|
239
|
+
L6470_run(0,runspeed);
|
240
|
+
|
241
|
+
L6470_run2(0,runspeed);
|
242
|
+
|
243
|
+
L6470_run3(1,runspeed);
|
244
|
+
|
245
|
+
L6470_run4(1,runspeed);
|
246
|
+
|
247
|
+
delay(5000);
|
248
|
+
|
249
|
+
L6470_softstop();//回転停止、保持トルクあり
|
250
|
+
|
251
|
+
L6470_softstop2();//回転停止、保持トルクあり
|
252
|
+
|
253
|
+
L6470_softstop3();//回転停止、保持トルクあり
|
254
|
+
|
255
|
+
L6470_softstop4();//回転停止、保持トルクあり
|
256
|
+
|
257
|
+
delay(2000);
|
258
|
+
|
259
|
+
Serial.println("run");
|
260
|
+
|
261
|
+
}
|
52
262
|
|
53
263
|
|
54
264
|
|
55
265
|
void L6470_setup(){
|
56
266
|
|
267
|
+
/////////SM-42BYG011-25 setting
|
268
|
+
|
269
|
+
//L6470_setparam_acc(0x005); //[R, WS] 加速度default 0x08A (12bit) (14.55*val+14.55[step/s^2])
|
270
|
+
|
271
|
+
//L6470_setparam_dec(0x005); //[R, WS] 減速度default 0x08A (12bit) (14.55*val+14.55[step/s^2])
|
272
|
+
|
273
|
+
//L6470_setparam_maxspeed(0x25); //[R, WR]最大速度default 0x041 (10bit) (15.25*val+15.25[step/s])
|
274
|
+
|
275
|
+
//L6470_setparam_minspeed(0x02); //[R, WS]最小速度default 0x000 (1+12bit) (0.238*val[step/s])
|
276
|
+
|
277
|
+
//L6470_setparam_fsspd(0x027); //[R, WR]μステップからフルステップへの切替点速度default 0x027 (10bit) (15.25*val+7.63[step/s])
|
278
|
+
|
279
|
+
//L6470_setparam_kvalhold(0x50); //[R, WR]停止時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
280
|
+
|
281
|
+
//L6470_setparam_kvalrun(0xFF); //[R, WR]定速回転時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
282
|
+
|
283
|
+
//L6470_setparam_kvalacc(0xFF); //[R, WR]加速時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
284
|
+
|
285
|
+
//L6470_setparam_kvaldec(0xFF); //[R, WR]減速時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
286
|
+
|
287
|
+
//L6470_setparam_stepmood(0x01); //ステップモードdefault 0x07 (1+3+1+3bit)
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
/////////42SHD4404-24 setting
|
292
|
+
|
57
293
|
L6470_setparam_acc(0x005); //[R, WS] 加速度default 0x08A (12bit) (14.55*val+14.55[step/s^2])
|
58
294
|
|
59
295
|
L6470_setparam_dec(0x005); //[R, WS] 減速度default 0x08A (12bit) (14.55*val+14.55[step/s^2])
|
@@ -78,25 +314,155 @@
|
|
78
314
|
|
79
315
|
|
80
316
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
317
|
+
void L6470_setup2(){
|
318
|
+
|
319
|
+
L6470_setparam_acc2(0x005); //[R, WS] 加速度default 0x08A (12bit) (14.55*val+14.55[step/s^2])
|
320
|
+
|
321
|
+
L6470_setparam_dec2(0x005); //[R, WS] 減速度default 0x08A (12bit) (14.55*val+14.55[step/s^2])
|
322
|
+
|
323
|
+
L6470_setparam_maxspeed2(0x25); //[R, WR]最大速度default 0x041 (10bit) (15.25*val+15.25[step/s])
|
324
|
+
|
325
|
+
L6470_setparam_minspeed2(0x02); //[R, WS]最小速度default 0x000 (1+12bit) (0.238*val[step/s])
|
326
|
+
|
327
|
+
L6470_setparam_fsspd2(0x027); //[R, WR]μステップからフルステップへの切替点速度default 0x027 (10bit) (15.25*val+7.63[step/s])
|
328
|
+
|
329
|
+
L6470_setparam_kvalhold2(0x50); //[R, WR]停止時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
330
|
+
|
331
|
+
L6470_setparam_kvalrun2(0xFF); //[R, WR]定速回転時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
332
|
+
|
333
|
+
L6470_setparam_kvalacc2(0xFF); //[R, WR]加速時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
334
|
+
|
335
|
+
L6470_setparam_kvaldec2(0xFF); //[R, WR]減速時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
336
|
+
|
337
|
+
L6470_setparam_stepmood2(0x01); //ステップモードdefault 0x07 (1+3+1+3bit)
|
338
|
+
|
339
|
+
}
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
void L6470_setup3(){
|
344
|
+
|
345
|
+
L6470_setparam_acc3(0x005); //[R, WS] 加速度default 0x08A (12bit) (14.55*val+14.55[step/s^2])
|
346
|
+
|
347
|
+
L6470_setparam_dec3(0x005); //[R, WS] 減速度default 0x08A (12bit) (14.55*val+14.55[step/s^2])
|
348
|
+
|
349
|
+
L6470_setparam_maxspeed3(0x25); //[R, WR]最大速度default 0x041 (10bit) (15.25*val+15.25[step/s])
|
350
|
+
|
351
|
+
L6470_setparam_minspeed3(0x02); //[R, WS]最小速度default 0x000 (1+12bit) (0.238*val[step/s])
|
352
|
+
|
353
|
+
L6470_setparam_fsspd3(0x027); //[R, WR]μステップからフルステップへの切替点速度default 0x027 (10bit) (15.25*val+7.63[step/s])
|
354
|
+
|
355
|
+
L6470_setparam_kvalhold3(0x50); //[R, WR]停止時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
356
|
+
|
357
|
+
L6470_setparam_kvalrun3(0xFF); //[R, WR]定速回転時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
358
|
+
|
359
|
+
L6470_setparam_kvalacc3(0xFF); //[R, WR]加速時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
360
|
+
|
361
|
+
L6470_setparam_kvaldec3(0xFF); //[R, WR]減速時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
362
|
+
|
363
|
+
L6470_setparam_stepmood3(0x01); //ステップモードdefault 0x07 (1+3+1+3bit)
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
void L6470_setup4(){
|
370
|
+
|
371
|
+
L6470_setparam_acc4(0x005); //[R, WS] 加速度default 0x08A (12bit) (14.55*val+14.55[step/s^2])
|
372
|
+
|
373
|
+
L6470_setparam_dec4(0x005); //[R, WS] 減速度default 0x08A (12bit) (14.55*val+14.55[step/s^2])
|
374
|
+
|
375
|
+
L6470_setparam_maxspeed4(0x25); //[R, WR]最大速度default 0x041 (10bit) (15.25*val+15.25[step/s])
|
376
|
+
|
377
|
+
L6470_setparam_minspeed4(0x02); //[R, WS]最小速度default 0x000 (1+12bit) (0.238*val[step/s])
|
378
|
+
|
379
|
+
L6470_setparam_fsspd4(0x027); //[R, WR]μステップからフルステップへの切替点速度default 0x027 (10bit) (15.25*val+7.63[step/s])
|
380
|
+
|
381
|
+
L6470_setparam_kvalhold4(0x50); //[R, WR]停止時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
382
|
+
|
383
|
+
L6470_setparam_kvalrun4(0xFF); //[R, WR]定速回転時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
384
|
+
|
385
|
+
L6470_setparam_kvalacc4(0xFF); //[R, WR]加速時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
386
|
+
|
387
|
+
L6470_setparam_kvaldec4(0xFF); //[R, WR]減速時励磁電圧default 0x29 (8bit) (Vs[V]*val/256)
|
388
|
+
|
389
|
+
L6470_setparam_stepmood4(0x01); //ステップモードdefault 0x07 (1+3+1+3bit)
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
void fulash(){
|
398
|
+
|
399
|
+
//long a=L6470_getparam_abspos();
|
400
|
+
|
401
|
+
//long b=L6470_getparam_speed();
|
402
|
+
|
403
|
+
//long c=L6470_getparam_abspos2();
|
404
|
+
|
405
|
+
//long d=L6470_getparam_speed2();
|
406
|
+
|
407
|
+
//long e=L6470_getparam_abspos3();
|
408
|
+
|
409
|
+
//long f=L6470_getparam_speed3();
|
410
|
+
|
411
|
+
//long g=L6470_getparam_abspos4();
|
412
|
+
|
413
|
+
//long h=L6470_getparam_speed4();
|
414
|
+
|
415
|
+
//char str[15];
|
416
|
+
|
417
|
+
//snprintf(str,sizeof(str),"1pos=0x%6.6X ",a);
|
418
|
+
|
419
|
+
//Serial.print(str);
|
420
|
+
|
421
|
+
//snprintf(str,sizeof(str),"1spd=0x%5.5X ",b);
|
422
|
+
|
423
|
+
//Serial.print(str);
|
424
|
+
|
425
|
+
//snprintf(str,sizeof(str),"2pos=0x%6.6X ",c);
|
426
|
+
|
427
|
+
//Serial.print(str);
|
428
|
+
|
429
|
+
//snprintf(str,sizeof(str),"2spd=0x%5.5X ",d);
|
430
|
+
|
431
|
+
//Serial.println(str);
|
432
|
+
|
433
|
+
//snprintf(str,sizeof(str),"3pos=0x%6.6X ",e);
|
434
|
+
|
435
|
+
//Serial.print(str);
|
436
|
+
|
437
|
+
//snprintf(str,sizeof(str),"3spd=0x%5.5X ",f);
|
438
|
+
|
439
|
+
//Serial.println(str);
|
440
|
+
|
441
|
+
//snprintf(str,sizeof(str),"3pos=0x%6.6X ",g);
|
442
|
+
|
443
|
+
//Serial.print(str);
|
444
|
+
|
445
|
+
//snprintf(str,sizeof(str),"3spd=0x%5.5X ",h);
|
446
|
+
|
447
|
+
//Serial.println(str);
|
448
|
+
|
449
|
+
/* Serial.print("0x");
|
450
|
+
|
451
|
+
Serial.print( L6470_getparam_abspos(),HEX);
|
452
|
+
|
453
|
+
Serial.print(" 0x");
|
454
|
+
|
455
|
+
Serial.print( L6470_getparam_speed(),HEX);
|
456
|
+
|
457
|
+
Serial.print(" 0x");
|
458
|
+
|
459
|
+
Serial.print( L6470_getparam_abspos2(),HEX);
|
460
|
+
|
461
|
+
Serial.print(" 0x");
|
462
|
+
|
463
|
+
Serial.println( L6470_getparam_speed2(),HEX);
|
464
|
+
|
465
|
+
*/
|
100
466
|
|
101
467
|
}
|
102
468
|
|
1
使用電池の種類を記述しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -145,3 +145,5 @@
|
|
145
145
|
|
146
146
|
|
147
147
|
ドライバへの印加電圧は14Vです。
|
148
|
+
|
149
|
+
[電池](https://www.amazon.co.jp/gp/product/B07VFD6797/ref=ppx_yo_dt_b_asin_title_o06_s00?ie=UTF8&psc=1)を使って駆動しています
|