|
@@ -7,6 +7,9 @@
|
|
|
#define TRQ_I_MAX MAX_TRQ_POINTS
|
|
#define TRQ_I_MAX MAX_TRQ_POINTS
|
|
|
#define RPM_INTVAL TBL_SPD_INTVAL
|
|
#define RPM_INTVAL TBL_SPD_INTVAL
|
|
|
#define IDX2RPM(I) ((I)*RPM_INTVAL + RPM_INTVAL)
|
|
#define IDX2RPM(I) ((I)*RPM_INTVAL + RPM_INTVAL)
|
|
|
|
|
+
|
|
|
|
|
+#define _DEBUG(fmt, args...) no_debug(fmt, ##args)
|
|
|
|
|
+
|
|
|
static trq2dq_t **table_map = NULL;
|
|
static trq2dq_t **table_map = NULL;
|
|
|
//x -> rpm
|
|
//x -> rpm
|
|
|
//z -> torque
|
|
//z -> torque
|
|
@@ -14,16 +17,16 @@ static void intp_line2(float frac_x, float z, trq2dq_t **map, DQ_t *dq_out) {
|
|
|
float frac_z1 = 0; //对应x1索引的t_maps
|
|
float frac_z1 = 0; //对应x1索引的t_maps
|
|
|
float frac_z2 = 0; //对应x2索引的t_maps
|
|
float frac_z2 = 0; //对应x2索引的t_maps
|
|
|
|
|
|
|
|
- sys_debug("low --> %d %d\n", map[1]->torque, map[0]->torque);
|
|
|
|
|
|
|
+ _DEBUG("low --> %d %d\n", map[1]->torque, map[0]->torque);
|
|
|
if ((map[1]->torque != map[0]->torque)) {
|
|
if ((map[1]->torque != map[0]->torque)) {
|
|
|
frac_z1 = (float)(z - map[0]->torque)/(map[1]->torque - map[0]->torque);
|
|
frac_z1 = (float)(z - map[0]->torque)/(map[1]->torque - map[0]->torque);
|
|
|
}
|
|
}
|
|
|
- sys_debug("high --> %d %d\n", map[3]->torque, map[2]->torque);
|
|
|
|
|
|
|
+ _DEBUG("high --> %d %d\n", map[3]->torque, map[2]->torque);
|
|
|
if ((map[3]->torque != map[2]->torque)) {
|
|
if ((map[3]->torque != map[2]->torque)) {
|
|
|
frac_z2 = (float)(z - map[2]->torque)/(map[3]->torque - map[2]->torque);
|
|
frac_z2 = (float)(z - map[2]->torque)/(map[3]->torque - map[2]->torque);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- sys_debug("%f -- %f -- %f\n", frac_x, frac_z1, frac_z2);
|
|
|
|
|
|
|
+ _DEBUG("%f -- %f -- %f\n", frac_x, frac_z1, frac_z2);
|
|
|
|
|
|
|
|
float c1 = (1.0f - frac_z1) * map[0]->d + frac_z1 * map[1]->d; //第一行插值
|
|
float c1 = (1.0f - frac_z1) * map[0]->d + frac_z1 * map[1]->d; //第一行插值
|
|
|
float c2 = (1.0f - frac_z2) * map[2]->d + frac_z2 * map[3]->d; //第二行插值
|
|
float c2 = (1.0f - frac_z2) * map[2]->d + frac_z2 * map[3]->d; //第二行插值
|
|
@@ -42,7 +45,7 @@ static void get_torque_range(float z, int index, int max_index, int *left, int *
|
|
|
low_right = low_left = max_index - 1;
|
|
low_right = low_left = max_index - 1;
|
|
|
}else {
|
|
}else {
|
|
|
for (int i = 0; i < max_index; i++) {
|
|
for (int i = 0; i < max_index; i++) {
|
|
|
- sys_debug("index %d, trq %d\n", i, table_map[index][i].torque);
|
|
|
|
|
|
|
+ _DEBUG("index %d, trq %d\n", i, table_map[index][i].torque);
|
|
|
if (z >= table_map[index][i].torque) {
|
|
if (z >= table_map[index][i].torque) {
|
|
|
low_left = i;
|
|
low_left = i;
|
|
|
low_right = i + 1;
|
|
low_right = i + 1;
|
|
@@ -57,19 +60,22 @@ static void get_torque_range(float z, int index, int max_index, int *left, int *
|
|
|
*right = low_right;
|
|
*right = low_right;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void trq2dq_lookup(int rpm, float torque, DQ_t *dq_out) {
|
|
|
|
|
|
|
+void trq2dq_lookup_init(void) {
|
|
|
if (table_map == NULL) {
|
|
if (table_map == NULL) {
|
|
|
trq2dq_table_t *table = nv_get_trq2dq_table();
|
|
trq2dq_table_t *table = nv_get_trq2dq_table();
|
|
|
if (table != NULL) {
|
|
if (table != NULL) {
|
|
|
table_map = (trq2dq_t **)&table->tdq[0][0];
|
|
table_map = (trq2dq_t **)&table->tdq[0][0];
|
|
|
}
|
|
}
|
|
|
- if (table_map == NULL) {
|
|
|
|
|
- dq_out->d = 0;
|
|
|
|
|
- dq_out->q = torque;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void trq2dq_lookup(int rpm, float torque, DQ_t *dq_out) {
|
|
|
|
|
+ if (table_map == NULL) {
|
|
|
|
|
+ dq_out->d = 0;
|
|
|
|
|
+ dq_out->q = torque;
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
int low = 0, high = 0;
|
|
int low = 0, high = 0;
|
|
|
|
|
|
|
|
low = rpm / RPM_INTVAL - 1;
|
|
low = rpm / RPM_INTVAL - 1;
|
|
@@ -82,15 +88,15 @@ void trq2dq_lookup(int rpm, float torque, DQ_t *dq_out) {
|
|
|
}else {
|
|
}else {
|
|
|
high = low + 1;
|
|
high = low + 1;
|
|
|
}
|
|
}
|
|
|
- sys_debug("speed %d-%d\n", low, high);
|
|
|
|
|
|
|
+ _DEBUG("speed %d-%d\n", low, high);
|
|
|
|
|
|
|
|
int low_left = TRQ_I_MAX - 1, low_right = TRQ_I_MAX - 1;
|
|
int low_left = TRQ_I_MAX - 1, low_right = TRQ_I_MAX - 1;
|
|
|
get_torque_range(torque, low, TRQ_I_MAX, &low_left, &low_right);
|
|
get_torque_range(torque, low, TRQ_I_MAX, &low_left, &low_right);
|
|
|
- sys_debug("low speed torque %d-%d\n", low_left, low_right);
|
|
|
|
|
|
|
+ _DEBUG("low speed torque %d-%d\n", low_left, low_right);
|
|
|
|
|
|
|
|
int high_left = TRQ_I_MAX - 1, high_right = TRQ_I_MAX - 1;
|
|
int high_left = TRQ_I_MAX - 1, high_right = TRQ_I_MAX - 1;
|
|
|
get_torque_range(torque, high, TRQ_I_MAX, &high_left, &high_right);
|
|
get_torque_range(torque, high, TRQ_I_MAX, &high_left, &high_right);
|
|
|
- sys_debug("high speed torque %d-%d\n", high_left, high_right);
|
|
|
|
|
|
|
+ _DEBUG("high speed torque %d-%d\n", high_left, high_right);
|
|
|
trq2dq_t *maps[4];
|
|
trq2dq_t *maps[4];
|
|
|
maps[0] = &table_map[low][low_left];
|
|
maps[0] = &table_map[low][low_left];
|
|
|
maps[1] = &table_map[low][low_right];
|
|
maps[1] = &table_map[low][low_right];
|