|
|
@@ -3,17 +3,45 @@
|
|
|
#include "foc/motor/motor.h"
|
|
|
#include "foc/core/e_ctrl.h"
|
|
|
#include "foc/core/PMSM_FOC_Core.h"
|
|
|
-
|
|
|
+#include "app/nv_storage.h"
|
|
|
/*
|
|
|
通过查表获取对应扭矩和速度时的Id和IQ的分配
|
|
|
*/
|
|
|
-void torque_init(void) {
|
|
|
+static torque_lut_t *_trq_tbl = NULL;
|
|
|
|
|
|
+void torque_init(void) {
|
|
|
+ _trq_tbl = nv_get_trq_tlb();
|
|
|
}
|
|
|
|
|
|
void torque_get_idq(float torque, float rpm, DQ_t *dq_out) {
|
|
|
- dq_out->d = 0;
|
|
|
- dq_out->q = torque;
|
|
|
+ if ((_trq_tbl == NULL) || (torque < 0 || rpm < 0)) {
|
|
|
+ dq_out->d = 0;
|
|
|
+ dq_out->q = torque;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int trq_idx = (int)torque / TBL_TRQ_INTVAL;
|
|
|
+ int rpm_idx = (int)rpm / TBL_SPD_INTVAL;
|
|
|
+ if (trq_idx >= MAX_TRQ_POINTS) {
|
|
|
+ trq_idx = MAX_TRQ_POINTS -1;
|
|
|
+ }
|
|
|
+ if (rpm_idx >= MAX_SPD_POINTS) {
|
|
|
+ rpm_idx = MAX_SPD_POINTS -1;
|
|
|
+ }
|
|
|
+ s16 d = _trq_tbl->d[trq_idx][rpm_idx];
|
|
|
+ s16 q = _trq_tbl->q[trq_idx][rpm_idx];
|
|
|
+ if (trq_idx < MAX_TRQ_POINTS - 1) {
|
|
|
+ trq_idx += 1;
|
|
|
+ }
|
|
|
+ if (rpm_idx < MAX_SPD_POINTS - 1) {
|
|
|
+ rpm_idx += 1;
|
|
|
+ }
|
|
|
+ s16 d_delta = _trq_tbl->d[trq_idx][rpm_idx] - d;
|
|
|
+ s16 q_delta = _trq_tbl->q[trq_idx][rpm_idx] - q;
|
|
|
+ float comp_ceof = 0.5f * ((torque - torque/TBL_TRQ_INTVAL*TBL_TRQ_INTVAL)/(float)TBL_TRQ_INTVAL + (rpm - rpm/TBL_SPD_INTVAL*TBL_SPD_INTVAL)/(float)TBL_SPD_INTVAL);
|
|
|
+
|
|
|
+ dq_out->d = d + d_delta * comp_ceof;
|
|
|
+ dq_out->q = q + q_delta * comp_ceof;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
float speed_target_from_throttle(float f_throttle) {
|