Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ jobs:
with:
flakes: nixpkgs#llvmPackages_18.clang-tools, nixpkgs#pre-commit

- name: Run clang-format
id: clang-format
run: pre-commit run --all-files --show-diff-on-failure --color always

- name: Build Package
if: success() || (failure() && steps.clang-format.conclusion == 'failure')
uses: ./.github/actions/build
with:
cache-auth-token: '${{ secrets.CACHIX_AUTH_TOKEN }}'

- name: Upload refloat.vescpkg
uses: actions/upload-artifact@v4
with:
name: refloat-package
path: refloat.vescpkg
3 changes: 3 additions & 0 deletions package_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

A full-featured self-balancing skateboard package.

## Experiments
Playing with reverse stop config for anti ghosting protection

## New in 1.2
- BMS alerting support (Pushback and Haptic)
- Speed-based alerting (Pushback and Haptic)
Expand Down
3 changes: 3 additions & 0 deletions src/conf/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ typedef struct {
bool enable_quickstop;
bool fault_darkride_enabled;
bool fault_reversestop_enabled;
uint32_t reverse_tolerance;
uint16_t reverse_stop_trigger_erpm;
float reverse_erpm_incr;
float tiltback_duty_angle;
float tiltback_duty_speed;
float tiltback_duty;
Expand Down
69 changes: 69 additions & 0 deletions src/conf/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,69 @@ p, li { white-space: pre-wrap; }
<cDefine>CFG_DFLT_FAULT_REVERSESTOP_ENABLED</cDefine>
<valInt>0</valInt>
</fault_reversestop_enabled>
<reverse_tolerance>
<longName>Reverse Stop Tolerance</longName>
<type>2</type>
<transmittable>1</transmittable>
<description>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt; &lt;/p&gt;
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;ERPM deadzone before Reverse Stop begins to slow the board. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description>
<cDefine>CFG_DFLT_REVERSE_TOLERANCE</cDefine>
<editorScale>1</editorScale>
<editAsPercentage>0</editAsPercentage>
<maxInt>100000000</maxInt>
<minInt>0</minInt>
<showDisplay>0</showDisplay>
<stepInt>5000</stepInt>
<valInt>400000</valInt>
<suffix> ERPM</suffix>
<vTx>5</vTx>
</reverse_tolerance>
<reverse_stop_trigger_erpm>
<longName>Reverse Stop Trigger ERPM</longName>
<type>2</type>
<transmittable>1</transmittable>
<description>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Minimum reverse speed to trigger Reverse Stop detection. The board must be moving backwards faster than this ERPM value before Reverse Stop can engage.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description>
<cDefine>CFG_DFLT_REVERSE_STOP_TRIGGER_ERPM</cDefine>
<editorScale>1</editorScale>
<editAsPercentage>0</editAsPercentage>
<maxInt>65000</maxInt>
<minInt>0</minInt>
<showDisplay>0</showDisplay>
<stepInt>200</stepInt>
<valInt>2000</valInt>
<suffix> ERPM</suffix>
<vTx>3</vTx>
</reverse_stop_trigger_erpm>
<reverse_erpm_incr>
<longName>Reverse Stop ERPM Increment</longName>
<type>1</type>
<transmittable>1</transmittable>
<description>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Roboto'; ; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Scale factor used to convert aggregated ERPM over the reverse tolerance into a tiltback setpoint angle. Smaller values make the system less aggressive.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description>
<cDefine>CFG_DFLT_REVERSE_ERPM_INCR</cDefine>
<editorDecimalsDouble>8</editorDecimalsDouble>
<editorScale>1</editorScale>
<editAsPercentage>0</editAsPercentage>
<maxDouble>10</maxDouble>
<minDouble>0</minDouble>
<showDisplay>0</showDisplay>
<stepDouble>1e-05</stepDouble>
<valDouble>8e-05</valDouble>
<vTxDoubleScale>1</vTxDoubleScale>
<suffix></suffix>
<vTx>9</vTx>
</reverse_erpm_incr>
<tiltback_duty_angle>
<longName>Pushback Angle</longName>
<type>1</type>
Expand Down Expand Up @@ -3944,6 +4007,9 @@ p, li { white-space: pre-wrap; }
<ser>enable_quickstop</ser>
<ser>fault_darkride_enabled</ser>
<ser>fault_reversestop_enabled</ser>
<ser>reverse_tolerance</ser>
<ser>reverse_stop_trigger_erpm</ser>
<ser>reverse_erpm_incr</ser>
<ser>tiltback_duty_angle</ser>
<ser>tiltback_duty_speed</ser>
<ser>tiltback_duty</ser>
Expand Down Expand Up @@ -4204,6 +4270,9 @@ p, li { white-space: pre-wrap; }
<param>::sep::Features</param>
<param>fault_darkride_enabled</param>
<param>fault_reversestop_enabled</param>
<param>reverse_tolerance</param>
<param>reverse_stop_trigger_erpm</param>
<param>reverse_erpm_incr</param>
</subgroupParams>
</subgroup>
<subgroup>
Expand Down
1 change: 1 addition & 0 deletions src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ typedef struct {

// Feature: Reverse Stop
float reverse_stop_step_size, reverse_tolerance, reverse_total_erpm;
float reverse_total_erpm_plot;
time_t reverse_timer;

// Feature: Soft Start
Expand Down
33 changes: 18 additions & 15 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ static void cmd_flywheel_toggle(Data *d, unsigned char *cfg, int len);

const VESC_PIN beeper_pin = VESC_PIN_PPM;

#define REVSTOP_ERPM_INCR 0.00008
#define EXT_BEEPER_ON() VESC_IF->io_write(beeper_pin, 1)
#define EXT_BEEPER_OFF() VESC_IF->io_write(beeper_pin, 0)

Expand Down Expand Up @@ -205,8 +204,9 @@ static void configure(Data *d) {
}

// Feature: Reverse Stop
d->reverse_tolerance = 20000;
d->reverse_tolerance = d->float_conf.reverse_tolerance;
d->reverse_stop_step_size = 100.0 / d->float_conf.hertz;
d->reverse_total_erpm_plot = d->reverse_total_erpm * 0.001f;

// Speed above which to warn users about an impending full switch fault
d->switch_warn_beep_erpm = d->float_conf.is_footbeep_enabled ? 2000 : 100000;
Expand Down Expand Up @@ -518,28 +518,31 @@ static void calculate_setpoint_target(Data *d) {
} else if (d->state.sat == SAT_REVERSESTOP) {
// accumalete erpms:
d->reverse_total_erpm += d->motor.erpm;
if (fabsf(d->reverse_total_erpm) > d->reverse_tolerance) {
// tilt down by 10 degrees after exceeding aggregate erpm
d->setpoint_target =
(fabsf(d->reverse_total_erpm) - d->reverse_tolerance) * REVSTOP_ERPM_INCR;
} else {
d->reverse_total_erpm_plot = d->reverse_total_erpm * 0.001f;
if (fabsf(d->reverse_total_erpm) > d->reverse_tolerance) {
// tilt down by 10 degrees after exceeding aggregate erpm
d->setpoint_target =
(fabsf(d->reverse_total_erpm) - d->reverse_tolerance) *
d->float_conf.reverse_erpm_incr;
} else {
if (fabsf(d->reverse_total_erpm) <= d->reverse_tolerance * 0.5) {
if (d->motor.erpm >= 0) {
if (d->motor.erpm >= -(int) d->float_conf.reverse_stop_trigger_erpm) {
d->state.sat = SAT_NONE;
d->reverse_total_erpm = 0;
d->setpoint_target = 0;
}
}
}
} else if (d->float_conf.fault_reversestop_enabled && d->motor.erpm < -200 &&
} else if (d->float_conf.fault_reversestop_enabled && d->motor.erpm < -(int)d->float_conf.reverse_stop_trigger_erpm &&
!d->state.darkride) {
// Detecting reverse stop takes priority over any error condition SAT
if (d->state.sat >= SAT_PB_HIGH_VOLTAGE) {
// If this happens while in Error-Tiltback (LV/HV/TEMP) then we need to
// take the already existing setpoint into account
d->reverse_total_erpm =
-(d->reverse_tolerance + d->setpoint_target_interpolated / REVSTOP_ERPM_INCR);
} else {
if (d->state.sat >= SAT_PB_HIGH_VOLTAGE) {
// If this happens while in Error-Tiltback (LV/HV/TEMP) then we need to
// take the already existing setpoint into account
d->reverse_total_erpm = -(d->reverse_tolerance +
d->setpoint_target_interpolated /
d->float_conf.reverse_erpm_incr);
} else {
d->reverse_total_erpm = 0;
}
d->state.sat = SAT_REVERSESTOP;
Expand Down
2 changes: 2 additions & 0 deletions src/rt_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
S(turn_tilt.setpoint) \
S(remote.setpoint) \
R(balance_current) \
R(reverse_total_erpm_plot) \
R(reverse_timer) \
S(atr.accel_diff) \
S(atr.speed_boost) \
S(booster.current)
Expand Down
2 changes: 2 additions & 0 deletions ui.qml.in
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,8 @@ Item {
["footpad.adc1", {"name": "ADC1 Voltage", "color": "#69aad7", "visible": false}],
["footpad.adc2", {"name": "ADC2 Voltage", "color": "#4a8772", "visible": false}],
["balance_current", {"name": "Balance Current", "color": "#36738b", "visible": false}],
["reverse_total_erpm_plot", {"name": "Reverse Total ERPM (k)", "color": "#748b36", "visible": false}],
["reverse_timer", {"name": "Reverse Timer", "color": "#368b5c", "visible": false}],
["booster.current", {"name": "Booster Current", "color": "#8f2f26", "visible": false}],
["atr.accel_diff", {"name": "ATR Accel Diff", "color": "#4f5984", "visible": false}],
["atr.speed_boost", {"name": "ATR Speed Boost", "color": "#34633c", "visible": false}],
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.3
1.2.4