Skip to content

Commit

Permalink
Improved DC link voltage constraints, DRV updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
rombrew committed Feb 6, 2024
1 parent d108267 commit 786817d
Show file tree
Hide file tree
Showing 53 changed files with 760 additions and 404 deletions.
4 changes: 2 additions & 2 deletions bench/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ $(TARGET): $(SIM_OBJS)
@ echo " LD " $(notdir $@)
@ $(LD) $(CFLAGS) -o $@ $^ $(LFLAGS)

verify: $(TARGET)
test: $(TARGET)
@ echo " TEST " $(notdir $<)
@ $< verify
@ $< test

run: $(TARGET)
@ echo " RUN " $(notdir $<)
Expand Down
67 changes: 45 additions & 22 deletions bench/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ tlm_plot_grab()
fmt_GP(pm.mtpa_D, "A");
fmt_GP(pm.weak_D, "A");

fmt_GP(pm.v_DC_MAX, 0);
fmt_GP(pm.v_DC_MIN, 0);

fmk_GP(pm.s_setpoint_speed, kRPM, "rpm");
fmk_GP(pm.s_track, kRPM, "rpm");
fmt_GP(pm.s_integral, "A");
Expand Down Expand Up @@ -372,41 +375,61 @@ void bench_script()

tlm_restart();

m.Rs = 14.E-3;
m.Ld = 10.E-6;
m.Lq = 15.E-6;
m.Udc = 22.;
m.Rs = 8.1E-3;
m.Ld = 3.2E-6;
m.Lq = 4.8E-6;
m.Udc = 48.;
m.Rdc = 0.1;
m.Zp = 21;
m.lambda = blm_Kv_lambda(&m, 109.);
m.Jm = 5.39E-3;

/*m.Rs = 28.E-3;
m.Ld = 14.E-6;
m.Lq = 22.E-6;
m.Udc = 48.;
m.Rdc = 0.1;
m.Zp = 14;
m.lambda = blm_Kv_lambda(&m, 270.);
m.Jm = 3.E-4;

m.eabi_ERES = 16384;
m.eabi_WRAP = 16384;
m.lambda = blm_Kv_lambda(&m, 87.);
m.Jm = 0.82E-3;*/

/*m.Rs = 0.24;
m.Ld = 520.E-6;
m.Lq = 650.E-6;
m.Udc = 48.;
m.Rdc = 0.5;
m.Zp = 15;
m.lambda = blm_Kv_lambda(&m, 15.7);
m.Jm = 6.E-3;*/

ts_script_default();
ts_script_base();
blm_restart(&m);

pm.config_EABI_FRONTEND = PM_EABI_ABSOLUTE;
//pm.config_LU_FORCED = PM_DISABLED;
pm.watt_uDC_maximal = 49.f;
pm.watt_uDC_minimal = 47.f;
//pm.zone_threshold = 5.0 / pm.const_lambda;

ts_adjust_sensor_eabi();
blm_restart(&m);
pm.s_accel = 500000.f;

//pm.config_LU_ESTIMATE = PM_FLUX_NONE;
pm.config_LU_SENSOR = PM_SENSOR_EABI;
//m.Udc = 10.;
m.Rdc = 0.5;

pm.fsm_req = PM_STATE_LU_STARTUP;
ts_wait_for_idle();

pm.s_setpoint_speed = 40.f;
sim_runtime(1.);
pm.s_setpoint_speed = 2000.f;
sim_runtime(1.0);

m.Mq[0] = - 1.5 * m.Zp * m.lambda * 10.f;
sim_runtime(1.0);

pm.s_setpoint_speed = 200.f;
sim_runtime(2.);
m.Mq[0] = 0.f;
sim_runtime(1.0);

pm.s_setpoint_speed = -50.f;
sim_runtime(2.);
pm.s_setpoint_speed = 100.f;
sim_runtime(2.0);

tlm_PWM_grab();
}
Expand All @@ -420,9 +443,9 @@ int main(int argc, char *argv[])

lfg_start((int) time(NULL));

if (strcmp(argv[1], "verify") == 0) {
if (strcmp(argv[1], "test") == 0) {

ts_script_verify();
ts_script_test();
}
else if (strcmp(argv[1], "bench") == 0) {

Expand Down
2 changes: 1 addition & 1 deletion bench/blm.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void blm_enable(blm_t *m)
m->range_A = 165.; /* (Ampere) */
m->range_B = 60.; /* (Volt) */

/* Hall sensor mount angles.
/* Hall sensor installation angles.
* */
m->hall[0] = 30.7;
m->hall[1] = 150.1;
Expand Down
8 changes: 6 additions & 2 deletions bench/tsfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ ts_script_eabi(int knob_EABI)
pm.config_LU_SENSOR = PM_SENSOR_NONE;
}

void ts_script_verify()
void ts_script_test()
{
blm_enable(&m);
blm_restart(&m);
Expand Down Expand Up @@ -701,6 +701,8 @@ void ts_script_verify()

printf("\n---- Turnigy RotoMax 1.20 ----\n");

tlm_restart();

m.Rs = 14.E-3;
m.Ld = 10.E-6;
m.Lq = 15.E-6;
Expand All @@ -726,7 +728,9 @@ void ts_script_verify()
ts_script_eabi(PM_EABI_ABSOLUTE);
blm_restart(&m);

printf("\n---- 8-inch Hub Motor (350W) ----\n");
printf("\n---- Hub Motor (250W) ----\n");

tlm_restart();

m.Rs = 0.24;
m.Ld = 520.E-6;
Expand Down
2 changes: 1 addition & 1 deletion bench/tsfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int ts_wait_for_spinup();

void ts_script_default();
void ts_script_base();
void ts_script_verify();
void ts_script_test();

#endif /* _H_TSFUNC_ */

2 changes: 1 addition & 1 deletion doc/CommandLineInterface.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Overview

This page introduces you to the Command Line Interface (CLI). We have a regular
CLI with autocompletion and command history.
CLI with autocompletion function and command history.

## Key mapping

Expand Down
23 changes: 11 additions & 12 deletions doc/HardwareDesign.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ PMC internals. Also this page will be useful for understanding.

We have a three-phase Voltage Source Inverter (VSI) which consists of at least
six metal–oxide–semiconductor field-effect transistors (MOSFET). The voltage at
each of the output terminals is measured. Phase current A and B (optionally
C) is measured. The output terminals are connected to the machine.
each of the output terminals is measured. Phase current A and B (optionally C)
is measured. The output terminals are connected to the machine.

```
(VCC) >---+--------+---------+---------+
Expand Down Expand Up @@ -88,10 +88,11 @@ amount of uncertainty in the output voltage `dU` expressed as follows:
```

The voltage divider (R1, R2) and filter capacitor (C1) are used to measure the
terminal voltage (uA, uB, uC). This RC scheme forms an exponential integrator
that allows us to restore the pulse width by measured voltage. Additional
resistor R3 is used to bias the operating point into the linear region. You
can skip voltage sensing if you do not need related features.
terminal voltage (uA, uB, uC) and supply voltage (uS). This RC scheme forms an
exponential integrator that allows us to restore the pulse width by measured
voltage. Additional resistor R3 is used to bias the operating point into the
linear region. You can skip the terminal voltage sensing if you do not need
related features but supply voltage measuring is mandatory.

To get acceptable accuracy you need to make sure that the RC scheme time
constant is comparable to dT. Also make sure that your capacitors are stable
Expand Down Expand Up @@ -143,9 +144,7 @@ measurement you will need to configure the software appropriately.
+---< Terminal
```

Also supply voltage (uS) is measured using a voltage divider.

## Control loop
## Sampling scheme

Currents are sampled strictly in the middle of PWM period simultaneously using
three ADCs. Then the voltages and other signals are sampled depending on
Expand Down Expand Up @@ -188,9 +187,9 @@ switching occur at this time then ADC result is discarded.
| | | | | |
---*--*--*-------------------------------------------*--*--*--------
| |
-->| clearence |<--
| |
-->| skip |<--
-->| clearence |<--
| |
-->| skip |<--
```

The diagram above shows `clearance` and `skip` parameters that is used in
Expand Down
2 changes: 1 addition & 1 deletion doc/HardwareVESC.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This page gives you an overview of VESC hardware supported by PMC.
| VESC 6 MkVI | VESC6C | Original |
| Holybro Mini FOC ESC Based on VESC6 | VESC6H | |
| FLIPSKY 75100 V202 ESC | VESC75A | Low side shunts |
| Makerbase VESC 75200 V2 84V 200A | VESC75A | Bad PCB design |
| Makerbase VESC 75200 V2 84V 200A | VESC75A | |
| VESC 75/300 R3 | VESC75B | Original |

Note that some of VESC clone have bad PCB design that causes distorted current
Expand Down
4 changes: 2 additions & 2 deletions doc/InputAnalogKnob.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ the control variable will be interpolated to this value.
If you need you can change input lost range. If signal goes beyond this range
it is considered lost and halt happens with `PM_ERROR_SENSOR_HALL_FAULT` reason.

(pmc) reg ap.knob_range_LST0 <V>
(pmc) reg ap.knob_range_LST1 <V>
(pmc) reg ap.knob_range_LOS0 <V>
(pmc) reg ap.knob_range_LOS1 <V>

Enable machine startup control. Each time when `ANG` signal is in range the
startup is requested.
Expand Down
6 changes: 4 additions & 2 deletions doc/MachineProbe.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ you will need to decrease probe currents for a small machine.
amplitude that is used to estimate stator impedance.
* `pm.probe_speed_hold` - Speed setpoint for the initial spinup. At this speed
flux linkage and noise threshold will be estimated.
* `pm.probe_loss_maximal` - Maximal heating losses on stator winding. This
allows us to assume maximal machine current.

Also pay attention to the forced control parameters which are used to achieve
initial spinup.

(pmc) reg pm.forced

* `pm.forced_hold_D` - Current setpoint which should be enough to hold rotor in
aligned position and force it turn.
* `pm.forced_hold_D` - Forced current setpoint which should be enough to hold
rotor in aligned position and force it turn.
* `pm.forced_accel` - Allowed acceleration of the forced control.

If you use power supply that not tolerate reverse current then consider the
Expand Down
10 changes: 5 additions & 5 deletions doc/MachineTuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ conditions. We will consider the most important of them.

## Forced control

If the machine is at low speed then FLUX observer is unable to provide reliable
estimates. You need to use some sort of position sensor. If this is not
possible the forced control is used. We apply a current vector without feedback
to force rotor turn. You can adapt the current value and acceleration to your
needs.
If the machine is at low speed then sensorless flux observer is unable to
provide reliable estimates. You need to use some sort of position sensor. If
this is not possible the forced control is used. We apply a current vector
without feedback to force rotor turn. You can adapt the current value and
acceleration to your needs.

(pmc) reg pm.forced_hold_D <A>
(pmc) reg pm.forced_accel <rad/s2>
Expand Down
2 changes: 1 addition & 1 deletion phobia/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,6 @@ void config_default(struct config_phobia *fe)

strcpy(fe->fuzzy, "setpoint");

fe->regfile = 480;
fe->regfile = 485;
}

3 changes: 2 additions & 1 deletion phobia/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ void link_remote(struct link_pmc *lp)

lp->reg_MAX_N = 0;

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

sprintf(priv->lbuf, "ap_version" LINK_EOL);
serial_fputs(priv->fd, priv->lbuf);
Expand Down
6 changes: 3 additions & 3 deletions phobia/nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -7662,9 +7662,9 @@ nk_rgb_factor(struct nk_color col, const float factor)
{
if (factor == 1.0f)
return col;
col.r *= factor;
col.g *= factor;
col.b *= factor;
col.r = (nk_byte)(col.r * factor);
col.g = (nk_byte)(col.g * factor);
col.b = (nk_byte)(col.b * factor);
return col;
}
NK_API struct nk_color
Expand Down
34 changes: 23 additions & 11 deletions phobia/phobia.c
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ pub_popup_telemetry_grab(struct public *pub, int popup)

if (reg_tlm != NULL) {

reg_tlm->lval = 1;
reg_tlm->lval = 0;
}
}
}
Expand Down Expand Up @@ -3220,6 +3220,12 @@ page_hal(struct public *pub)
nk_layout_row_dynamic(ctx, 0, 1);
nk_spacer(ctx);

reg_float(pub, "hal.CAN_bitfreq", "CAN frequency");
reg_float(pub, "hal.CAN_errate", "CAN bus errate");

nk_layout_row_dynamic(ctx, 0, 1);
nk_spacer(ctx);

reg_enum_combo(pub, "hal.DPS_mode", "DPS operation mode", 0);
reg_enum_combo(pub, "hal.PPM_mode", "PPM operation mode", 0);
reg_float(pub, "hal.PPM_frequency", "PPM frequency");
Expand All @@ -3234,7 +3240,6 @@ page_hal(struct public *pub)
reg_float(pub, "hal.DRV.status_raw", "DRV status raw");
reg_float(pub, "hal.DRV.gate_current", "DRV gate current");
reg_float(pub, "hal.DRV.ocp_level", "DRV OCP level");
reg_float(pub, "hal.DRV.fault_safety", "DRV fault safety");

nk_layout_row_dynamic(ctx, 0, 1);
nk_spacer(ctx);
Expand Down Expand Up @@ -3693,8 +3698,8 @@ page_in_knob(struct public *pub)
reg_float(pub, "ap.knob_range_ANG2", "ANG range HIGH");
reg_float(pub, "ap.knob_range_BRK0", "BRK range LOW");
reg_float(pub, "ap.knob_range_BRK1", "BRK range HIGH");
reg_float(pub, "ap.knob_range_LST0", "Lost range LOW");
reg_float(pub, "ap.knob_range_LST1", "Lost range HIGH");
reg_float(pub, "ap.knob_range_LOS0", "LOST range LOW");
reg_float(pub, "ap.knob_range_LOS1", "LOST range HIGH");
reg_float(pub, "ap.knob_control_ANG0", "Control range LOW");
reg_float(pub, "ap.knob_control_ANG1", "Control range MID");
reg_float(pub, "ap.knob_control_ANG2", "Control range HIGH");
Expand Down Expand Up @@ -3886,7 +3891,7 @@ page_config(struct public *pub)
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 facilities");
reg_enum_toggle(pub, "pm.config_DBG", "Debug information gather");

nk_layout_row_dynamic(ctx, 0, 1);
nk_spacer(ctx);
Expand Down Expand Up @@ -3952,10 +3957,10 @@ page_config(struct public *pub)
nk_layout_row_dynamic(ctx, 0, 1);
nk_spacer(ctx);

reg_float(pub, "pm.fault_voltage_tol", "Voltage tolerance");
reg_float(pub, "pm.fault_current_tol", "Current tolerance");
reg_float(pub, "pm.fault_accuracy_tol", "Accuracy tolerance");
reg_float(pub, "pm.fault_terminal_tol", "Terminal tolerance");
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");

Expand Down Expand Up @@ -4586,6 +4591,13 @@ page_wattage(struct public *pub)
nk_layout_row_dynamic(ctx, 0, 1);
nk_spacer(ctx);

reg_float(pub, "pm.v_uDC_tol", "DC regulation tolerance");
reg_float(pub, "pm.v_gain_P", "DC link proportional gain");
reg_float(pub, "pm.v_gain_I", "DC link integral gain");

nk_layout_row_dynamic(ctx, 0, 1);
nk_spacer(ctx);

reg = link_reg_lookup(lp, "pm.lu_MODE");

if (reg != NULL) {
Expand Down Expand Up @@ -4821,8 +4833,8 @@ page_lp_location(struct public *pub)

reg_float_um(pub, "pm.x_maximal", "Maximal location limit", um_def);
reg_float_um(pub, "pm.x_minimal", "Minimal location limit", um_def);
reg_float_um(pub, "pm.x_damping", "Damping range", 0);
reg_float_um(pub, "pm.x_tolerance", "Tolerance", 0);
reg_float_um(pub, "pm.x_damping", "Damping distance", 0);
reg_float_um(pub, "pm.x_residual_tol", "Residual tolerance", 0);
reg_float_um(pub, "pm.x_gain_P", "Proportional gain", 0);
reg_float(pub, "pm.x_gain_D", "Damped gain");

Expand Down
Loading

0 comments on commit 786817d

Please sign in to comment.