From 21f7f972caf5d2a011657e89f8c6592b3eb1e79a Mon Sep 17 00:00:00 2001 From: Roman Belov Date: Sat, 11 Jan 2025 15:48:31 +0300 Subject: [PATCH] Added configuration export in PGUI. --- bench/tsfunc.c | 3 - doc/TroubleShooting.md | 13 +- pgui/Makefile.mingw | 2 +- pgui/config.c | 43 ++- pgui/config.h | 2 + pgui/gp/dirent.c | 2 +- pgui/gp/gp.c | 4 + pgui/link.c | 134 ++++++--- pgui/link.h | 4 +- pgui/nksdl.c | 2 +- pgui/nksdl.h | 5 +- pgui/phobia.c | 583 ++++++++++++++++++++++++++++-------- src/hal/hal.h | 4 +- src/hal/hw/FSESC_67.h | 2 +- src/hal/hw/FSESC_67_mini.h | 2 +- src/hal/hw/FSESC_75100_v2.h | 2 +- src/hal/hw/HBRO_foc_mini.h | 2 +- src/hal/hw/KLEN_r1.h | 2 +- src/hal/hw/MKESC_60100_v2.h | 2 +- src/hal/hw/MKESC_84200.h | 4 +- src/hal/hw/PHOBIA_rev2.h | 2 +- src/hal/hw/PHOBIA_rev3.h | 2 +- src/hal/hw/PHOBIA_rev4b.h | 2 +- src/hal/hw/PHOBIA_rev4c.h | 2 +- src/hal/hw/PHOBIA_rev5.h | 2 +- src/hal/hw/RIO_r1.h | 2 +- src/hal/hw/VESC_60_mk6.h | 4 +- src/hal/hw/VESC_75_300_r3.h | 4 +- src/hal/hw/ZAEV_r3.h | 2 +- src/main.c | 12 +- src/ntc.c | 8 +- src/ntc.h | 4 +- src/phobia/pm.c | 23 ++ src/phobia/pm.h | 4 +- src/phobia/pm_fsm.c | 43 +-- src/regdefs.h | 4 +- src/regfile.c | 12 +- 37 files changed, 692 insertions(+), 257 deletions(-) diff --git a/bench/tsfunc.c b/bench/tsfunc.c index d6eb770..7947ed8 100644 --- a/bench/tsfunc.c +++ b/bench/tsfunc.c @@ -804,9 +804,6 @@ void ts_script_test() ts_script_base(); blm_restart(&m); - //pm.config_DCU_VOLTAGE = PM_DISABLED; - //pm.dcu_tol = 1.f; - ts_script_speed(); blm_restart(&m); diff --git a/doc/TroubleShooting.md b/doc/TroubleShooting.md index 86cf52f..a140af4 100644 --- a/doc/TroubleShooting.md +++ b/doc/TroubleShooting.md @@ -25,8 +25,17 @@ completely inoperable. the output terminals. Power stages or terminal voltage sensors are definitely broken. -`PM_ERROR_LOW_ACCURACY` - Result of adjustment shows the parameter deviation is -above the fault threshold. Check the voltage and current measurement circuit. +`PM_ERROR_LOW_CURRENT_ACCURACY` - Result of current sensor adjustment shows the +deviation is above the fault threshold. Check your current measurement circuit +or increse the fault threshold. + +`PM_ERROR_LOW_VOLTAGE_ACCURACY` - Result of voltage circuit adjustment shows +the deviation is above the fault threshold. Check your voltage measurement +circuit or increse the fault threshold. + +`PM_ERROR_LOW_DEADBAND_ACCURACY` - Result of deadband distortion adjustment +shows the deviation is above the fault threshold. If your motor winding +resistance is too high (over ~0.1 Ohm) consider to disable DCU compensation. `PM_ERROR_CURRENT_LOOP_FAULT` - This means that we apply the full voltage but actual current is still low. If current sensing circuit is OK this may be diff --git a/pgui/Makefile.mingw b/pgui/Makefile.mingw index b70ba96..8d7d2ba 100644 --- a/pgui/Makefile.mingw +++ b/pgui/Makefile.mingw @@ -23,7 +23,7 @@ CFLAGS += -fno-math-errno \ CFLAGS += -fno-stack-protector CFLAGS += -I$(MINGW)/include -CFLAGS += -D_EMBED_GP -D_WINDOWS +CFLAGS += -D_EMBED_GP -D_LOCAL_GP -D_LOCAL_PGUI -D_WINDOWS LFLAGS = -lm -lSDL2 -lSDL2_ttf -lSDL2_image -static -mwindows LFLAGS += -L$(MINGW)/lib diff --git a/pgui/config.c b/pgui/config.c index 7e54141..8bb6f03 100644 --- a/pgui/config.c +++ b/pgui/config.c @@ -76,12 +76,13 @@ void config_read(struct config_phobia *fe) name = strtok(line, sep); value = strtok(NULL, sep); - if ( name == NULL - || value == NULL) { + if (name == NULL) + goto config_read_SKIP; - /* Skip empty lines */ - } - else if (strcmp(name, "version") == 0) { + if (value == NULL) + value = ""; + + if (strcmp(name, "version") == 0) { fe->version = strtol(value, NULL, 10); } @@ -113,6 +114,8 @@ void config_read(struct config_phobia *fe) fe->regfile = strtol(value, NULL, 10); } +config_read_SKIP: + } fclose(fd); @@ -123,8 +126,6 @@ void config_open(struct config_phobia *fe) { char *path_HOME; - config_default(fe); - #ifdef _WINDOWS path_HOME = getenv("APPDATA"); #else /* _WINDOWS */ @@ -136,6 +137,10 @@ void config_open(struct config_phobia *fe) fe->local = 1; } +#ifdef _LOCAL_PGUI + fe->local = 1; +#endif /* _LOCAL_PGUI */ + if (fe->local == 0) { #ifdef _WINDOWS @@ -145,6 +150,8 @@ void config_open(struct config_phobia *fe) #endif strcat(fe->rcfile, DIRSEP FILE_HIDDEN_CONFIG); + config_default(fe); + if (config_rcfiletry(fe) == 0) { config_write(fe); @@ -224,21 +231,33 @@ void config_default(struct config_phobia *fe) fe->windowsize = 1; -#ifdef _WINDOWS if (fe->local == 0) { - +#ifdef _WINDOWS GetTempPathA(sizeof(lptemp), lptemp); config_ACP_to_UTF8(fe->storage, lptemp, sizeof(fe->storage)); +#else /* _WINDOWS */ + strcpy(fe->storage, "/tmp"); +#endif } else { fe->storage[0] = 0; } -#else /* _WINDOWS */ - strcpy(fe->storage, "/tmp"); -#endif strcpy(fe->fuzzy, "setpoint"); fe->regfile = 500; } +void config_storage_path(struct config_phobia *fe, char *lbuf, const char *file) +{ + lbuf[0] = 0; + + if (fe->storage[0] != 0) { + + strcat(lbuf, fe->storage); + strcat(lbuf, DIRSEP); + } + + strcat(lbuf, file); +} + diff --git a/pgui/config.h b/pgui/config.h index 9c9eeab..8857855 100644 --- a/pgui/config.h +++ b/pgui/config.h @@ -41,5 +41,7 @@ void config_open(struct config_phobia *fe); void config_write(struct config_phobia *fe); void config_default(struct config_phobia *fe); +void config_storage_path(struct config_phobia *fe, char *lbuf, const char *file); + #endif /* _H_CONFIG_ */ diff --git a/pgui/gp/dirent.c b/pgui/gp/dirent.c index 13c2e58..c26eb5a 100644 --- a/pgui/gp/dirent.c +++ b/pgui/gp/dirent.c @@ -52,7 +52,7 @@ int dirent_open(struct dirent_stat *sb, const char *path) MultiByteToWideChar(CP_UTF8, 0, path, -1, p->wpath, DIRENT_PATH_MAX); - wcscat(p->wpath, L"/*"); + wcscat(p->wpath, L"\\*"); p->hDIR = FindFirstFileW(p->wpath, &p->fDATA); diff --git a/pgui/gp/gp.c b/pgui/gp/gp.c index abc5db5..5ba7746 100644 --- a/pgui/gp/gp.c +++ b/pgui/gp/gp.c @@ -4694,6 +4694,10 @@ gpcon_t *gp_Alloc() gpFileGetPath(gp); +#ifdef _LOCAL_GP + gpFileGetLocal(gp); +#endif /* _LOCAL_GP */ + if (gp->rcfile[0] != 0) { if (gpFileExist(gp->rcfile) == 0) { diff --git a/pgui/link.c b/pgui/link.c index 4a37631..ea5a1c0 100644 --- a/pgui/link.c +++ b/pgui/link.c @@ -12,7 +12,7 @@ #define LINK_EOL "\r\n" #define LINK_SPACE " \t" -#define LINK_EXTRA "])" +#define LINK_EXTRA " \t])" #define LINK_ALLOC_MAX 92160U #define LINK_CACHE_MAX 4096U @@ -51,51 +51,50 @@ struct link_priv { const char *lk_stoi(int *x, const char *s) { - int n, k, i; + int n, d, i; if (*s == '-') { n = - 1; s++; } else if (*s == '+') { n = 1; s++; } else { n = 1; } - k = 0; + d = 0; i = 0; while (*s >= '0' && *s <= '9') { i = 10 * i + (*s++ - '0') * n; - k++; - - if (k > 9) return NULL; + d += 1; } - if (k == 0) return NULL; + if (d == 0 || d > 9) { return NULL; } - if (*s == 0 || strchr(LINK_SPACE LINK_EXTRA LINK_EOL, *s) != NULL) { + if (*s == 0 || strchr(LINK_EXTRA, *s) != NULL + || strchr(LINK_EOL, *s) != NULL) { *x = i; } - else return NULL; + else { return NULL; } return s; } const char *lk_stod(double *x, const char *s) { - int n, k, v, e; - double f = 0.; + int n, d, v, e; + double f; if (*s == '-') { n = - 1; s++; } else if (*s == '+') { n = 1; s++; } else { n = 1; } - k = 0; + d = 0; v = 0; f = 0.; while (*s >= '0' && *s <= '9') { f = 10. * f + (*s++ - '0') * n; - k++; + d += 1; } if (*s == '.') { @@ -105,11 +104,11 @@ const char *lk_stod(double *x, const char *s) while (*s >= '0' && *s <= '9') { f = 10. * f + (*s++ - '0') * n; - k++; v--; + d += 1; v -= 1; } } - if (k == 0) return NULL; + if (d == 0) { return NULL; } if (*s == 'n') { v += - 9; s++; } else if (*s == 'u') { v += - 6; s++; } @@ -122,17 +121,18 @@ const char *lk_stod(double *x, const char *s) s = lk_stoi(&e, s + 1); if (s != NULL) { v += e; } - else return NULL; + else { return NULL; } } - if (*s == 0 || strchr(LINK_SPACE LINK_EXTRA LINK_EOL, *s) != NULL) { + if (*s == 0 || strchr(LINK_EXTRA, *s) != NULL + || strchr(LINK_EOL, *s) != NULL) { - while (v < 0) { f /= 10.; v++; } - while (v > 0) { f *= 10.; v--; } + while (v < 0) { f /= 10.; v += 1; } + while (v > 0) { f *= 10.; v -= 1; } *x = f; } - else return NULL; + else { return NULL; } return s; } @@ -145,6 +145,14 @@ lk_space(const char *s) return s; } +static const char * +lk_eol(const char *s) +{ + while (*s != 0 && strchr(LINK_EOL, *s) == 0) { ++s; } + + return s; +} + static const char * lk_token(char **sp) { @@ -564,7 +572,6 @@ void link_open(struct link_pmc *lp, struct config_phobia *fe, sprintf(lp->devname, "%.79s", devname); lp->baudrate = baudrate; - lp->quantum = 10; if (lp->priv != NULL) { @@ -804,6 +811,7 @@ int link_fetch(struct link_pmc *lp, int clock) fprintf(priv->fd_grab, "%s\n", priv->lbuf); fflush(priv->fd_grab); + lp->locked = lp->clock; lp->grab_N++; break; @@ -823,8 +831,14 @@ int link_fetch(struct link_pmc *lp, int clock) N++; } - if (priv->link_mode != LINK_MODE_DATA_GRAB) { + if (priv->link_mode == LINK_MODE_DATA_GRAB) { + + if (lp->active + 1000 < lp->clock) { + link_grab_file_close(lp); + } + } + else { if (lp->active + 12000 < lp->clock) { link_close(lp); @@ -851,31 +865,51 @@ int link_fetch(struct link_pmc *lp, int clock) } } } - else { - if (lp->active + 1000 < lp->clock) { - - link_grab_file_close(lp); - } - } lp->line_N += N; return N; } +static int +link_reg_all_queued(struct link_pmc *lp) +{ + struct link_reg *reg; + int reg_ID; + int busy_N = 0; + + for (reg_ID = 0; reg_ID < lp->reg_MAX_N; ++reg_ID) { + + if (lp->reg[reg_ID].sym[0] != 0) { + + reg = &lp->reg[reg_ID]; + + if (reg->queued != 0) + busy_N++; + } + } + + return busy_N; +} + void link_push(struct link_pmc *lp) { struct link_priv *priv = lp->priv; struct link_reg *reg; - int reg_ID, dofetch; + int reg_ID, dofetch, busy_N; if (lp->linked == 0) return ; + if (lp->locked > lp->clock) + return ; + if (priv->link_mode == LINK_MODE_DATA_GRAB) return ; - if (lp->locked > lp->clock) + busy_N = link_reg_all_queued(lp); + + if (busy_N > 10) return ; reg_ID = priv->reg_push_ID; @@ -916,11 +950,10 @@ void link_push(struct link_pmc *lp) if (serial_fputs(priv->fd, priv->lbuf) == SERIAL_OK) { reg->queued = lp->clock; + lp->locked = lp->clock; - lp->locked = lp->clock + lp->quantum; + busy_N++; } - - break; } else if (dofetch != 0) { @@ -929,11 +962,10 @@ void link_push(struct link_pmc *lp) if (serial_fputs(priv->fd, priv->lbuf) == SERIAL_OK) { reg->queued = lp->clock; + lp->locked = lp->clock; - lp->locked = lp->clock + lp->quantum; + busy_N++; } - - break; } if ( (reg->mode & LINK_REG_TYPE_ENUMERATE) != 0 @@ -946,10 +978,10 @@ void link_push(struct link_pmc *lp) reg->queued = lp->clock; reg->enumerated = lp->clock; - lp->locked = lp->clock + lp->quantum; - } + lp->locked = lp->clock; - break; + busy_N++; + } } } else { @@ -962,6 +994,9 @@ void link_push(struct link_pmc *lp) if (reg_ID >= lp->reg_MAX_N) reg_ID = 0; + if (busy_N > 10) + break; + if (reg_ID == priv->reg_push_ID) break; } @@ -978,7 +1013,7 @@ int link_command(struct link_pmc *lp, const char *command) if (lp->linked == 0) return 0; - if (lp->locked > lp->clock + 100) + if (lp->locked > lp->clock) return 0; sprintf(priv->lbuf, "%.90s" LINK_EOL, command); @@ -1078,7 +1113,7 @@ int link_reg_lookup_range(struct link_pmc *lp, const char *sym, int *min, int *m void link_reg_fetch_all_shown(struct link_pmc *lp) { - struct link_reg *reg = NULL; + struct link_reg *reg; int reg_ID; for (reg_ID = 0; reg_ID < lp->reg_MAX_N; ++reg_ID) { @@ -1106,18 +1141,21 @@ void link_config_write(struct link_pmc *lp, const char *file) if (fd != NULL) { - for (reg_ID = 0; reg_ID < lp->reg_MAX_N; ++reg_ID) { + for (reg_ID = 1; reg_ID < lp->reg_MAX_N; ++reg_ID) { if (lp->reg[reg_ID].sym[0] != 0) { reg = &lp->reg[reg_ID]; - if (reg->mode & LINK_REG_LINKED) { + if (reg->mode & LINK_REG_CONFIG) { - fprintf(fd, "%s %s\n", reg->sym, reg->um); - } - else { - fprintf(fd, "%s %s\n", reg->sym, reg->val); + if (reg->mode & LINK_REG_LINKED) { + + fprintf(fd, "%s %s\n", reg->sym, reg->um); + } + else { + fprintf(fd, "%s %s\n", reg->sym, reg->val); + } } } } @@ -1152,6 +1190,8 @@ void link_config_read(struct link_pmc *lp, const char *file) if (reg != NULL) { + * (char *) lk_eol(val) = 0; + sprintf(reg->val, "%.70s", val); reg->modified = lp->clock; diff --git a/pgui/link.h b/pgui/link.h index 5313ea3..f2f954f 100644 --- a/pgui/link.h +++ b/pgui/link.h @@ -78,7 +78,6 @@ struct link_pmc { char devname[LINK_NAME_MAX]; int baudrate; - int quantum; int linked; int uptime; @@ -132,8 +131,9 @@ int link_command(struct link_pmc *lp, const char *command); struct link_reg *link_reg_lookup(struct link_pmc *lp, const char *sym); int link_reg_lookup_range(struct link_pmc *lp, const char *sym, int *min, int *max); void link_reg_fetch_all_shown(struct link_pmc *lp); -void link_reg_clean_all_always(struct link_pmc *lp); +void link_config_write(struct link_pmc *lp, const char *file); +void link_config_read(struct link_pmc *lp, const char *file); int link_log_file_open(struct link_pmc *lp, const char *file); int link_grab_file_open(struct link_pmc *lp, const char *file); void link_grab_file_close(struct link_pmc *lp); diff --git a/pgui/nksdl.c b/pgui/nksdl.c index d632bea..0aad42d 100644 --- a/pgui/nksdl.c +++ b/pgui/nksdl.c @@ -34,8 +34,8 @@ #define NK_MEMSET memset #define NK_MEMCPY memcpy -#define NK_INV_SQRT #define NK_SQRT sqrtf +#define NK_INV_SQRT #define NK_SIN sinf #define NK_COS cosf diff --git a/pgui/nksdl.h b/pgui/nksdl.h index bab63f5..77e0fba 100644 --- a/pgui/nksdl.h +++ b/pgui/nksdl.h @@ -36,8 +36,9 @@ struct nk_sdl { struct nk_recti scissor; struct nk_color table[NK_COLOR_COUNT + 20]; - int clock; - int updated; + Uint32 clock; + Uint32 updated; + int idled; SDL_Window *window; diff --git a/pgui/phobia.c b/pgui/phobia.c index 6f7a6b4..4c76836 100644 --- a/pgui/phobia.c +++ b/pgui/phobia.c @@ -36,7 +36,8 @@ enum { POPUP_FLASH_WIPE, POPUP_SYSTEM_REBOOT, POPUP_SYSTEM_BOOTLOAD, - POPUP_TELEMETRY_GRAB + POPUP_TELEMETRY_GRAB, + POPUP_CONFIG_EXPORT }; enum { @@ -747,6 +748,9 @@ pub_popup_progress(struct public *pub, int popup, int pce) if (nk_popup_begin(ctx, NK_POPUP_DYNAMIC, "Reading", NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR, bounds)) { + nk_layout_row_dynamic(ctx, pub->fe_font_h / 2, 1); + nk_spacer(ctx); + nk_layout_row_template_begin(ctx, 0); nk_layout_row_template_push_static(ctx, pub->fe_base * 2); nk_layout_row_template_push_variable(ctx, 1); @@ -757,6 +761,9 @@ pub_popup_progress(struct public *pub, int popup, int pce) nk_prog(ctx, pce, 1000, nk_false); nk_spacer(ctx); + nk_layout_row_dynamic(ctx, pub->fe_font_h / 2, 1); + nk_spacer(ctx); + if (pce >= 1000) { nk_popup_close(ctx); @@ -789,6 +796,9 @@ pub_popup_command(struct public *pub, int popup, int command_state) if (nk_popup_begin(ctx, NK_POPUP_DYNAMIC, "Waiting", NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR, bounds)) { + nk_layout_row_dynamic(ctx, pub->fe_font_h / 2, 1); + nk_spacer(ctx); + nk_layout_row_template_begin(ctx, 0); nk_layout_row_template_push_variable(ctx, 1); nk_layout_row_template_push_static(ctx, pub->fe_base * 2); @@ -805,6 +815,9 @@ pub_popup_command(struct public *pub, int popup, int command_state) nk_prog(ctx, ((clock & 3U) == 3U) ? 10 : 0, 10, nk_false); nk_spacer(ctx); + nk_layout_row_dynamic(ctx, pub->fe_font_h / 2, 1); + nk_spacer(ctx); + if (command_state == LINK_COMMAND_NONE) { nk_popup_close(ctx); @@ -891,8 +904,15 @@ pub_directory_scan(struct public *pub, const char *sup) { int len, ofs, bsz, kmg, N; - if (dirent_open(&pub->scan.sb, pub->fe->storage) != ENT_OK) - return ; + if (pub->fe->storage[0] != 0) { + + if (dirent_open(&pub->scan.sb, pub->fe->storage) != ENT_OK) + return ; + } + else { + if (dirent_open(&pub->scan.sb, ".") != ENT_OK) + return ; + } len = strlen(sup); N = 0; @@ -1029,9 +1049,9 @@ pub_popup_telemetry_grab(struct public *pub, int popup) if (nk_button_label(ctx, "Flush GP")) { - strcpy(pub->lbuf, pub->fe->storage); - strcat(pub->lbuf, DIRSEP); - strcat(pub->lbuf, pub->telemetry.file_grab); + config_storage_path(pub->fe, pub->lbuf, + pub->telemetry.file_grab); + strcpy(pub->telemetry.file_snap, pub->lbuf); if (link_grab_file_open(lp, pub->telemetry.file_snap) != 0) { @@ -1068,9 +1088,9 @@ pub_popup_telemetry_grab(struct public *pub, int popup) if (nk_button_label(ctx, "Live GP")) { - strcpy(pub->lbuf, pub->fe->storage); - strcat(pub->lbuf, DIRSEP); - strcat(pub->lbuf, pub->telemetry.file_grab); + config_storage_path(pub->fe, pub->lbuf, + pub->telemetry.file_grab); + strcpy(pub->telemetry.file_snap, pub->lbuf); if (link_grab_file_open(lp, pub->telemetry.file_snap) != 0) { @@ -1206,9 +1226,9 @@ pub_popup_telemetry_grab(struct public *pub, int popup) if (nk_button_label(ctx, "Plot GP")) { - strcpy(pub->lbuf, pub->fe->storage); - strcat(pub->lbuf, DIRSEP); - strcat(pub->lbuf, pub->telemetry.file_grab); + config_storage_path(pub->fe, pub->lbuf, + pub->telemetry.file_grab); + strcpy(pub->telemetry.file_snap, pub->lbuf); pub_open_GP(pub, pub->telemetry.file_snap); @@ -1218,9 +1238,8 @@ pub_popup_telemetry_grab(struct public *pub, int popup) if (nk_button_label(ctx, "Remove")) { - strcpy(pub->lbuf, pub->fe->storage); - strcat(pub->lbuf, DIRSEP); - strcat(pub->lbuf, pub->telemetry.file_grab); + config_storage_path(pub->fe, pub->lbuf, + pub->telemetry.file_grab); file_remove(pub->lbuf); @@ -1264,13 +1283,203 @@ pub_popup_telemetry_grab(struct public *pub, int popup) } } +static void +pub_popup_config_export(struct public *pub, int popup) +{ + struct nk_sdl *nk = pub->nk; + struct link_pmc *lp = pub->lp; + struct nk_context *ctx = &nk->ctx; + + struct nk_rect bounds; + struct nk_style_button disabled; + + int height; + int N, sel, newsel; + + if (pub->popup_enum != popup) + return ; + + bounds = pub_get_popup_bounds_full(pub); + + if (nk_popup_begin(ctx, NK_POPUP_STATIC, " ", NK_WINDOW_CLOSABLE + | NK_WINDOW_NO_SCROLLBAR, bounds)) { + + nk_layout_row_dynamic(ctx, pub->fe_base, 1); + nk_spacer(ctx); + + nk_layout_row_template_begin(ctx, 0); + nk_layout_row_template_push_static(ctx, pub->fe_base); + nk_layout_row_template_push_static(ctx, pub->fe_base * 7); + nk_layout_row_template_push_static(ctx, pub->fe_base); + nk_layout_row_template_push_variable(ctx, 1); + nk_layout_row_template_push_static(ctx, pub->fe_base); + nk_layout_row_template_end(ctx); + + nk_spacer(ctx); + + if (nk_button_label(ctx, "Export")) { + + config_storage_path(pub->fe, pub->lbuf, + pub->config.file_grab); + + strcpy(pub->config.file_snap, pub->lbuf); + + link_config_write(lp, pub->config.file_snap); + + pub_directory_scan(pub, FILE_CONFIG_EXT); + } + + nk_spacer(ctx); + + nk_edit_string_zero_terminated(ctx, NK_EDIT_FIELD, + pub->config.file_grab, + sizeof(pub->config.file_grab), + nk_filter_default); + + if ( pub->scan.selected >= 0 + && pub->scan.selected < PHOBIA_FILE_MAX) { + + N = pub->scan.selected; + + if ( strcmp(pub->scan.file[N].name, + pub->config.file_grab) != 0) { + + pub->scan.selected = -1; + } + } + + nk_spacer(ctx); + + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); + + height = ctx->current->bounds.h - ctx->current->layout->row.height * 6; + + nk_layout_row_template_begin(ctx, height); + nk_layout_row_template_push_static(ctx, pub->fe_base); + nk_layout_row_template_push_variable(ctx, 1); + nk_layout_row_template_push_static(ctx, pub->fe_base); + nk_layout_row_template_end(ctx); + + nk_spacer(ctx); + + if (nk_group_begin(ctx, "FILES", NK_WINDOW_BORDER)) { + + nk_layout_row_template_begin(ctx, 0); + nk_layout_row_template_push_variable(ctx, 1); + nk_layout_row_template_push_static(ctx, pub->fe_base * 10); + nk_layout_row_template_push_static(ctx, pub->fe_base * 5); + nk_layout_row_template_end(ctx); + + for (N = 0; N < PHOBIA_FILE_MAX; ++N) { + + if (pub->scan.file[N].name[0] == 0) + break; + + sel = (N == pub->scan.selected) ? 1 : 0; + + newsel = nk_select_label(ctx, pub->scan.file[N].name, + NK_TEXT_LEFT, sel); + + newsel |= nk_select_label(ctx, pub->scan.file[N].time, + NK_TEXT_LEFT, sel); + + newsel |= nk_select_label(ctx, pub->scan.file[N].size, + NK_TEXT_RIGHT, sel); + + if (newsel != sel && newsel != 0) { + + pub->scan.selected = N; + + strcpy(pub->config.file_grab, + pub->scan.file[N].name); + } + } + + nk_group_end(ctx); + } + + nk_spacer(ctx); + + nk_layout_row_dynamic(ctx, pub->fe_base, 1); + nk_spacer(ctx); + + nk_layout_row_template_begin(ctx, 0); + nk_layout_row_template_push_static(ctx, pub->fe_base); + nk_layout_row_template_push_static(ctx, pub->fe_base * 7); + nk_layout_row_template_push_static(ctx, pub->fe_base); + nk_layout_row_template_push_static(ctx, pub->fe_base * 7); + nk_layout_row_template_push_static(ctx, pub->fe_base); + nk_layout_row_template_push_static(ctx, pub->fe_base * 7); + nk_layout_row_template_push_static(ctx, pub->fe_base); + nk_layout_row_template_end(ctx); + + nk_spacer(ctx); + + if (nk_button_label(ctx, "Scan")) { + + pub_directory_scan(pub, FILE_CONFIG_EXT); + } + + nk_spacer(ctx); + + if ( pub->scan.selected >= 0 + && pub->scan.selected < PHOBIA_FILE_MAX) { + + if (nk_button_label(ctx, "Load")) { + + config_storage_path(pub->fe, pub->lbuf, + pub->config.file_grab); + + strcpy(pub->config.file_snap, pub->lbuf); + + link_config_read(lp, pub->config.file_snap); + } + + nk_spacer(ctx); + + if (nk_button_label(ctx, "Remove")) { + + config_storage_path(pub->fe, pub->lbuf, + pub->config.file_grab); + + file_remove(pub->lbuf); + + pub_directory_scan(pub, FILE_CONFIG_EXT); + } + } + else { + disabled = ctx->style.button; + + disabled.normal = disabled.active; + disabled.hover = disabled.active; + disabled.text_normal = disabled.text_active; + disabled.text_hover = disabled.text_active; + + nk_button_label_styled(ctx, &disabled, "Load"); + + nk_spacer(ctx); + + nk_button_label_styled(ctx, &disabled, "Remove"); + } + + nk_spacer(ctx); + + nk_popup_end(ctx); + } + else { + pub->popup_enum = 0; + } +} + static void pub_drawing_machine_position(struct public *pub, float fpos[2], int dtype) { struct nk_sdl *nk = pub->nk; struct link_pmc *lp = pub->lp; struct nk_context *ctx = &nk->ctx; - struct nk_command_buffer *canvas = nk_window_get_canvas(ctx); + + struct nk_command_buffer *out = nk_window_get_canvas(ctx); struct nk_rect space; float tfm[4], arrow[10], pbuf[10]; @@ -1288,14 +1497,14 @@ pub_drawing_machine_position(struct public *pub, float fpos[2], int dtype) space.w += - 2.f * thickness; space.h += - 2.f * thickness; - nk_fill_circle(canvas, space, nk->table[NK_COLOR_DESIGN]); + nk_fill_circle(out, space, nk->table[NK_COLOR_DESIGN]); space.x += thickness; space.y += thickness; space.w += - 2.f * thickness; space.h += - 2.f * thickness; - nk_fill_circle(canvas, space, nk->table[NK_COLOR_WINDOW]); + nk_fill_circle(out, space, nk->table[NK_COLOR_WINDOW]); tfm[0] = space.x + space.w / 2.f; tfm[1] = space.y + space.h / 2.f; @@ -1336,7 +1545,7 @@ pub_drawing_machine_position(struct public *pub, float fpos[2], int dtype) pbuf[6] = tfm[0] + (tfm[2] * arrow[6] - tfm[3] * arrow[7]); pbuf[7] = tfm[1] + (tfm[3] * arrow[6] + tfm[2] * arrow[7]); - nk_fill_polygon(canvas, pbuf, 4, nk->table[NK_COLOR_DESIGN]); + nk_fill_polygon(out, pbuf, 4, nk->table[NK_COLOR_DESIGN]); } if (dtype == DRAWING_WITH_HALL) { @@ -1384,7 +1593,7 @@ pub_drawing_machine_position(struct public *pub, float fpos[2], int dtype) col = (N == hall) ? nk->table[NK_COLOR_ENABLED] : nk->table[NK_COLOR_HIDDEN]; - nk_fill_polygon(canvas, pbuf, 4, col); + nk_fill_polygon(out, pbuf, 4, col); } } @@ -1422,7 +1631,7 @@ pub_drawing_machine_position(struct public *pub, float fpos[2], int dtype) pbuf[8] = tfm[0] + (tfm[2] * arrow[8] - tfm[3] * arrow[9]); pbuf[9] = tfm[1] + (tfm[3] * arrow[8] + tfm[2] * arrow[9]); - nk_fill_polygon(canvas, pbuf, 5, nk->table[NK_COLOR_EDIT_NUMBER]); + nk_fill_polygon(out, pbuf, 5, nk->table[NK_COLOR_EDIT_NUMBER]); } static void @@ -2432,9 +2641,7 @@ page_serial(struct public *pub) if (lp->linked != 0) { - strcpy(pub->lbuf, fe->storage); - strcat(pub->lbuf, DIRSEP); - strcat(pub->lbuf, FILE_LINK_LOG); + config_storage_path(pub->fe, pub->lbuf, FILE_LINK_LOG); link_log_file_open(lp, pub->lbuf); @@ -2633,6 +2840,7 @@ page_diagnose(struct public *pub) struct nk_context *ctx = &nk->ctx; struct link_reg *reg; + struct nk_color warning; float maximal[4] = { 100.f, 100.f, 100.f, 35.f }; nk_menubar_begin(ctx); @@ -2681,8 +2889,8 @@ page_diagnose(struct public *pub) if (nk_menu_item_label(ctx, "RAM log flush", NK_TEXT_LEFT)) { - strcpy(pub->lbuf, pub->fe->storage); - strcat(pub->lbuf, DIRSEP FILE_DEBUG_LOG); + config_storage_path(pub->fe, pub->lbuf, FILE_DEBUG_LOG); + strcpy(pub->debug.file_snap, pub->lbuf); if (link_grab_file_open(lp, pub->debug.file_snap) != 0) { @@ -2759,6 +2967,20 @@ page_diagnose(struct public *pub) nk_layout_row_dynamic(ctx, 0, 1); nk_spacer(ctx); + reg = link_reg_lookup(lp, "pm.scale_iA1"); + + if (reg != NULL && reg->fval == 1.0f) { + + warning = nk->table[NK_COLOR_FLICKER_ALERT]; + + nk_label_colored(ctx, "NOTE: Select self-test and " + " self-adjustment from `Test` menu", + NK_TEXT_LEFT, warning); + + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); + } + reg_float(pub, "pm.const_fb_U", "DC link voltage"); reg_float(pub, "pm.scale_iA0", "A sensor drift"); reg_float(pub, "pm.scale_iB0", "B sensor drift"); @@ -3634,6 +3856,8 @@ page_in_stepdir(struct public *pub) struct nk_context *ctx = &nk->ctx; struct link_reg *reg; + struct nk_color warning; + reg = link_reg_lookup(lp, "ap.step_POS"); if (reg != NULL) { reg->update = 100; } @@ -3643,6 +3867,19 @@ page_in_stepdir(struct public *pub) nk_layout_row_dynamic(ctx, 0, 1); nk_spacer(ctx); + reg = link_reg_lookup(lp, "hal.STEP_mode"); + + if (reg != NULL && reg->lval == 0) { + + warning = nk->table[NK_COLOR_FLICKER_ALERT]; + + nk_label_colored(ctx, "NOTE: Select STEP mode `STEP_ON_STEP_DIR`" + " on `HAL` page", NK_TEXT_LEFT, warning); + + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); + } + reg_float_prog_um(pub, "ap.step_POS", "STEP position", 0.f, 0.f, 0); nk_layout_row_dynamic(ctx, 0, 1); @@ -3678,6 +3915,8 @@ page_in_pwm(struct public *pub) struct nk_context *ctx = &nk->ctx; struct link_reg *reg; + struct nk_color warning; + reg = link_reg_lookup(lp, "ap.ppm_PULSE"); if (reg != NULL) { reg->update = 100; } @@ -3690,6 +3929,19 @@ page_in_pwm(struct public *pub) nk_layout_row_dynamic(ctx, 0, 1); nk_spacer(ctx); + reg = link_reg_lookup(lp, "hal.PPM_mode"); + + if (reg != NULL && reg->lval != 1) { + + warning = nk->table[NK_COLOR_FLICKER_ALERT]; + + nk_label_colored(ctx, "NOTE: Select PPM mode `PPM_PULSE_WIDTH`" + " on `HAL` page", NK_TEXT_LEFT, warning); + + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); + } + reg_float_prog_um(pub, "ap.ppm_PULSE", "PWM pulse received", 0.f, 0.f, 0); reg_float_prog_um(pub, "ap.ppm_FREQ", "PWM frequency received", 0.f, 0.f, 0); @@ -3990,7 +4242,10 @@ page_config(struct public *pub) if (nk_menu_item_label(ctx, "Export configuration", NK_TEXT_LEFT)) { - /* TODO */ + pub->popup_enum = POPUP_CONFIG_EXPORT; + + strcpy(pub->config.file_grab, FILE_CONFIG_DEFAULT); + pub_directory_scan(pub, FILE_CONFIG_EXT); } if (nk_menu_item_label(ctx, "Default configuration", NK_TEXT_LEFT)) { @@ -4007,119 +4262,124 @@ page_config(struct public *pub) nk_style_pop_vec2(ctx); nk_menubar_end(ctx); - nk_layout_row_dynamic(ctx, 0, 1); - nk_spacer(ctx); + if (pub->popup_enum != POPUP_CONFIG_EXPORT) { - reg_float(pub, "pm.dc_resolution", "PWM resolution"); - reg_float(pub, "pm.dc_minimal", "Minimal pulse"); - reg_float(pub, "pm.dc_clearance", "Clearance before ADC sample"); - reg_float(pub, "pm.dc_skip", "Skip after ADC sample"); - reg_float(pub, "pm.dc_bootstrap", "Bootstrap retention time"); + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); - nk_layout_row_dynamic(ctx, 0, 1); - nk_spacer(ctx); + reg_float(pub, "pm.dc_resolution", "PWM resolution"); + reg_float(pub, "pm.dc_minimal", "Minimal pulse"); + reg_float(pub, "pm.dc_clearance", "Clearance before ADC sample"); + reg_float(pub, "pm.dc_skip", "Skip after ADC sample"); + reg_float(pub, "pm.dc_bootstrap", "Bootstrap retention time"); - reg_enum_combo(pub, "pm.config_NOP", "Number of machine phases", 0); - reg_enum_combo(pub, "pm.config_IFB", "Current measurement scheme", 0); - reg_enum_toggle(pub, "pm.config_TVM", "Terminal voltage measurement"); - reg_enum_toggle(pub, "pm.config_DBG", "DEBUG information gather"); + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); - nk_layout_row_dynamic(ctx, 0, 1); - nk_spacer(ctx); + reg_enum_combo(pub, "pm.config_NOP", "Number of machine phases", 0); + reg_enum_combo(pub, "pm.config_IFB", "Current measurement scheme", 0); + reg_enum_toggle(pub, "pm.config_TVM", "Terminal voltage measurement"); + reg_enum_toggle(pub, "pm.config_DBG", "DEBUG information gather"); - reg_enum_combo(pub, "pm.config_VSI_ZERO", "ZERO sequence modulation", 1); - reg_enum_toggle(pub, "pm.config_VSI_CLAMP", "Circular voltage clamping"); - reg_enum_toggle(pub, "pm.config_DCU_VOLTAGE", "DCU voltage compensation"); + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); - nk_layout_row_dynamic(ctx, 0, 1); - nk_spacer(ctx); + reg_enum_combo(pub, "pm.config_VSI_ZERO", "ZERO sequence modulation", 1); + reg_enum_toggle(pub, "pm.config_VSI_CLAMP", "Circular voltage clamping"); + reg_enum_toggle(pub, "pm.config_DCU_VOLTAGE", "DCU voltage compensation"); - reg_enum_toggle(pub, "pm.config_LU_FORCED", "FORCED control"); - reg_enum_toggle(pub, "pm.config_LU_FREEWHEEL", "Allow FREEWHEELING"); - reg_enum_combo(pub, "pm.config_LU_ESTIMATE", "SENSORLESS estimate", 1); - reg_enum_combo(pub, "pm.config_LU_SENSOR", "Position SENSOR type", 1); - reg_enum_combo(pub, "pm.config_LU_LOCATION", "Servo LOCATION source", 1); - reg_enum_combo(pub, "pm.config_LU_DRIVE", "DRIVE control loop", 0); + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); - reg_enum_combo(pub, "pm.config_HFI_WAVETYPE", "HFI waveform type", 1); - reg_enum_toggle(pub, "pm.config_HFI_PERMANENT", "HFI permanent injection"); + reg_enum_toggle(pub, "pm.config_LU_FORCED", "FORCED control"); + reg_enum_toggle(pub, "pm.config_LU_FREEWHEEL", "Allow FREEWHEELING"); + reg_enum_combo(pub, "pm.config_LU_ESTIMATE", "SENSORLESS estimate", 1); + reg_enum_combo(pub, "pm.config_LU_SENSOR", "Position SENSOR type", 1); + reg_enum_combo(pub, "pm.config_LU_LOCATION", "Servo LOCATION source", 1); + reg_enum_combo(pub, "pm.config_LU_DRIVE", "DRIVE control loop", 0); - reg_enum_combo(pub, "pm.config_EXCITATION", "Machine EXCITATION", 0); - reg_enum_combo(pub, "pm.config_SALIENCY", "Machine SALIENCY", 0); - reg_enum_toggle(pub, "pm.config_RELUCTANCE", "Reluctance MTPA control"); - reg_enum_toggle(pub, "pm.config_WEAKENING", "Flux WEAKENING control"); + reg_enum_combo(pub, "pm.config_HFI_WAVETYPE", "HFI waveform type", 1); + reg_enum_toggle(pub, "pm.config_HFI_PERMANENT", "HFI permanent injection"); - reg_enum_toggle(pub, "pm.config_CC_BRAKE_STOP", "CC brake (no reverse)"); - reg_enum_toggle(pub, "pm.config_CC_SPEED_TRACK", "CC speed tracking"); + reg_enum_combo(pub, "pm.config_EXCITATION", "Machine EXCITATION", 0); + reg_enum_combo(pub, "pm.config_SALIENCY", "Machine SALIENCY", 0); + reg_enum_toggle(pub, "pm.config_RELUCTANCE", "Reluctance MTPA control"); + reg_enum_toggle(pub, "pm.config_WEAKENING", "Flux WEAKENING control"); - reg_enum_combo(pub, "pm.config_EABI_FRONTEND", "EABI frontend", 0); - reg_enum_combo(pub, "pm.config_SINCOS_FRONTEND", "SINCOS frontend", 0); + reg_enum_toggle(pub, "pm.config_CC_BRAKE_STOP", "CC brake (no reverse)"); + reg_enum_toggle(pub, "pm.config_CC_SPEED_TRACK", "CC speed tracking"); - nk_layout_row_dynamic(ctx, 0, 1); - nk_spacer(ctx); + reg_enum_combo(pub, "pm.config_EABI_FRONTEND", "EABI frontend", 0); + reg_enum_combo(pub, "pm.config_SINCOS_FRONTEND", "SINCOS frontend", 0); - reg_float(pub, "pm.tm_transient_slow", "Transient time slow"); - reg_float(pub, "pm.tm_transient_fast", "Transient time fast"); - reg_float(pub, "pm.tm_voltage_hold", "Voltage hold time"); - reg_float(pub, "pm.tm_current_hold", "Current hold time"); - reg_float(pub, "pm.tm_current_ramp", "Current ramp time"); - reg_float(pub, "pm.tm_instant_probe", "Instant probe time"); - reg_float(pub, "pm.tm_average_probe", "Average probe time"); - reg_float(pub, "pm.tm_average_drift", "Average drift time"); - reg_float(pub, "pm.tm_average_inertia", "Average inertia time"); - reg_float(pub, "pm.tm_pause_startup", "Startup pause"); - reg_float(pub, "pm.tm_pause_forced", "FORCED pause"); - reg_float(pub, "pm.tm_pause_halt", "Halt pause"); + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); - nk_layout_row_dynamic(ctx, 0, 1); - nk_spacer(ctx); + reg_float(pub, "pm.tm_transient_slow", "Transient time slow"); + reg_float(pub, "pm.tm_transient_fast", "Transient time fast"); + reg_float(pub, "pm.tm_voltage_hold", "Voltage hold time"); + reg_float(pub, "pm.tm_current_hold", "Current hold time"); + reg_float(pub, "pm.tm_current_ramp", "Current ramp time"); + reg_float(pub, "pm.tm_instant_probe", "Instant probe time"); + reg_float(pub, "pm.tm_average_probe", "Average probe time"); + reg_float(pub, "pm.tm_average_drift", "Average drift time"); + reg_float(pub, "pm.tm_average_inertia", "Average inertia time"); + reg_float(pub, "pm.tm_pause_startup", "Startup pause"); + reg_float(pub, "pm.tm_pause_forced", "FORCED pause"); + reg_float(pub, "pm.tm_pause_halt", "Halt pause"); - reg_float(pub, "pm.probe_current_hold", "Probe hold current"); - reg_float(pub, "pm.probe_weak_level", "Probe weak level"); - reg_float(pub, "pm.probe_hold_angle", "Probe hold angle"); - reg_float(pub, "pm.probe_current_sine", "Probe sine current"); - reg_float(pub, "pm.probe_current_bias", "Probe bias current"); - reg_float(pub, "pm.probe_freq_sine", "Probe sine frequency"); - reg_float_um(pub, "pm.probe_speed_hold", "Probe hold speed", 1); - reg_float_um(pub, "pm.probe_speed_tol", "Settle speed tolerance", 1); - reg_float_um(pub, "pm.probe_location_tol", "Settle location tolerance", 0); - reg_float(pub, "pm.probe_loss_maximal", "Maximal heating LOSSES"); - reg_float(pub, "pm.probe_gain_P", "Probe loop GAIN P"); - reg_float(pub, "pm.probe_gain_I", "Probe loop GAIN I"); + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); - nk_layout_row_dynamic(ctx, 0, 1); - nk_spacer(ctx); + reg_float(pub, "pm.probe_current_hold", "Probe hold current"); + reg_float(pub, "pm.probe_weak_level", "Probe weak level"); + reg_float(pub, "pm.probe_hold_angle", "Probe hold angle"); + reg_float(pub, "pm.probe_current_sine", "Probe sine current"); + reg_float(pub, "pm.probe_current_bias", "Probe bias current"); + reg_float(pub, "pm.probe_freq_sine", "Probe sine frequency"); + reg_float_um(pub, "pm.probe_speed_hold", "Probe hold speed", 1); + reg_float_um(pub, "pm.probe_speed_tol", "Settle speed tolerance", 1); + reg_float_um(pub, "pm.probe_location_tol", "Settle location tolerance", 0); + reg_float(pub, "pm.probe_loss_maximal", "Maximal heating LOSSES"); + reg_float(pub, "pm.probe_gain_P", "Probe loop GAIN P"); + reg_float(pub, "pm.probe_gain_I", "Probe loop GAIN I"); - reg_float(pub, "pm.fault_voltage_tol", "Voltage fault tolerance"); - reg_float(pub, "pm.fault_current_tol", "Current fault tolerance"); - reg_float(pub, "pm.fault_accuracy_tol", "Accuracy fault tolerance"); - reg_float(pub, "pm.fault_terminal_tol", "Terminal fault tolerance"); - reg_float(pub, "pm.fault_current_halt", "Current halt threshold"); - reg_float(pub, "pm.fault_voltage_halt", "Voltage halt threshold"); + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); - nk_layout_row_dynamic(ctx, 0, 1); - nk_spacer(ctx); + reg_float(pub, "pm.fault_voltage_tol", "Voltage fault tolerance"); + reg_float(pub, "pm.fault_current_tol", "Current fault tolerance"); + reg_float(pub, "pm.fault_accuracy_tol", "Accuracy fault tolerance"); + reg_float(pub, "pm.fault_terminal_tol", "Terminal fault tolerance"); + reg_float(pub, "pm.fault_current_halt", "Current halt threshold"); + reg_float(pub, "pm.fault_voltage_halt", "Voltage halt threshold"); + + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); - reg_float(pub, "pm.vsi_gain_LP", "VSI gain LP"); + reg_float(pub, "pm.vsi_gain_LP", "VSI gain LP"); - nk_layout_row_dynamic(ctx, 0, 1); - nk_spacer(ctx); + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); - reg_float(pub, "pm.dcu_deadband", "DCU deadband time"); - reg_float(pub, "pm.dcu_tol", "DCU tolerance"); + reg_float(pub, "pm.dcu_deadband", "DCU deadband time"); + reg_float(pub, "pm.dcu_tol", "DCU tolerance"); - nk_layout_row_dynamic(ctx, 0, 1); - nk_spacer(ctx); + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); - reg_float(pub, "pm.lu_transient", "LU transient rate"); - reg_float(pub, "pm.lu_gain_mq_LP", "LU load torque GAIN LP"); + reg_float(pub, "pm.lu_transient", "LU transient rate"); + reg_float(pub, "pm.lu_gain_mq_LP", "LU load torque GAIN LP"); - nk_layout_row_dynamic(ctx, 0, 1); - nk_spacer(ctx); + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); + } + + pub_popup_config_export(pub, POPUP_CONFIG_EXPORT); if (pub_popup_ok_cancel(pub, POPUP_RESET_DEFAULT, "Please confirm that you really" - " want to reset all PMC configuration.") != 0) { + " want to reset all of PMC configuration.") != 0) { link_command(lp, "pm_default_config"); link_reg_fetch_all_shown(lp); @@ -4350,6 +4610,7 @@ page_lu_hfi(struct public *pub) struct nk_context *ctx = &nk->ctx; struct link_reg *reg; + struct nk_color warning; int m_drawing = pub->fe_def_size_x / 4; nk_layout_row_dynamic(ctx, 0, 1); @@ -4360,6 +4621,26 @@ page_lu_hfi(struct public *pub) nk_layout_row_dynamic(ctx, 0, 1); nk_spacer(ctx); + reg = link_reg_lookup(lp, "pm.config_LU_ESTIMATE"); + + if (reg != NULL && reg->lval != 2) { + + warning = nk->table[NK_COLOR_FLICKER_ALERT]; + + nk_label_colored(ctx, "NOTE: Select sensorless estimate" + " `PM_FLUX_KALMAN` on `Config` page", + NK_TEXT_LEFT, warning); + + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); + } + + reg_enum_combo(pub, "pm.config_HFI_WAVETYPE", "HFI waveform type", 1); + reg_enum_toggle(pub, "pm.config_HFI_PERMANENT", "HFI permanent injection"); + + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); + reg_float(pub, "pm.hfi_freq", "HF injection frequency"); reg_float(pub, "pm.hfi_sine", "HF injection current"); @@ -4437,6 +4718,7 @@ page_lu_hall(struct public *pub) struct nk_context *ctx = &nk->ctx; struct link_reg *reg; + struct nk_color warning; int m_drawing = pub->fe_def_size_x / 4; nk_menubar_begin(ctx); @@ -4473,6 +4755,19 @@ page_lu_hall(struct public *pub) nk_layout_row_dynamic(ctx, 0, 1); nk_spacer(ctx); + reg = link_reg_lookup(lp, "hal.DPS_mode"); + + if (reg != NULL && reg->lval != 1) { + + warning = nk->table[NK_COLOR_FLICKER_ALERT]; + + nk_label_colored(ctx, "NOTE: Select DPS mode `DPS_DRIVE_HALL`" + " on `HAL` page", NK_TEXT_LEFT, warning); + + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); + } + reg_float(pub, "pm.hall_ST1", "HALL ST 1"); reg_float(pub, "pm.hall_ST2", "HALL ST 2"); reg_float(pub, "pm.hall_ST3", "HALL ST 3"); @@ -4588,6 +4883,7 @@ page_lu_eabi(struct public *pub) struct nk_context *ctx = &nk->ctx; struct link_reg *reg; + struct nk_color warning; int m_drawing = pub->fe_def_size_x / 4; nk_menubar_begin(ctx); @@ -4633,6 +4929,19 @@ page_lu_eabi(struct public *pub) nk_layout_row_dynamic(ctx, 0, 1); nk_spacer(ctx); + reg = link_reg_lookup(lp, "hal.DPS_mode"); + + if (reg != NULL && reg->lval != 2) { + + warning = nk->table[NK_COLOR_FLICKER_ALERT]; + + nk_label_colored(ctx, "NOTE: Select DPS mode `DPS_DRIVE_EABI`" + " on `HAL` page", NK_TEXT_LEFT, warning); + + nk_layout_row_dynamic(ctx, 0, 1); + nk_spacer(ctx); + } + reg_float(pub, "pm.eabi_F0", "EABI adjustment position"); reg_float(pub, "pm.eabi_const_EP", "EABI pulse resolution"); reg_float(pub, "pm.eabi_const_Zs", "Gear teeth number S"); @@ -5542,23 +5851,23 @@ menu_group_layout(struct public *pub) menu_select_button(pub, "Diagnose", &page_diagnose); menu_select_button(pub, "Probe", &page_probe); menu_select_button(pub, "HAL", &page_hal); - menu_select_button(pub, "in Network", &page_in_network); - menu_select_button(pub, "in STEP/DIR", &page_in_stepdir); - menu_select_button(pub, "in PWM", &page_in_pwm); - menu_select_button(pub, "in Knob", &page_in_knob); + menu_select_button(pub, "IN Network", &page_in_network); + menu_select_button(pub, "IN STEP/DIR", &page_in_stepdir); + menu_select_button(pub, "IN PWM", &page_in_pwm); + menu_select_button(pub, "IN Knob", &page_in_knob); menu_select_button(pub, "Application", &page_application); menu_select_button(pub, "Thermal", &page_thermal); menu_select_button(pub, "Config", &page_config); - menu_select_button(pub, "lu Forced", &page_lu_forced); - menu_select_button(pub, "lu FLUX", &page_lu_flux); - menu_select_button(pub, "lu HFI", &page_lu_hfi); - menu_select_button(pub, "lu Hall", &page_lu_hall); - menu_select_button(pub, "lu EABI", &page_lu_eabi); - menu_select_button(pub, "lu SIN/COS", &page_lu_sincos); + menu_select_button(pub, "LU Forced", &page_lu_forced); + menu_select_button(pub, "LU FLUX", &page_lu_flux); + menu_select_button(pub, "LU HFI", &page_lu_hfi); + menu_select_button(pub, "LU Hall", &page_lu_hall); + menu_select_button(pub, "LU EABI", &page_lu_eabi); + menu_select_button(pub, "LU SIN/COS", &page_lu_sincos); menu_select_button(pub, "Wattage", &page_wattage); - menu_select_button(pub, "lp Current", &page_lp_current); - menu_select_button(pub, "lp Speed", &page_lp_speed); - menu_select_button(pub, "lp Location", &page_lp_location); + menu_select_button(pub, "LP Current", &page_lp_current); + menu_select_button(pub, "LP Speed", &page_lp_speed); + menu_select_button(pub, "LP Location", &page_lp_location); menu_select_button(pub, "Telemetry", &page_telemetry); menu_select_button(pub, "Flash", &page_flash); menu_select_button(pub, "Upgrade", &page_upgrade); @@ -5758,9 +6067,31 @@ int main(int argc, char **argv) if (nk_begin(&nk->ctx, pub->lbuf, bounds, NK_WINDOW_TITLE | NK_WINDOW_NO_SCROLLBAR)) { + struct nk_command_buffer *out; + struct nk_panel *panel; + + out = nk_window_get_canvas(&nk->ctx); + panel = nk_window_get_panel(&nk->ctx); + menu_group_layout(pub); nk_end(&nk->ctx); + + if (lp->linked != 0 && lp->locked + 50 > lp->clock) { + + struct nk_rect busy; + struct nk_color led; + + busy.w = pub->fe_font_h; + busy.h = pub->fe_font_h; + + busy.x = nk->surface->w - busy.w * 1.5f; + busy.y = (panel->header_height - busy.h) * 0.5f; + + led = nk->table[NK_COLOR_TEXT]; + + nk_fill_rect(out, busy, 1, led); + } } nk_sdl_render(nk); diff --git a/src/hal/hal.h b/src/hal/hal.h index 19f4a16..feddec0 100644 --- a/src/hal/hal.h +++ b/src/hal/hal.h @@ -158,10 +158,10 @@ typedef struct { DRV_config_t DRV; #endif /* HW_HAVE_DRV_ON_PCB */ -#ifdef HW_HAVE_ADC_FILTER +#ifdef HW_HAVE_OPT_FILTER int OPT_filter_current; int OPT_filter_voltage; -#endif /* HW_HAVE_ADC_FILTER */ +#endif /* HW_HAVE_OPT_FILTER */ uint32_t CNT_raw[4]; float CNT_diag[3]; diff --git a/src/hal/hw/FSESC_67.h b/src/hal/hw/FSESC_67.h index 0685725..49fbcf8 100644 --- a/src/hal/hw/FSESC_67.h +++ b/src/hal/hw/FSESC_67.h @@ -40,7 +40,7 @@ #define HW_ADC_KNOB_R1 0.f /* have no */ #define HW_ADC_KNOB_R2 10000.f -#define HW_NTC_PCB_TYPE NTC_VCC +#define HW_NTC_PCB_TYPE NTC_ON_VCC #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/FSESC_67_mini.h b/src/hal/hw/FSESC_67_mini.h index 79e3aab..4b156d3 100644 --- a/src/hal/hw/FSESC_67_mini.h +++ b/src/hal/hw/FSESC_67_mini.h @@ -41,7 +41,7 @@ #define HW_ADC_KNOB_R1 0.f /* have no */ #define HW_ADC_KNOB_R2 10000.f -#define HW_NTC_PCB_TYPE NTC_VCC +#define HW_NTC_PCB_TYPE NTC_ON_VCC #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/FSESC_75100_v2.h b/src/hal/hw/FSESC_75100_v2.h index 9df3c8f..3fecf42 100644 --- a/src/hal/hw/FSESC_75100_v2.h +++ b/src/hal/hw/FSESC_75100_v2.h @@ -34,7 +34,7 @@ #define HW_ADC_KNOB_R1 0.f /* have no */ #define HW_ADC_KNOB_R2 10000.f -#define HW_NTC_PCB_TYPE NTC_VCC +#define HW_NTC_PCB_TYPE NTC_ON_VCC #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/HBRO_foc_mini.h b/src/hal/hw/HBRO_foc_mini.h index 7da50d8..0b1cd1b 100644 --- a/src/hal/hw/HBRO_foc_mini.h +++ b/src/hal/hw/HBRO_foc_mini.h @@ -32,7 +32,7 @@ #define HW_ADC_KNOB_R1 0.f /* have no */ #define HW_ADC_KNOB_R2 10000.f -#define HW_NTC_PCB_TYPE NTC_VCC +#define HW_NTC_PCB_TYPE NTC_ON_VCC #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/KLEN_r1.h b/src/hal/hw/KLEN_r1.h index d1ddfa6..ce12455 100644 --- a/src/hal/hw/KLEN_r1.h +++ b/src/hal/hw/KLEN_r1.h @@ -23,7 +23,7 @@ #define HW_ADC_VOLTAGE_R1 47000.f #define HW_ADC_VOLTAGE_R2 2200.f -#define HW_NTC_PCB_TYPE NTC_GND +#define HW_NTC_PCB_TYPE NTC_ON_GND #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/MKESC_60100_v2.h b/src/hal/hw/MKESC_60100_v2.h index a95478b..774268f 100644 --- a/src/hal/hw/MKESC_60100_v2.h +++ b/src/hal/hw/MKESC_60100_v2.h @@ -40,7 +40,7 @@ #define HW_ADC_KNOB_R1 0.f /* have no */ #define HW_ADC_KNOB_R2 10000.f -#define HW_NTC_PCB_TYPE NTC_VCC +#define HW_NTC_PCB_TYPE NTC_ON_VCC #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/MKESC_84200.h b/src/hal/hw/MKESC_84200.h index 774af8c..2dc00bc 100644 --- a/src/hal/hw/MKESC_84200.h +++ b/src/hal/hw/MKESC_84200.h @@ -10,7 +10,7 @@ #define HW_HAVE_NTC_MACHINE #define HW_HAVE_USB_CDC_ACM #define HW_HAVE_NETWORK_EPCAN -#define HW_HAVE_ADC_FILTER +#define HW_HAVE_OPT_FILTER #define HW_CLOCK_CRYSTAL_HZ 8000000U @@ -34,7 +34,7 @@ #define HW_ADC_KNOB_R1 0.f /* have no */ #define HW_ADC_KNOB_R2 10000.f -#define HW_NTC_PCB_TYPE NTC_VCC +#define HW_NTC_PCB_TYPE NTC_ON_VCC #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/PHOBIA_rev2.h b/src/hal/hw/PHOBIA_rev2.h index a47a2fe..87bb183 100644 --- a/src/hal/hw/PHOBIA_rev2.h +++ b/src/hal/hw/PHOBIA_rev2.h @@ -23,7 +23,7 @@ #define HW_ADC_VOLTAGE_R1 470000.f #define HW_ADC_VOLTAGE_R2 27000.f -#define HW_NTC_PCB_TYPE NTC_GND +#define HW_NTC_PCB_TYPE NTC_ON_GND #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/PHOBIA_rev3.h b/src/hal/hw/PHOBIA_rev3.h index fca67d2..69c2cb6 100644 --- a/src/hal/hw/PHOBIA_rev3.h +++ b/src/hal/hw/PHOBIA_rev3.h @@ -27,7 +27,7 @@ #define HW_ADC_KNOB_R1 10000.f #define HW_ADC_KNOB_R2 10000.f -#define HW_NTC_PCB_TYPE NTC_GND +#define HW_NTC_PCB_TYPE NTC_ON_GND #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/PHOBIA_rev4b.h b/src/hal/hw/PHOBIA_rev4b.h index 9885fc3..73c76f2 100644 --- a/src/hal/hw/PHOBIA_rev4b.h +++ b/src/hal/hw/PHOBIA_rev4b.h @@ -24,7 +24,7 @@ #define HW_ADC_VOLTAGE_R1 470000.f #define HW_ADC_VOLTAGE_R2 27000.f -#define HW_NTC_PCB_TYPE NTC_GND +#define HW_NTC_PCB_TYPE NTC_ON_GND #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/PHOBIA_rev4c.h b/src/hal/hw/PHOBIA_rev4c.h index 8028c5a..fbd26a5 100644 --- a/src/hal/hw/PHOBIA_rev4c.h +++ b/src/hal/hw/PHOBIA_rev4c.h @@ -30,7 +30,7 @@ #define HW_ADC_KNOB_R1 10000.f #define HW_ADC_KNOB_R2 10000.f -#define HW_NTC_PCB_TYPE NTC_GND +#define HW_NTC_PCB_TYPE NTC_ON_GND #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/PHOBIA_rev5.h b/src/hal/hw/PHOBIA_rev5.h index 2488660..0f289d8 100644 --- a/src/hal/hw/PHOBIA_rev5.h +++ b/src/hal/hw/PHOBIA_rev5.h @@ -30,7 +30,7 @@ #define HW_ADC_KNOB_R1 10000.f #define HW_ADC_KNOB_R2 10000.f -#define HW_NTC_PCB_TYPE NTC_GND +#define HW_NTC_PCB_TYPE NTC_ON_GND #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/RIO_r1.h b/src/hal/hw/RIO_r1.h index a527429..e156934 100644 --- a/src/hal/hw/RIO_r1.h +++ b/src/hal/hw/RIO_r1.h @@ -25,7 +25,7 @@ #define HW_ADC_VOLTAGE_R1 47000.f #define HW_ADC_VOLTAGE_R2 4700.f -#define HW_NTC_PCB_TYPE NTC_VCC +#define HW_NTC_PCB_TYPE NTC_ON_VCC #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/VESC_60_mk6.h b/src/hal/hw/VESC_60_mk6.h index 1f089d3..d269deb 100644 --- a/src/hal/hw/VESC_60_mk6.h +++ b/src/hal/hw/VESC_60_mk6.h @@ -11,7 +11,7 @@ #define HW_HAVE_NTC_MACHINE #define HW_HAVE_USB_CDC_ACM #define HW_HAVE_NETWORK_EPCAN -#define HW_HAVE_ADC_FILTER +#define HW_HAVE_OPT_FILTER #define HW_CLOCK_CRYSTAL_HZ 8000000U @@ -41,7 +41,7 @@ #define HW_ADC_KNOB_R1 0.f /* have no */ #define HW_ADC_KNOB_R2 10000.f -#define HW_NTC_PCB_TYPE NTC_VCC +#define HW_NTC_PCB_TYPE NTC_ON_VCC #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/VESC_75_300_r3.h b/src/hal/hw/VESC_75_300_r3.h index 0416bd7..d55b117 100644 --- a/src/hal/hw/VESC_75_300_r3.h +++ b/src/hal/hw/VESC_75_300_r3.h @@ -10,7 +10,7 @@ #define HW_HAVE_NTC_MACHINE #define HW_HAVE_USB_CDC_ACM #define HW_HAVE_NETWORK_EPCAN -#define HW_HAVE_ADC_FILTER +#define HW_HAVE_OPT_FILTER #define HW_CLOCK_CRYSTAL_HZ 8000000U @@ -34,7 +34,7 @@ #define HW_ADC_KNOB_R1 0.f /* have no */ #define HW_ADC_KNOB_R2 10000.f -#define HW_NTC_PCB_TYPE NTC_VCC +#define HW_NTC_PCB_TYPE NTC_ON_VCC #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/hal/hw/ZAEV_r3.h b/src/hal/hw/ZAEV_r3.h index 757842d..cb4ebc8 100644 --- a/src/hal/hw/ZAEV_r3.h +++ b/src/hal/hw/ZAEV_r3.h @@ -28,7 +28,7 @@ #define HW_ADC_KNOB_R1 10000.f #define HW_ADC_KNOB_R2 10000.f -#define HW_NTC_PCB_TYPE NTC_GND +#define HW_NTC_PCB_TYPE NTC_ON_GND #define HW_NTC_PCB_BALANCE 10000.f #define HW_NTC_PCB_NTC0 10000.f #define HW_NTC_PCB_TA0 25.f diff --git a/src/main.c b/src/main.c index ff0ce37..afee562 100644 --- a/src/main.c +++ b/src/main.c @@ -168,13 +168,14 @@ LD_TASK void task_TEMP(void *pData) GPIO_set_mode_ANALOG(ap.ntc_EXT.gpio); } +#ifdef HW_HAVE_OPT_FILTER #ifdef GPIO_FILTER_CURRENT GPIO_set_mode_OUTPUT(GPIO_FILTER_CURRENT); #endif /* GPIO_FILTER_CURRENT */ - #ifdef GPIO_FILTER_VOLTAGE GPIO_set_mode_OUTPUT(GPIO_FILTER_VOLTAGE); #endif /* GPIO_FILTER_VOLTAGE */ +#endif /* HW_HAVE_OPT_FILTER */ xWake = xTaskGetTickCount(); @@ -296,6 +297,7 @@ LD_TASK void task_TEMP(void *pData) } #endif /* HW_HAVE_DRV_ON_PCB */ +#ifdef HW_HAVE_OPT_FILTER #ifdef GPIO_FILTER_CURRENT if (hal.OPT_filter_current == PM_ENABLED) { @@ -305,7 +307,6 @@ LD_TASK void task_TEMP(void *pData) GPIO_set_LOW(GPIO_FILTER_CURRENT); } #endif /* GPIO_FILTER_CURRENT */ - #ifdef GPIO_FILTER_VOLTAGE if (hal.OPT_filter_voltage == PM_ENABLED) { @@ -315,6 +316,7 @@ LD_TASK void task_TEMP(void *pData) GPIO_set_LOW(GPIO_FILTER_VOLTAGE); } #endif /* GPIO_FILTER_VOLTAGE */ +#endif /* HW_HAVE_OPT_FILTER */ #ifdef GPIO_LED_MODE if (pm.lu_MODE != PM_LU_DISABLED) { @@ -593,10 +595,10 @@ default_flash_load() hal.DRV.ocp_level = HW_DRV_OCP_LEVEL; #endif /* HW_HAVE_DRV_ON_PCB */ -#ifdef HW_HAVE_ADC_FILTER +#ifdef HW_HAVE_OPT_FILTER hal.OPT_filter_current = PM_DISABLED; hal.OPT_filter_voltage = PM_DISABLED; -#endif /* HW_HAVE_ADC_FILTER */ +#endif /* HW_HAVE_OPT_FILTER */ #ifdef HW_HAVE_NETWORK_EPCAN net.node_ID = 0; @@ -672,7 +674,7 @@ default_flash_load() #endif /* HW_HAVE_NTC_ON_PCB */ #ifdef HW_HAVE_NTC_MACHINE - ap.ntc_EXT.type = NTC_GND; + ap.ntc_EXT.type = NTC_ON_GND; ap.ntc_EXT.gpio = GPIO_ADC_NTC_EXT; ap.ntc_EXT.balance = HW_NTC_EXT_BALANCE; ap.ntc_EXT.ntc0 = 10000.f; diff --git a/src/ntc.c b/src/ntc.c index c5b6063..75fbd50 100644 --- a/src/ntc.c +++ b/src/ntc.c @@ -13,7 +13,7 @@ float ntc_read_temperature(ntc_t *ntc) switch (ntc->type) { - case NTC_GND: + case NTC_ON_GND: ohm = um * ntc->balance / (1.f - um); @@ -21,7 +21,7 @@ float ntc_read_temperature(ntc_t *ntc) + m_logf(ohm / ntc->ntc0)) - 273.f; break; - case NTC_VCC: + case NTC_ON_VCC: ohm = (1.f - um) * ntc->balance / um; @@ -42,7 +42,7 @@ float ntc_read_temperature(ntc_t *ntc) ohm = um * ntc->balance / (1.f - um); - ohm = (ohm < 480.f) ? 480.f + ohm = (ohm < 480.f) ? 480.f : (ohm > 2647.f) ? 2647.f : ohm; temp = 1.0572638E-8f; @@ -55,7 +55,7 @@ float ntc_read_temperature(ntc_t *ntc) ohm = um * ntc->balance / (1.f - um); - ohm = (ohm < 332.f) ? 332.f + ohm = (ohm < 332.f) ? 332.f : (ohm > 2791.f) ? 2791.f : ohm; temp = 1.7536720E-8f; diff --git a/src/ntc.h b/src/ntc.h index a1314fe..9a0ed16 100644 --- a/src/ntc.h +++ b/src/ntc.h @@ -28,8 +28,8 @@ enum { NTC_NONE = 0, - NTC_GND, - NTC_VCC, + NTC_ON_GND, + NTC_ON_VCC, NTC_LMT87, NTC_KTY83_GND, diff --git a/src/phobia/pm.c b/src/phobia/pm.c index daa3502..cecd5b4 100644 --- a/src/phobia/pm.c +++ b/src/phobia/pm.c @@ -373,6 +373,29 @@ pm_auto_maximal_current(pmc_t *pm) pm->i_maximal = (float) (int) maximal_A; pm->i_reverse = pm->i_maximal; } + + /* Hold current based on maximal machine current. + * */ + maximal_A = pm->i_maximal * 0.8f; + + if (pm->probe_current_hold > maximal_A) { + + pm->probe_current_hold = maximal_A; + } + + if (pm->forced_hold_D > maximal_A) { + + pm->forced_hold_D = maximal_A; + } + + /* Sine current based on maximal machine current. + * */ + maximal_A = pm->i_maximal * 0.2f; + + if (pm->probe_current_sine > maximal_A) { + + pm->probe_current_sine = maximal_A; + } } static void diff --git a/src/phobia/pm.h b/src/phobia/pm.h index 1328ad9..d501f60 100644 --- a/src/phobia/pm.h +++ b/src/phobia/pm.h @@ -167,7 +167,9 @@ enum { PM_ERROR_NO_MOTOR_CONNECTED, PM_ERROR_BOOTSTRAP_FAULT, PM_ERROR_POWER_STAGE_BROKEN, - PM_ERROR_LOW_ACCURACY, + PM_ERROR_LOW_CURRENT_ACCURACY, + PM_ERROR_LOW_VOLTAGE_ACCURACY, + PM_ERROR_LOW_DEADBAND_ACCURACY, PM_ERROR_CURRENT_LOOP_FAULT, PM_ERROR_INSTANT_OVERCURRENT, PM_ERROR_DC_LINK_OVERVOLTAGE, diff --git a/src/phobia/pm_fsm.c b/src/phobia/pm_fsm.c index 8b6ee60..a5891cb 100644 --- a/src/phobia/pm_fsm.c +++ b/src/phobia/pm_fsm.c @@ -79,7 +79,7 @@ pm_fsm_state_zero_drift(pmc_t *pm) || pm->self_STDi[1] > pm->fault_current_tol || pm->self_STDi[2] > pm->fault_current_tol) { - pm->fsm_errno = PM_ERROR_LOW_ACCURACY; + pm->fsm_errno = PM_ERROR_LOW_CURRENT_ACCURACY; } } else { @@ -525,14 +525,14 @@ pm_fsm_state_self_test_clearance(pmc_t *pm) || pm->self_RMSi[1] > pm->fault_current_tol || pm->self_RMSi[2] > pm->fault_current_tol) { - pm->fsm_errno = PM_ERROR_LOW_ACCURACY; + pm->fsm_errno = PM_ERROR_LOW_CURRENT_ACCURACY; } else if ( pm->self_RMSu > pm->fault_voltage_tol || pm->self_RMSt[0] > pm->fault_voltage_tol || pm->self_RMSt[1] > pm->fault_voltage_tol || pm->self_RMSt[2] > pm->fault_voltage_tol) { - pm->fsm_errno = PM_ERROR_LOW_ACCURACY; + pm->fsm_errno = PM_ERROR_LOW_VOLTAGE_ACCURACY; } } else { @@ -658,7 +658,7 @@ pm_fsm_state_adjust_on_pcb_voltage(pmc_t *pm) || m_fabsf(ls->sol.m[2]) > pm->fault_voltage_tol || m_fabsf(ls->sol.m[4]) > pm->fault_voltage_tol) { - pm->fsm_errno = PM_ERROR_LOW_ACCURACY; + pm->fsm_errno = PM_ERROR_LOW_VOLTAGE_ACCURACY; pm->fsm_state = PM_STATE_HALT; pm->fsm_phase = 0; break; @@ -668,7 +668,7 @@ pm_fsm_state_adjust_on_pcb_voltage(pmc_t *pm) || m_fabsf(ls->sol.m[3] - 1.f) > pm->fault_accuracy_tol || m_fabsf(ls->sol.m[5] - 1.f) > pm->fault_accuracy_tol) { - pm->fsm_errno = PM_ERROR_LOW_ACCURACY; + pm->fsm_errno = PM_ERROR_LOW_VOLTAGE_ACCURACY; pm->fsm_state = PM_STATE_HALT; pm->fsm_phase = 0; break; @@ -965,7 +965,7 @@ pm_fsm_state_adjust_on_pcb_current(pmc_t *pm) || m_fabsf(pm->scale_iB[1] - 1.f) > pm->fault_accuracy_tol || m_fabsf(pm->scale_iC[1] - 1.f) > pm->fault_accuracy_tol) { - pm->fsm_errno = PM_ERROR_LOW_ACCURACY; + pm->fsm_errno = PM_ERROR_LOW_CURRENT_ACCURACY; } pm->fsm_state = PM_STATE_HALT; @@ -1302,10 +1302,19 @@ pm_fsm_state_adjust_dcu_voltage(pmc_t *pm) break; } - if ( m_isfinitef(ls->sol.m[3]) != 0 - && ls->sol.m[3] > M_EPSILON) { + lse_std(ls); - pm->dcu_deadband = ls->sol.m[3]; + pm->self_DTu = ls->std.m[0]; + + if (m_isfinitef(pm->self_DTu) != 0) { + + if (pm->self_DTu > pm->fault_terminal_tol) { + + pm->fsm_errno = PM_ERROR_LOW_DEADBAND_ACCURACY; + pm->fsm_state = PM_STATE_HALT; + pm->fsm_phase = 0; + break; + } } else { pm->fsm_errno = PM_ERROR_UNCERTAIN_RESULT; @@ -1314,16 +1323,10 @@ pm_fsm_state_adjust_dcu_voltage(pmc_t *pm) break; } - lse_std(ls); - - pm->self_DTu = ls->std.m[0]; - - if (m_isfinitef(pm->self_DTu) != 0) { - - if (pm->self_DTu > pm->fault_terminal_tol) { + if ( m_isfinitef(ls->sol.m[3]) != 0 + && ls->sol.m[3] > M_EPSILON) { - pm->fsm_errno = PM_ERROR_LOW_ACCURACY; - } + pm->dcu_deadband = ls->sol.m[3]; } else { pm->fsm_errno = PM_ERROR_UNCERTAIN_RESULT; @@ -2549,7 +2552,9 @@ const char *pm_strerror(int fsm_errno) PM_SFI_CASE(PM_ERROR_NO_MOTOR_CONNECTED); PM_SFI_CASE(PM_ERROR_BOOTSTRAP_FAULT); PM_SFI_CASE(PM_ERROR_POWER_STAGE_BROKEN); - PM_SFI_CASE(PM_ERROR_LOW_ACCURACY); + PM_SFI_CASE(PM_ERROR_LOW_CURRENT_ACCURACY); + PM_SFI_CASE(PM_ERROR_LOW_VOLTAGE_ACCURACY); + PM_SFI_CASE(PM_ERROR_LOW_DEADBAND_ACCURACY); PM_SFI_CASE(PM_ERROR_CURRENT_LOOP_FAULT); PM_SFI_CASE(PM_ERROR_INSTANT_OVERCURRENT); PM_SFI_CASE(PM_ERROR_DC_LINK_OVERVOLTAGE); diff --git a/src/regdefs.h b/src/regdefs.h index 6fc4b3f..c437e66 100644 --- a/src/regdefs.h +++ b/src/regdefs.h @@ -32,10 +32,10 @@ ID_HAL_DRV_STATUS_RAW, ID_HAL_DRV_GATE_CURRENT, ID_HAL_DRV_OCP_LEVEL, #endif /* HW_HAVE_DRV_ON_PCB */ -#ifdef HW_HAVE_ADC_FILTER +#ifdef HW_HAVE_OPT_FILTER ID_HAL_OPT_FILTER_CURRENT, ID_HAL_OPT_FILTER_VOLTAGE, -#endif /* HW_HAVE_ADC_FILTER */ +#endif /* HW_HAVE_OPT_FILTER */ ID_HAL_CNT_DIAG0, ID_HAL_CNT_DIAG0_PC, ID_HAL_CNT_DIAG1, diff --git a/src/regfile.c b/src/regfile.c index 4efa100..8d4a39e 100644 --- a/src/regfile.c +++ b/src/regfile.c @@ -1203,7 +1203,7 @@ reg_format_enumerate(const reg_t *reg, const rval_t *rval) break; #endif /* HW_HAVE_DRV_ON_PCB */ -#ifdef HW_HAVE_ADC_FILTER +#ifdef HW_HAVE_OPT_FILTER case ID_HAL_OPT_FILTER_CURRENT: case ID_HAL_OPT_FILTER_VOLTAGE: @@ -1215,7 +1215,7 @@ reg_format_enumerate(const reg_t *reg, const rval_t *rval) default: break; } break; -#endif /* HW_HAVE_ADC_FILTER */ +#endif /* HW_HAVE_OPT_FILTER */ #ifdef HW_HAVE_NETWORK_EPCAN case ID_NET_LOG_MODE: @@ -1305,8 +1305,8 @@ reg_format_enumerate(const reg_t *reg, const rval_t *rval) switch (val) { PM_SFI_CASE(NTC_NONE); - PM_SFI_CASE(NTC_GND); - PM_SFI_CASE(NTC_VCC); + PM_SFI_CASE(NTC_ON_GND); + PM_SFI_CASE(NTC_ON_VCC); PM_SFI_CASE(NTC_LMT87); PM_SFI_CASE(NTC_KTY83_GND); PM_SFI_CASE(NTC_KTY84_GND); @@ -1623,10 +1623,10 @@ const reg_t regfile[] = { REG_DEF(hal.DRV.ocp_level,,, "", "%0i", REG_CONFIG, ®_proc_DRV_configure, ®_format_DRV_ocp_level), #endif /* HW_HAVE_DRV_ON_PCB */ -#ifdef HW_HAVE_ADC_FILTER +#ifdef HW_HAVE_OPT_FILTER REG_DEF(hal.OPT_filter_current,,, "", "%0i", REG_CONFIG, NULL, ®_format_enum), REG_DEF(hal.OPT_filter_voltage,,, "", "%0i", REG_CONFIG, NULL, ®_format_enum), -#endif /* HW_HAVE_ADC_FILTER */ +#endif /* HW_HAVE_OPT_FILTER */ REG_DEF(hal.CNT_diag, 0, [0], "us", "%2f", REG_READ_ONLY, ®_proc_CNT_diag_us, NULL), REG_DEF(hal.CNT_diag, 0_pc, [0], "%", "%1f", REG_READ_ONLY, ®_proc_CNT_diag_pc, NULL),