mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-23 00:05:28 +03:00
PID Controller Cleanup
Documentation Draft add cli names Cli name adaption cli set numeric and string correct names change Only PID1 and PID2 Add PID3
This commit is contained in:
parent
83109dbf17
commit
e347e7d4bf
6 changed files with 76 additions and 429 deletions
|
@ -186,6 +186,11 @@ static const rxFailsafeChannelMode_e rxFailsafeModesTable[RX_FAILSAFE_TYPE_COUNT
|
|||
{ RX_FAILSAFE_MODE_INVALID, RX_FAILSAFE_MODE_HOLD, RX_FAILSAFE_MODE_SET }
|
||||
};
|
||||
|
||||
// sync this with pidControllerType_e
|
||||
static const char * const pidControllers[] = {
|
||||
"REWRITE", "LUXFLOAT", "MULTIWII23", NULL
|
||||
};
|
||||
|
||||
#ifndef CJMCU
|
||||
// sync this with sensors_e
|
||||
static const char * const sensorTypeNames[] = {
|
||||
|
@ -478,7 +483,7 @@ const clivalue_t valueTable[] = {
|
|||
{ "mag_hardware", VAR_UINT8 | MASTER_VALUE, &masterConfig.mag_hardware, 0, MAG_MAX },
|
||||
{ "mag_declination", VAR_INT16 | PROFILE_VALUE, &masterConfig.profile[0].mag_declination, -18000, 18000 },
|
||||
|
||||
{ "pid_controller", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.pidController, 0, 5 },
|
||||
{ "pid_controller", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.pidController, 1, 3 },
|
||||
|
||||
{ "p_pitch", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.P8[PITCH], 0, 200 },
|
||||
{ "i_pitch", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PITCH], 0, 200 },
|
||||
|
@ -516,13 +521,10 @@ const clivalue_t valueTable[] = {
|
|||
{ "i_vel", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.I8[PIDVEL], 0, 200 },
|
||||
{ "d_vel", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.D8[PIDVEL], 0, 200 },
|
||||
|
||||
{ "yaw_p_limit", VAR_UINT16 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.yaw_p_limit, YAW_P_LIMIT_MIN, YAW_P_LIMIT_MAX },
|
||||
{ "dterm_cut_hz", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.dterm_cut_hz, 0, 200 },
|
||||
{ "pterm_cut_hz", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.pterm_cut_hz, 0, 200 },
|
||||
{ "gyro_cut_hz", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.gyro_cut_hz, 0, 200 },
|
||||
|
||||
{ "pid5_oldyw", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.pid5_oldyw, 0, 1 },
|
||||
|
||||
#ifdef GTUNE
|
||||
{ "gtune_loP_rll", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.gtune_lolimP[FD_ROLL], 10, 200 },
|
||||
{ "gtune_loP_ptch", VAR_UINT8 | PROFILE_VALUE, &masterConfig.profile[0].pidProfile.gtune_lolimP[FD_PITCH], 10, 200 },
|
||||
|
@ -1410,8 +1412,14 @@ static void dumpValues(uint16_t mask)
|
|||
continue;
|
||||
}
|
||||
|
||||
printf("set %s = ", valueTable[i].name);
|
||||
cliPrintVar(value, 0);
|
||||
if (strstr(valueTable[i].name, "pid_controller")) {
|
||||
void *pidPtr= value->ptr;
|
||||
pidPtr= ((uint8_t *)pidPtr) + (sizeof(profile_t) * masterConfig.current_profile_index);
|
||||
cliPrint(pidControllers[*(uint8_t *)pidPtr-1]);
|
||||
} else {
|
||||
cliPrintVar(value, 0);
|
||||
}
|
||||
|
||||
cliPrint("\r\n");
|
||||
}
|
||||
}
|
||||
|
@ -2051,9 +2059,42 @@ static void cliSet(char *cmdline)
|
|||
valuef = fastA2F(eqptr);
|
||||
for (i = 0; i < VALUE_COUNT; i++) {
|
||||
val = &valueTable[i];
|
||||
// ensure exact match when setting to prevent setting variables with shorter names
|
||||
if (strncasecmp(cmdline, valueTable[i].name, strlen(valueTable[i].name)) == 0 && variableNameLength == strlen(valueTable[i].name)) {
|
||||
if (valuef >= valueTable[i].min && valuef <= valueTable[i].max) { // here we compare the float value since... it should work, RIGHT?
|
||||
// ensure exact match when setting to prevent setting variables with shorter names
|
||||
if (strstr(valueTable[i].name, "pid_controller")) {
|
||||
int_float_value_t tmp;
|
||||
tmp.int_value = 0;
|
||||
bool pidControllerSet = false;
|
||||
|
||||
if (value) {
|
||||
if (value >= valueTable[i].min && value <= valueTable[i].max) {
|
||||
tmp.int_value = value;
|
||||
cliSetVar(val, tmp);
|
||||
printf("%s set to %s \r\n", valueTable[i].name, pidControllers[value - 1]);
|
||||
pidControllerSet = true;
|
||||
}
|
||||
} else {
|
||||
for (int pid = 0; pid < (PID_COUNT - 1); pid++) {
|
||||
if (strstr(eqptr, pidControllers[pid])) {
|
||||
tmp.int_value = pid + 1;
|
||||
cliSetVar(val, tmp);
|
||||
printf("%s set to %s \r\n", valueTable[i].name, pidControllers[pid]);
|
||||
pidControllerSet = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!pidControllerSet) {
|
||||
printf("Invalid Value! (Available PID Controllers: ");
|
||||
for (int pid = 0; pid < (PID_COUNT - 1); pid++) {
|
||||
printf(pidControllers[pid]);
|
||||
printf(" ");
|
||||
}
|
||||
printf(")\r\n");
|
||||
}
|
||||
|
||||
return;
|
||||
} else if (valuef >= valueTable[i].min && valuef <= valueTable[i].max) { // here we compare the float value since... it should work, RIGHT?
|
||||
int_float_value_t tmp;
|
||||
if (valueTable[i].type & VAR_FLOAT)
|
||||
tmp.float_value = valuef;
|
||||
|
@ -2085,7 +2126,15 @@ static void cliGet(char *cmdline)
|
|||
if (strstr(valueTable[i].name, cmdline)) {
|
||||
val = &valueTable[i];
|
||||
printf("%s = ", valueTable[i].name);
|
||||
cliPrintVar(val, 0);
|
||||
|
||||
if (strstr(valueTable[i].name, "pid_controller")) {
|
||||
void *pidPtr= val->ptr;
|
||||
pidPtr= ((uint8_t *)pidPtr) + (sizeof(profile_t) * masterConfig.current_profile_index);
|
||||
cliPrint(pidControllers[*(uint8_t *)pidPtr-1]);
|
||||
} else {
|
||||
cliPrintVar(val, 0);
|
||||
}
|
||||
|
||||
cliPrint("\r\n");
|
||||
|
||||
matchedCommands++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue