-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTorqueVectoringSystem.cpp
1154 lines (852 loc) · 42.1 KB
/
TorqueVectoringSystem.cpp
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
#include "TorqueVectoringSystem.h"
// Serial pc(USBTX, USBRX, 115200);
TorqueVectoringSystem::TorqueVectoringSystem(
PinName TVS_SWITCH_PIN, PinName FL_HALL_PIN, PinName FR_HALL_PIN, PinName RL_HALL_PIN, PinName RR_HALL_PIN,
PinName HANDLE_SENSOR_PIN, PinName MPU_SDA, PinName MPU_SCL, PinName PEDAL_SENSOR_PIN,
PinName FL_CURRENT_SENSOR_PIN, PinName FR_CURRENT_SENSOR_PIN, PinName RL_CURRENT_SENSOR_PIN, PinName RR_CURRENT_SENSOR_PIN,
PinName FL_OUTPUT_THROTTLE_PIN, PinName FR_OUTPUT_THROTTLE_PIN, PinName RL_OUTPUT_THROTTLE_PIN, PinName RR_OUTPUT_THROTTLE_PIN
)
: RL_Hall_A(RL_HALL_PIN), RR_Hall_A(RR_HALL_PIN),
mpu(MPU_SDA, MPU_SCL),
Handle_Sensor(HANDLE_SENSOR_PIN),
FL_Current_OUT(FL_CURRENT_SENSOR_PIN),
FR_Current_OUT(FR_CURRENT_SENSOR_PIN),
RL_Current_OUT(RL_CURRENT_SENSOR_PIN),
RR_Current_OUT(RR_CURRENT_SENSOR_PIN),
Pedal_Sensor(PEDAL_SENSOR_PIN),
FL_Throttle_PWM(FL_OUTPUT_THROTTLE_PIN),
FR_Throttle_PWM(FR_OUTPUT_THROTTLE_PIN),
RL_Throttle_PWM(RL_OUTPUT_THROTTLE_PIN),
RR_Throttle_PWM(RR_OUTPUT_THROTTLE_PIN)
{
FL_Throttle_PWM.period_us(PWM_PERIOD_US);
FR_Throttle_PWM.period_us(PWM_PERIOD_US);
RL_Throttle_PWM.period_us(PWM_PERIOD_US);
RR_Throttle_PWM.period_us(PWM_PERIOD_US);
/*
FL_Throttle_PWM.period_ms(PWM_PERIOD_MS);
FR_Throttle_PWM.period_ms(PWM_PERIOD_MS);
RL_Throttle_PWM.period_ms(PWM_PERIOD_MS);
RR_Throttle_PWM.period_ms(PWM_PERIOD_MS);
*/
f_motor_current_FL_A = 0.0;
f_motor_current_FR_A = 0.0;
f_motor_current_RL_A = 0.0;
f_motor_current_RR_A = 0.0;
f_motor_RPM_FL = 0.0;
f_motor_RPM_FR = 0.0;
f_motor_RPM_RL = 0.0;
f_motor_RPM_RR = 0.0;
//pedal box
f_pedal_sensor_value = 0.0;
//handle
f_pedal_modified_sensor_value = 0.0;
i_PWR_percentage = 0;
f_steering_sensor_value = 0.0;
f_yaw_rate_meas_filtered_degs = 0.0;
//temp value
f_wheel_angle_deg = 0.0;
f_vel_FL_ms = 0.0;
f_vel_FR_ms = 0.0;
f_vel_RL_ms = 0.0;
f_vel_RR_ms = 0.0;
f_vehicle_vel_ms = 0.0;
f_yawrate_input_deg = 0.0;
f_wheel_torque_FL_Nm = 0.0;
f_wheel_torque_FR_Nm = 0.0;
f_wheel_torque_RL_Nm = 0.0;
f_wheel_torque_RR_Nm = 0.0;
f_feedforward_throttle_FL = 0.0;
f_feedforward_throttle_FR = 0.0;
f_feedforward_throttle_RL = 0.0;
f_feedforward_throttle_RR = 0.0;
f_PID_yaw_rate2torque_FL_Nm = 0.0;
f_PID_yaw_rate2torque_FR_Nm = 0.0;
f_PID_yaw_rate2torque_RL_Nm = 0.0;
f_PID_yaw_rate2torque_RR_Nm = 0.0;
f_measured_torque_FL_Nm = 0.0;
f_measured_torque_FR_Nm = 0.0;
f_measured_torque_RL_Nm = 0.0;
f_measured_torque_RR_Nm = 0.0;
f_torque_FL_Nm = 0.0; // targetted torque
f_torque_FR_Nm = 0.0;
f_torque_RL_Nm = 0.0;
f_torque_RR_Nm = 0.0;
f_output_throttle_FL = 0.0;
f_output_throttle_FR = 0.0;
f_output_throttle_RL = 0.0;
f_output_throttle_RR = 0.0;
f_PID_throttle_FL = 0.0;
f_PID_throttle_FR = 0.0;
f_PID_throttle_RL = 0.0;
f_PID_throttle_RR = 0.0;
f_PWM_input_FL = 0.0;
f_PWM_input_FR = 0.0;
f_PWM_input_RL = 0.0;
f_PWM_input_RR = 0.0;
IMU_gx = 0.0, IMU_gy = 0.0, IMU_gz = 0.0, IMU_ax = 0.0, IMU_ay = 0.0, IMU_az = 0.0;
f_yawrate_meas_degs = 0.0;
FL_Throttle_PWM = 0.0;
FR_Throttle_PWM = 0.0;
RL_Throttle_PWM = 0.0;
RR_Throttle_PWM = 0.0;
}
/*
- RPM 구하는 함수
- rising edge 시간 차를 이용해 계산
- input
??
- output
f_motor_RPM
- configuration
MOTOR_POLE = 7
float TorqueVectoringSystem::CalRPM(HallSensor hall)
{
// pc.printf("rpm: %f\n", hall.getRPM()); // for debuging
float rpm = hall.getRPM();
return rpm;
}
*/
/*
- 단순한 map 함수 구현(아두이노 함수 참조)
- float형 return
*/
float TorqueVectoringSystem::map_f(float input, float in_min, float in_max, float out_min, float out_max)
{
return (input - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
/*
- motor RPM --> m/s 변환하는 함수.
- input
f_motor_RPM: float, motor(RPM)
- output
f_vel_ms: float, velocity(m/s)
- configuration
WHEEL_RADIUS = 0.15m
GEAR_RATIO = 5.27
*/
float TorqueVectoringSystem::CvtRPM2Vel(float f_motor_RPM)
{
float f_vel_ms = 2. * PI * WHEEL_RADIUS * (f_motor_RPM / GEAR_RATIO) / 60;
return f_vel_ms;
}
/*
- 평균속도 구하는 함수.
- input
f_vel_RR_ms: float, velocity(m/s), RR
f_vel_RL_ms: float, velocity(m/s), RL
- output
f_avg_vel_ms: float, velocity(m/s), average
- configuration: X
*/
float TorqueVectoringSystem::CalAvgVel(float f_velocity1_ms, float f_velocity2_ms)
{
float f_avg_vel_ms = (f_velocity1_ms + f_velocity2_ms) / 2;
return f_avg_vel_ms;
}
/*
- 가변 저항 센서 값을 조향 각으로 변환하는 함수.
- configuration
*/
float TorqueVectoringSystem::CalHandlingVolt2WheelSteeringAngle(float f_handling_sensor_value)
{
// float resistor_angle = (f_handling_sensor_value - DEFAULT_VOLTAGE_INPUT) * MAX_RESISTOR_ANGLE;
// float handle_angle = resistor_angle * (MAX_HANDLE_ANGLE / MAX_RESISTOR_LIMITED_ANGLE);
// return handle_angle * (MAX_STEERING_ANGLE / MAX_HANDLE_ANGLE);
float resistor_angle;
float handle_angle;
resistor_angle = (f_handling_sensor_value - DEFAULT_VOLTAGE_INPUT) * MAX_RESISTOR_ANGLE;
handle_angle = resistor_angle * (MAX_HANDLE_ANGLE / MAX_RESISTOR_LIMITED_ANGLE);
handle_angle = handle_angle * (MAX_STEERING_ANGLE / MAX_HANDLE_ANGLE);
return handle_angle;
}
/*
- 차량 평균 속도와 바퀴 회전각을 이용하여 yawrate를 반환하는 함수.
- input
f_wheel_steering_angle_deg: float, degree
f_avg_vel_ms: float, velocity(m/s), average
- output
f_input_yaw_rate_degps: float, yawrate(rad/s)
- configuration
WHEEL_BASE = 1.390m
*/
float TorqueVectoringSystem::CalInputYawRate(float f_avg_vel_ms, float f_wheel_steering_angle_deg)
{
float f_input_yaw_rate_degps;
float f_steering_angle_rad;
f_steering_angle_rad = f_wheel_steering_angle_deg * PI / 180;
f_input_yaw_rate_degps = f_avg_vel_ms * sin(f_steering_angle_rad) / WHEEL_BASE;
return f_input_yaw_rate_degps;
}
/*
- imu로 측정한 yawrate를 지수감쇠필터를 이용해 노이즈를 제거한 yawrate를 반환하는 함수.
- input
f_IMU_yaw_rate_degps: from imu, yawrate(rad/s)
- output
f_filtered_yaw_rate_degps: filtered, yawrate(rad/s)
- configuration
ALPHA = 0.85
*/
float TorqueVectoringSystem::IMUFilter(float i_IMU_yaw_rate_degps)
{
static float f_prev_yaw_rate_degps = 0.0;
float f_filtered_yaw_rate_degps = ((1.0 - ALPHA) * f_prev_yaw_rate_degps) + (ALPHA * i_IMU_yaw_rate_degps);
f_prev_yaw_rate_degps = f_filtered_yaw_rate_degps;
return f_filtered_yaw_rate_degps;
}
/*
- 회전 반경, phi, 조향각을 이용하여 팔 길이를 구한 후, 팔 길이의 비율로 토크를 분배하는 함수.
- 팔 길이 계산
fl = R * sin(phi - f_wheel_steering_angle_deg);
fr = R * sin(phi + f_wheel_steering_angle_deg);
rl = (-1) * R * sin(phi);
rr = R * sin(phi)
- weight = 팔 길이 * 조향각 * throttle + throttle
- sum = weight(4방향)
- torque(1방향) = throttle / sum * weight(1방향)
- input
f_wheel_steering_angle_deg: float, degree
f_pedal_sensor_value : float, voltage(V)
- output
f_wheel_torque_(4방향)_Nm: 4개 출력, float, torque(N*m)
- configuration
WHEEL_BASE = 1.390m
TRACK = 1.300m
-가장 큰 주의사항
이 함수는 페달신호 최대 5V를 입력받는다고 가정하며, 이 것을 5V 스로틀신호 입력을 받는
컨트롤러에 4개의 적절한 값 분배(스로틀신호)를 이룬 후에, 이에 대한 목표 토크를 출력한다.
*/
bool TorqueVectoringSystem::WheelSteeringAngle2Torque(float f_wheel_steering_angle_deg, float f_pedal_sensor_value,
float& f_wheel_torque_FL_Nm, float& f_wheel_torque_FR_Nm, float& f_wheel_torque_RL_Nm, float& f_wheel_torque_RR_Nm)
{
int dir;
// normalize값 중 최대를 계산
float max_weight;
float f_wheel_torque_Nm[4];
float f_steering_angle_rad;
float pedal_throttle_voltage;
float R; // 팔길이 계산에 필요한 조향각 0도일 때 차량 중심과 바퀴축 거리
float phi;
float FL_arm_m;
float FR_arm_m;
float RL_arm_m;
float RR_arm_m;
float weight[4] = {0.0, 0.0, 0.0, 0.0};
float normalized_weight[4] = {0.0, 0.0, 0.0, 0.0};
float sum = 0.;
f_steering_angle_rad = f_wheel_steering_angle_deg * PI / 180;
pedal_throttle_voltage = f_pedal_sensor_value * CONTROLLER_INPUT_VOLT_RANGE; // need to set by configuration
if (pedal_throttle_voltage == 0.000000)
{
f_wheel_torque_FL_Nm = 0.0;
f_wheel_torque_FR_Nm = 0.0;
f_wheel_torque_RL_Nm = 0.0;
f_wheel_torque_RR_Nm = 0.0;
return -1;
}
R = sqrt(pow(WHEEL_BASE / 2.0, 2.0) + pow(TRACK / 2.0, 2.0));
phi = atan((TRACK / 2.) / (WHEEL_BASE / 2.));
// 팔길이 계산
FL_arm_m = (-1) * R * sin(phi - f_steering_angle_rad);
FR_arm_m = R * sin(phi + f_steering_angle_rad);
RL_arm_m = (-1) * R * sin(phi);
RR_arm_m = R * sin(phi);
/*
// only positive value of arm length used
if(FL_arm_m < 0.0) FL_arm_m = 0.0;
if(FR_arm_m < 0.0) FR_arm_m = 0.0;
if(RL_arm_m < 0.0) RL_arm_m = 0.0;
if(RR_arm_m < 0.0) RR_arm_m = 0.0;
*/
// need to erase this
// pc.printf("\tfirst feed forward func \r\n");
// pc.printf("\tarm length : \r\n\tFL : %f, FR : %f, RL : %f, RR : %f\r\n", FL_arm_m, FR_arm_m, RL_arm_m, RR_arm_m);
// 프로파일 함수에 대한 결과 계산 (rad 입력으로 수정)
weight[FL] = FL_arm_m * f_steering_angle_rad * pedal_throttle_voltage + pedal_throttle_voltage;
weight[FR] = FR_arm_m * f_steering_angle_rad * pedal_throttle_voltage + pedal_throttle_voltage;
weight[RL] = RL_arm_m * f_steering_angle_rad * pedal_throttle_voltage + pedal_throttle_voltage;
weight[RR] = RR_arm_m * f_steering_angle_rad * pedal_throttle_voltage + pedal_throttle_voltage;
// pc.printf("\tweight (profile func output) \r\n");
// pc.printf("\tFL : %f, FR : %f, RL : %f, RR : %f\r\n", weight[FL], weight[FR], weight[RL], weight[RR]);
sum = weight[FL] + weight[FR] + weight[RL] + weight[RR];
// pc.printf("\tsum : %f\r\n", sum);
//normalize
for(dir = 0; dir < 4; dir++)
normalized_weight[dir] = 4 * (pedal_throttle_voltage / sum) * weight[dir];
// pc.printf("\tnormalized weight\r\n");
// pc.printf("\tFL : %f, FR : %f, RL : %f, RR : %f\r\n", normalized_weight[FL], normalized_weight[FR], normalized_weight[RL], normalized_weight[RR]);
// find maximum normalized value
max_weight = normalized_weight[FL];
for(dir = 0; dir < 4; dir++)
{
if(max_weight < normalized_weight[dir]){
max_weight = normalized_weight[dir];
}
}
// pc.printf("\tmax weight : %f\r\n", max_weight);
// 0~max_weight 범위의 normalize된 값을 0~페달스로틀입력 으로 mapping
for (dir = 0; dir < 4; dir++)
{
f_wheel_torque_Nm[dir] = map_f(normalized_weight[dir], TORQUE_VECTORING_RATE, max_weight, 0.0, pedal_throttle_voltage)
* (ACTUAL_MAX_TORQUE_NY / CONTROLLER_INPUT_VOLT_RANGE);
// 홀전류센서 장착 이후 실제 MAX_TORQUE 수정 요망
}
// pc.printf("\tnormalized torque \r\n");
// pc.printf("\tFL : %f, FR : %f, RL : %f, RR : %f\r\n", f_wheel_torque_Nm[FL], f_wheel_torque_Nm[FR], f_wheel_torque_Nm[RL], f_wheel_torque_Nm[RR]);
// 안전장치
for (dir = 0; dir < 4; dir++)
{
if (f_wheel_torque_Nm[dir] < 0.0) f_wheel_torque_Nm[dir] = 0;
}
f_wheel_torque_FL_Nm = f_wheel_torque_Nm[FL];
f_wheel_torque_FR_Nm = f_wheel_torque_Nm[FR];
f_wheel_torque_RL_Nm = f_wheel_torque_Nm[RL];
f_wheel_torque_RR_Nm = f_wheel_torque_Nm[RR];
return 0;
}
/*
- 회전 반경, phi, 조향각을 이용하여 팔 길이를 구한 후, 팔 길이의 비율로 토크를 분배하는 함수.
- 팔 길이 계산
fl = R * sin(phi - f_wheel_steering_angle_deg);
fr = R * sin(phi + f_wheel_steering_angle_deg);
rl = (-1) * R * sin(phi);
rr = R * sin(phi)
- weight = 팔 길이 * 조향각 * throttle + throttle
- sum = weight(4방향)
- torque(1방향) = throttle / sum * weight(1방향)
- input
f_wheel_steering_angle_deg: float, degree
f_pedal_sensor_value : float, voltage(V)
- output
f_feedforward_throttle(방향)
- configuration
WHEEL_BASE = 1.390m
TRACK = 1.300m
- 결과 출력은 각 바퀴에 인가될 스로틀전압.
*/
bool TorqueVectoringSystem::WheelSteeringAngle2Throttle(float f_wheel_steering_angle_deg, float f_pedal_sensor_value,
float& f_feedforward_throttle_FL, float& f_feedforward_throttle_FR,
float& f_feedforward_throttle_RL, float& f_feedforward_throttle_RR)
{
int dir;
// normalize값 중 최대를 계산
float max_weight;
float f_throttle[4];
float f_steering_angle_rad;
float pedal_throttle_voltage;
float R; // 팔길이 계산에 필요한 조향각 0도일 때 차량 중심과 바퀴축 거리
float phi;
float FL_arm_m;
float FR_arm_m;
float RL_arm_m;
float RR_arm_m;
float weight[4] = {0.0, 0.0, 0.0, 0.0};
float normalized_weight[4] = {0.0, 0.0, 0.0, 0.0};
float sum = 0.;
f_steering_angle_rad = f_wheel_steering_angle_deg * PI / 180;
pedal_throttle_voltage = f_pedal_sensor_value * CONTROLLER_INPUT_VOLT_RANGE; // need to set by configuration
if (pedal_throttle_voltage == 0.000000)
{
f_feedforward_throttle_FL = 0.0;
f_feedforward_throttle_FR = 0.0;
f_feedforward_throttle_RL = 0.0;
f_feedforward_throttle_RR = 0.0;
// pc.printf("\tnormalized throttle \r\n");
// pc.printf("\tFL : %f, FR : %f, RL : %f, RR : %f\r\n", f_feedforward_throttle_FL, f_feedforward_throttle_FR, f_feedforward_throttle_RL, f_feedforward_throttle_RR);
return -1;
}
R = sqrt(pow(WHEEL_BASE / 2.0, 2.0) + pow(TRACK / 2.0, 2.0));
phi = atan((TRACK / 2.) / (WHEEL_BASE / 2.));
// 팔길이 계산
FL_arm_m = (-1) * R * sin(phi - f_steering_angle_rad);
FR_arm_m = R * sin(phi + f_steering_angle_rad);
RL_arm_m = (-1) * R * sin(phi);
RR_arm_m = R * sin(phi);
/*
// only positive value of arm length used
if(FL_arm_m < 0.0) FL_arm_m = 0.0;
if(FR_arm_m < 0.0) FR_arm_m = 0.0;
if(RL_arm_m < 0.0) RL_arm_m = 0.0;
if(RR_arm_m < 0.0) RR_arm_m = 0.0;
*/
// need to erase this
// pc.printf("\tfirst feed forward func \r\n");
// pc.printf("\tarm length : \r\n\tFL : %f, FR : %f, RL : %f, RR : %f\r\n", FL_arm_m, FR_arm_m, RL_arm_m, RR_arm_m);
// 프로파일 함수에 대한 결과 계산 (rad 입력으로 수정)
weight[FL] = FL_arm_m * f_steering_angle_rad * pedal_throttle_voltage + pedal_throttle_voltage;
weight[FR] = FR_arm_m * f_steering_angle_rad * pedal_throttle_voltage + pedal_throttle_voltage;
weight[RL] = RL_arm_m * f_steering_angle_rad * pedal_throttle_voltage + pedal_throttle_voltage;
weight[RR] = RR_arm_m * f_steering_angle_rad * pedal_throttle_voltage + pedal_throttle_voltage;
// pc.printf("\tweight (profile func output) \r\n");
// pc.printf("\tFL : %f, FR : %f, RL : %f, RR : %f\r\n", weight[FL], weight[FR], weight[RL], weight[RR]);
sum = weight[FL] + weight[FR] + weight[RL] + weight[RR];
// pc.printf("\tsum : %f\r\n", sum);
//normalize
for(dir = 0; dir < 4; dir++)
normalized_weight[dir] = 4 * (pedal_throttle_voltage / sum) * weight[dir];
// pc.printf("\tnormalized weight\r\n");
// pc.printf("\tFL : %f, FR : %f, RL : %f, RR : %f\r\n", normalized_weight[FL], normalized_weight[FR], normalized_weight[RL], normalized_weight[RR]);
// find maximum normalized value
max_weight = normalized_weight[FL];
for(dir = 0; dir < 4; dir++)
{
if(max_weight < normalized_weight[dir]){
max_weight = normalized_weight[dir];
}
}
// pc.printf("\tmax weight : %f\r\n", max_weight);
/*
// 0~max_weight 범위의 normalize된 값을 0~페달스로틀입력 으로 mapping
for (dir = 0; dir < 4; dir++)
{
f_wheel_torque_Nm[dir] = map_f(normalized_weight[dir], TORQUE_VECTORING_RATE, max_weight, 0.0, pedal_throttle_voltage)
* (ACTUAL_MAX_TORQUE_NY / CONTROLLER_INPUT_VOLT_RANGE);
// 홀전류센서 장착 이후 실제 MAX_TORQUE 수정 요망
} */
for (dir = 0; dir < 4; dir++) {
f_throttle[dir] = map_f(normalized_weight[dir], TORQUE_VECTORING_RATE, max_weight, 0.0, pedal_throttle_voltage);
}
// pc.printf("\tnormalized throttle \r\n");
// pc.printf("\tFL : %f, FR : %f, RL : %f, RR : %f\r\n", f_throttle[FL], f_throttle[FR], f_throttle[RL], f_throttle[RR]);
// 안전장치
for (dir = 0; dir < 4; dir++)
{
if (f_throttle[dir] < 0.0) f_throttle[dir] = 0;
}
f_feedforward_throttle_FL = f_throttle[FL];
f_feedforward_throttle_FR = f_throttle[FR];
f_feedforward_throttle_RL = f_throttle[RL];
f_feedforward_throttle_RR = f_throttle[RR];
return 0;
}
/*
- 차량 평균 속도와 바퀴 회전각을 이용해 계산한 yawrate와 imu로 측정하여 필터링된 yawrate를 입력으로 받아 PID 제어기로 torque 계산하는 함수.
- PID 제어기를 위한 error = 입력값(f_input_yaw_rate_degps) - 측정값(f_filtered_yaw_rate_degps)
- f_PID_yaw_rate2torque_Nm = KP * error (각각 4개)
- input
f_input_yaw_rate_degps: float, yawrate(rad/s), 차량 평균 속도와 바퀴 회전각으로 계산.
f_filtered_yaw_rate_degps: float, yawrate(rad/s), imu로 측정한 값을 필터링함.
- output
f_PID_yaw_rate2torque_Nm (4개 각각 출력): float, torque(N*m)
- configuration
KP_FOR_TORQUE (4개)
*/
void TorqueVectoringSystem::PIDYawRate2Torque(float f_input_yaw_rate_degps, float f_filtered_yaw_rate_degps,
float& f_PID_yaw_rate2torque_FL_Nm, float& f_PID_yaw_rate2torque_FR_Nm,
float& f_PID_yaw_rate2torque_RL_Nm, float& f_PID_yaw_rate2torque_RR_Nm)
{
float f_yaw_rate_error_degps = f_input_yaw_rate_degps - f_filtered_yaw_rate_degps;
if (f_yaw_rate_error_degps < 0.0)
{
f_PID_yaw_rate2torque_FL_Nm = KP_FOR_TORQUE_FL * abs(f_yaw_rate_error_degps);
f_PID_yaw_rate2torque_RL_Nm = KP_FOR_TORQUE_RL * abs(f_yaw_rate_error_degps);
f_PID_yaw_rate2torque_FR_Nm = 0;
f_PID_yaw_rate2torque_RR_Nm = 0;
}
else
{
f_PID_yaw_rate2torque_FL_Nm = 0;
f_PID_yaw_rate2torque_RL_Nm = 0;
f_PID_yaw_rate2torque_FR_Nm = KP_FOR_TORQUE_FR * abs(f_yaw_rate_error_degps);
f_PID_yaw_rate2torque_RR_Nm = KP_FOR_TORQUE_RR * abs(f_yaw_rate_error_degps);
}
}
/*
- 차량 평균 속도와 바퀴 회전각을 이용해 계산한 yawrate와 imu로 측정하여 필터링된 yawrate를 입력으로 받아 PID 제어기로 torque 계산하는 함수.
- PID 제어기를 위한 error = 입력값(f_input_yaw_rate_degps) - 측정값(f_filtered_yaw_rate_degps)
- f_PID_yaw_rate2torque_Nm = KP * error (각각 4개)
- input
f_input_yaw_rate_degps: float, yawrate(rad/s), 차량 평균 속도와 바퀴 회전각으로 계산.
f_filtered_yaw_rate_degps: float, yawrate(rad/s), imu로 측정한 값을 필터링함.
- output
피드백되는 스로틀 수치
- configuration
KP_FOR_TORQUE (4개)
*/
void TorqueVectoringSystem::PIDYawRate2Throttle(float f_input_yaw_rate_degps, float f_filtered_yaw_rate_degps,
float& f_PID_throttle_FL, float& f_PID_throttle_FR,
float& f_PID_throttle_RL, float& f_PID_throttle_RR)
{
float f_yaw_rate_error_degps = f_input_yaw_rate_degps - f_filtered_yaw_rate_degps;
if (f_yaw_rate_error_degps < 0.0)
{
f_PID_throttle_FL = KP_FOR_TORQUE_FL * abs(f_yaw_rate_error_degps);
f_PID_throttle_RL = KP_FOR_TORQUE_RL * abs(f_yaw_rate_error_degps);
f_PID_throttle_FR = 0;
f_PID_throttle_RR = 0;
}
else
{
f_PID_throttle_FL = 0;
f_PID_throttle_RL = 0;
f_PID_throttle_FR = KP_FOR_TORQUE_FR * abs(f_yaw_rate_error_degps);
f_PID_throttle_RR = KP_FOR_TORQUE_RR * abs(f_yaw_rate_error_degps);
}
}
/*
- opamp 이용 전압 측정
- 션트 저항 양단 전압 증폭값을 읽음
- 옴의 법칙 이용 전류로 환산
- configuration
amp rate(200)
shunt resistance(50u)float
*/
float TorqueVectoringSystem::OpAmp2Current(float f_opamp_ADC)
{
float opamp_voltage = f_opamp_ADC * ANALOG_RANGE;
float shunt_voltage = opamp_voltage / AMP_RATE_MOTOR;
float motor_current = shunt_voltage / SHUNT_R;
return motor_current;
}
/*
- hall current transducer 이용 전류 측정
- 3.3V 전원 공급한 transducer의 출력 전압값을 전류로 환산
- map 함수 이용
- configuration
입력 : ANALOG_RANGE (3.3V)
출력 : CURRENT_SENSOR_VALUE (200A)
*/
float TorqueVectoringSystem::ReadCurrentSensor(float current_sensor_value)
{
float current_sensor_output_V = current_sensor_value * ANALOG_RANGE;
// map 함수 형식 이용, (-50A일 때의 센서값 ~ 100A일 때의 센서값) 을 (-50A ~ 100A) 로
// long map(long x, long in_min, long in_max, long out_min, long out_max) {
// return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; }
// 사용한 전류센서는 wcs1500
return (current_sensor_output_V - CURRENT_SENSOR_VALUE_m50A) * (100. * (-50.))
/ (CURRENT_SENSOR_VALUE_100A - CURRENT_SENSOR_VALUE_m50A) + (-50.);
}
/*
- 캔 통신 인터페이스 모듈(MCP2515)로 측정한 전류를 플레밍의 왼손 법칙을 이용하여 토크로 계산하는 함수.
- input
f_motor_current_A(4개): float, current(A)
- output
f_measured_torque_Nm(4개): float, torque(N*m)
- configuration
KT(모터 토크 상수) = 17 / 148
*/
float TorqueVectoringSystem::CvtCurrent2Torque(float f_motor_current_A)
{
return KT * f_motor_current_A;
}
/*
- PID 제어기로 계산한 torque를 이용해 output_throttle 생성하는 함수.
- input
f_torque_(4방향)_Nm: 각각 4개, float, torque(N*m)
- output
f_output_throttle_(4방향): 각각 4개, float, voltage(V)
- configuration
MAX_TORQUE = 17Nm
ACTUAL_MAX_TORQUE 는 추후 측정 예정.
*/
float TorqueVectoringSystem::Torque2Throttle(float f_torque_Nm)
{
float f_output_throttle = f_torque_Nm * (ANALOG_RANGE / ACTUAL_MAX_TORQUE_NY);
return f_output_throttle;
}
/*
- PID 제어기로 계산한 torque와 캔 통신으로 측정한 전류를 이용해 계산한 torque를 입력으로 받아 PID 제어기로 throttle을 계산하는 함수.
- PID 제어기를 위한 error = 입력값(f_torque_(4방향)_Nm) - 측정값(f_output_throttle_(4방향))
- f_PID_throttle_(4방향) = KP_FOR_THROTTLE * error (각각 4개)
- input
f_torque_(4방향)_Nm: 각각 4개, float, torque(N*m), PID 제어기로 계산한 토크.
f_output_throttle_(4방향): 각각 4개, float, torque(N*m), 캔 통신으로 측정한 전류를 이용해 계산한 토크.
- output
f_PID_throttle_(4방향): 각각 4개, float, voltage(V)
- configuration
KP_FOR_THROTTLE
*/
float TorqueVectoringSystem::PIDforThrottle(float f_torque_Nm, float f_measured_torque_Nm, int direction)
{
float error = f_torque_Nm - f_measured_torque_Nm;
float f_PID_throttle;
if (direction == FL) f_PID_throttle = KP_FOR_THROTTLE_FL * error * (ANALOG_RANGE / ACTUAL_MAX_TORQUE_NY);
else if (direction == FR) f_PID_throttle = KP_FOR_THROTTLE_FR * error * (ANALOG_RANGE / ACTUAL_MAX_TORQUE_NY);
else if (direction == RL) f_PID_throttle = KP_FOR_THROTTLE_RL * error * (ANALOG_RANGE / ACTUAL_MAX_TORQUE_NY);
else if (direction == RR) f_PID_throttle = KP_FOR_THROTTLE_RR * error * (ANALOG_RANGE / ACTUAL_MAX_TORQUE_NY);
return f_PID_throttle;
}
/*
- PWM 함수의 입력 범위가 올바르도록 Saturation하는 함수.
- input
f_output_throttle_(4방향): 각각 4개, float, voltage
f_PID_throttle_(4방향): 각각 4개, float, voltage(V)
- output
f_PWM_input: 각각 4개, float, PWM 출력
- configuration
LOWER_BOUND = 0
UPPER_BOUND = 1
*/
float TorqueVectoringSystem::SumFFandPID(float f_output_throttle, float f_PID_throttle)
{
float PWM_throttle_mbed_value = (f_output_throttle + f_PID_throttle) / ANALOG_RANGE;
if (PWM_throttle_mbed_value >= UPPER_BOUND)
return UPPER_BOUND;
else if (PWM_throttle_mbed_value <= LOWER_BOUND)
return LOWER_BOUND;
else
return PWM_throttle_mbed_value;
}
/*
페달의 최대각, 최소각에 따른 실제 입력값(mbed의 경우 0.0~1.0)
의 값을 실제로 측정 후, 이를 0.0~1.0의 값으로 mapping하는 함수
*/
float TorqueVectoringSystem::ModifyPedalThrottle(float input, float in_min, float in_max, float out_min, float out_max)
{
return (input - in_min)*(out_max - out_min) / (in_max - in_min) + out_min;
}
void TorqueVectoringSystem::process_accel()
{
// pc.printf("entered WHILE : \r\n");
//f_motor_RPM_FL = FL_Hall_A.getRPM();
//f_motor_RPM_FR = FR_Hall_A.getRPM();
f_motor_RPM_RL = RL_Hall_A.getRPM();
f_motor_RPM_RR = RR_Hall_A.getRPM();
// pc.printf("RL RPM : %f, RR RPM : %f\r\n", f_motor_RPM_RL, f_motor_RPM_RR);
//f_vel_FL_ms = CvtRPM2Vel(f_motor_RPM_FL);
//f_vel_FR_ms = CvtRPM2Vel(f_motor_RPM_FR);
f_vel_RL_ms = CvtRPM2Vel(f_motor_RPM_RL);
f_vel_RR_ms = CvtRPM2Vel(f_motor_RPM_RR);
// pc.printf("RL vel : %f, RR vel : %f m/s\r\n", f_vel_RL_ms, f_vel_RR_ms);
f_vehicle_vel_ms = CalAvgVel(f_vel_RR_ms, f_vel_RL_ms);
// pc.printf("Car velocity : %f \r\n", f_vehicle_vel_ms);
//f_steering_sensor_value 받기!
// pc.printf("Handle sensor value : %f\r\n", Handle_Sensor.read());
f_wheel_angle_deg = map_f(Handle_Sensor.read(), RESISTOR_RIGHT_MAX, RESISTOR_LEFT_MAX,
(-1.0)*MAX_STEERING_ANGLE, MAX_STEERING_ANGLE);
if (f_wheel_angle_deg < (-1.0)*MAX_STEERING_ANGLE) f_wheel_angle_deg = (-1.0)*MAX_STEERING_ANGLE;
if (f_wheel_angle_deg > MAX_STEERING_ANGLE) f_wheel_angle_deg = MAX_STEERING_ANGLE;
// pc.printf("wheel angle : %f\r\n",f_wheel_angle_deg);
///////////////////////////////////////////////////////////////
f_yawrate_input_deg = CalInputYawRate(f_vehicle_vel_ms, f_wheel_angle_deg);
// pc.printf("target yaw rate : %f \t\t", f_yawrate_input_deg);
mpu.read(&IMU_gx, &IMU_gy, &IMU_gz, &IMU_ax, &IMU_ay, &IMU_az);
f_yawrate_meas_degs = IMU_gz;
//////////////////////////////////////////////////////////////////
f_yaw_rate_meas_filtered_degs = IMUFilter(f_yawrate_meas_degs);
// pc.printf("measured yaw rate : %f \r\n", f_yaw_rate_meas_filtered_degs);
//f_pedal_sensor_value 받기!
f_pedal_sensor_value = Pedal_Sensor.read();
if (f_pedal_sensor_value <= PEDAL_MIN_VALUE) f_pedal_sensor_value = PEDAL_MIN_VALUE; // 안전장치
if (f_pedal_sensor_value > PEDAL_MAX_VALUE) f_pedal_sensor_value = PEDAL_MAX_VALUE;
// pc.printf("pedal raw value (0.0~1.0 value) : %f\r\n", f_pedal_sensor_value);
//Modify pedal sensor vlaue range(true sensor value min~max) ----> (0.0 ~ 1.0)
f_pedal_modified_sensor_value = ModifyPedalThrottle(f_pedal_sensor_value, PEDAL_MIN_VALUE, PEDAL_MAX_VALUE, 0.0, 1.0);
if (f_pedal_modified_sensor_value < 0.0) f_pedal_modified_sensor_value = 0.0;
if (f_pedal_modified_sensor_value > 1.0) f_pedal_modified_sensor_value = 1.0;
// pc.printf("modified pedal value(0.0~1.0 value) : %f\r\n", f_pedal_modified_sensor_value);
// for MMS PWR
i_PWR_percentage = (int)(f_pedal_modified_sensor_value * 100);
// pc.printf("PWR percentage : %d\r\n", i_PWR_percentage);
WheelSteeringAngle2Throttle(f_wheel_angle_deg, f_pedal_modified_sensor_value,
f_feedforward_throttle_FL, f_feedforward_throttle_FR,
f_feedforward_throttle_RL, f_feedforward_throttle_RR);
// pc.printf("feedforward throttle : \r\n");
// pc.printf("FL : %f, FR : %f, RL : %f, RR : %f\r\n", f_feedforward_throttle_FL, f_feedforward_throttle_FR, f_feedforward_throttle_RL, f_feedforward_throttle_RR);
/* 가슴이 아프다 ㅠㅠ
PIDYawRate2Throttle(f_yawrate_input_deg, f_yaw_rate_meas_filtered_degs,
f_PID_throttle_FL, f_PID_throttle_FR,
f_PID_throttle_RL, f_PID_throttle_RR);
// pc.printf("P controlled throttle output \r\n");
// pc.printf("FL : %f, FR : %f, RL : %f, RR : %f\r\n", f_PID_throttle_FL, f_PID_throttle_FR, f_PID_throttle_RL, f_PID_throttle_RR);
f_output_throttle_FL = f_feedforward_throttle_FL + f_PID_throttle_FL;
f_output_throttle_FR = f_feedforward_throttle_FR + f_PID_throttle_FR;
f_output_throttle_RL = f_feedforward_throttle_RL + f_PID_throttle_RL;
f_output_throttle_RR = f_feedforward_throttle_RR + f_PID_throttle_RR;
if (f_output_throttle_FL > 5.0) f_output_throttle_FL = 5.0;
if (f_output_throttle_FR > 5.0) f_output_throttle_FR = 5.0;
if (f_output_throttle_RL > 5.0) f_output_throttle_RL = 5.0;
if (f_output_throttle_RR > 5.0) f_output_throttle_RR = 5.0;
// pc.printf("raw output throttle signal(voltage)\r\n");
// pc.printf("FL : %f, FR : %f, RL : %f, RR : %f\r\n", f_output_throttle_FL, f_output_throttle_FR, f_output_throttle_RL, f_output_throttle_RR);
f_PWM_input_FL = map_f(f_output_throttle_FL, 0.0, 5.0, CONTROLLER_IN_MIN, CONTROLLER_IN_MAX); // 0~5V의 전압값을 0~1의 pwm출력으로 변환
f_PWM_input_FR = map_f(f_output_throttle_FR, 0.0, 5.0, CONTROLLER_IN_MIN, CONTROLLER_IN_MAX); // 0~5V의 전압값을 0~1의 pwm출력으로 변환
f_PWM_input_RL = map_f(f_output_throttle_RL, 0.0, 5.0, CONTROLLER_IN_MIN, CONTROLLER_IN_MAX); // 0~5V의 전압값을 0~1의 pwm출력으로 변환
f_PWM_input_RR = map_f(f_output_throttle_RR, 0.0, 5.0, CONTROLLER_IN_MIN, CONTROLLER_IN_MAX); // 0~5V의 전압값을 0~1의 pwm출력으로 변환
// pc.printf("modified PWM value : \r\n");
// pc.printf("FL : %f, FR : %f, RL : %f, RR : %f\r\n", f_PWM_input_FL, f_PWM_input_FR, f_PWM_input_RL, f_PWM_input_RR);
FL_Throttle_PWM = f_PWM_input_FL; // float 값을 PwmOut 변수에 대입!
FR_Throttle_PWM = f_PWM_input_FR;
RL_Throttle_PWM = f_PWM_input_RL;
RR_Throttle_PWM = f_PWM_input_RR;
// pc.printf("actual throttle signal(voltage)\r\n");
// pc.printf("FL : %f, FR : %f, RL : %f, RR : %f\r\n", FL_Throttle_PWM.read() * 3.3, FR_Throttle_PWM.read() * 3.3, RL_Throttle_PWM.read() * 3.3, RR_Throttle_PWM.read() * 3.3);
// pc.printf("\r\n\n\n\n\n");
}
/*=====================================================================================================
=======================================================================================================
for autonomous driving
=======================================================================================================*/
void TorqueVectoringSystem::process_accel(float accel_value) // accel value 0.0 ~ 1.0
{
// DigitalIn TVS_SWITCH(TVS_SWITCH_PIN);
float trimmed_throttle_FL; // 0.5V에서 4.1V로 출력 변경을 위한 변수
float trimmed_throttle_FR;
float trimmed_throttle_RL;
float trimmed_throttle_RR;
// pc.printf("entered WHILE : \r\n");
//f_motor_RPM_FL = FL_Hall_A.getRPM();
//f_motor_RPM_FR = FR_Hall_A.getRPM();
f_motor_RPM_RL = RL_Hall_A.getRPM();
f_motor_RPM_RR = RR_Hall_A.getRPM();
// pc.printf("FL RPM : %f, FR RPM : %f, RL RPM : %f, RR RPM : %f\r\n", f_motor_RPM_FL, f_motor_RPM_FR, f_motor_RPM_RL, f_motor_RPM_RR);
f_vel_FL_ms = CvtRPM2Vel(f_motor_RPM_FL);
f_vel_FR_ms = CvtRPM2Vel(f_motor_RPM_FR);
f_vel_RL_ms = CvtRPM2Vel(f_motor_RPM_RL);
f_vel_RR_ms = CvtRPM2Vel(f_motor_RPM_RR);
// pc.printf("FL vel : %f, FR vel : %f, RL vel : %f, RR vel : %f\r\n", f_vel_FL_ms, f_vel_FR_ms, f_vel_RL_ms, f_vel_RR_ms);
f_vehicle_vel_ms = CalAvgVel(f_vel_RR_ms, f_vel_RL_ms);
// pc.printf("Car velocity : %f \r\n", f_vehicle_vel_ms);
//f_steering_sensor_value 받기!
// pc.printf("Handle sensor value : %f\r\n", Handle_Sensor.read());
f_wheel_angle_deg = CalHandlingVolt2WheelSteeringAngle(Handle_Sensor.read());
// pc.printf("wheel angle : %f\r\n",f_wheel_angle_deg);
f_yawrate_input_deg = CalInputYawRate(f_vehicle_vel_ms, f_wheel_angle_deg);
// pc.printf("target yaw rate : %f \t\t", f_yawrate_input_deg);
mpu.read(&IMU_gx, &IMU_gy, &IMU_gz, &IMU_ax, &IMU_ay, &IMU_az);
f_yawrate_meas_degs = IMU_gz; // 김치박스가 다시 눕힘
//////////////////////////////////////////////////////////////////
f_yaw_rate_meas_filtered_degs = IMUFilter(f_yawrate_meas_degs);
// pc.printf("measured yaw rate : %f \r\n", f_yaw_rate_meas_filtered_degs);
/*
// 수동 주행 페달 신호 가공 제외
//f_pedal_sensor_value 받기!
f_pedal_sensor_value = Pedal_Sensor.read();
if (f_pedal_sensor_value <= PEDAL_MIN_VALUE) f_pedal_sensor_value = PEDAL_MIN_VALUE; // 안전장치
if (f_pedal_sensor_value > PEDAL_MAX_VALUE) f_pedal_sensor_value = PEDAL_MAX_VALUE;
// pc.printf("pedal raw value (0.0~1.0 value) : %f\r\n", f_pedal_sensor_value);
//Modify pedal sensor vlaue range(true sensor value min~max) ----> (0.0 ~ 1.0)
f_pedal_modified_sensor_value = ModifyPedalThrottle(f_pedal_sensor_value, PEDAL_MIN_VALUE, PEDAL_MAX_VALUE, 0.0, 1.0);
if (f_pedal_modified_sensor_value < 0.0) f_pedal_modified_sensor_value = 0.0;
if (f_pedal_modified_sensor_value > 1.0) f_pedal_modified_sensor_value = 1.0;
// pc.printf("modified pedal value(0.0~1.0 value) : %f\r\n", f_pedal_modified_sensor_value);
*/
// publish한 accel값을 구동에 이용
f_pedal_modified_sensor_value = accel_value;
if (f_pedal_modified_sensor_value < 0.0) f_pedal_modified_sensor_value = 0.0;
// for MMS PWR
i_PWR_percentage = (int)(f_pedal_modified_sensor_value * 100);
// pc.printf("PWR percentage : %d\r\n", i_PWR_percentage);
WheelSteeringAngle2Torque(f_wheel_angle_deg, f_pedal_modified_sensor_value,
f_wheel_torque_FL_Nm, f_wheel_torque_FR_Nm,
f_wheel_torque_RL_Nm, f_wheel_torque_RR_Nm);
// pc.printf("feedforward torque : \r\n");
// pc.printf("FL : %f, FR : %f, RL : %f, RR : %f\r\n", f_wheel_torque_FL_Nm, f_wheel_torque_FR_Nm, f_wheel_torque_RL_Nm, f_wheel_torque_RR_Nm);
/* 가슴이 아프다 ㅠㅠ
PIDYawRate2Torque(f_yawrate_input_deg, f_yaw_rate_meas_filtered_degs,
f_PID_yaw_rate2torque_FL_Nm, f_PID_yaw_rate2torque_FR_Nm,
f_PID_yaw_rate2torque_RL_Nm, f_PID_yaw_rate2torque_RR_Nm);
*/
// pc.printf("P controlled torque output \r\n");
// pc.printf("FL : %f, FR : %f, RL : %f, RR : %f\r\n", f_PID_yaw_rate2torque_FL_Nm, f_PID_yaw_rate2torque_FR_Nm, f_PID_yaw_rate2torque_RL_Nm, f_PID_yaw_rate2torque_RR_Nm);
f_torque_FL_Nm = f_wheel_torque_FL_Nm + f_PID_yaw_rate2torque_FL_Nm;
f_torque_FR_Nm = f_wheel_torque_FR_Nm + f_PID_yaw_rate2torque_FR_Nm;
f_torque_RL_Nm = f_wheel_torque_RL_Nm + f_PID_yaw_rate2torque_RL_Nm;
f_torque_RR_Nm = f_wheel_torque_RR_Nm + f_PID_yaw_rate2torque_RR_Nm;
// pc.printf("actual generating torque\r\n");
// pc.printf("FL : %f, FR : %f, RL : %f, RR : %f\r\n", f_torque_FL_Nm, f_torque_FR_Nm, f_torque_RL_Nm, f_torque_RR_Nm);