user_motor.c
72.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
#include "user_motor.h"
DriverStruct DriverMotor1;
DriverStruct DriverMotor2;
DriverStruct DriverMotor3;
DriverStruct DriverMotor4;
DriverStruct DriverSteering1;
DriverStruct DriverSteering2;
DriverStruct DriverSteering3;
DriverStruct DriverSteering4;
DriverStruct DriverLifter1;
DriverStruct DriverLifter2;
DriverStruct DriverLifter3;
DriverStruct DriverLifter4;
DriverStruct DriverShifter1;
DriverStruct DriverShifter2;
DriverStruct DriverShifter3;
DriverStruct DriverPusher1;
DriverStruct DriverPusher2;
DriverStruct DriverPusher3;
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_SDO))
unsigned char quick_stop_back[] = {0x00};
unsigned char motor_reset[] = {0x81, 0x00};
unsigned char msg_set_heartbeat_time[] = {0x2B, 0x16, 0x10, 0x01, 0xD0, 0x07, 0x01, 0x00};
unsigned char msg_set_heartbeat[] = {0x2B, 0x17, 0x10, 0x00, 0xB8, 0x0B, 0x00, 0x00};
unsigned char msg_send_heartbeat[] = {0x00};
unsigned char msg_setmode[8] = {0x2F, 0x60, 0x60, 0x00, 0x03, 0x00, 0x00, 0x00}; //速度模式
unsigned char msg_setmode_back[8] = {0x60, 0x60, 0x60, 0x00, 0x03, 0x00, 0x00, 0x00};
unsigned char msg_disable06[] = {0x2B, 0x40, 0x60, 0x00, 0x06, 0x00, 0x00, 0x00}; // node 禁止
unsigned char msg_disable[] = {0x2B, 0x40, 0x60, 0x00, 0x07, 0x00, 0x00, 0x00}; // node 禁止
unsigned char msg_enable[] = {0x2B, 0x40, 0x60, 0x00, 0x0F, 0x00, 0x00, 0x00}; // node 使能
unsigned char enable_back[] = {0x60, 0x40, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}; //使能驱动器成功返回
//unsigned char msg_BK_disable_backTwo[8] = {0x0F,0x40,0x60,0x00,0x07,0x00,0x00,0x00};
unsigned char msg_setspeed[8] = {0x23, 0xFF, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}; //设置速度
unsigned char msg_setspeed_back[8] = {0x60, 0xFF, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char msg_getpos[8] = {0x40, 0x64, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char msg_getpos_back[8] = {0x43, 0x64, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char msg_getspeed[8] = {0x40, 0x6C, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char msg_getspeed_back[8] = {0x43, 0x6C, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char msg_getVoltage[8] = {0x40, 0x79, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char msg_getVoltage_back[8] = {0x43, 0x79, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00};
unsigned char msg_get_state[] = {0x40, 0x41, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}; //获取驱动器状态
unsigned char msg_get_state_back[] = {0x4B, 0x41, 0x60, 0x00, 0x28, 0x00, 0x00, 0x00};
unsigned char msg_read_ampere[] = {0x40, 0x77, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}; //读驱动器的温度
unsigned char msg_read_ampere_back[] = {0x4B, 0x77, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}; //读驱动器的温度返回
#endif
static u8 EmptyBuffer[] = {0, 0, 0, 0, 0, 0, 0, 0};
u32 driverShareErrorInfo = 0; //由于结构体不能定义static 变量 此变量为所有驱动器可读写的变量 代表有驱动出现错误
bool allDriverEnable = 0; //所有驱动在速度为0时候不关使能
double SendSpeedCoefficient(void)
{
double num = P_SETUP_MOTOR_SPEED_RATIO_NUM;
double den = P_SETUP_MOTOR_SPEED_RATIO_DEN;
return num / den;
}
double GetPosCoefficient(void)
{
double num = P_SETUP_MOTOR_DIS_RATIO_NUM;
double den = P_SETUP_MOTOR_DIS_RATIO_DEN;
return num / den;
}
double SendPalstanceCoefficient(void)
{
double num = P_SETUP_STEERING_SPEED_RATIO_NUM;
double den = P_SETUP_STEERING_SPEED_RATIO_DEN;
return num / den;
}
double GetPalstanceCoefficient(void)
{
double num = P_SETUP_STEERING_SPEED_RATIO_NUM;
double den = P_SETUP_STEERING_SPEED_RATIO_DEN;
return num / den;
}
double SendLiftingSpeedCoefficient(void)
{
double num = P_SETUP_LIFTER_SPEED_RATIO_NUM;
double den = P_SETUP_LIFTER_SPEED_RATIO_DEN;
return num / den;
// return 1;
}
double GetLiftingPosValueBack(void)
{
double num = P_SETUP_LIFTER_DIS_RATIO_NUM;
double den = P_SETUP_LIFTER_DIS_RATIO_DEN;
return num / den; //1
// return 1.0/100000.0;
}
double SendShifterSpeedValue(void)
{
double num = P_SETUP_SHIFTER_SPEED_RATIO_NUM;
double den = P_SETUP_SHIFTER_SPEED_RATIO_DEN;
return num / den;
// return 1;
}
double GetShifterPosValueBack(void)
{
double num = P_SETUP_SHIFTER_DIS_RATIO_NUM;
double den = P_SETUP_SHIFTER_DIS_RATIO_DEN;
return num / den;
// return 1.0/260000.0;
}
double SendPusherSpeedValue(void)
{
double num = P_SETUP_PUSHER_SPEED_RATIO_NUM;
double den = P_SETUP_PUSHER_SPEED_RATIO_DEN;
return num / den;
// return 1;
}
double GetPusherPosValueBack(void)
{
double num = P_SETUP_PUSHER_DIS_RATIO_NUM;
double den = P_SETUP_PUSHER_DIS_RATIO_DEN;
return num / den;
// return 1.0/60000.0;
}
float getSpeedSlope(DriverStruct *Motor)
{
float currentSpeed = Motor->Private.lastSpeed;
float speedSlope = Motor->Command.speedSlope;
float tarSpeed = Motor->Command.speed;
float sendSpeed = 0;
if (tarSpeed > currentSpeed)
{
sendSpeed = currentSpeed + speedSlope;
}
else if (tarSpeed < currentSpeed)
{
sendSpeed = currentSpeed - speedSlope;
}
if (_fabsf(currentSpeed - tarSpeed) <= speedSlope)
{
sendSpeed = tarSpeed;
}
Motor->Private.lastSpeed = sendSpeed;
return sendSpeed;
}
int getDecimalMap(short Dec, u8 Bit)
{
if (Bit == 5)
{
if (Dec / 10000 % 10 == 1)
return -1;
else
return 1;
}
else if (Bit == 4)
{
if (Dec / 1000 % 10 == 1)
return -1;
else
return 1;
}
else if (Bit == 3)
{
if (Dec / 100 % 10 == 1)
return -1;
else
return 1;
}
else if (Bit == 2)
{
if (Dec / 10 % 10 == 1)
return -1;
else
return 1;
}
else if (Bit == 1)
{
if (Dec / 1 % 10 == 1)
return -1;
else
return 1;
}
return 0;
}
void change_data(u8 *_data, int data)
{
u32 ch_data = (u32)data;
_data[4] = ch_data & 0xff;
_data[5] = (ch_data >> 8) & 0xff;
_data[6] = (ch_data >> 16) & 0xff;
_data[7] = (ch_data >> 24) & 0xff;
}
void change_data_zero(u8 *_data)
{
_data[4] = 0;
_data[5] = 0;
_data[6] = 0;
_data[7] = 0;
}
void initDriverParam(void)
{
u8 hinsEmptyBuffer[8] = {0, 1, 0, 0, 0, 0, 0, 0};
/***********************************************行走驱动参数初始化************************************************************************************************/
{
DriverMotor1.Private.driverID = MOTOR1_ID; //驱动ID
DriverMotor2.Private.driverID = MOTOR2_ID;
DriverMotor3.Private.driverID = MOTOR3_ID;
DriverMotor4.Private.driverID = MOTOR4_ID;
#if (P_SETUP_MOTOR_NUM == P_SETUP_STEERING_NUM)
{
hinsEmptyBuffer[1] = 1;
DriverMotor1.Private.slaveID = hinsEmptyBuffer[0] = 1; //一拖二驱动 驱动子ID
memcpy(DriverMotor1.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverMotor2.Private.slaveID = hinsEmptyBuffer[0] = 1;
memcpy(DriverMotor2.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverMotor3.Private.slaveID = hinsEmptyBuffer[0] = 1;
memcpy(DriverMotor3.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverMotor4.Private.slaveID = hinsEmptyBuffer[0] = 1;
memcpy(DriverMotor4.Private.sendBuffer, hinsEmptyBuffer, 8);
}
#else
{
#if (P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_HINS_BLD2L)
{
DriverMotor1.Private.slaveID = hinsEmptyBuffer[0] = 1; //一拖二驱动 驱动子ID
memcpy(DriverMotor1.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverMotor2.Private.slaveID = hinsEmptyBuffer[0] = 2;
memcpy(DriverMotor2.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverMotor3.Private.slaveID = hinsEmptyBuffer[0] = 1;
memcpy(DriverMotor3.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverMotor4.Private.slaveID = hinsEmptyBuffer[0] = 2;
memcpy(DriverMotor4.Private.sendBuffer, hinsEmptyBuffer, 8);
}
#else
{
DriverMotor1.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 1; //一拖二驱动 驱动子ID
memcpy(DriverMotor1.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverMotor2.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 2;
memcpy(DriverMotor2.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverMotor3.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 1;
memcpy(DriverMotor3.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverMotor4.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 2;
memcpy(DriverMotor4.Private.sendBuffer, hinsEmptyBuffer, 8);
}
#endif
}
#endif
DriverMotor1.driverShareErrorInfo = DriverMotor2.driverShareErrorInfo = DriverMotor3.driverShareErrorInfo = DriverMotor4.driverShareErrorInfo = &driverShareErrorInfo;
DriverMotor1.Private.sendHeartBeatCount = DriverMotor1.Private.readStateCount = DriverMotor1.Private.readAmpereCount = 0;
DriverMotor2.Private.sendHeartBeatCount = DriverMotor2.Private.readStateCount = DriverMotor2.Private.readAmpereCount = 1;
DriverMotor3.Private.sendHeartBeatCount = DriverMotor3.Private.readStateCount = DriverMotor3.Private.readAmpereCount = 2;
DriverMotor4.Private.sendHeartBeatCount = DriverMotor4.Private.readStateCount = DriverMotor4.Private.readAmpereCount = 3;
DriverMotor1.Private.canSelect = getDecimalMap(P_SETUP_MOTOR_CAN_CONNECTION, 4); //CAN口选择
DriverMotor2.Private.canSelect = getDecimalMap(P_SETUP_MOTOR_CAN_CONNECTION, 3);
DriverMotor3.Private.canSelect = getDecimalMap(P_SETUP_MOTOR_CAN_CONNECTION, 2);
DriverMotor4.Private.canSelect = getDecimalMap(P_SETUP_MOTOR_CAN_CONNECTION, 1);
DriverMotor1.Private.driverBrand = DriverMotor2.Private.driverBrand = DriverMotor3.Private.driverBrand = DriverMotor4.Private.driverBrand = P_SETUP_MOTOR_DRIVER_BRAND; //驱动品牌
//发送速度系数 读取速度系数 读取位置系数
DriverMotor1.Private.sendSpeedCoefficient = DriverMotor2.Private.sendSpeedCoefficient = DriverMotor3.Private.sendSpeedCoefficient = DriverMotor4.Private.sendSpeedCoefficient = SendSpeedCoefficient();
DriverMotor1.Private.getSpeedCoefficient = DriverMotor2.Private.getSpeedCoefficient = DriverMotor3.Private.getSpeedCoefficient = DriverMotor4.Private.getSpeedCoefficient = (1.0 / SendSpeedCoefficient());
DriverMotor1.Private.getPoseCoefficient = DriverMotor2.Private.getPoseCoefficient = DriverMotor3.Private.getPoseCoefficient = DriverMotor4.Private.getPoseCoefficient = GetPosCoefficient();
//发送速度系数正反转方向调整
DriverMotor1.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_MOTOR_DIR, 4);
DriverMotor2.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_MOTOR_DIR, 3);
DriverMotor3.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_MOTOR_DIR, 2);
DriverMotor4.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_MOTOR_DIR, 1);
//读取速度系数正反转方向调整
DriverMotor1.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_MOTOR_DIR, 4);
DriverMotor2.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_MOTOR_DIR, 3);
DriverMotor3.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_MOTOR_DIR, 2);
DriverMotor4.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_MOTOR_DIR, 1);
//读取位置系数正反转方向调整
DriverMotor1.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_MOTOR_DIR, 4);
DriverMotor2.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_MOTOR_DIR, 3);
DriverMotor3.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_MOTOR_DIR, 2);
DriverMotor4.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_MOTOR_DIR, 1);
}
/***********************************************转向驱动参数初始化********************************************************************************************/
{
DriverSteering1.Private.driverID = STEERING1_ID; //驱动ID
DriverSteering2.Private.driverID = STEERING2_ID;
DriverSteering3.Private.driverID = STEERING3_ID;
DriverSteering4.Private.driverID = STEERING4_ID;
#if (P_SETUP_MOTOR_NUM == P_SETUP_STEERING_NUM)
{
hinsEmptyBuffer[1] = 1;
DriverSteering1.Private.slaveID = hinsEmptyBuffer[0] = 1; //一拖二驱动 驱动子ID
memcpy(DriverSteering1.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverSteering2.Private.slaveID = hinsEmptyBuffer[0] = 2;
memcpy(DriverSteering2.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverSteering3.Private.slaveID = hinsEmptyBuffer[0] = 1;
memcpy(DriverSteering3.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverSteering4.Private.slaveID = hinsEmptyBuffer[0] = 2;
memcpy(DriverSteering4.Private.sendBuffer, hinsEmptyBuffer, 8);
}
#else
{
DriverSteering1.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 1; //一拖二驱动 驱动子ID
memcpy(DriverSteering1.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverSteering2.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 2;
memcpy(DriverSteering2.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverSteering3.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 1;
memcpy(DriverSteering3.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverSteering4.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 2;
memcpy(DriverSteering4.Private.sendBuffer, hinsEmptyBuffer, 8);
}
#endif
DriverSteering1.driverShareErrorInfo = DriverSteering2.driverShareErrorInfo = DriverSteering3.driverShareErrorInfo = DriverSteering4.driverShareErrorInfo = &driverShareErrorInfo;
DriverSteering1.Private.sendHeartBeatCount = DriverSteering1.Private.readStateCount = DriverSteering1.Private.readAmpereCount = 4;
DriverSteering2.Private.sendHeartBeatCount = DriverSteering2.Private.readStateCount = DriverSteering2.Private.readAmpereCount = 5;
DriverSteering3.Private.sendHeartBeatCount = DriverSteering3.Private.readStateCount = DriverSteering3.Private.readAmpereCount = 6;
DriverSteering4.Private.sendHeartBeatCount = DriverSteering4.Private.readStateCount = DriverSteering4.Private.readAmpereCount = 7;
DriverSteering1.Private.canSelect = getDecimalMap(P_SETUP_STEERING_CAN_CONNECTION, 4); //CAN口选择
DriverSteering2.Private.canSelect = getDecimalMap(P_SETUP_STEERING_CAN_CONNECTION, 3);
DriverSteering3.Private.canSelect = getDecimalMap(P_SETUP_STEERING_CAN_CONNECTION, 2);
DriverSteering4.Private.canSelect = getDecimalMap(P_SETUP_STEERING_CAN_CONNECTION, 1);
DriverSteering1.Private.driverBrand = DriverSteering2.Private.driverBrand = DriverSteering3.Private.driverBrand = DriverSteering4.Private.driverBrand = P_SETUP_STEERING_DRIVER_BRAND; //驱动品牌
//发送速度系数 读取速度系数 读取位置系数
DriverSteering1.Private.sendSpeedCoefficient = DriverSteering2.Private.sendSpeedCoefficient = DriverSteering3.Private.sendSpeedCoefficient = DriverSteering4.Private.sendSpeedCoefficient = SendPalstanceCoefficient();
DriverSteering1.Private.getSpeedCoefficient = DriverSteering2.Private.getSpeedCoefficient = DriverSteering3.Private.getSpeedCoefficient = DriverSteering4.Private.getSpeedCoefficient = (1.0 / SendPalstanceCoefficient());
DriverSteering1.Private.getPoseCoefficient = DriverSteering2.Private.getPoseCoefficient = DriverSteering3.Private.getPoseCoefficient = DriverSteering4.Private.getPoseCoefficient = GetPalstanceCoefficient();
//发送速度系数正反转方向调整
DriverSteering1.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_STEERING_DIR, 4);
DriverSteering2.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_STEERING_DIR, 3);
DriverSteering3.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_STEERING_DIR, 2);
DriverSteering4.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_STEERING_DIR, 1);
//读取速度系数正反转方向调整
DriverSteering1.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_STEERING_DIR, 4);
DriverSteering2.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_STEERING_DIR, 3);
DriverSteering3.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_STEERING_DIR, 2);
DriverSteering4.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_STEERING_DIR, 1);
}
/***********************************************举升驱动参数初始化************************************************************************************************/
{
DriverLifter1.Private.driverID = LIFTER1_ID; //驱动ID
DriverLifter2.Private.driverID = LIFTER2_ID;
DriverLifter3.Private.driverID = LIFTER3_ID;
DriverLifter4.Private.driverID = LIFTER4_ID;
#if (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L)
{
hinsEmptyBuffer[1] = 1;
DriverLifter1.Private.slaveID = hinsEmptyBuffer[0] = 1; //一拖二驱动 驱动子ID
memcpy(DriverLifter1.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverLifter2.Private.slaveID = hinsEmptyBuffer[0] = 2;
memcpy(DriverLifter2.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverLifter3.Private.slaveID = hinsEmptyBuffer[0] = 1;
memcpy(DriverLifter3.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverLifter4.Private.slaveID = hinsEmptyBuffer[0] = 2;
memcpy(DriverLifter4.Private.sendBuffer, hinsEmptyBuffer, 8);
}
#else
{
DriverLifter1.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 1; //一拖二驱动 驱动子ID
memcpy(DriverLifter1.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverLifter2.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 2;
memcpy(DriverLifter2.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverLifter3.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 1;
memcpy(DriverLifter3.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverLifter4.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 2;
memcpy(DriverLifter4.Private.sendBuffer, hinsEmptyBuffer, 8);
}
#endif
DriverLifter1.driverShareErrorInfo = DriverLifter2.driverShareErrorInfo = DriverLifter3.driverShareErrorInfo = DriverLifter4.driverShareErrorInfo = &driverShareErrorInfo;
DriverLifter1.Private.sendHeartBeatCount = DriverLifter1.Private.readStateCount = DriverLifter1.Private.readAmpereCount = 8;
DriverLifter2.Private.sendHeartBeatCount = DriverLifter2.Private.readStateCount = DriverLifter2.Private.readAmpereCount = 9;
DriverLifter3.Private.sendHeartBeatCount = DriverLifter3.Private.readStateCount = DriverLifter3.Private.readAmpereCount = 10;
DriverLifter4.Private.sendHeartBeatCount = DriverLifter4.Private.readStateCount = DriverLifter4.Private.readAmpereCount = 11;
DriverLifter1.Private.canSelect = getDecimalMap(P_SETUP_LIFTER_CAN_CONNECTION, 4); //CAN口选择
DriverLifter2.Private.canSelect = getDecimalMap(P_SETUP_LIFTER_CAN_CONNECTION, 3);
DriverLifter3.Private.canSelect = getDecimalMap(P_SETUP_LIFTER_CAN_CONNECTION, 2);
DriverLifter4.Private.canSelect = getDecimalMap(P_SETUP_LIFTER_CAN_CONNECTION, 1);
DriverLifter1.Private.driverBrand = DriverLifter2.Private.driverBrand = DriverLifter3.Private.driverBrand = DriverLifter4.Private.driverBrand = P_SETUP_LIFTER_DRIVER_BRAND; //驱动品牌
//发送速度系数 读取速度系数 读取位置系数
DriverLifter1.Private.sendSpeedCoefficient = DriverLifter2.Private.sendSpeedCoefficient = DriverLifter3.Private.sendSpeedCoefficient = DriverLifter4.Private.sendSpeedCoefficient = SendLiftingSpeedCoefficient();
DriverLifter1.Private.getSpeedCoefficient = DriverLifter2.Private.getSpeedCoefficient = DriverLifter3.Private.getSpeedCoefficient = DriverLifter4.Private.getSpeedCoefficient = (1.0 / SendLiftingSpeedCoefficient());
DriverLifter1.Private.getPoseCoefficient = DriverLifter2.Private.getPoseCoefficient = DriverLifter3.Private.getPoseCoefficient = DriverLifter4.Private.getPoseCoefficient = GetLiftingPosValueBack();
//发送速度系数正反转方向调整
DriverLifter1.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_LIFTER_DIR, 4);
DriverLifter2.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_LIFTER_DIR, 3);
DriverLifter3.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_LIFTER_DIR, 2);
DriverLifter4.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_LIFTER_DIR, 1);
//读取速度系数正反转方向调整
DriverLifter1.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_LIFTER_DIR, 4);
DriverLifter2.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_LIFTER_DIR, 3);
DriverLifter3.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_LIFTER_DIR, 2);
DriverLifter4.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_LIFTER_DIR, 1);
//读取位置系数正反转方向调整
DriverLifter1.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_LIFTER_DIR, 4);
DriverLifter2.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_LIFTER_DIR, 3);
DriverLifter3.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_LIFTER_DIR, 2);
DriverLifter4.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_LIFTER_DIR, 1);
}
/***********************************************移轴驱动参数初始化************************************************************************************************/
{
DriverShifter1.Private.driverID = SHIFTER1_ID;
DriverShifter2.Private.driverID = SHIFTER2_ID;
DriverShifter3.Private.driverID = SHIFTER3_ID;
#if (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L)
{
hinsEmptyBuffer[1] = 1;
DriverShifter1.Private.slaveID = hinsEmptyBuffer[0] = 2; //一拖二驱动 驱动子ID
memcpy(DriverShifter1.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverShifter2.Private.slaveID = hinsEmptyBuffer[0] = 2;
memcpy(DriverShifter2.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverShifter3.Private.slaveID = hinsEmptyBuffer[0] = 1;
memcpy(DriverShifter3.Private.sendBuffer, hinsEmptyBuffer, 8);
}
#else
{
DriverShifter1.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 1; //一拖二驱动 驱动子ID
memcpy(DriverShifter1.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverShifter2.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 2;
memcpy(DriverShifter2.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverShifter3.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 1;
memcpy(DriverShifter3.Private.sendBuffer, hinsEmptyBuffer, 8);
}
#endif
DriverShifter1.driverShareErrorInfo = DriverShifter2.driverShareErrorInfo = DriverShifter3.driverShareErrorInfo = &driverShareErrorInfo;
DriverShifter1.Private.sendHeartBeatCount = DriverShifter1.Private.readStateCount = DriverShifter1.Private.readAmpereCount = 12;
DriverShifter2.Private.sendHeartBeatCount = DriverShifter2.Private.readStateCount = DriverShifter2.Private.readAmpereCount = 13;
DriverShifter3.Private.sendHeartBeatCount = DriverShifter3.Private.readStateCount = DriverShifter3.Private.readAmpereCount = 14;
DriverShifter1.Private.canSelect = getDecimalMap(P_SETUP_SHIFTER_CAN_CONNECTION, 4); //CAN口选择
DriverShifter2.Private.canSelect = getDecimalMap(P_SETUP_SHIFTER_CAN_CONNECTION, 3);
DriverShifter3.Private.canSelect = getDecimalMap(P_SETUP_SHIFTER_CAN_CONNECTION, 2);
DriverShifter1.Private.driverBrand = DriverShifter2.Private.driverBrand = DriverShifter3.Private.driverBrand = P_SETUP_SHIFTER_DRIVER_BRAND; //驱动品牌
//发送速度系数 读取速度系数 读取位置系数
DriverShifter1.Private.sendSpeedCoefficient = DriverShifter2.Private.sendSpeedCoefficient = DriverShifter3.Private.sendSpeedCoefficient = SendShifterSpeedValue();
DriverShifter1.Private.getSpeedCoefficient = DriverShifter2.Private.getSpeedCoefficient = DriverShifter3.Private.getSpeedCoefficient = (1.0 / SendShifterSpeedValue());
DriverShifter1.Private.getPoseCoefficient = DriverShifter2.Private.getPoseCoefficient = DriverShifter3.Private.getPoseCoefficient = GetShifterPosValueBack();
//发送速度系数正反转方向调整
DriverShifter1.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_SHIFTER_DIR, 4);
DriverShifter2.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_SHIFTER_DIR, 3);
DriverShifter3.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_SHIFTER_DIR, 2);
//读取速度系数正反转方向调整
DriverShifter1.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_SHIFTER_DIR, 4);
DriverShifter2.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_SHIFTER_DIR, 3);
DriverShifter3.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_SHIFTER_DIR, 2);
//读取位置系数正反转方向调整
DriverShifter1.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_SHIFTER_DIR, 4);
DriverShifter2.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_SHIFTER_DIR, 3);
DriverShifter3.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_SHIFTER_DIR, 2);
}
/***********************************************推杆驱动参数初始化************************************************************************************************/
{
DriverPusher1.Private.driverID = PUSHER1_ID;
DriverPusher2.Private.driverID = PUSHER2_ID;
DriverPusher3.Private.driverID = PUSHER3_ID;
#if (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_HINS_BLD2L)
{
hinsEmptyBuffer[1] = 1;
DriverPusher1.Private.slaveID = hinsEmptyBuffer[0] = 1; //一拖二驱动 驱动子ID
memcpy(DriverPusher1.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverPusher2.Private.slaveID = hinsEmptyBuffer[0] = 2;
memcpy(DriverPusher2.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverPusher3.Private.slaveID = hinsEmptyBuffer[0] = 1;
memcpy(DriverPusher3.Private.sendBuffer, hinsEmptyBuffer, 8);
}
#else
{
DriverPusher1.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 1; //一拖二驱动 驱动子ID
memcpy(DriverPusher1.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverPusher2.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 2;
memcpy(DriverPusher2.Private.sendBuffer, hinsEmptyBuffer, 8);
DriverPusher3.Private.slaveID = hinsEmptyBuffer[0] = hinsEmptyBuffer[1] = 1;
memcpy(DriverPusher3.Private.sendBuffer, hinsEmptyBuffer, 8);
}
#endif
DriverPusher1.driverShareErrorInfo = DriverPusher2.driverShareErrorInfo = DriverPusher3.driverShareErrorInfo = &driverShareErrorInfo;
DriverPusher1.Private.sendHeartBeatCount = DriverPusher1.Private.readStateCount = DriverPusher1.Private.readAmpereCount = 12;
DriverPusher2.Private.sendHeartBeatCount = DriverPusher2.Private.readStateCount = DriverPusher2.Private.readAmpereCount = 13;
DriverPusher3.Private.sendHeartBeatCount = DriverPusher3.Private.readStateCount = DriverPusher3.Private.readAmpereCount = 14;
DriverPusher1.Private.canSelect = getDecimalMap(P_SETUP_PUSHER_CAN_CONNECTION, 4); //CAN口选择
DriverPusher2.Private.canSelect = getDecimalMap(P_SETUP_PUSHER_CAN_CONNECTION, 3);
DriverPusher3.Private.canSelect = getDecimalMap(P_SETUP_PUSHER_CAN_CONNECTION, 2);
DriverPusher1.Private.driverBrand = DriverPusher2.Private.driverBrand = DriverPusher3.Private.driverBrand = P_SETUP_PUSHER_DRIVER_BRAND; //驱动品牌
//发送速度系数 读取速度系数 读取位置系数
DriverPusher1.Private.sendSpeedCoefficient = DriverPusher2.Private.sendSpeedCoefficient = DriverPusher3.Private.sendSpeedCoefficient = SendPusherSpeedValue();
DriverPusher1.Private.getSpeedCoefficient = DriverPusher2.Private.getSpeedCoefficient = DriverPusher3.Private.getSpeedCoefficient = (1.0 / SendPusherSpeedValue());
DriverPusher1.Private.getPoseCoefficient = DriverPusher2.Private.getPoseCoefficient = DriverPusher3.Private.getPoseCoefficient = GetPusherPosValueBack();
//发送速度系数正反转方向调整
DriverPusher1.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_PUSHER_DIR, 4);
DriverPusher2.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_PUSHER_DIR, 3);
DriverPusher3.Private.sendSpeedCoefficient *= getDecimalMap(P_SETUP_PUSHER_DIR, 2);
//读取速度系数正反转方向调整
DriverPusher1.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_PUSHER_DIR, 4);
DriverPusher2.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_PUSHER_DIR, 3);
DriverPusher3.Private.getSpeedCoefficient *= getDecimalMap(P_SETUP_PUSHER_DIR, 2);
//读取位置系数正反转方向调整
DriverPusher1.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_PUSHER_DIR, 4);
DriverPusher2.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_PUSHER_DIR, 3);
DriverPusher3.Private.getPoseCoefficient *= getDecimalMap(P_SETUP_PUSHER_DIR, 2);
}
}
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_SDO))
void Set_Heartbeat_Time(DriverStruct *Motor) //设置心跳时间
{
Motor->Private.compareNum = 0;
CAN_Send_Msg(Motor->Private.driverID, msg_set_heartbeat_time, 8, 3, Motor->Private.canSelect);
CAN_Send_Msg(Motor->Private.driverID, msg_set_heartbeat, 8, 3, Motor->Private.canSelect);
}
void send_heartbeat(DriverStruct *Motor) //发送心跳
{
CAN_Send_Msg(Motor->Private.driverID + 0x100, msg_send_heartbeat, 1, 0, Motor->Private.canSelect);
}
void send_reset_command(DriverStruct *Motor) //驱动复位
{
Motor->Private.compareNum = 0; //需要比较的长度
Motor->Private.tarFlag = DONTSETVALUE; //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
motor_reset[1] = Motor->Private.driverID & 0xff;
Motor->Private.compareBuffer = EmptyBuffer;
CAN_Send_Msg(0, motor_reset, 2, 0, Motor->Private.canSelect);
}
void motor_disable06(DriverStruct *Motor) //电机关使能
{
Motor->Private.noResponseNum++;
Motor->Private.compareNum = 4; //需要比较的长度
Motor->Private.tarFlag = 0x06; //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
Motor->Private.setFlagOffset = &Motor->Private.enable; //如果返回数据比较成功则在中断中将0赋值给Motor->Private.enable
Motor->Private.setSpeed = 0; //如果已经关使能则setspeed = 0;
Motor->Private.realEnable = 0;
Motor->Private.lastSpeed = 0;
Motor->Private.enableDelay = 0;
Motor->Private.compareBuffer = enable_back; //需要在中断中进行比较的字符串地址
CAN_Send_Msg(Motor->Private.driverID, msg_disable06, 8, 0, Motor->Private.canSelect);
}
void motor_disable07(DriverStruct *Motor) //电机关使能
{
Motor->Private.noResponseNum++;
Motor->Private.compareNum = 4; //需要比较的长度
Motor->Private.tarFlag = 0x07; //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
Motor->Private.setFlagOffset = &Motor->Private.enable; //如果返回数据比较成功则在中断中将0赋值给Motor->Private.enable
Motor->Private.setSpeed = 0; //如果已经关使能则setspeed = 0;
Motor->Private.realEnable = 0;
Motor->Private.lastSpeed = 0;
Motor->Private.enableDelay = 0;
Motor->Private.compareBuffer = enable_back; //需要在中断中进行比较的字符串地址
CAN_Send_Msg(Motor->Private.driverID, msg_disable, 8, 0, Motor->Private.canSelect);
}
void motor_enable(DriverStruct *Motor) //电机开使能
{
Motor->Private.noResponseNum++;
Motor->Private.compareNum = 4; //需要比较的长度
Motor->Private.tarFlag = 0x0f; //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
Motor->Private.setFlagOffset = &Motor->Private.enable; //如果返回数据比较成功则在中断中将1赋值给Motor->Private.enable
Motor->Private.compareBuffer = enable_back; //需要在中断中进行比较的字符串地址
CAN_Send_Msg(Motor->Private.driverID, msg_enable, 8, 0, Motor->Private.canSelect);
}
void set_speed_model(DriverStruct *Motor) //设置速度模式
{
Motor->Private.noResponseNum++;
Motor->Private.compareNum = 4; //需要比较的长度
Motor->Private.tarFlag = 0; //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
Motor->Private.setFlagOffset = &Motor->Private.currentMode; //如果返回数据比较成功则在中断中将0赋值给Motor->Private.currentMode
Motor->Private.compareBuffer = msg_setmode_back;
CAN_Send_Msg(Motor->Private.driverID, msg_setmode, 8, 0, Motor->Private.canSelect);
}
void set_pos_model(DriverStruct *Motor) //设置位置模式
{
// Motor->Private.noResponseNum++;
// Motor->Private.compareNum = 4;//需要比较的长度
// Motor->Private.tarFlag = 1; //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
// Motor->Private.setFlagOffset = &Motor->Private.currentMode;//如果返回数据比较成功则在中断中将1赋值给Motor->Private.currentMode
// Motor->Private.compareBuffer = msg_set_mode_back;
// CAN_Send_Msg(Motor->Private.driverID,msg_set_model_pos,8,0,Motor->Private.canSelect);
}
void send_speed_to_buffer(DriverStruct *Motor)
{
float sendSpeed = getSpeedSlope(Motor) * Motor->Private.sendSpeedCoefficient; //计算速度斜坡
Motor->Private.noResponseNum++;
Motor->Private.compareNum = 4; //需要比较的长度
Motor->Private.tarFlag = (int)(sendSpeed * 1000); //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
Motor->Private.setFlagOffset = &Motor->Private.setSpeed; //如果返回数据比较成功则在中断中将Motor->Command.speed赋值给Motor->Private.setSpeed
if (fabs(Motor->Command.speed) > 0.1)
change_data(msg_setspeed, (int)sendSpeed);
else
change_data_zero(msg_setspeed);
Motor->Private.compareBuffer = msg_setspeed_back; //需要在中断中进行比较的字符串地址
CAN_Send_Msg(Motor->Private.driverID, msg_setspeed, 8, 0, Motor->Private.canSelect); //发送8个字节
}
void get_actual_speed(DriverStruct *Motor)
{
Motor->Private.noResponseNum++;
Motor->Private.compareNum = 4; //需要比较的长度
Motor->Private.tarFlag = DONTSETVALUE; //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
Motor->Private.compareBuffer = msg_getspeed_back; //需要在中断中进行比较的字符串地址
CAN_Send_Msg(Motor->Private.driverID, msg_getspeed, 8, 0, Motor->Private.canSelect); //发送8个字节
}
void get_actual_pos(DriverStruct *Motor)
{
Motor->Private.noResponseNum++;
Motor->Private.compareNum = 4; //需要比较的长度
Motor->Private.tarFlag = DONTSETVALUE; //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
Motor->Private.compareBuffer = msg_getpos_back; //需要在中断中进行比较的字符串地址
CAN_Send_Msg(Motor->Private.driverID, msg_getpos, 8, 0, Motor->Private.canSelect); //发送8个字节
}
void clr_actual_pos(DriverStruct *Motor)
{
// Motor->Private.noResponseNum++;
// Motor->Private.compareNum = 4;//需要比较的长度
// Motor->Private.tarFlag = 0;//是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
// Motor->Private.setFlagOffset = &Motor->Command.clrPos;//如果返回数据比较成功则在中断中将0赋值给Motor->Public.encoderPose
// Motor->Private.compareBuffer = clean_actual_pos_back;//需要在中断中进行比较的字符串地址
// CAN_Send_Msg(Motor->Private.driverID, msg_clean_actual_pos, 8, 0,Motor->Private.canSelect);//发送8个字节
}
void get_driver_state(DriverStruct *Motor)
{
Motor->Private.noResponseNum++;
Motor->Private.compareNum = 4; //需要比较的长度
Motor->Private.tarFlag = DONTSETVALUE; //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
Motor->Private.compareBuffer = msg_get_state_back; //需要在中断中进行比较的字符串地址
CAN_Send_Msg(Motor->Private.driverID, msg_get_state, 8, 0, Motor->Private.canSelect); //发送8个字节
if (Motor->Private.noResponseNum > 20) //如果20次未收到驱动器应答
{
Motor->Private.noResponseNum = 0;
Motor->Private.initStep = 0; //重新初始化
Motor->Public.errorState = 1; //错误状态置1
*Motor->driverShareErrorInfo |= (1 << ((Motor->Private.driverID - 1) & 0xff));
Uart_Printf(COM1, "noresponse id = %d ,%04X\r\n", *Motor->driverShareErrorInfo, Motor->Private.driverID);
}
}
void get_driver_ampere(DriverStruct *Motor)
{
Motor->Private.noResponseNum++;
Motor->Private.compareNum = 4; //需要比较的长度
Motor->Private.tarFlag = DONTSETVALUE; //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
Motor->Private.compareBuffer = msg_read_ampere_back; //需要在中断中进行比较的字符串地址
CAN_Send_Msg(Motor->Private.driverID, msg_read_ampere, 8, 0, Motor->Private.canSelect); //发送8个字节
}
#endif
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_HINS_BLD2L)) || ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_HINS_BLD30))
void hins_driver_init(DriverStruct *Motor, u8 reset)
{
Motor->Private.noResponseNum++;
Motor->Private.tarFlag = DONTSETVALUE; //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
Motor->Private.lastSpeed = 0;
Motor->Private.sendBuffer[3] = reset;
Motor->Private.sendBuffer[6] = 0; //速度高位
Motor->Private.sendBuffer[7] = 0; //速度低位
CAN_Send_Msg(Motor->Private.driverID, Motor->Private.sendBuffer, 8, 0, Motor->Private.canSelect); //发送8个字节
}
void hins_driver_proc(DriverStruct *Motor)
{
short sendSpeed = (short)(getSpeedSlope(Motor) * Motor->Private.sendSpeedCoefficient); //计算速度斜坡
if (sendSpeed < 0)
Motor->Private.dir = 1;
else
Motor->Private.dir = 0;
if (*Motor->driverShareErrorInfo) //如果有其他驱动报错则速度给0
{
Motor->Private.lastSpeed = sendSpeed = 0;
}
Motor->Private.noResponseNum++;
Motor->Private.tarFlag = (int)(sendSpeed); //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
Motor->Private.setFlagOffset = &Motor->Private.setSpeed; //如果返回数据比较成功则在中断中将Motor->Command.speed赋值给Motor->Private.setSpeed
if (allDriverEnable || abs(sendSpeed) > 0) //如果要求驱动器一直使能或者速度不为0
Motor->Private.sendBuffer[4] = 1; //使能
else
Motor->Private.sendBuffer[4] = 0; //使能
if (abs(sendSpeed) > 1 && abs(sendSpeed) < 50)
{
sendSpeed = 50;
}
Motor->Private.sendBuffer[5] = Motor->Private.dir; //方向
Motor->Private.sendBuffer[6] = abs(sendSpeed) >> 8; //速度高位
Motor->Private.sendBuffer[7] = abs(sendSpeed); //速度低位
CAN_Send_Msg(Motor->Private.driverID, Motor->Private.sendBuffer, 8, 0, Motor->Private.canSelect); //发送8个字节
if (Motor->Private.noResponseNum > 20) //如果20次未收到驱动器应答
{
Motor->Private.noResponseNum = 0;
Motor->Private.initStep = 0; //重新初始化
Motor->Public.errorState = 1; //错误状态置1
*Motor->driverShareErrorInfo |= (1 << ((Motor->Private.driverID - 1) & 0xff));
Uart_Printf(COM1, "noresponse id = %d ,%04X\r\n", *Motor->driverShareErrorInfo, Motor->Private.driverID);
}
}
#endif
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_STEERING_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_CURTIS))
void curtis_driver_proc(DriverStruct *Motor)
{
short sendSpeed = (short)(getSpeedSlope(Motor) * Motor->Private.sendSpeedCoefficient); //计算速度斜坡
short sendAngle = (short)Motor->Command.pose;
if (sendSpeed < 0)
Motor->Private.dir = 5;
else
Motor->Private.dir = 3;
if (*Motor->driverShareErrorInfo) //如果有其他驱动报错则速度给0
Motor->Private.lastSpeed = sendSpeed = 0;
Motor->Private.noResponseNum++;
Motor->Private.tarFlag = (u32)((sendSpeed << 16) | sendAngle); //是否需要在比较成功后置位一个变量 为DONTSETVALUE时候不设置变量 为其他值得时候设置变量
Motor->Private.setFlagOffset = &Motor->Private.responseValue; //如果返回数据比较成功则在中断中将Motor->Command.speed赋值给Motor->Private.setSpeed
Motor->Private.sendBuffer[0] = Motor->Private.dir; //方向
Motor->Private.sendBuffer[1] = abs(sendSpeed); //速度低位
Motor->Private.sendBuffer[2] = abs(sendSpeed) >> 8; //速度高位
Motor->Private.sendBuffer[3] = 2;
Motor->Private.sendBuffer[4] = 2;
Motor->Private.sendBuffer[5] = abs(sendAngle); //速度低位
Motor->Private.sendBuffer[6] = abs(sendAngle) >> 8; //速度高位
Motor->Private.sendBuffer[7] = 0;
CAN_Send_Msg(Motor->Private.driverID, Motor->Private.sendBuffer, 8, 0, Motor->Private.canSelect); //发送8个字节
if (Motor->Private.noResponseNum > 20) //如果20次未收到驱动器应答
{
Motor->Private.noResponseNum = 0;
Motor->Private.initStep = 0; //重新初始化
Motor->Public.errorState = 1; //错误状态置1
*Motor->driverShareErrorInfo |= (1 << ((Motor->Private.driverID - 1) & 0xff));
Uart_Printf(COM1, "noresponse id = %d ,%04X\r\n", *Motor->driverShareErrorInfo, Motor->Private.driverID);
}
}
#endif
int get_int_data(u8 *RawData)
{
return (RawData[3] << 24 | RawData[2] << 16 | RawData[1] << 8 | RawData[0]);
}
void DriverDataProcess(DriverStruct *Motor, CanRxMsg *CanRxMsg)
{
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_STEERING_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_SDO))
if (Motor->Private.driverBrand == DRIVER_SDO)
{
if (memcmp(Motor->Private.compareBuffer, CanRxMsg->Data, Motor->Private.compareNum) == 0) //如果接收到的数据和要比较的数据一致则
{
Motor->Private.noResponseNum = 0; //无应答累计清零
if (Motor->Private.tarFlag != DONTSETVALUE) //如果需要设置变量
{
*Motor->Private.setFlagOffset = Motor->Private.tarFlag;
}
if (Motor->Private.compareBuffer == msg_getspeed_back) //如果要接收速度值
{
if (abs(get_int_data(CanRxMsg->Data + 4)) > 40000)
Motor->Public.encoderSpeed = get_int_data(CanRxMsg->Data + 4) * Motor->Private.getSpeedCoefficient; //返回的速度原始值乘以转换系数
else
Motor->Public.encoderSpeed = 0;
}
else if (Motor->Private.compareBuffer == msg_getpos_back) //如果要接收编码器位置值
{
Motor->Public.encoderPose = (int)((float)get_int_data(CanRxMsg->Data + 4) * Motor->Private.getPoseCoefficient); //返回的位置原始值乘以转换系数
}
else if (Motor->Private.compareBuffer == msg_get_state_back) //如果要获取状态值
{
if ((CanRxMsg->Data[4] & 0xf) == 0x8) //驱动报错
{
Motor->Private.initStep = 0; //重新初始化
Motor->Public.errorState = 1; //错误状态置1
*Motor->driverShareErrorInfo |= (1 << ((Motor->Private.driverID - 1) & 0xff)); //驱动错误状态共享信息对应bit置1
//Uart_Printf(COM1,"id = %04X,ERROR = %X\r\n",Motor->Private.driverID,CanRxMsg->Data[4]);
}
else
{
Motor->Public.errorState = 0;
*Motor->driverShareErrorInfo &= ~(1 << ((Motor->Private.driverID - 1) & 0xff));
}
}
else if (Motor->Private.compareBuffer == msg_read_ampere_back) //如果要获取电流值
{
Motor->Public.ampere = abs(get_int_data(CanRxMsg->Data + 4));
}
}
else
{
Uart_Printf(COM1, "id = %04x com = %02X %02X %02X %02X,rec = %02X %02X %02X %02X %02X %02X %02X %02X\r\n",
Motor->Private.driverID, Motor->Private.compareBuffer[0], Motor->Private.compareBuffer[1], Motor->Private.compareBuffer[2], Motor->Private.compareBuffer[3], CanRxMsg->Data[0], CanRxMsg->Data[1], CanRxMsg->Data[2], CanRxMsg->Data[3], CanRxMsg->Data[4], CanRxMsg->Data[5], CanRxMsg->Data[6], CanRxMsg->Data[7]);
}
Motor->Private.compareBuffer = EmptyBuffer;
Motor->Private.compareNum = 0;
}
#endif
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_STEERING_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_HINS_BLD2L))
if (Motor->Private.driverBrand == DRIVER_HINS_BLD2L && Motor->Private.slaveID == CanRxMsg->Data[0])
{
Motor->Private.noResponseNum = 0; //无应答累计清零
if (Motor->Private.tarFlag != DONTSETVALUE) //如果需要设置变量
{
*Motor->Private.setFlagOffset = Motor->Private.tarFlag;
}
if (CanRxMsg->Data[0] == 2)
{
Motor->Private.tarFlag = 0;
}
if (CanRxMsg->Data[1]) //驱动报错
{
Motor->Private.initStep = 0; //重新初始化
*Motor->driverShareErrorInfo |= (1 << ((Motor->Private.driverID - 1) & 0xff)); //驱动错误状态共享信息对应bit置1
Motor->Public.errorState = CanRxMsg->Data[1];
//Uart_Printf(COM1,"id = %04X,ERROR = %X\r\n",Motor->Private.driverID,CanRxMsg->Data[4]);
}
else
{
Motor->Public.errorState = 0;
*Motor->driverShareErrorInfo &= ~(1 << ((Motor->Private.driverID - 1) & 0xff));
}
Motor->Public.voltage = (float)((short)(CanRxMsg->Data[2] << 8 | CanRxMsg->Data[3])) / 100;
if (Motor->Private.dir == 0)
Motor->Public.encoderSpeed = (float)((short)(CanRxMsg->Data[4] << 8 | CanRxMsg->Data[5])) * Motor->Private.getSpeedCoefficient;
else
Motor->Public.encoderSpeed = (float)((short)(CanRxMsg->Data[4] << 8 | CanRxMsg->Data[5])) * Motor->Private.getSpeedCoefficient;
Motor->Public.ampere = (float)((short)(CanRxMsg->Data[6] << 8 | CanRxMsg->Data[7])) / 10;
}
#endif
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_STEERING_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_HINS_BLD30))
if (Motor->Private.driverBrand == DRIVER_HINS_BLD30 && Motor->Private.slaveID == CanRxMsg->Data[0])
{
if (CanRxMsg->Data[0] == 1) //A电机
{
Motor->Private.noResponseNum = 0; //无应答累计清零
if (Motor->Private.tarFlag != DONTSETVALUE) //如果需要设置变量
{
*Motor->Private.setFlagOffset = Motor->Private.tarFlag;
}
Motor->Public.ampere = (float)((short)(CanRxMsg->Data[1] << 8 | CanRxMsg->Data[2])) / 10;
if (CanRxMsg->Data[3] == 0)
Motor->Public.encoderSpeed = (float)((short)(CanRxMsg->Data[4] << 8 | CanRxMsg->Data[5])) * Motor->Private.getSpeedCoefficient;
else
Motor->Public.encoderSpeed = -(float)((short)(CanRxMsg->Data[4] << 8 | CanRxMsg->Data[5])) * Motor->Private.getSpeedCoefficient;
if (CanRxMsg->Data[6] || CanRxMsg->Data[7]) //驱动报错
{
Motor->Private.initStep = 0; //重新初始化
*Motor->driverShareErrorInfo |= (1 << ((Motor->Private.driverID - 1) & 0xff)); //驱动错误状态共享信息对应bit置1
Motor->Public.errorState = CanRxMsg->Data[6] | CanRxMsg->Data[7];
//Uart_Printf(COM1,"id = %04X,ERROR = %X\r\n",Motor->Private.driverID,CanRxMsg->Data[4]);
}
else
{
Motor->Public.errorState = 0;
*Motor->driverShareErrorInfo &= ~(1 << ((Motor->Private.driverID - 1) & 0xff));
}
}
else if (CanRxMsg->Data[0] == 2) //B电机
{
Motor->Private.noResponseNum = 0; //无应答累计清零
if (Motor->Private.tarFlag != DONTSETVALUE) //如果需要设置变量
{
*Motor->Private.setFlagOffset = Motor->Private.tarFlag;
}
Motor->Public.ampere = (float)((short)(CanRxMsg->Data[1] << 8 | CanRxMsg->Data[2])) / 10;
Motor->Public.voltage = (float)((short)(CanRxMsg->Data[6] << 8 | CanRxMsg->Data[7])) / 100;
if (CanRxMsg->Data[3] == 0)
Motor->Public.encoderSpeed = (float)((short)(CanRxMsg->Data[4] << 8 | CanRxMsg->Data[5])) * Motor->Private.getSpeedCoefficient;
else
Motor->Public.encoderSpeed = -(float)((short)(CanRxMsg->Data[4] << 8 | CanRxMsg->Data[5])) * Motor->Private.getSpeedCoefficient;
}
}
#endif
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_STEERING_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_CURTIS))
if (Motor->Private.driverBrand == DRIVER_CURTIS)
{
Motor->Private.noResponseNum = 0; //无应答累计清零
if (Motor->Private.tarFlag != DONTSETVALUE) //如果需要设置变量
{
*Motor->Private.setFlagOffset = Motor->Private.tarFlag;
}
Motor->Public.voltage = CanRxMsg->Data[6];
Motor->Public.encoderSpeed = (float)((short)(CanRxMsg->Data[1] << 8 | CanRxMsg->Data[0])) * Motor->Private.getSpeedCoefficient;
float encoderPose = (float)((short)(CanRxMsg->Data[3] << 8 | CanRxMsg->Data[2])) * Motor->Private.getPoseCoefficient;
if (encoderPose > 180)
encoderPose -= 360;
encoderPose *= 0.017453;
Motor->Public.encoderPose = encoderPose;
// if(CanRxMsg->Data[6] || CanRxMsg->Data[7])//驱动报错
// {
// Motor->Private.initStep = 0;//重新初始化
// *Motor->driverShareErrorInfo |=(1<<((Motor->Private.driverID-1)&0xff));//驱动错误状态共享信息对应bit置1
// Motor->Public.errorState = CanRxMsg->Data[6] | CanRxMsg->Data[7];
// //Uart_Printf(COM1,"id = %04X,ERROR = %X\r\n",Motor->Private.driverID,CanRxMsg->Data[4]);
// }
// else
// {
// Motor->Public.errorState = 0;
// *Motor->driverShareErrorInfo &=~(1<<((Motor->Private.driverID-1)&0xff));
// }
}
#endif
}
void init_driver(DriverStruct *Motor)
{
*Motor->driverShareErrorInfo |= (1 << ((Motor->Private.driverID - 1) & 0xff)); //驱动错误状态共享信息对应bit置1 Motor->Private.setSpeed = 0;
Motor->Private.realEnable = 0;
Motor->Private.setSpeed = 0;
Motor->Private.lastSpeed = 0;
Motor->Public.encoderSpeed = 0;
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_STEERING_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_SDO))
if (Motor->Private.driverBrand == DRIVER_SDO) //(Motor->Private.driverBrand == 0)
{
switch (Motor->Private.initStep)
{
case 0:
if (Motor->Private.initSubStep == 0)
{
Uart_Printf(COM1, "0 %x\r\n", Motor->Private.driverID);
Motor->Command.speed = 0;
send_speed_to_buffer(Motor); //发速度
Motor->Private.initSubStep++;
}
else if (Motor->Private.initSubStep++ > 2) //延迟2循环去下一个
{
if (Motor->Private.noResponseNum == 0) //判断是否无响应
{
Motor->Private.initStep = 1;
}
else if (Motor->Private.noResponseNum > 20)
{
Motor->Private.initStep = 0;
}
Motor->Private.initSubStep = 0;
}
break;
case 1:
if (Motor->Private.initSubStep == 0) //第一次进发送指令,然后延迟多少个循环进入下一个
{
Uart_Printf(COM1, "1 %x\r\n", Motor->Private.driverID);
send_reset_command(Motor); /*复位驱动器*/
send_reset_command(Motor); /*复位驱动器*/
Motor->Private.initSubStep++;
}
else if (Motor->Private.initSubStep++ > 200) //延迟200循环去下一个
{
Motor->Private.initStep = 2;
Motor->Private.initSubStep = 0;
}
break;
case 2:
if (Motor->Private.initSubStep == 0)
{
Uart_Printf(COM1, "2 %x\r\n", Motor->Private.driverID);
motor_disable06(Motor); /*使能06驱动器*/
Motor->Private.initSubStep++;
}
else if (Motor->Private.initSubStep++ > 2) //延迟2循环去下一个
{
if (Motor->Private.noResponseNum == 0) //判断是否无响应
{
Motor->Private.initStep = 3;
}
else if (Motor->Private.noResponseNum > 20)
{
Motor->Private.initStep = 0;
}
Motor->Private.initSubStep = 0;
}
break;
case 3:
if (Motor->Private.initSubStep == 0)
{
Uart_Printf(COM1, "3 %x\r\n", Motor->Private.driverID);
motor_disable07(Motor); /*使能07驱动器*/
Motor->Private.initSubStep++;
}
else if (Motor->Private.initSubStep++ > 2) //延迟2循环去下一个
{
if (Motor->Private.noResponseNum == 0) //判断是否无响应
{
Motor->Private.initStep = 4;
}
else if (Motor->Private.noResponseNum > 20)
{
Motor->Private.initStep = 0;
}
Motor->Private.initSubStep = 0;
}
break;
case 4:
if (Motor->Private.initSubStep == 0)
{
Uart_Printf(COM1, "4 %x\r\n", Motor->Private.driverID);
motor_enable(Motor); /*使能0f驱动器*/
Motor->Private.initSubStep++;
}
else if (Motor->Private.initSubStep++ > 2) //延迟2循环去下一个
{
if (Motor->Private.noResponseNum == 0) //判断是否无响应
{
Motor->Private.initStep = 5;
}
else if (Motor->Private.noResponseNum > 20)
{
Motor->Private.initStep = 0;
}
Motor->Private.initSubStep = 0;
}
break;
case 5:
if (Motor->Private.initSubStep == 0)
{
Uart_Printf(COM1, "5 %x\r\n", Motor->Private.driverID);
set_speed_model(Motor); /*设置为速度模式*/
Motor->Private.initSubStep++;
}
else if (Motor->Private.initSubStep++ > 2) //延迟2循环去下一个
{
if (Motor->Private.noResponseNum == 0) //判断是否无响应
{
Motor->Private.initStep = 6;
}
else if (Motor->Private.noResponseNum > 20)
{
Motor->Private.initStep = 1;
}
Motor->Private.initSubStep = 0;
}
break;
case 6:
Uart_Printf(COM1, "6 %x\r\n", Motor->Private.driverID);
// os_dly_wait (1);
// Set_Heartbeat_Time(Motor);//设置心跳
// os_dly_wait (1);
// Set_Heartbeat_Time(Motor);//设置心跳
os_dly_wait(1);
send_heartbeat(Motor);
Motor->Private.initStep = 255;
*Motor->driverShareErrorInfo &= ~(1 << ((Motor->Private.driverID - 1) & 0xff));
Motor->Private.setSpeed = 0;
break;
default:
break;
}
}
#endif
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_STEERING_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_HINS_BLD2L))
if (Motor->Private.driverBrand == DRIVER_HINS_BLD2L || Motor->Private.driverBrand == DRIVER_HINS_BLD30)
{
switch (Motor->Private.initStep)
{
case 0:
if (Motor->Private.initSubStep == 0)
{
Uart_Printf(COM1, "0 %x\r\n", Motor->Private.driverID);
hins_driver_init(Motor, 1); //驱动复位
Motor->Private.initSubStep++;
}
else if (Motor->Private.initSubStep++ > 10) //延迟10循环去下一个
{
if (Motor->Private.noResponseNum == 0) //判断是否无响应
{
Motor->Private.initStep = 1;
}
else if (Motor->Private.noResponseNum > 20)
{
Motor->Private.initStep = 0;
}
Motor->Private.initSubStep = 0;
}
break;
case 1:
if (Motor->Private.initSubStep == 0)
{
Uart_Printf(COM1, "1 %x\r\n", Motor->Private.driverID);
hins_driver_init(Motor, 0); //驱动复位
Motor->Private.initSubStep++;
}
else if (Motor->Private.initSubStep++ > 10) //延迟10循环去下一个
{
if (Motor->Private.noResponseNum == 0) //判断是否无响应
{
Motor->Private.initStep = 255;
}
else if (Motor->Private.noResponseNum > 20)
{
Motor->Private.initStep = 0;
}
Motor->Private.initSubStep = 0;
}
break;
default:
break;
}
}
#endif
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_STEERING_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_HINS_BLD30))
if (Motor->Private.driverBrand == DRIVER_HINS_BLD2L || Motor->Private.driverBrand == DRIVER_HINS_BLD30)
{
switch (Motor->Private.initStep)
{
case 0:
if (Motor->Private.initSubStep == 0)
{
Uart_Printf(COM1, "0 %x\r\n", Motor->Private.driverID);
hins_driver_init(Motor, 1); //驱动复位
Motor->Private.initSubStep++;
}
else if (Motor->Private.initSubStep++ > 10) //延迟10循环去下一个
{
if (Motor->Private.noResponseNum == 0) //判断是否无响应
{
Motor->Private.initStep = 1;
}
else if (Motor->Private.noResponseNum > 20)
{
Motor->Private.initStep = 0;
}
Motor->Private.initSubStep = 0;
}
break;
case 1:
if (Motor->Private.initSubStep == 0)
{
Uart_Printf(COM1, "1 %x\r\n", Motor->Private.driverID);
hins_driver_init(Motor, 0); //驱动复位
Motor->Private.initSubStep++;
}
else if (Motor->Private.initSubStep++ > 10) //延迟10循环去下一个
{
if (Motor->Private.noResponseNum == 0) //判断是否无响应
{
Motor->Private.initStep = 255;
}
else if (Motor->Private.noResponseNum > 20)
{
Motor->Private.initStep = 0;
}
Motor->Private.initSubStep = 0;
}
break;
default:
break;
}
}
#endif
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_STEERING_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_CURTIS))
if (Motor->Private.driverBrand == DRIVER_CURTIS)
{
Motor->Private.initStep = 255;
}
#endif
}
void DriverState(DriverStruct *Motor, float speedThreshold)
{
if (Motor->Private.initStep == 255) //如果已经初始化完成
{
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_SDO))
if (Motor->Private.driverBrand == DRIVER_SDO) //如果是步科 风得控驱动
{
Motor->Private.readStateCount++;
Motor->Private.sendHeartBeatCount++;
Motor->Private.readAmpereCount++;
if (Motor->Private.readAmpereCount > 30) //30个循环读电流
{
Motor->Private.readAmpereCount = 0;
if (fabs(Motor->Command.speed) > 0.01f)
{
get_driver_ampere(Motor); //获取状态
}
else
{
Motor->Public.ampere = 0;
}
}
else if (Motor->Private.readStateCount > 15) //15个循环读状态
{
Motor->Private.readStateCount = 0;
get_driver_state(Motor); //获取状态
}
else if (Motor->Private.sendHeartBeatCount > 14) //14个循环发心跳
{
Motor->Private.sendHeartBeatCount = 0;
send_heartbeat(Motor); //发送心跳
}
else
{
if (Motor->Private.sendStep == 0)
{
get_actual_speed(Motor); //获取速度
Motor->Private.sendStep = 1;
}
else
{
get_actual_pos(Motor); //获取位置
Motor->Private.sendStep = 0;
}
}
if (Motor->Private.realEnable == 0 && (fabs(Motor->Command.speed) > speedThreshold)) //如果还未真正使能
{
if (fabs(Motor->Public.encoderSpeed) > speedThreshold && Motor->Private.enable == 0x0f) //如果已经发了使能指令和速度并且有返回速度
{
Motor->Private.realEnable = 1; //真正使能信号置1
}
else
{
// Uart_Printf(COM1, "id:%x speed: %.1f\r\n", Motor->Private.driverID, Motor->Public.encoderSpeed);
}
}
}
#endif
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_HINS_BLD2L)) || ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_HINS_BLD30))
if (Motor->Private.driverBrand == DRIVER_HINS_BLD2L || Motor->Private.driverBrand == DRIVER_HINS_BLD30) //如果是兴颂驱动
{
Motor->Private.sendHeartBeatCount++;
if (Motor->Private.sendHeartBeatCount > 10) //500ms内要发一次数据
{
Motor->Private.sendHeartBeatCount = 0;
hins_driver_proc(Motor); //发送心跳
}
if (Motor->Private.realEnable == 0 && (fabs(Motor->Command.speed) > speedThreshold)) //如果还未真正使能
{
if (fabs(Motor->Public.encoderSpeed) > speedThreshold && Motor->Private.enable == 0x0f) //如果已经发了使能指令和速度并且有返回速度
{
Motor->Private.realEnable = 1; //真正使能信号置1
}
else
{
// Uart_Printf(COM1, "id:%x speed: %.1f\r\n", Motor->Private.driverID, Motor->Public.encoderSpeed);
}
}
}
#endif
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_STEERING_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_CURTIS))
if (Motor->Private.driverBrand == DRIVER_CURTIS) //如果是兴颂驱动
{
Motor->Private.sendHeartBeatCount++;
if (Motor->Private.sendHeartBeatCount > 10) //500ms内要发一次数据
{
Motor->Private.sendHeartBeatCount = 0;
curtis_driver_proc(Motor); //发送心跳
}
}
#endif
}
}
u8 set_speed(DriverStruct *Motor) //return 0 代表发了指令 则本轮不能再发指令
{
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_SDO) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_SDO))
if (Motor->Private.driverBrand == DRIVER_SDO)
{
// 有其他驱动器报错 or 速度为0 进入只使能状态
if ((*Motor->driverShareErrorInfo) || (Motor->Command.speed < 0.1 && Motor->Command.speed > -0.1 && allDriverEnable))
{
if (Motor->Private.enable != 0x0f) //如果是关使能状态
{
if (Motor->Private.enable == 0x06) //如果还没关使能
{
motor_disable07(Motor); //关使能
return 0;
}
else if (Motor->Private.enable == 0x07)
{
motor_enable(Motor); //开使能
return 0;
}
motor_disable06(Motor); //关使能
return 0;
}
else if (Motor->Private.setSpeed != 0) //如果设置的速度!= 0
{
send_speed_to_buffer(Motor); //发速度
return 0;
}
}
else if (fabs(Motor->Command.speed) < 0.001f) //速度为 0代表要关使能并且给速度0
{
if (Motor->Private.enable == 0x0f) //如果还没关使能
{
/*如果发现此次速度为0 那么先发送给驱动器速度0 然后再关闭驱动器*/
if (fabs(Motor->Public.encoderSpeed) > 15) //速度大于5时候不关闭驱动
{
if (abs(Motor->Private.setSpeed) != 0)
{
send_speed_to_buffer(Motor); //发速度
return 0;
}
}
else
{
motor_disable07(Motor); //关使能
return 0;
}
}
else if (Motor->Private.enable == 0x07)
{
motor_disable06(Motor); //关使能
return 0;
}
}
else //有速度
{
if (Motor->Private.enable == 0x06)
{
Motor->Private.enableDelay++;
motor_disable07(Motor); //开使能07
return 0;
}
else if (Motor->Private.enable == 0x07)
{
Motor->Private.enableDelay++;
motor_enable(Motor); //开使能
return 0;
}
else if (Motor->Private.enable != 0x0f)
{
Motor->Private.enableDelay++;
motor_disable06(Motor); //开使能06
return 0;
}
else if (Motor->Private.enableDelay < 30)
{
Motor->Private.enableDelay++;
}
else if (((int)(Motor->Command.speed * 1000 * Motor->Private.sendSpeedCoefficient) != Motor->Private.setSpeed) || (Motor->Private.realEnable == 0)) //如果指令速度和已经设置的速度不同 或者 在未真正使能的时候发了速度
{
//Uart_Printf(COM1,"motor = %d , %d , %d\r\n",(int)(Motor->Command.speed*1000), Motor->Private.setSpeed,(Motor->Private.realEnable));
send_speed_to_buffer(Motor); //发速度
return 0;
}
}
}
#endif
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_HINS_BLD2L)) || ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_HINS_BLD30))
if (Motor->Private.driverBrand == DRIVER_HINS_BLD2L || Motor->Private.driverBrand == DRIVER_HINS_BLD30)
{
if (((int)(Motor->Command.speed * Motor->Private.sendSpeedCoefficient) != Motor->Private.setSpeed) || (Motor->Private.realEnable == 0 && abs(Motor->Command.speed) > 0.1f)) //如果指令速度和已经设置的速度不同 或者 在未真正使能的时候发了速度
{
//Uart_Printf(COM1,"motor = %d , %d , %d\r\n",(int)(Motor->Command.speed*1000), Motor->Private.setSpeed,(Motor->Private.realEnable));
hins_driver_proc(Motor); //发速度
return 0;
}
}
#endif
return 1;
}
u8 set_steering_speed(DriverStruct *Motor, DriverStruct *refMotor)
{
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_HINS_BLD2L) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_HINS_BLD2L)) || ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_HINS_BLD30) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_HINS_BLD30))
if (Motor->Private.driverBrand == DRIVER_HINS_BLD2L || Motor->Private.driverBrand == DRIVER_HINS_BLD30)
{
if (((int)(Motor->Command.speed * Motor->Private.sendSpeedCoefficient) != Motor->Private.setSpeed) || (Motor->Private.realEnable == 0)) //如果指令速度和已经设置的速度不同 或者 在未真正使能的时候发了速度
{
//Uart_Printf(COM1,"motor = %d , %d , %d\r\n",(int)(Motor->Command.speed*1000), Motor->Private.setSpeed,(Motor->Private.realEnable));
hins_driver_proc(Motor); //发速度
return 0;
}
}
#endif
#if ((P_SETUP_MOTOR_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_STEERING_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_LIFTER_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_SHIFTER_DRIVER_BRAND == DRIVER_CURTIS) | (P_SETUP_PUSHER_DRIVER_BRAND == DRIVER_CURTIS))
if (Motor->Private.driverBrand == DRIVER_CURTIS)
{
if (((int)(Motor->Command.speed * Motor->Private.sendSpeedCoefficient) != (int)(Motor->Private.responseValue >> 16)) || ((int)(Motor->Command.pose * Motor->Private.sendSpeedCoefficient) != (int)(Motor->Private.responseValue & 0xffff)) || (Motor->Private.realEnable == 0)) //如果指令速度和已经设置的速度不同 或者 在未真正使能的时候发了速度
{
curtis_driver_proc(Motor);
return 0;
}
}
#endif
return 1;
}