forked from vedderb/bldc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
confgenerator.c
1167 lines (1148 loc) · 68.9 KB
/
confgenerator.c
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
// This file is autogenerated by VESC Tool
#include <string.h>
#include "buffer.h"
#include "conf_general.h"
#include "confgenerator.h"
int32_t confgenerator_serialize_mcconf(uint8_t *buffer, const mc_configuration *conf) {
int32_t ind = 0;
buffer_append_uint32(buffer, MCCONF_SIGNATURE, &ind);
buffer[ind++] = conf->pwm_mode;
buffer[ind++] = conf->comm_mode;
buffer[ind++] = conf->motor_type;
buffer[ind++] = conf->sensor_mode;
buffer_append_float32_auto(buffer, conf->l_current_max, &ind);
buffer_append_float32_auto(buffer, conf->l_current_min, &ind);
buffer_append_float32_auto(buffer, conf->l_in_current_max, &ind);
buffer_append_float32_auto(buffer, conf->l_in_current_min, &ind);
buffer_append_float32_auto(buffer, conf->l_abs_current_max, &ind);
buffer_append_float32_auto(buffer, conf->l_min_erpm, &ind);
buffer_append_float32_auto(buffer, conf->l_max_erpm, &ind);
buffer_append_float16(buffer, conf->l_erpm_start, 10000, &ind);
buffer_append_float32_auto(buffer, conf->l_max_erpm_fbrake, &ind);
buffer_append_float32_auto(buffer, conf->l_max_erpm_fbrake_cc, &ind);
buffer_append_float32_auto(buffer, conf->l_min_vin, &ind);
buffer_append_float32_auto(buffer, conf->l_max_vin, &ind);
buffer_append_float32_auto(buffer, conf->l_battery_cut_start, &ind);
buffer_append_float32_auto(buffer, conf->l_battery_cut_end, &ind);
buffer[ind++] = conf->l_slow_abs_current;
buffer_append_float16(buffer, conf->l_temp_fet_start, 10, &ind);
buffer_append_float16(buffer, conf->l_temp_fet_end, 10, &ind);
buffer_append_float16(buffer, conf->l_temp_motor_start, 10, &ind);
buffer_append_float16(buffer, conf->l_temp_motor_end, 10, &ind);
buffer_append_float16(buffer, conf->l_temp_accel_dec, 10000, &ind);
buffer_append_float16(buffer, conf->l_min_duty, 10000, &ind);
buffer_append_float16(buffer, conf->l_max_duty, 10000, &ind);
buffer_append_float32_auto(buffer, conf->l_watt_max, &ind);
buffer_append_float32_auto(buffer, conf->l_watt_min, &ind);
buffer_append_float16(buffer, conf->l_current_max_scale, 10000, &ind);
buffer_append_float16(buffer, conf->l_current_min_scale, 10000, &ind);
buffer_append_float16(buffer, conf->l_duty_start, 10000, &ind);
buffer_append_float32_auto(buffer, conf->sl_min_erpm, &ind);
buffer_append_float32_auto(buffer, conf->sl_min_erpm_cycle_int_limit, &ind);
buffer_append_float32_auto(buffer, conf->sl_max_fullbreak_current_dir_change, &ind);
buffer_append_float16(buffer, conf->sl_cycle_int_limit, 10, &ind);
buffer_append_float16(buffer, conf->sl_phase_advance_at_br, 10000, &ind);
buffer_append_float32_auto(buffer, conf->sl_cycle_int_rpm_br, &ind);
buffer_append_float32_auto(buffer, conf->sl_bemf_coupling_k, &ind);
buffer[ind++] = (uint8_t)conf->hall_table[0];
buffer[ind++] = (uint8_t)conf->hall_table[1];
buffer[ind++] = (uint8_t)conf->hall_table[2];
buffer[ind++] = (uint8_t)conf->hall_table[3];
buffer[ind++] = (uint8_t)conf->hall_table[4];
buffer[ind++] = (uint8_t)conf->hall_table[5];
buffer[ind++] = (uint8_t)conf->hall_table[6];
buffer[ind++] = (uint8_t)conf->hall_table[7];
buffer_append_float32_auto(buffer, conf->hall_sl_erpm, &ind);
buffer_append_float32_auto(buffer, conf->foc_current_kp, &ind);
buffer_append_float32_auto(buffer, conf->foc_current_ki, &ind);
buffer_append_float32_auto(buffer, conf->foc_f_zv, &ind);
buffer_append_float32_auto(buffer, conf->foc_dt_us, &ind);
buffer[ind++] = conf->foc_encoder_inverted;
buffer_append_float32_auto(buffer, conf->foc_encoder_offset, &ind);
buffer_append_float32_auto(buffer, conf->foc_encoder_ratio, &ind);
buffer_append_float16(buffer, conf->foc_encoder_sin_gain, 1000, &ind);
buffer_append_float16(buffer, conf->foc_encoder_cos_gain, 1000, &ind);
buffer_append_float16(buffer, conf->foc_encoder_sin_offset, 1000, &ind);
buffer_append_float16(buffer, conf->foc_encoder_cos_offset, 1000, &ind);
buffer_append_float16(buffer, conf->foc_encoder_sincos_filter_constant, 1000, &ind);
buffer[ind++] = conf->foc_sensor_mode;
buffer_append_float32_auto(buffer, conf->foc_pll_kp, &ind);
buffer_append_float32_auto(buffer, conf->foc_pll_ki, &ind);
buffer_append_float32_auto(buffer, conf->foc_motor_l, &ind);
buffer_append_float32_auto(buffer, conf->foc_motor_ld_lq_diff, &ind);
buffer_append_float32_auto(buffer, conf->foc_motor_r, &ind);
buffer_append_float32_auto(buffer, conf->foc_motor_flux_linkage, &ind);
buffer_append_float32_auto(buffer, conf->foc_observer_gain, &ind);
buffer_append_float32_auto(buffer, conf->foc_observer_gain_slow, &ind);
buffer_append_float16(buffer, conf->foc_observer_offset, 1000, &ind);
buffer_append_float32_auto(buffer, conf->foc_duty_dowmramp_kp, &ind);
buffer_append_float32_auto(buffer, conf->foc_duty_dowmramp_ki, &ind);
buffer_append_float16(buffer, conf->foc_start_curr_dec, 10000, &ind);
buffer_append_float32_auto(buffer, conf->foc_start_curr_dec_rpm, &ind);
buffer_append_float32_auto(buffer, conf->foc_openloop_rpm, &ind);
buffer_append_float16(buffer, conf->foc_openloop_rpm_low, 1000, &ind);
buffer_append_float16(buffer, conf->foc_d_gain_scale_start, 1000, &ind);
buffer_append_float16(buffer, conf->foc_d_gain_scale_max_mod, 1000, &ind);
buffer_append_float16(buffer, conf->foc_sl_openloop_hyst, 100, &ind);
buffer_append_float16(buffer, conf->foc_sl_openloop_time_lock, 100, &ind);
buffer_append_float16(buffer, conf->foc_sl_openloop_time_ramp, 100, &ind);
buffer_append_float16(buffer, conf->foc_sl_openloop_time, 100, &ind);
buffer_append_float16(buffer, conf->foc_sl_openloop_boost_q, 100, &ind);
buffer_append_float16(buffer, conf->foc_sl_openloop_max_q, 100, &ind);
buffer[ind++] = (uint8_t)conf->foc_hall_table[0];
buffer[ind++] = (uint8_t)conf->foc_hall_table[1];
buffer[ind++] = (uint8_t)conf->foc_hall_table[2];
buffer[ind++] = (uint8_t)conf->foc_hall_table[3];
buffer[ind++] = (uint8_t)conf->foc_hall_table[4];
buffer[ind++] = (uint8_t)conf->foc_hall_table[5];
buffer[ind++] = (uint8_t)conf->foc_hall_table[6];
buffer[ind++] = (uint8_t)conf->foc_hall_table[7];
buffer_append_float32_auto(buffer, conf->foc_hall_interp_erpm, &ind);
buffer_append_float32_auto(buffer, conf->foc_sl_erpm, &ind);
buffer[ind++] = conf->foc_sample_v0_v7;
buffer[ind++] = conf->foc_sample_high_current;
buffer[ind++] = conf->foc_sat_comp_mode;
buffer_append_float16(buffer, conf->foc_sat_comp, 1000, &ind);
buffer[ind++] = conf->foc_temp_comp;
buffer_append_float16(buffer, conf->foc_temp_comp_base_temp, 100, &ind);
buffer_append_float16(buffer, conf->foc_current_filter_const, 10000, &ind);
buffer[ind++] = conf->foc_cc_decoupling;
buffer[ind++] = conf->foc_observer_type;
buffer_append_float16(buffer, conf->foc_hfi_voltage_start, 10, &ind);
buffer_append_float16(buffer, conf->foc_hfi_voltage_run, 10, &ind);
buffer_append_float16(buffer, conf->foc_hfi_voltage_max, 10, &ind);
buffer_append_float16(buffer, conf->foc_hfi_gain, 1000, &ind);
buffer_append_float16(buffer, conf->foc_hfi_hyst, 100, &ind);
buffer_append_float32_auto(buffer, conf->foc_sl_erpm_hfi, &ind);
buffer_append_uint16(buffer, conf->foc_hfi_start_samples, &ind);
buffer_append_float32_auto(buffer, conf->foc_hfi_obs_ovr_sec, &ind);
buffer[ind++] = conf->foc_hfi_samples;
buffer[ind++] = conf->foc_offsets_cal_on_boot;
buffer_append_float32_auto(buffer, conf->foc_offsets_current[0], &ind);
buffer_append_float32_auto(buffer, conf->foc_offsets_current[1], &ind);
buffer_append_float32_auto(buffer, conf->foc_offsets_current[2], &ind);
buffer_append_float16(buffer, conf->foc_offsets_voltage[0], 10000, &ind);
buffer_append_float16(buffer, conf->foc_offsets_voltage[1], 10000, &ind);
buffer_append_float16(buffer, conf->foc_offsets_voltage[2], 10000, &ind);
buffer_append_float16(buffer, conf->foc_offsets_voltage_undriven[0], 10000, &ind);
buffer_append_float16(buffer, conf->foc_offsets_voltage_undriven[1], 10000, &ind);
buffer_append_float16(buffer, conf->foc_offsets_voltage_undriven[2], 10000, &ind);
buffer[ind++] = conf->foc_phase_filter_enable;
buffer[ind++] = conf->foc_phase_filter_disable_fault;
buffer_append_float32_auto(buffer, conf->foc_phase_filter_max_erpm, &ind);
buffer[ind++] = conf->foc_mtpa_mode;
buffer_append_float32_auto(buffer, conf->foc_fw_current_max, &ind);
buffer_append_float16(buffer, conf->foc_fw_duty_start, 10000, &ind);
buffer_append_float16(buffer, conf->foc_fw_ramp_time, 1000, &ind);
buffer_append_float16(buffer, conf->foc_fw_q_current_factor, 10000, &ind);
buffer[ind++] = conf->foc_speed_soure;
buffer_append_int16(buffer, conf->gpd_buffer_notify_left, &ind);
buffer_append_int16(buffer, conf->gpd_buffer_interpol, &ind);
buffer_append_float16(buffer, conf->gpd_current_filter_const, 10000, &ind);
buffer_append_float32_auto(buffer, conf->gpd_current_kp, &ind);
buffer_append_float32_auto(buffer, conf->gpd_current_ki, &ind);
buffer[ind++] = conf->sp_pid_loop_rate;
buffer_append_float32_auto(buffer, conf->s_pid_kp, &ind);
buffer_append_float32_auto(buffer, conf->s_pid_ki, &ind);
buffer_append_float32_auto(buffer, conf->s_pid_kd, &ind);
buffer_append_float16(buffer, conf->s_pid_kd_filter, 10000, &ind);
buffer_append_float32_auto(buffer, conf->s_pid_min_erpm, &ind);
buffer[ind++] = conf->s_pid_allow_braking;
buffer_append_float32_auto(buffer, conf->s_pid_ramp_erpms_s, &ind);
buffer_append_float32_auto(buffer, conf->p_pid_kp, &ind);
buffer_append_float32_auto(buffer, conf->p_pid_ki, &ind);
buffer_append_float32_auto(buffer, conf->p_pid_kd, &ind);
buffer_append_float32_auto(buffer, conf->p_pid_kd_proc, &ind);
buffer_append_float16(buffer, conf->p_pid_kd_filter, 10000, &ind);
buffer_append_float32_auto(buffer, conf->p_pid_ang_div, &ind);
buffer_append_float16(buffer, conf->p_pid_gain_dec_angle, 10, &ind);
buffer_append_float32_auto(buffer, conf->p_pid_offset, &ind);
buffer_append_float16(buffer, conf->cc_startup_boost_duty, 10000, &ind);
buffer_append_float32_auto(buffer, conf->cc_min_current, &ind);
buffer_append_float32_auto(buffer, conf->cc_gain, &ind);
buffer_append_float16(buffer, conf->cc_ramp_step_max, 10000, &ind);
buffer_append_int32(buffer, conf->m_fault_stop_time_ms, &ind);
buffer_append_float16(buffer, conf->m_duty_ramp_step, 10000, &ind);
buffer_append_float32_auto(buffer, conf->m_current_backoff_gain, &ind);
buffer_append_uint32(buffer, conf->m_encoder_counts, &ind);
buffer[ind++] = conf->m_sensor_port_mode;
buffer[ind++] = conf->m_invert_direction;
buffer[ind++] = conf->m_drv8301_oc_mode;
buffer[ind++] = (uint8_t)conf->m_drv8301_oc_adj;
buffer_append_float32_auto(buffer, conf->m_bldc_f_sw_min, &ind);
buffer_append_float32_auto(buffer, conf->m_bldc_f_sw_max, &ind);
buffer_append_float32_auto(buffer, conf->m_dc_f_sw, &ind);
buffer_append_float32_auto(buffer, conf->m_ntc_motor_beta, &ind);
buffer[ind++] = conf->m_out_aux_mode;
buffer[ind++] = conf->m_motor_temp_sens_type;
buffer_append_float32_auto(buffer, conf->m_ptc_motor_coeff, &ind);
buffer_append_float16(buffer, conf->m_ntcx_ptcx_res, 0.1, &ind);
buffer_append_float16(buffer, conf->m_ntcx_ptcx_temp_base, 10, &ind);
buffer[ind++] = (uint8_t)conf->m_hall_extra_samples;
buffer[ind++] = (uint8_t)conf->si_motor_poles;
buffer_append_float32_auto(buffer, conf->si_gear_ratio, &ind);
buffer_append_float32_auto(buffer, conf->si_wheel_diameter, &ind);
buffer[ind++] = conf->si_battery_type;
buffer[ind++] = (uint8_t)conf->si_battery_cells;
buffer_append_float32_auto(buffer, conf->si_battery_ah, &ind);
buffer_append_float32_auto(buffer, conf->si_motor_nl_current, &ind);
buffer[ind++] = conf->bms.type;
buffer[ind++] = conf->bms.limit_mode;
buffer_append_float16(buffer, conf->bms.t_limit_start, 100, &ind);
buffer_append_float16(buffer, conf->bms.t_limit_end, 100, &ind);
buffer_append_float16(buffer, conf->bms.soc_limit_start, 1000, &ind);
buffer_append_float16(buffer, conf->bms.soc_limit_end, 1000, &ind);
buffer[ind++] = conf->bms.fwd_can_mode;
return ind;
}
int32_t confgenerator_serialize_appconf(uint8_t *buffer, const app_configuration *conf) {
int32_t ind = 0;
buffer_append_uint32(buffer, APPCONF_SIGNATURE, &ind);
buffer[ind++] = (uint8_t)conf->controller_id;
buffer_append_uint32(buffer, conf->timeout_msec, &ind);
buffer_append_float32_auto(buffer, conf->timeout_brake_current, &ind);
buffer_append_uint16(buffer, conf->can_status_rate_1, &ind);
buffer_append_uint16(buffer, conf->can_status_rate_2, &ind);
buffer[ind++] = conf->can_status_msgs_r1;
buffer[ind++] = conf->can_status_msgs_r2;
buffer[ind++] = conf->can_baud_rate;
buffer[ind++] = conf->pairing_done;
buffer[ind++] = conf->permanent_uart_enabled;
buffer[ind++] = conf->shutdown_mode;
buffer[ind++] = conf->can_mode;
buffer[ind++] = (uint8_t)conf->uavcan_esc_index;
buffer[ind++] = conf->uavcan_raw_mode;
buffer_append_float32_auto(buffer, conf->uavcan_raw_rpm_max, &ind);
buffer[ind++] = conf->uavcan_status_current_mode;
buffer[ind++] = conf->servo_out_enable;
buffer[ind++] = conf->kill_sw_mode;
buffer[ind++] = conf->app_to_use;
buffer[ind++] = conf->app_ppm_conf.ctrl_type;
buffer_append_float32_auto(buffer, conf->app_ppm_conf.pid_max_erpm, &ind);
buffer_append_float32_auto(buffer, conf->app_ppm_conf.hyst, &ind);
buffer_append_float32_auto(buffer, conf->app_ppm_conf.pulse_start, &ind);
buffer_append_float32_auto(buffer, conf->app_ppm_conf.pulse_end, &ind);
buffer_append_float32_auto(buffer, conf->app_ppm_conf.pulse_center, &ind);
buffer[ind++] = conf->app_ppm_conf.median_filter;
buffer[ind++] = conf->app_ppm_conf.safe_start;
buffer_append_float32_auto(buffer, conf->app_ppm_conf.throttle_exp, &ind);
buffer_append_float32_auto(buffer, conf->app_ppm_conf.throttle_exp_brake, &ind);
buffer[ind++] = conf->app_ppm_conf.throttle_exp_mode;
buffer_append_float32_auto(buffer, conf->app_ppm_conf.ramp_time_pos, &ind);
buffer_append_float32_auto(buffer, conf->app_ppm_conf.ramp_time_neg, &ind);
buffer[ind++] = conf->app_ppm_conf.multi_esc;
buffer[ind++] = conf->app_ppm_conf.tc;
buffer_append_float32_auto(buffer, conf->app_ppm_conf.tc_max_diff, &ind);
buffer_append_float16(buffer, conf->app_ppm_conf.max_erpm_for_dir, 1, &ind);
buffer_append_float32_auto(buffer, conf->app_ppm_conf.smart_rev_max_duty, &ind);
buffer_append_float32_auto(buffer, conf->app_ppm_conf.smart_rev_ramp_time, &ind);
buffer[ind++] = conf->app_adc_conf.ctrl_type;
buffer_append_float32_auto(buffer, conf->app_adc_conf.hyst, &ind);
buffer_append_float16(buffer, conf->app_adc_conf.voltage_start, 1000, &ind);
buffer_append_float16(buffer, conf->app_adc_conf.voltage_end, 1000, &ind);
buffer_append_float16(buffer, conf->app_adc_conf.voltage_min, 1000, &ind);
buffer_append_float16(buffer, conf->app_adc_conf.voltage_max, 1000, &ind);
buffer_append_float16(buffer, conf->app_adc_conf.voltage_center, 1000, &ind);
buffer_append_float16(buffer, conf->app_adc_conf.voltage2_start, 1000, &ind);
buffer_append_float16(buffer, conf->app_adc_conf.voltage2_end, 1000, &ind);
buffer[ind++] = conf->app_adc_conf.use_filter;
buffer[ind++] = conf->app_adc_conf.safe_start;
buffer[ind++] = conf->app_adc_conf.buttons;
buffer[ind++] = conf->app_adc_conf.voltage_inverted;
buffer[ind++] = conf->app_adc_conf.voltage2_inverted;
buffer_append_float32_auto(buffer, conf->app_adc_conf.throttle_exp, &ind);
buffer_append_float32_auto(buffer, conf->app_adc_conf.throttle_exp_brake, &ind);
buffer[ind++] = conf->app_adc_conf.throttle_exp_mode;
buffer_append_float32_auto(buffer, conf->app_adc_conf.ramp_time_pos, &ind);
buffer_append_float32_auto(buffer, conf->app_adc_conf.ramp_time_neg, &ind);
buffer[ind++] = conf->app_adc_conf.multi_esc;
buffer[ind++] = conf->app_adc_conf.tc;
buffer_append_float32_auto(buffer, conf->app_adc_conf.tc_max_diff, &ind);
buffer_append_uint16(buffer, conf->app_adc_conf.update_rate_hz, &ind);
buffer_append_uint32(buffer, conf->app_uart_baudrate, &ind);
buffer[ind++] = conf->app_chuk_conf.ctrl_type;
buffer_append_float32_auto(buffer, conf->app_chuk_conf.hyst, &ind);
buffer_append_float32_auto(buffer, conf->app_chuk_conf.ramp_time_pos, &ind);
buffer_append_float32_auto(buffer, conf->app_chuk_conf.ramp_time_neg, &ind);
buffer_append_float32_auto(buffer, conf->app_chuk_conf.stick_erpm_per_s_in_cc, &ind);
buffer_append_float32_auto(buffer, conf->app_chuk_conf.throttle_exp, &ind);
buffer_append_float32_auto(buffer, conf->app_chuk_conf.throttle_exp_brake, &ind);
buffer[ind++] = conf->app_chuk_conf.throttle_exp_mode;
buffer[ind++] = conf->app_chuk_conf.multi_esc;
buffer[ind++] = conf->app_chuk_conf.tc;
buffer_append_float32_auto(buffer, conf->app_chuk_conf.tc_max_diff, &ind);
buffer[ind++] = conf->app_chuk_conf.use_smart_rev;
buffer_append_float32_auto(buffer, conf->app_chuk_conf.smart_rev_max_duty, &ind);
buffer_append_float32_auto(buffer, conf->app_chuk_conf.smart_rev_ramp_time, &ind);
buffer[ind++] = conf->app_nrf_conf.speed;
buffer[ind++] = conf->app_nrf_conf.power;
buffer[ind++] = conf->app_nrf_conf.crc_type;
buffer[ind++] = conf->app_nrf_conf.retry_delay;
buffer[ind++] = (uint8_t)conf->app_nrf_conf.retries;
buffer[ind++] = (uint8_t)conf->app_nrf_conf.channel;
buffer[ind++] = (uint8_t)conf->app_nrf_conf.address[0];
buffer[ind++] = (uint8_t)conf->app_nrf_conf.address[1];
buffer[ind++] = (uint8_t)conf->app_nrf_conf.address[2];
buffer[ind++] = conf->app_nrf_conf.send_crc_ack;
buffer[ind++] = conf->app_balance_conf.pid_mode;
buffer_append_float32_auto(buffer, conf->app_balance_conf.kp, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.ki, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.kd, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.kp2, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.ki2, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.kd2, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.hertz, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.loop_time_filter, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.fault_pitch, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.fault_roll, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.fault_duty, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.fault_adc1, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.fault_adc2, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.fault_delay_pitch, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.fault_delay_roll, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.fault_delay_duty, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.fault_delay_switch_half, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.fault_delay_switch_full, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.fault_adc_half_erpm, &ind);
buffer[ind++] = conf->app_balance_conf.fault_is_dual_switch;
buffer_append_float16(buffer, conf->app_balance_conf.tiltback_duty_angle, 100, &ind);
buffer_append_float16(buffer, conf->app_balance_conf.tiltback_duty_speed, 100, &ind);
buffer_append_float16(buffer, conf->app_balance_conf.tiltback_duty, 1000, &ind);
buffer_append_float16(buffer, conf->app_balance_conf.tiltback_hv_angle, 100, &ind);
buffer_append_float16(buffer, conf->app_balance_conf.tiltback_hv_speed, 100, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.tiltback_hv, &ind);
buffer_append_float16(buffer, conf->app_balance_conf.tiltback_lv_angle, 100, &ind);
buffer_append_float16(buffer, conf->app_balance_conf.tiltback_lv_speed, 100, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.tiltback_lv, &ind);
buffer_append_float16(buffer, conf->app_balance_conf.tiltback_return_speed, 100, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.tiltback_constant, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.tiltback_constant_erpm, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.tiltback_variable, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.tiltback_variable_max, &ind);
buffer_append_float16(buffer, conf->app_balance_conf.noseangling_speed, 100, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.startup_pitch_tolerance, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.startup_roll_tolerance, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.startup_speed, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.deadzone, &ind);
buffer[ind++] = conf->app_balance_conf.multi_esc;
buffer_append_float32_auto(buffer, conf->app_balance_conf.yaw_kp, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.yaw_ki, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.yaw_kd, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.roll_steer_kp, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.roll_steer_erpm_kp, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.brake_current, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.brake_timeout, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.yaw_current_clamp, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.ki_limit, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.kd_pt1_lowpass_frequency, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.kd_pt1_highpass_frequency, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.booster_angle, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.booster_ramp, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.booster_current, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.torquetilt_start_current, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.torquetilt_angle_limit, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.torquetilt_on_speed, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.torquetilt_off_speed, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.torquetilt_strength, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.torquetilt_filter, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.turntilt_strength, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.turntilt_angle_limit, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.turntilt_start_angle, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.turntilt_start_erpm, &ind);
buffer_append_float32_auto(buffer, conf->app_balance_conf.turntilt_speed, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.turntilt_erpm_boost, &ind);
buffer_append_uint16(buffer, conf->app_balance_conf.turntilt_erpm_boost_end, &ind);
buffer[ind++] = conf->app_pas_conf.ctrl_type;
buffer[ind++] = conf->app_pas_conf.sensor_type;
buffer_append_float16(buffer, conf->app_pas_conf.current_scaling, 1000, &ind);
buffer_append_float16(buffer, conf->app_pas_conf.pedal_rpm_start, 10, &ind);
buffer_append_float16(buffer, conf->app_pas_conf.pedal_rpm_end, 10, &ind);
buffer[ind++] = conf->app_pas_conf.invert_pedal_direction;
buffer_append_uint16(buffer, conf->app_pas_conf.magnets, &ind);
buffer[ind++] = conf->app_pas_conf.use_filter;
buffer_append_float16(buffer, conf->app_pas_conf.ramp_time_pos, 100, &ind);
buffer_append_float16(buffer, conf->app_pas_conf.ramp_time_neg, 100, &ind);
buffer_append_uint16(buffer, conf->app_pas_conf.update_rate_hz, &ind);
buffer[ind++] = conf->imu_conf.type;
buffer[ind++] = conf->imu_conf.mode;
buffer[ind++] = conf->imu_conf.filter;
buffer_append_float32_auto(buffer, conf->imu_conf.accel_lowpass_filter, &ind);
buffer_append_uint16(buffer, conf->imu_conf.sample_rate_hz, &ind);
buffer[ind++] = conf->imu_conf.use_magnetometer;
buffer_append_float32_auto(buffer, conf->imu_conf.accel_confidence_decay, &ind);
buffer_append_float32_auto(buffer, conf->imu_conf.mahony_kp, &ind);
buffer_append_float32_auto(buffer, conf->imu_conf.mahony_ki, &ind);
buffer_append_float32_auto(buffer, conf->imu_conf.madgwick_beta, &ind);
buffer_append_float32_auto(buffer, conf->imu_conf.rot_roll, &ind);
buffer_append_float32_auto(buffer, conf->imu_conf.rot_pitch, &ind);
buffer_append_float32_auto(buffer, conf->imu_conf.rot_yaw, &ind);
buffer_append_float32_auto(buffer, conf->imu_conf.accel_offsets[0], &ind);
buffer_append_float32_auto(buffer, conf->imu_conf.accel_offsets[1], &ind);
buffer_append_float32_auto(buffer, conf->imu_conf.accel_offsets[2], &ind);
buffer_append_float32_auto(buffer, conf->imu_conf.gyro_offsets[0], &ind);
buffer_append_float32_auto(buffer, conf->imu_conf.gyro_offsets[1], &ind);
buffer_append_float32_auto(buffer, conf->imu_conf.gyro_offsets[2], &ind);
return ind;
}
bool confgenerator_deserialize_mcconf(const uint8_t *buffer, mc_configuration *conf) {
int32_t ind = 0;
uint32_t signature = buffer_get_uint32(buffer, &ind);
if (signature != MCCONF_SIGNATURE) {
return false;
}
conf->pwm_mode = buffer[ind++];
conf->comm_mode = buffer[ind++];
conf->motor_type = buffer[ind++];
conf->sensor_mode = buffer[ind++];
conf->l_current_max = buffer_get_float32_auto(buffer, &ind);
conf->l_current_min = buffer_get_float32_auto(buffer, &ind);
conf->l_in_current_max = buffer_get_float32_auto(buffer, &ind);
conf->l_in_current_min = buffer_get_float32_auto(buffer, &ind);
conf->l_abs_current_max = buffer_get_float32_auto(buffer, &ind);
conf->l_min_erpm = buffer_get_float32_auto(buffer, &ind);
conf->l_max_erpm = buffer_get_float32_auto(buffer, &ind);
conf->l_erpm_start = buffer_get_float16(buffer, 10000, &ind);
conf->l_max_erpm_fbrake = buffer_get_float32_auto(buffer, &ind);
conf->l_max_erpm_fbrake_cc = buffer_get_float32_auto(buffer, &ind);
conf->l_min_vin = buffer_get_float32_auto(buffer, &ind);
conf->l_max_vin = buffer_get_float32_auto(buffer, &ind);
conf->l_battery_cut_start = buffer_get_float32_auto(buffer, &ind);
conf->l_battery_cut_end = buffer_get_float32_auto(buffer, &ind);
conf->l_slow_abs_current = buffer[ind++];
conf->l_temp_fet_start = buffer_get_float16(buffer, 10, &ind);
conf->l_temp_fet_end = buffer_get_float16(buffer, 10, &ind);
conf->l_temp_motor_start = buffer_get_float16(buffer, 10, &ind);
conf->l_temp_motor_end = buffer_get_float16(buffer, 10, &ind);
conf->l_temp_accel_dec = buffer_get_float16(buffer, 10000, &ind);
conf->l_min_duty = buffer_get_float16(buffer, 10000, &ind);
conf->l_max_duty = buffer_get_float16(buffer, 10000, &ind);
conf->l_watt_max = buffer_get_float32_auto(buffer, &ind);
conf->l_watt_min = buffer_get_float32_auto(buffer, &ind);
conf->l_current_max_scale = buffer_get_float16(buffer, 10000, &ind);
conf->l_current_min_scale = buffer_get_float16(buffer, 10000, &ind);
conf->l_duty_start = buffer_get_float16(buffer, 10000, &ind);
conf->sl_min_erpm = buffer_get_float32_auto(buffer, &ind);
conf->sl_min_erpm_cycle_int_limit = buffer_get_float32_auto(buffer, &ind);
conf->sl_max_fullbreak_current_dir_change = buffer_get_float32_auto(buffer, &ind);
conf->sl_cycle_int_limit = buffer_get_float16(buffer, 10, &ind);
conf->sl_phase_advance_at_br = buffer_get_float16(buffer, 10000, &ind);
conf->sl_cycle_int_rpm_br = buffer_get_float32_auto(buffer, &ind);
conf->sl_bemf_coupling_k = buffer_get_float32_auto(buffer, &ind);
conf->hall_table[0] = (int8_t)buffer[ind++];
conf->hall_table[1] = (int8_t)buffer[ind++];
conf->hall_table[2] = (int8_t)buffer[ind++];
conf->hall_table[3] = (int8_t)buffer[ind++];
conf->hall_table[4] = (int8_t)buffer[ind++];
conf->hall_table[5] = (int8_t)buffer[ind++];
conf->hall_table[6] = (int8_t)buffer[ind++];
conf->hall_table[7] = (int8_t)buffer[ind++];
conf->hall_sl_erpm = buffer_get_float32_auto(buffer, &ind);
conf->foc_current_kp = buffer_get_float32_auto(buffer, &ind);
conf->foc_current_ki = buffer_get_float32_auto(buffer, &ind);
conf->foc_f_zv = buffer_get_float32_auto(buffer, &ind);
conf->foc_dt_us = buffer_get_float32_auto(buffer, &ind);
conf->foc_encoder_inverted = buffer[ind++];
conf->foc_encoder_offset = buffer_get_float32_auto(buffer, &ind);
conf->foc_encoder_ratio = buffer_get_float32_auto(buffer, &ind);
conf->foc_encoder_sin_gain = buffer_get_float16(buffer, 1000, &ind);
conf->foc_encoder_cos_gain = buffer_get_float16(buffer, 1000, &ind);
conf->foc_encoder_sin_offset = buffer_get_float16(buffer, 1000, &ind);
conf->foc_encoder_cos_offset = buffer_get_float16(buffer, 1000, &ind);
conf->foc_encoder_sincos_filter_constant = buffer_get_float16(buffer, 1000, &ind);
conf->foc_sensor_mode = buffer[ind++];
conf->foc_pll_kp = buffer_get_float32_auto(buffer, &ind);
conf->foc_pll_ki = buffer_get_float32_auto(buffer, &ind);
conf->foc_motor_l = buffer_get_float32_auto(buffer, &ind);
conf->foc_motor_ld_lq_diff = buffer_get_float32_auto(buffer, &ind);
conf->foc_motor_r = buffer_get_float32_auto(buffer, &ind);
conf->foc_motor_flux_linkage = buffer_get_float32_auto(buffer, &ind);
conf->foc_observer_gain = buffer_get_float32_auto(buffer, &ind);
conf->foc_observer_gain_slow = buffer_get_float32_auto(buffer, &ind);
conf->foc_observer_offset = buffer_get_float16(buffer, 1000, &ind);
conf->foc_duty_dowmramp_kp = buffer_get_float32_auto(buffer, &ind);
conf->foc_duty_dowmramp_ki = buffer_get_float32_auto(buffer, &ind);
conf->foc_start_curr_dec = buffer_get_float16(buffer, 10000, &ind);
conf->foc_start_curr_dec_rpm = buffer_get_float32_auto(buffer, &ind);
conf->foc_openloop_rpm = buffer_get_float32_auto(buffer, &ind);
conf->foc_openloop_rpm_low = buffer_get_float16(buffer, 1000, &ind);
conf->foc_d_gain_scale_start = buffer_get_float16(buffer, 1000, &ind);
conf->foc_d_gain_scale_max_mod = buffer_get_float16(buffer, 1000, &ind);
conf->foc_sl_openloop_hyst = buffer_get_float16(buffer, 100, &ind);
conf->foc_sl_openloop_time_lock = buffer_get_float16(buffer, 100, &ind);
conf->foc_sl_openloop_time_ramp = buffer_get_float16(buffer, 100, &ind);
conf->foc_sl_openloop_time = buffer_get_float16(buffer, 100, &ind);
conf->foc_sl_openloop_boost_q = buffer_get_float16(buffer, 100, &ind);
conf->foc_sl_openloop_max_q = buffer_get_float16(buffer, 100, &ind);
conf->foc_hall_table[0] = buffer[ind++];
conf->foc_hall_table[1] = buffer[ind++];
conf->foc_hall_table[2] = buffer[ind++];
conf->foc_hall_table[3] = buffer[ind++];
conf->foc_hall_table[4] = buffer[ind++];
conf->foc_hall_table[5] = buffer[ind++];
conf->foc_hall_table[6] = buffer[ind++];
conf->foc_hall_table[7] = buffer[ind++];
conf->foc_hall_interp_erpm = buffer_get_float32_auto(buffer, &ind);
conf->foc_sl_erpm = buffer_get_float32_auto(buffer, &ind);
conf->foc_sample_v0_v7 = buffer[ind++];
conf->foc_sample_high_current = buffer[ind++];
conf->foc_sat_comp_mode = buffer[ind++];
conf->foc_sat_comp = buffer_get_float16(buffer, 1000, &ind);
conf->foc_temp_comp = buffer[ind++];
conf->foc_temp_comp_base_temp = buffer_get_float16(buffer, 100, &ind);
conf->foc_current_filter_const = buffer_get_float16(buffer, 10000, &ind);
conf->foc_cc_decoupling = buffer[ind++];
conf->foc_observer_type = buffer[ind++];
conf->foc_hfi_voltage_start = buffer_get_float16(buffer, 10, &ind);
conf->foc_hfi_voltage_run = buffer_get_float16(buffer, 10, &ind);
conf->foc_hfi_voltage_max = buffer_get_float16(buffer, 10, &ind);
conf->foc_hfi_gain = buffer_get_float16(buffer, 1000, &ind);
conf->foc_hfi_hyst = buffer_get_float16(buffer, 100, &ind);
conf->foc_sl_erpm_hfi = buffer_get_float32_auto(buffer, &ind);
conf->foc_hfi_start_samples = buffer_get_uint16(buffer, &ind);
conf->foc_hfi_obs_ovr_sec = buffer_get_float32_auto(buffer, &ind);
conf->foc_hfi_samples = buffer[ind++];
conf->foc_offsets_cal_on_boot = buffer[ind++];
conf->foc_offsets_current[0] = buffer_get_float32_auto(buffer, &ind);
conf->foc_offsets_current[1] = buffer_get_float32_auto(buffer, &ind);
conf->foc_offsets_current[2] = buffer_get_float32_auto(buffer, &ind);
conf->foc_offsets_voltage[0] = buffer_get_float16(buffer, 10000, &ind);
conf->foc_offsets_voltage[1] = buffer_get_float16(buffer, 10000, &ind);
conf->foc_offsets_voltage[2] = buffer_get_float16(buffer, 10000, &ind);
conf->foc_offsets_voltage_undriven[0] = buffer_get_float16(buffer, 10000, &ind);
conf->foc_offsets_voltage_undriven[1] = buffer_get_float16(buffer, 10000, &ind);
conf->foc_offsets_voltage_undriven[2] = buffer_get_float16(buffer, 10000, &ind);
conf->foc_phase_filter_enable = buffer[ind++];
conf->foc_phase_filter_disable_fault = buffer[ind++];
conf->foc_phase_filter_max_erpm = buffer_get_float32_auto(buffer, &ind);
conf->foc_mtpa_mode = buffer[ind++];
conf->foc_fw_current_max = buffer_get_float32_auto(buffer, &ind);
conf->foc_fw_duty_start = buffer_get_float16(buffer, 10000, &ind);
conf->foc_fw_ramp_time = buffer_get_float16(buffer, 1000, &ind);
conf->foc_fw_q_current_factor = buffer_get_float16(buffer, 10000, &ind);
conf->foc_speed_soure = buffer[ind++];
conf->gpd_buffer_notify_left = buffer_get_int16(buffer, &ind);
conf->gpd_buffer_interpol = buffer_get_int16(buffer, &ind);
conf->gpd_current_filter_const = buffer_get_float16(buffer, 10000, &ind);
conf->gpd_current_kp = buffer_get_float32_auto(buffer, &ind);
conf->gpd_current_ki = buffer_get_float32_auto(buffer, &ind);
conf->sp_pid_loop_rate = buffer[ind++];
conf->s_pid_kp = buffer_get_float32_auto(buffer, &ind);
conf->s_pid_ki = buffer_get_float32_auto(buffer, &ind);
conf->s_pid_kd = buffer_get_float32_auto(buffer, &ind);
conf->s_pid_kd_filter = buffer_get_float16(buffer, 10000, &ind);
conf->s_pid_min_erpm = buffer_get_float32_auto(buffer, &ind);
conf->s_pid_allow_braking = buffer[ind++];
conf->s_pid_ramp_erpms_s = buffer_get_float32_auto(buffer, &ind);
conf->p_pid_kp = buffer_get_float32_auto(buffer, &ind);
conf->p_pid_ki = buffer_get_float32_auto(buffer, &ind);
conf->p_pid_kd = buffer_get_float32_auto(buffer, &ind);
conf->p_pid_kd_proc = buffer_get_float32_auto(buffer, &ind);
conf->p_pid_kd_filter = buffer_get_float16(buffer, 10000, &ind);
conf->p_pid_ang_div = buffer_get_float32_auto(buffer, &ind);
conf->p_pid_gain_dec_angle = buffer_get_float16(buffer, 10, &ind);
conf->p_pid_offset = buffer_get_float32_auto(buffer, &ind);
conf->cc_startup_boost_duty = buffer_get_float16(buffer, 10000, &ind);
conf->cc_min_current = buffer_get_float32_auto(buffer, &ind);
conf->cc_gain = buffer_get_float32_auto(buffer, &ind);
conf->cc_ramp_step_max = buffer_get_float16(buffer, 10000, &ind);
conf->m_fault_stop_time_ms = buffer_get_int32(buffer, &ind);
conf->m_duty_ramp_step = buffer_get_float16(buffer, 10000, &ind);
conf->m_current_backoff_gain = buffer_get_float32_auto(buffer, &ind);
conf->m_encoder_counts = buffer_get_uint32(buffer, &ind);
conf->m_sensor_port_mode = buffer[ind++];
conf->m_invert_direction = buffer[ind++];
conf->m_drv8301_oc_mode = buffer[ind++];
conf->m_drv8301_oc_adj = buffer[ind++];
conf->m_bldc_f_sw_min = buffer_get_float32_auto(buffer, &ind);
conf->m_bldc_f_sw_max = buffer_get_float32_auto(buffer, &ind);
conf->m_dc_f_sw = buffer_get_float32_auto(buffer, &ind);
conf->m_ntc_motor_beta = buffer_get_float32_auto(buffer, &ind);
conf->m_out_aux_mode = buffer[ind++];
conf->m_motor_temp_sens_type = buffer[ind++];
conf->m_ptc_motor_coeff = buffer_get_float32_auto(buffer, &ind);
conf->m_ntcx_ptcx_res = buffer_get_float16(buffer, 0.1, &ind);
conf->m_ntcx_ptcx_temp_base = buffer_get_float16(buffer, 10, &ind);
conf->m_hall_extra_samples = buffer[ind++];
conf->si_motor_poles = buffer[ind++];
conf->si_gear_ratio = buffer_get_float32_auto(buffer, &ind);
conf->si_wheel_diameter = buffer_get_float32_auto(buffer, &ind);
conf->si_battery_type = buffer[ind++];
conf->si_battery_cells = buffer[ind++];
conf->si_battery_ah = buffer_get_float32_auto(buffer, &ind);
conf->si_motor_nl_current = buffer_get_float32_auto(buffer, &ind);
conf->bms.type = buffer[ind++];
conf->bms.limit_mode = buffer[ind++];
conf->bms.t_limit_start = buffer_get_float16(buffer, 100, &ind);
conf->bms.t_limit_end = buffer_get_float16(buffer, 100, &ind);
conf->bms.soc_limit_start = buffer_get_float16(buffer, 1000, &ind);
conf->bms.soc_limit_end = buffer_get_float16(buffer, 1000, &ind);
conf->bms.fwd_can_mode = buffer[ind++];
return true;
}
bool confgenerator_deserialize_appconf(const uint8_t *buffer, app_configuration *conf) {
int32_t ind = 0;
uint32_t signature = buffer_get_uint32(buffer, &ind);
if (signature != APPCONF_SIGNATURE) {
return false;
}
conf->controller_id = buffer[ind++];
conf->timeout_msec = buffer_get_uint32(buffer, &ind);
conf->timeout_brake_current = buffer_get_float32_auto(buffer, &ind);
conf->can_status_rate_1 = buffer_get_uint16(buffer, &ind);
conf->can_status_rate_2 = buffer_get_uint16(buffer, &ind);
conf->can_status_msgs_r1 = buffer[ind++];
conf->can_status_msgs_r2 = buffer[ind++];
conf->can_baud_rate = buffer[ind++];
conf->pairing_done = buffer[ind++];
conf->permanent_uart_enabled = buffer[ind++];
conf->shutdown_mode = buffer[ind++];
conf->can_mode = buffer[ind++];
conf->uavcan_esc_index = buffer[ind++];
conf->uavcan_raw_mode = buffer[ind++];
conf->uavcan_raw_rpm_max = buffer_get_float32_auto(buffer, &ind);
conf->uavcan_status_current_mode = buffer[ind++];
conf->servo_out_enable = buffer[ind++];
conf->kill_sw_mode = buffer[ind++];
conf->app_to_use = buffer[ind++];
conf->app_ppm_conf.ctrl_type = buffer[ind++];
conf->app_ppm_conf.pid_max_erpm = buffer_get_float32_auto(buffer, &ind);
conf->app_ppm_conf.hyst = buffer_get_float32_auto(buffer, &ind);
conf->app_ppm_conf.pulse_start = buffer_get_float32_auto(buffer, &ind);
conf->app_ppm_conf.pulse_end = buffer_get_float32_auto(buffer, &ind);
conf->app_ppm_conf.pulse_center = buffer_get_float32_auto(buffer, &ind);
conf->app_ppm_conf.median_filter = buffer[ind++];
conf->app_ppm_conf.safe_start = buffer[ind++];
conf->app_ppm_conf.throttle_exp = buffer_get_float32_auto(buffer, &ind);
conf->app_ppm_conf.throttle_exp_brake = buffer_get_float32_auto(buffer, &ind);
conf->app_ppm_conf.throttle_exp_mode = buffer[ind++];
conf->app_ppm_conf.ramp_time_pos = buffer_get_float32_auto(buffer, &ind);
conf->app_ppm_conf.ramp_time_neg = buffer_get_float32_auto(buffer, &ind);
conf->app_ppm_conf.multi_esc = buffer[ind++];
conf->app_ppm_conf.tc = buffer[ind++];
conf->app_ppm_conf.tc_max_diff = buffer_get_float32_auto(buffer, &ind);
conf->app_ppm_conf.max_erpm_for_dir = buffer_get_float16(buffer, 1, &ind);
conf->app_ppm_conf.smart_rev_max_duty = buffer_get_float32_auto(buffer, &ind);
conf->app_ppm_conf.smart_rev_ramp_time = buffer_get_float32_auto(buffer, &ind);
conf->app_adc_conf.ctrl_type = buffer[ind++];
conf->app_adc_conf.hyst = buffer_get_float32_auto(buffer, &ind);
conf->app_adc_conf.voltage_start = buffer_get_float16(buffer, 1000, &ind);
conf->app_adc_conf.voltage_end = buffer_get_float16(buffer, 1000, &ind);
conf->app_adc_conf.voltage_min = buffer_get_float16(buffer, 1000, &ind);
conf->app_adc_conf.voltage_max = buffer_get_float16(buffer, 1000, &ind);
conf->app_adc_conf.voltage_center = buffer_get_float16(buffer, 1000, &ind);
conf->app_adc_conf.voltage2_start = buffer_get_float16(buffer, 1000, &ind);
conf->app_adc_conf.voltage2_end = buffer_get_float16(buffer, 1000, &ind);
conf->app_adc_conf.use_filter = buffer[ind++];
conf->app_adc_conf.safe_start = buffer[ind++];
conf->app_adc_conf.buttons = buffer[ind++];
conf->app_adc_conf.voltage_inverted = buffer[ind++];
conf->app_adc_conf.voltage2_inverted = buffer[ind++];
conf->app_adc_conf.throttle_exp = buffer_get_float32_auto(buffer, &ind);
conf->app_adc_conf.throttle_exp_brake = buffer_get_float32_auto(buffer, &ind);
conf->app_adc_conf.throttle_exp_mode = buffer[ind++];
conf->app_adc_conf.ramp_time_pos = buffer_get_float32_auto(buffer, &ind);
conf->app_adc_conf.ramp_time_neg = buffer_get_float32_auto(buffer, &ind);
conf->app_adc_conf.multi_esc = buffer[ind++];
conf->app_adc_conf.tc = buffer[ind++];
conf->app_adc_conf.tc_max_diff = buffer_get_float32_auto(buffer, &ind);
conf->app_adc_conf.update_rate_hz = buffer_get_uint16(buffer, &ind);
conf->app_uart_baudrate = buffer_get_uint32(buffer, &ind);
conf->app_chuk_conf.ctrl_type = buffer[ind++];
conf->app_chuk_conf.hyst = buffer_get_float32_auto(buffer, &ind);
conf->app_chuk_conf.ramp_time_pos = buffer_get_float32_auto(buffer, &ind);
conf->app_chuk_conf.ramp_time_neg = buffer_get_float32_auto(buffer, &ind);
conf->app_chuk_conf.stick_erpm_per_s_in_cc = buffer_get_float32_auto(buffer, &ind);
conf->app_chuk_conf.throttle_exp = buffer_get_float32_auto(buffer, &ind);
conf->app_chuk_conf.throttle_exp_brake = buffer_get_float32_auto(buffer, &ind);
conf->app_chuk_conf.throttle_exp_mode = buffer[ind++];
conf->app_chuk_conf.multi_esc = buffer[ind++];
conf->app_chuk_conf.tc = buffer[ind++];
conf->app_chuk_conf.tc_max_diff = buffer_get_float32_auto(buffer, &ind);
conf->app_chuk_conf.use_smart_rev = buffer[ind++];
conf->app_chuk_conf.smart_rev_max_duty = buffer_get_float32_auto(buffer, &ind);
conf->app_chuk_conf.smart_rev_ramp_time = buffer_get_float32_auto(buffer, &ind);
conf->app_nrf_conf.speed = buffer[ind++];
conf->app_nrf_conf.power = buffer[ind++];
conf->app_nrf_conf.crc_type = buffer[ind++];
conf->app_nrf_conf.retry_delay = buffer[ind++];
conf->app_nrf_conf.retries = (int8_t)buffer[ind++];
conf->app_nrf_conf.channel = (int8_t)buffer[ind++];
conf->app_nrf_conf.address[0] = buffer[ind++];
conf->app_nrf_conf.address[1] = buffer[ind++];
conf->app_nrf_conf.address[2] = buffer[ind++];
conf->app_nrf_conf.send_crc_ack = buffer[ind++];
conf->app_balance_conf.pid_mode = buffer[ind++];
conf->app_balance_conf.kp = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.ki = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.kd = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.kp2 = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.ki2 = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.kd2 = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.hertz = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.loop_time_filter = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.fault_pitch = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.fault_roll = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.fault_duty = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.fault_adc1 = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.fault_adc2 = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.fault_delay_pitch = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.fault_delay_roll = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.fault_delay_duty = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.fault_delay_switch_half = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.fault_delay_switch_full = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.fault_adc_half_erpm = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.fault_is_dual_switch = buffer[ind++];
conf->app_balance_conf.tiltback_duty_angle = buffer_get_float16(buffer, 100, &ind);
conf->app_balance_conf.tiltback_duty_speed = buffer_get_float16(buffer, 100, &ind);
conf->app_balance_conf.tiltback_duty = buffer_get_float16(buffer, 1000, &ind);
conf->app_balance_conf.tiltback_hv_angle = buffer_get_float16(buffer, 100, &ind);
conf->app_balance_conf.tiltback_hv_speed = buffer_get_float16(buffer, 100, &ind);
conf->app_balance_conf.tiltback_hv = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.tiltback_lv_angle = buffer_get_float16(buffer, 100, &ind);
conf->app_balance_conf.tiltback_lv_speed = buffer_get_float16(buffer, 100, &ind);
conf->app_balance_conf.tiltback_lv = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.tiltback_return_speed = buffer_get_float16(buffer, 100, &ind);
conf->app_balance_conf.tiltback_constant = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.tiltback_constant_erpm = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.tiltback_variable = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.tiltback_variable_max = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.noseangling_speed = buffer_get_float16(buffer, 100, &ind);
conf->app_balance_conf.startup_pitch_tolerance = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.startup_roll_tolerance = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.startup_speed = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.deadzone = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.multi_esc = buffer[ind++];
conf->app_balance_conf.yaw_kp = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.yaw_ki = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.yaw_kd = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.roll_steer_kp = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.roll_steer_erpm_kp = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.brake_current = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.brake_timeout = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.yaw_current_clamp = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.ki_limit = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.kd_pt1_lowpass_frequency = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.kd_pt1_highpass_frequency = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.booster_angle = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.booster_ramp = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.booster_current = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.torquetilt_start_current = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.torquetilt_angle_limit = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.torquetilt_on_speed = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.torquetilt_off_speed = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.torquetilt_strength = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.torquetilt_filter = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.turntilt_strength = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.turntilt_angle_limit = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.turntilt_start_angle = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.turntilt_start_erpm = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.turntilt_speed = buffer_get_float32_auto(buffer, &ind);
conf->app_balance_conf.turntilt_erpm_boost = buffer_get_uint16(buffer, &ind);
conf->app_balance_conf.turntilt_erpm_boost_end = buffer_get_uint16(buffer, &ind);
conf->app_pas_conf.ctrl_type = buffer[ind++];
conf->app_pas_conf.sensor_type = buffer[ind++];
conf->app_pas_conf.current_scaling = buffer_get_float16(buffer, 1000, &ind);
conf->app_pas_conf.pedal_rpm_start = buffer_get_float16(buffer, 10, &ind);
conf->app_pas_conf.pedal_rpm_end = buffer_get_float16(buffer, 10, &ind);
conf->app_pas_conf.invert_pedal_direction = buffer[ind++];
conf->app_pas_conf.magnets = buffer_get_uint16(buffer, &ind);
conf->app_pas_conf.use_filter = buffer[ind++];
conf->app_pas_conf.ramp_time_pos = buffer_get_float16(buffer, 100, &ind);
conf->app_pas_conf.ramp_time_neg = buffer_get_float16(buffer, 100, &ind);
conf->app_pas_conf.update_rate_hz = buffer_get_uint16(buffer, &ind);
conf->imu_conf.type = buffer[ind++];
conf->imu_conf.mode = buffer[ind++];
conf->imu_conf.filter = buffer[ind++];
conf->imu_conf.accel_lowpass_filter = buffer_get_float32_auto(buffer, &ind);
conf->imu_conf.sample_rate_hz = buffer_get_uint16(buffer, &ind);
conf->imu_conf.use_magnetometer = buffer[ind++];
conf->imu_conf.accel_confidence_decay = buffer_get_float32_auto(buffer, &ind);
conf->imu_conf.mahony_kp = buffer_get_float32_auto(buffer, &ind);
conf->imu_conf.mahony_ki = buffer_get_float32_auto(buffer, &ind);
conf->imu_conf.madgwick_beta = buffer_get_float32_auto(buffer, &ind);
conf->imu_conf.rot_roll = buffer_get_float32_auto(buffer, &ind);
conf->imu_conf.rot_pitch = buffer_get_float32_auto(buffer, &ind);
conf->imu_conf.rot_yaw = buffer_get_float32_auto(buffer, &ind);
conf->imu_conf.accel_offsets[0] = buffer_get_float32_auto(buffer, &ind);
conf->imu_conf.accel_offsets[1] = buffer_get_float32_auto(buffer, &ind);
conf->imu_conf.accel_offsets[2] = buffer_get_float32_auto(buffer, &ind);
conf->imu_conf.gyro_offsets[0] = buffer_get_float32_auto(buffer, &ind);
conf->imu_conf.gyro_offsets[1] = buffer_get_float32_auto(buffer, &ind);
conf->imu_conf.gyro_offsets[2] = buffer_get_float32_auto(buffer, &ind);
return true;
}
void confgenerator_set_defaults_mcconf(mc_configuration *conf) {
conf->pwm_mode = MCCONF_PWM_MODE;
conf->comm_mode = MCCONF_COMM_MODE;
conf->motor_type = MCCONF_DEFAULT_MOTOR_TYPE;
conf->sensor_mode = MCCONF_SENSOR_MODE;
conf->l_current_max = MCCONF_L_CURRENT_MAX;
conf->l_current_min = MCCONF_L_CURRENT_MIN;
conf->l_in_current_max = MCCONF_L_IN_CURRENT_MAX;
conf->l_in_current_min = MCCONF_L_IN_CURRENT_MIN;
conf->l_abs_current_max = MCCONF_L_MAX_ABS_CURRENT;
conf->l_min_erpm = MCCONF_L_RPM_MIN;
conf->l_max_erpm = MCCONF_L_RPM_MAX;
conf->l_erpm_start = MCCONF_L_RPM_START;
conf->l_max_erpm_fbrake = MCCONF_L_CURR_MAX_RPM_FBRAKE;
conf->l_max_erpm_fbrake_cc = MCCONF_L_CURR_MAX_RPM_FBRAKE_CC;
conf->l_min_vin = MCCONF_L_MIN_VOLTAGE;
conf->l_max_vin = MCCONF_L_MAX_VOLTAGE;
conf->l_battery_cut_start = MCCONF_L_BATTERY_CUT_START;
conf->l_battery_cut_end = MCCONF_L_BATTERY_CUT_END;
conf->l_slow_abs_current = MCCONF_L_SLOW_ABS_OVERCURRENT;
conf->l_temp_fet_start = MCCONF_L_LIM_TEMP_FET_START;
conf->l_temp_fet_end = MCCONF_L_LIM_TEMP_FET_END;
conf->l_temp_motor_start = MCCONF_L_LIM_TEMP_MOTOR_START;
conf->l_temp_motor_end = MCCONF_L_LIM_TEMP_MOTOR_END;
conf->l_temp_accel_dec = MCCONF_L_LIM_TEMP_ACCEL_DEC;
conf->l_min_duty = MCCONF_L_MIN_DUTY;
conf->l_max_duty = MCCONF_L_MAX_DUTY;
conf->l_watt_max = MCCONF_L_WATT_MAX;
conf->l_watt_min = MCCONF_L_WATT_MIN;
conf->l_current_max_scale = MCCONF_L_CURRENT_MAX_SCALE;
conf->l_current_min_scale = MCCONF_L_CURRENT_MIN_SCALE;
conf->l_duty_start = MCCONF_L_DUTY_START;
conf->sl_min_erpm = MCCONF_SL_MIN_RPM;
conf->sl_min_erpm_cycle_int_limit = MCCONF_SL_MIN_ERPM_CYCLE_INT_LIMIT;
conf->sl_max_fullbreak_current_dir_change = MCCONF_SL_MAX_FB_CURR_DIR_CHANGE;
conf->sl_cycle_int_limit = MCCONF_SL_CYCLE_INT_LIMIT;
conf->sl_phase_advance_at_br = MCCONF_SL_PHASE_ADVANCE_AT_BR;
conf->sl_cycle_int_rpm_br = MCCONF_SL_CYCLE_INT_BR;
conf->sl_bemf_coupling_k = MCCONF_SL_BEMF_COUPLING_K;
conf->hall_table[0] = MCCONF_HALL_TAB_0;
conf->hall_table[1] = MCCONF_HALL_TAB_1;
conf->hall_table[2] = MCCONF_HALL_TAB_2;
conf->hall_table[3] = MCCONF_HALL_TAB_3;
conf->hall_table[4] = MCCONF_HALL_TAB_4;
conf->hall_table[5] = MCCONF_HALL_TAB_5;
conf->hall_table[6] = MCCONF_HALL_TAB_6;
conf->hall_table[7] = MCCONF_HALL_TAB_7;
conf->hall_sl_erpm = MCCONF_HALL_ERPM;
conf->foc_current_kp = MCCONF_FOC_CURRENT_KP;
conf->foc_current_ki = MCCONF_FOC_CURRENT_KI;
conf->foc_f_zv = MCCONF_FOC_F_ZV;
conf->foc_dt_us = MCCONF_FOC_DT_US;
conf->foc_encoder_inverted = MCCONF_FOC_ENCODER_INVERTED;
conf->foc_encoder_offset = MCCONF_FOC_ENCODER_OFFSET;
conf->foc_encoder_ratio = MCCONF_FOC_ENCODER_RATIO;
conf->foc_encoder_sin_gain = MCCONF_FOC_ENCODER_SIN_GAIN;
conf->foc_encoder_cos_gain = MCCONF_FOC_ENCODER_COS_GAIN;
conf->foc_encoder_sin_offset = MCCONF_FOC_ENCODER_SIN_OFFSET;
conf->foc_encoder_cos_offset = MCCONF_FOC_ENCODER_COS_OFFSET;
conf->foc_encoder_sincos_filter_constant = MCCONF_FOC_ENCODER_SINCOS_FILTER;
conf->foc_sensor_mode = MCCONF_FOC_SENSOR_MODE;
conf->foc_pll_kp = MCCONF_FOC_PLL_KP;
conf->foc_pll_ki = MCCONF_FOC_PLL_KI;
conf->foc_motor_l = MCCONF_FOC_MOTOR_L;
conf->foc_motor_ld_lq_diff = MCCONF_FOC_MOTOR_LD_LQ_DIFF;
conf->foc_motor_r = MCCONF_FOC_MOTOR_R;
conf->foc_motor_flux_linkage = MCCONF_FOC_MOTOR_FLUX_LINKAGE;
conf->foc_observer_gain = MCCONF_FOC_OBSERVER_GAIN;
conf->foc_observer_gain_slow = MCCONF_FOC_OBSERVER_GAIN_SLOW;
conf->foc_observer_offset = MCCONF_FOC_OBSERVER_OFFSET;
conf->foc_duty_dowmramp_kp = MCCONF_FOC_DUTY_DOWNRAMP_KP;
conf->foc_duty_dowmramp_ki = MCCONF_FOC_DUTY_DOWNRAMP_KI;
conf->foc_start_curr_dec = MCCONF_FOC_START_CURR_DEC;
conf->foc_start_curr_dec_rpm = MCCONF_FOC_START_CURR_DEC_RPM;
conf->foc_openloop_rpm = MCCONF_FOC_OPENLOOP_RPM;
conf->foc_openloop_rpm_low = MCCONF_FOC_OPENLOOP_RPM_LOW;
conf->foc_d_gain_scale_start = MCCONF_FOC_D_GAIN_SCALE_START;
conf->foc_d_gain_scale_max_mod = MCCONF_FOC_D_GAIN_SCALE_MAX_MOD;
conf->foc_sl_openloop_hyst = MCCONF_FOC_SL_OPENLOOP_HYST;
conf->foc_sl_openloop_time_lock = MCCONF_FOC_SL_OPENLOOP_T_LOCK;
conf->foc_sl_openloop_time_ramp = MCCONF_FOC_SL_OPENLOOP_T_RAMP;
conf->foc_sl_openloop_time = MCCONF_FOC_SL_OPENLOOP_TIME;
conf->foc_sl_openloop_boost_q = MCCONF_FOC_SL_OPENLOOP_BOOST_Q;
conf->foc_sl_openloop_max_q = MCCONF_FOC_SL_OPENLOOP_MAX_Q;
conf->foc_hall_table[0] = MCCONF_FOC_HALL_TAB_0;
conf->foc_hall_table[1] = MCCONF_FOC_HALL_TAB_1;
conf->foc_hall_table[2] = MCCONF_FOC_HALL_TAB_2;
conf->foc_hall_table[3] = MCCONF_FOC_HALL_TAB_3;
conf->foc_hall_table[4] = MCCONF_FOC_HALL_TAB_4;
conf->foc_hall_table[5] = MCCONF_FOC_HALL_TAB_5;
conf->foc_hall_table[6] = MCCONF_FOC_HALL_TAB_6;
conf->foc_hall_table[7] = MCCONF_FOC_HALL_TAB_7;
conf->foc_hall_interp_erpm = MCCONF_FOC_HALL_INTERP_ERPM;
conf->foc_sl_erpm = MCCONF_FOC_SL_ERPM;
conf->foc_sample_v0_v7 = MCCONF_FOC_SAMPLE_V0_V7;
conf->foc_sample_high_current = MCCONF_FOC_SAMPLE_HIGH_CURRENT;
conf->foc_sat_comp_mode = MCCONF_FOC_SAT_COMP_MODE;
conf->foc_sat_comp = MCCONF_FOC_SAT_COMP;
conf->foc_temp_comp = MCCONF_FOC_TEMP_COMP;
conf->foc_temp_comp_base_temp = MCCONF_FOC_TEMP_COMP_BASE_TEMP;
conf->foc_current_filter_const = MCCONF_FOC_CURRENT_FILTER_CONST;
conf->foc_cc_decoupling = MCCONF_FOC_CC_DECOUPLING;
conf->foc_observer_type = MCCONF_FOC_OBSERVER_TYPE;
conf->foc_hfi_voltage_start = MCCONF_FOC_HFI_VOLTAGE_START;
conf->foc_hfi_voltage_run = MCCONF_FOC_HFI_VOLTAGE_RUN;
conf->foc_hfi_voltage_max = MCCONF_FOC_HFI_VOLTAGE_MAX;
conf->foc_hfi_gain = MCCONF_FOC_HFI_GAIN;
conf->foc_hfi_hyst = MCCONF_FOC_HFI_HYST;
conf->foc_sl_erpm_hfi = MCCONF_FOC_SL_ERPM_HFI;
conf->foc_hfi_start_samples = MCCONF_FOC_HFI_START_SAMPLES;
conf->foc_hfi_obs_ovr_sec = MCCONF_FOC_HFI_OBS_OVR_SEC;
conf->foc_hfi_samples = MCCONF_FOC_HFI_SAMPLES;
conf->foc_offsets_cal_on_boot = MCCONF_FOC_OFFSETS_CAL_ON_BOOT;
conf->foc_offsets_current[0] = MCCONF_FOC_OFFSETS_CURRENT_0;
conf->foc_offsets_current[1] = MCCONF_FOC_OFFSETS_CURRENT_1;
conf->foc_offsets_current[2] = MCCONF_FOC_OFFSETS_CURRENT_2;
conf->foc_offsets_voltage[0] = MCCONF_FOC_OFFSETS_VOLTAGE_0;
conf->foc_offsets_voltage[1] = MCCONF_FOC_OFFSETS_VOLTAGE_1;
conf->foc_offsets_voltage[2] = MCCONF_FOC_OFFSETS_VOLTAGE_2;
conf->foc_offsets_voltage_undriven[0] = MCCONF_FOC_OFFSETS_VOLTAGE_UNDRIVEN_0;
conf->foc_offsets_voltage_undriven[1] = MCCONF_FOC_OFFSETS_VOLTAGE_UNDRIVEN_1;
conf->foc_offsets_voltage_undriven[2] = MCCONF_FOC_OFFSETS_VOLTAGE_UNDRIVEN_2;
conf->foc_phase_filter_enable = MCCONF_FOC_PHASE_FILTER_ENABLE;
conf->foc_phase_filter_disable_fault = MCCONF_FOC_PHASE_FILTER_DISABLE_FAULT;
conf->foc_phase_filter_max_erpm = MCCONF_FOC_PHASE_FILTER_MAX_ERPM;
conf->foc_mtpa_mode = MCCONF_FOC_MTPA_MODE;
conf->foc_fw_current_max = MCCONF_FOC_FW_CURRENT_MAX;
conf->foc_fw_duty_start = MCCONF_FOC_FW_DUTY_START;
conf->foc_fw_ramp_time = MCCONF_FOC_FW_RAMP_TIME;
conf->foc_fw_q_current_factor = MCCONF_FOC_FW_Q_CURRENT_FACTOR;
conf->foc_speed_soure = MCCONF_FOC_SPEED_SOURCE;
conf->gpd_buffer_notify_left = MCCONF_GPD_BUFFER_NOTIFY_LEFT;
conf->gpd_buffer_interpol = MCCONF_GPD_BUFFER_INTERPOL;
conf->gpd_current_filter_const = MCCONF_GPD_CURRENT_FILTER_CONST;
conf->gpd_current_kp = MCCONF_GPD_CURRENT_KP;
conf->gpd_current_ki = MCCONF_GPD_CURRENT_KI;
conf->sp_pid_loop_rate = MCCONF_SP_PID_LOOP_RATE;
conf->s_pid_kp = MCCONF_S_PID_KP;
conf->s_pid_ki = MCCONF_S_PID_KI;
conf->s_pid_kd = MCCONF_S_PID_KD;
conf->s_pid_kd_filter = MCCONF_S_PID_KD_FILTER;
conf->s_pid_min_erpm = MCCONF_S_PID_MIN_RPM;
conf->s_pid_allow_braking = MCCONF_S_PID_ALLOW_BRAKING;
conf->s_pid_ramp_erpms_s = MCCONF_S_PID_RAMP_ERPMS_S;
conf->p_pid_kp = MCCONF_P_PID_KP;
conf->p_pid_ki = MCCONF_P_PID_KI;
conf->p_pid_kd = MCCONF_P_PID_KD;
conf->p_pid_kd_proc = MCCONF_P_PID_KD_PROC;
conf->p_pid_kd_filter = MCCONF_P_PID_KD_FILTER;
conf->p_pid_ang_div = MCCONF_P_PID_ANG_DIV;
conf->p_pid_gain_dec_angle = MCCONF_P_PID_GAIN_DEC_ANGLE;
conf->p_pid_offset = MCCONF_P_PID_OFFSET;
conf->cc_startup_boost_duty = MCCONF_CC_STARTUP_BOOST_DUTY;
conf->cc_min_current = MCCONF_CC_MIN_CURRENT;
conf->cc_gain = MCCONF_CC_GAIN;
conf->cc_ramp_step_max = MCCONF_CC_RAMP_STEP;
conf->m_fault_stop_time_ms = MCCONF_M_FAULT_STOP_TIME;
conf->m_duty_ramp_step = MCCONF_M_RAMP_STEP;
conf->m_current_backoff_gain = MCCONF_M_CURRENT_BACKOFF_GAIN;
conf->m_encoder_counts = MCCONF_M_ENCODER_COUNTS;
conf->m_sensor_port_mode = MCCONF_M_SENSOR_PORT_MODE;
conf->m_invert_direction = MCCONF_M_INVERT_DIRECTION;
conf->m_drv8301_oc_mode = MCCONF_M_DRV8301_OC_MODE;
conf->m_drv8301_oc_adj = MCCONF_M_DRV8301_OC_ADJ;
conf->m_bldc_f_sw_min = MCCONF_M_BLDC_F_SW_MIN;
conf->m_bldc_f_sw_max = MCCONF_M_BLDC_F_SW_MAX;
conf->m_dc_f_sw = MCCONF_M_DC_F_SW;
conf->m_ntc_motor_beta = MCCONF_M_NTC_MOTOR_BETA;
conf->m_out_aux_mode = MCCONF_M_OUT_AUX_MODE;
conf->m_motor_temp_sens_type = MCCONF_M_MOTOR_TEMP_SENS_TYPE;
conf->m_ptc_motor_coeff = MCCONF_M_PTC_MOTOR_COEFF;
conf->m_ntcx_ptcx_res = MCCONF_M_NTCX_PTCX_RES;
conf->m_ntcx_ptcx_temp_base = MCCONF_M_NTCX_PTCX_BASE_TEMP;
conf->m_hall_extra_samples = MCCONF_M_HALL_EXTRA_SAMPLES;
conf->si_motor_poles = MCCONF_SI_MOTOR_POLES;
conf->si_gear_ratio = MCCONF_SI_GEAR_RATIO;
conf->si_wheel_diameter = MCCONF_SI_WHEEL_DIAMETER;
conf->si_battery_type = MCCONF_SI_BATTERY_TYPE;
conf->si_battery_cells = MCCONF_SI_BATTERY_CELLS;
conf->si_battery_ah = MCCONF_SI_BATTERY_AH;
conf->si_motor_nl_current = MCCONF_SI_MOTOR_NL_CURRENT;
conf->bms.type = MCCONF_BMS_TYPE;
conf->bms.limit_mode = MCCONF_BMS_LIMIT_MODE;
conf->bms.t_limit_start = MCCONF_BMS_T_LIMIT_START;
conf->bms.t_limit_end = MCCONF_BMS_T_LIMIT_END;
conf->bms.soc_limit_start = MCCONF_BMS_SOC_LIMIT_START;
conf->bms.soc_limit_end = MCCONF_BMS_SOC_LIMIT_END;
conf->bms.fwd_can_mode = MCCONF_BMS_FWD_CAN_MODE;
}
void confgenerator_set_defaults_appconf(app_configuration *conf) {
conf->controller_id = HW_DEFAULT_ID;
conf->timeout_msec = APPCONF_TIMEOUT_MSEC;
conf->timeout_brake_current = APPCONF_TIMEOUT_BRAKE_CURRENT;
conf->can_status_rate_1 = APPCONF_CAN_STATUS_RATE_1;
conf->can_status_rate_2 = APPCONF_CAN_STATUS_RATE_2;
conf->can_status_msgs_r1 = APPCONF_CAN_STATUS_MSGS_R1;
conf->can_status_msgs_r2 = APPCONF_CAN_STATUS_MSGS_R2;
conf->can_baud_rate = APPCONF_CAN_BAUD_RATE;
conf->pairing_done = APPCONF_PAIRING_DONE;
conf->permanent_uart_enabled = APPCONF_PERMANENT_UART_ENABLED;
conf->shutdown_mode = APPCONF_SHUTDOWN_MODE;
conf->can_mode = APPCONF_CAN_MODE;
conf->uavcan_esc_index = APPCONF_UAVCAN_ESC_INDEX;
conf->uavcan_raw_mode = APPCONF_UAVCAN_RAW_MODE;
conf->uavcan_raw_rpm_max = APPCONF_UAVCAN_RAW_RPM_MAX;
conf->uavcan_status_current_mode = APPCONF_UAVCAN_STATUS_CURRENT_MODE;
conf->servo_out_enable = APPCONF_SERVO_OUT_ENABLE;
conf->kill_sw_mode = APPCONF_KILL_SW_MODE;