Skip to content

Commit

Permalink
Some fixes in register enumeration.
Browse files Browse the repository at this point in the history
  • Loading branch information
rombrew committed Sep 17, 2024
1 parent 79e35b6 commit f1bc5c4
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 127 deletions.
4 changes: 2 additions & 2 deletions bench/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ tlm_plot_grab()
sym_GP(atan2(pm.flux_F[1], pm.flux_F[0]) * kDEG, "pm.flux_F", "deg");
fmk_GP(pm.flux_wS, kRPM, "rpm");

fmt_GP(pm.kalman_E[0], "A");
fmt_GP(pm.kalman_E[1], "A");
fmt_GP(pm.kalman_rsu[0], "A");
fmt_GP(pm.kalman_rsu[1], "A");
fmt_GP(pm.kalman_bias_Q, "V");
fmk_GP(pm.kalman_lpf_wS, kRPM, "rpm");

Expand Down
14 changes: 12 additions & 2 deletions doc/CommandLineInterface.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,19 @@ responsible for selecting one of several possible options. The textual
transcription corresponds to the enumeration in the source code of PMC.

(pmc) reg pm.config_IFB
1 [151] pm.config_IFB = 2 (PM_IFB_ABC_INLINE)
1 [153] pm.config_IFB = 2 (PM_IFB_ABC_INLINE)

## Examples
Use `enum_reg` command to show all of allowed values and its transcriptions.

(pmc) enum_reg pm.config_IFB
9 [103] pm.config_IFB = 0 (PM_IFB_AB_INLINE)
9 [103] pm.config_IFB = 1 (PM_IFB_AB_GND)
9 [103] pm.config_IFB = 2 (PM_IFB_ABC_INLINE)
9 [103] pm.config_IFB = 3 (PM_IFB_ABC_GND)
9 [103] pm.config_IFB = 4
1 [103] pm.config_IFB = 2 (PM_IFB_ABC_INLINE)

## Examples with registers

Show all raw feedback values that PMC uses in control loops.

Expand Down
2 changes: 1 addition & 1 deletion doc/MachineProbe.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ measurement channels between phases.
(pmc) pm_self_adjust

This is enough to do it once and store the values in the flash. But we recommend
to do it again if you change DC link voltage rating.
to do it again if you change DC link voltage.

Also look into [Integrity Self Test](IntegritySelfTest.md) page to get more
info about self-adjustment functions.
Expand Down
4 changes: 2 additions & 2 deletions doc/MachineTuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Quite different in the case of current control. You should enable
`CC_SPEED_TRACK` feature to apply above speed loop constraints to actual speed
and acceleration.

(pmc) reg pm.config_CC_SPEED_TRACK 1
(pmc) reg pm.config_CC_SPEED_TRACK 1

Here trackpoint is driven by actual speed estimate with acceleration
constraint. For system stability we have introduced a linear regulation region
Expand All @@ -125,7 +125,7 @@ backlash in case of direction change.

Also you can tune PID regulator and load torque gains manually.

(pmc) reg pm.lu_gain_mq_LP <x>
(pmc) reg pm.lu_gain_mq_LP <x>
(pmc) reg pm.s_gain_P <x>
(pmc) reg pm.s_gain_I <x>
(pmc) reg pm.s_gain_D <x>
Expand Down
63 changes: 47 additions & 16 deletions pgui/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,9 @@ link_reg_postproc(struct link_pmc *lp, struct link_reg *reg)
&& (reg->mode & LINK_REG_TYPE_INT) != 0
&& strlen(reg->um) >= 7
&& strlen(reg->um) < LINK_NAME_MAX
&& reg->lval >= 0
&& reg->lval < LINK_COMBO_MAX) {
&& reg->lval >= 0 && reg->lval < LINK_COMBO_MAX) {

reg->mode |= LINK_REG_TYPE_ENUM;
reg->mode |= LINK_REG_TYPE_ENUMERATE;

if (reg->combo[reg->lval] == NULL) {

Expand All @@ -317,6 +316,10 @@ link_reg_postproc(struct link_pmc *lp, struct link_reg *reg)
? reg->lval : reg->lmax_combo;
}
}
else if (reg->enumerated != 0) {

reg->mode |= LINK_REG_TYPE_ENUMERATE;
}
}

static void
Expand All @@ -325,7 +328,7 @@ link_fetch_reg_format(struct link_pmc *lp)
struct link_priv *priv = lp->priv;
char ldup[LINK_MESSAGE_MAX], *sp = ldup;
const char *tok, *sym;
int reg_mode, reg_ID, n;
int reg_mode, reg_ID, N;

strcpy(ldup, priv->lbuf);

Expand All @@ -335,18 +338,18 @@ link_fetch_reg_format(struct link_pmc *lp)

if (strlen(tok) <= 2) {

if (lk_stoi(&n, tok) != NULL) {
if (lk_stoi(&N, tok) != NULL) {

reg_mode = n;
reg_mode = N;

tok = lk_token(&sp);

if ( strlen(tok) <= 3
&& tok[-1] == '[') {

if (lk_stoi(&n, lk_space(tok)) != NULL) {
if (lk_stoi(&N, lk_space(tok)) != NULL) {

reg_ID = n;
reg_ID = N;
}
}
}
Expand All @@ -361,12 +364,19 @@ link_fetch_reg_format(struct link_pmc *lp)

if (strcmp(tok, "=") == 0) {

char text[80];
char text[80];
struct link_reg local;

sprintf(text, "%.79s", sp = (char *) lk_space(sp));

reg->mode = reg_mode;

if (reg->mode & LINK_REG_HIDDEN) {

local = *reg;
reg = &local;
}

sprintf(reg->sym, "%.79s", sym);
sprintf(reg->val, "%.79s", lk_token(&sp));
sprintf(reg->um, "%.79s", lk_token(&sp));
Expand All @@ -383,6 +393,17 @@ link_fetch_reg_format(struct link_pmc *lp)
reg->um[0] = 0;
}

if (reg->mode & LINK_REG_HIDDEN) {

reg = lp->reg + reg_ID;

reg->mode = local.mode;
reg->lmax_combo = local.lmax_combo;

for (N = 0; N <= reg->lmax_combo; ++N)
reg->combo[N] = local.combo[N];
}

reg->fetched = lp->clock;
reg->queued = 0;

Expand Down Expand Up @@ -804,15 +825,25 @@ int link_fetch(struct link_pmc *lp, int clock)

if (priv->link_mode != LINK_MODE_DATA_GRAB) {

if (lp->keep + 2000 < lp->clock) {
if (lp->active + 12000 < lp->clock) {

if (lp->active + 12000 < lp->clock) {
link_close(lp);

link_close(lp);
return N;
}
else if (lp->active + 1000 < lp->clock) {

if (lp->keep + 1000 < lp->clock) {

sprintf(priv->lbuf, "ap_time" LINK_EOL);
serial_fputs(priv->fd, priv->lbuf);

return N;
lp->keep = lp->clock;
}
else {
}
else {
if (lp->keep + 5000 < lp->clock) {

sprintf(priv->lbuf, "ap_time" LINK_EOL);
serial_fputs(priv->fd, priv->lbuf);

Expand Down Expand Up @@ -905,8 +936,8 @@ void link_push(struct link_pmc *lp)
break;
}

if ( (reg->mode & LINK_REG_TYPE_ENUM) != 0
&& reg->enumerated == 0) {
if ( (reg->mode & LINK_REG_TYPE_ENUMERATE) != 0
&& reg->enumerated + 10000 < reg->shown) {

sprintf(priv->lbuf, "enum_reg %i" LINK_EOL, reg_ID);

Expand Down
6 changes: 3 additions & 3 deletions pgui/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ enum {
LINK_REG_LINKED = 4U,
LINK_REG_HIDDEN = 8U,

LINK_REG_TYPE_INT = (1UL << 8),
LINK_REG_TYPE_FLOAT = (1UL << 9),
LINK_REG_TYPE_INT = (1U << 8),
LINK_REG_TYPE_FLOAT = (1U << 9),

LINK_REG_TYPE_ENUM = (1UL << 10)
LINK_REG_TYPE_ENUMERATE = (1U << 10)
};

enum {
Expand Down
2 changes: 1 addition & 1 deletion pgui/nksdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

/* Adapted from sdl2surface_rawfb.h for use in Phobia by Roman Belov.
/* Adapted from sdl2surface_rawfb.h to use in Phobia by Roman Belov.
* */

#include <stdlib.h>
Expand Down
10 changes: 7 additions & 3 deletions pgui/phobia.c
Original file line number Diff line number Diff line change
Expand Up @@ -5711,12 +5711,16 @@ int main(int argc, char **argv)

struct nk_color header;

if (strstr(lp->hwinfo, "does NOT match") == NULL) {
if (strstr(lp->hwinfo, "does NOT match") != NULL) {

header = nk->table[NK_COLOR_ENABLED];
header = nk->table[NK_COLOR_FLICKER_ALERT];
}
else if (lp->active + 2000 < lp->clock) {

header = nk->table[NK_COLOR_FLICKER_LIGHT];
}
else {
header = nk->table[NK_COLOR_FLICKER_ALERT];
header = nk->table[NK_COLOR_ENABLED];
}

nk->ctx.style.window.header.active = nk_style_item_color(header);
Expand Down
2 changes: 1 addition & 1 deletion src/phobia/lse.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#define LSE_RM_TOP(ls) ((ls)->rm + (ls)->n_cascades - 1)

/* Define external math functions.
/* Define which external math functions to use in LSE.
* */
#define lse_fabsf(x) m_fabsf(x)
#define lse_sqrtf(x) m_sqrtf(x)
Expand Down
33 changes: 17 additions & 16 deletions src/phobia/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ pm_auto_config_default(pmc_t *pm)
pm->config_EABI_FRONTEND = PM_EABI_INCREMENTAL;
pm->config_SINCOS_FRONTEND = PM_SINCOS_ANALOG;

pm->tm_transient_slow = 40.f; /* (ms) */
pm->tm_transient_fast = 4.f; /* (ms) */
pm->tm_transient_slow = 50.f; /* (ms) */
pm->tm_transient_fast = 2.f; /* (ms) */
pm->tm_voltage_hold = 100.f; /* (ms) */
pm->tm_current_hold = 200.f; /* (ms) */
pm->tm_current_ramp = 900.f; /* (ms) */
pm->tm_instant_probe = 4.f; /* (ms) */
pm->tm_instant_probe = 2.f; /* (ms) */
pm->tm_average_probe = 200.f; /* (ms) */
pm->tm_average_drift = 100.f; /* (ms) */
pm->tm_average_inertia = 900.f; /* (ms) */
Expand Down Expand Up @@ -650,7 +650,7 @@ pm_torque_approx_MTPA(pmc_t *pm, float iD, float iQ)
Wq = pm->quick_WiL4 * pm->quick_WiL4;
Bq = (bD < bQ) ? bD + bQ : bQ + bQ;

if (pm->quick_WiL4 < 0.f) {
if (unlikely(pm->quick_WiL4 < 0.f)) {

iD = - pm->quick_WiL4 - m_sqrtf(Wq + Bq * 0.5f);
}
Expand All @@ -663,14 +663,15 @@ pm_torque_approx_MTPA(pmc_t *pm, float iD, float iQ)

float pm_torque_feasible(pmc_t *pm, float iQ)
{
float MTPA_iD, mQ;
float iD, mQ;

if (pm->config_RELUCTANCE == PM_ENABLED) {

MTPA_iD = pm_torque_approx_MTPA(pm, 0.f, iQ);
MTPA_iD = pm_torque_approx_MTPA(pm, MTPA_iD, iQ);
iD = pm_torque_approx_MTPA(pm, 0.f, iQ);
iD = pm_torque_approx_MTPA(pm, iD, iQ);
iD = pm_torque_approx_MTPA(pm, iD, iQ);

mQ = pm_torque_equation(pm, MTPA_iD, iQ);
mQ = pm_torque_equation(pm, iD, iQ);
}
else {
mQ = pm_torque_equation(pm, 0.f, iQ);
Expand All @@ -687,15 +688,15 @@ pm_torque_get_current(pmc_t *pm, float mQ)
if (pm->config_RELUCTANCE == PM_ENABLED) {

if ( pm->const_lambda < M_EPSILON
&& pm->mtpa_approx_D < 1.f) {
&& pm->mtpa_load_D < 1.f) {

pm->mtpa_approx_D = 1.f;
pm->mtpa_load_D = 1.f;
}

rel = (pm->const_im_Ld - pm->const_im_Lq) * pm->mtpa_approx_D;
rel = (pm->const_im_Ld - pm->const_im_Lq) * pm->mtpa_load_D;
iQ = mQ / (pm->k_KWAT * (pm->const_lambda + rel));

pm->mtpa_approx_D = pm_torque_approx_MTPA(pm, pm->mtpa_approx_D, iQ);
pm->mtpa_load_D = pm_torque_approx_MTPA(pm, pm->mtpa_load_D, iQ);
}
else {
if (pm->const_lambda > M_EPSILON) {
Expand Down Expand Up @@ -1235,7 +1236,7 @@ pm_flux_kalman(pmc_t *pm)
{
const float *K = pm->kalman_K;
float *A = pm->kalman_A;
float *E = pm->kalman_E;
float *E = pm->kalman_rsu;

float tA, dA = 0.f;

Expand Down Expand Up @@ -1819,12 +1820,12 @@ pm_lu_FSM(pmc_t *pm)
if ( pm->config_LU_FORCED == PM_ENABLED
&& pm->config_LU_DRIVE == PM_DRIVE_CURRENT) {

float wSP;
float wSP, iSP = pm->i_setpoint_current;

/* Derive the speed SETPOINT in case of current control.
* */
wSP = (pm->i_setpoint_current < - M_EPSILON) ? - pm->forced_reverse
: (pm->i_setpoint_current > M_EPSILON) ? pm->forced_maximal : 0.f;
wSP = (iSP < - M_EPSILON) ? - pm->forced_reverse
: (iSP > M_EPSILON) ? pm->forced_maximal : 0.f;

pm->s_setpoint_speed = wSP;
}
Expand Down
4 changes: 2 additions & 2 deletions src/phobia/pm.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ typedef struct {
float kalman_P[15];
float kalman_A[10];
float kalman_K[10];
float kalman_E[2];
float kalman_rsu[2];
float kalman_bias_Q;
float kalman_lpf_wS;
float kalman_gain_Q[4];
Expand Down Expand Up @@ -545,7 +545,7 @@ typedef struct {
float i_gain_P;
float i_gain_I;

float mtpa_approx_D;
float mtpa_load_D;
float mtpa_D;
float mtpa_gain_LP;

Expand Down
Loading

0 comments on commit f1bc5c4

Please sign in to comment.