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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PKGS = balance float refloat tnt vbms32 vbms32_micro
PKGS = balance float refloat tnt vbms32 vbms32_micro timeout
PKGS += lib_files lib_interpolation lib_nau7802 lib_pn532
PKGS += lib_ws2812 logui lib_code_server lib_midi lib_disp_ui
PKGS += vdisp lib_tca9535 vbms_harmony32
Expand Down
1 change: 1 addition & 0 deletions res_all.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<file>vdisp/vdisp.vescpkg</file>
<file>vdisp/vdisp_esc.vescpkg</file>
<file>vbms_harmony32/vbms_harmony32.vescpkg</file>
<file>timeout/timeout.vescpkg</file>
</qresource>
</RCC>

18 changes: 18 additions & 0 deletions timeout/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
VESC_TOOL ?= vesc_tool
OLDVT ?= 0

all: timeout.vescpkg

timeout.vescpkg: timeout.lisp README.md pkgdesc.qml
ifeq ($(OLDVT), 1)
$(VESC_TOOL) --buildPkg "timeout.vescpkg:timeout.lisp::0:README.md:Remote Timeout"
else
$(VESC_TOOL) --buildPkgFromDesc pkgdesc.qml --testPkgDesc 'custom:test' --testPkgDesc 'vesc:test'
endif

clean:
rm -f timeout.vescpkg

.PHONY: all clean


22 changes: 22 additions & 0 deletions timeout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Remote Timeout

A simple safety script for VESC-based ESCs that do not properly handle remote disconnect timeouts. If the remote input stops updating for 1.00 s, motor current is set to zero.

## What it does

- Monitors the age of the last received remote input using `get-remote-state`.
- If the age exceeds 1.00 s, commands zero current to stop the motor.
- Runs at a low cadence to minimize load.

## Usage

1. Install the package from the VESC Tool package store.
2. Start the package once from the Packages page to save it.
3. After that it runs at boot automatically. The timeout is fixed to 1.00 s.

## Compatibility

- Works on VESC-based ESCs that support packages and expose `get-remote-state`.
- Not compatible with the classic VESC BMS.


32 changes: 32 additions & 0 deletions timeout/pkgdesc.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import QtQuick 2.15

Item {
property string pkgName: "Remote Timeout"
property string pkgDescriptionMd: "README.md"
property string pkgLisp: "timeout.lisp"
property string pkgQml: ""
property bool pkgQmlIsFullscreen: false
property string pkgOutput: "timeout.vescpkg"

// This function should return true when this package is compatible
// with the connected vesc-based device
function isCompatible (fwRxParams) {
var hwName = fwRxParams.hw.toLowerCase();
var fwName = fwRxParams.fwName.toLowerCase();
var hwType = fwRxParams.hwTypeStr().toLowerCase();

// The classic VESC BMS does not support packages at all
if (hwType == "vesc bms") {
return false
}

// Works on vesc-based ESCs only
if (hwType != "vesc") {
return false
}

return true
}
}


27 changes: 27 additions & 0 deletions timeout/timeout.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; Remote timeout safety feature
@const-start
(def remote_drop_s 1.00) ; fixed timeout (s)
(def loop_dt_s 0.02) ; loop cadence (s)
@const-end

(def mote-age 0.0)
(def state nil)
(def age-val 0.0)

(defun main () (loopwhile t {
(def state (get-remote-state)) ; (js-y js-x bt-c bt-z is-rev update-age)

(def age-val (ix state 5))
(def mote-age (if age-val age-val 9999.0))

; if age > threshold ? zero current
(if (> mote-age remote_drop_s)
(set-current 0 0.05)
0)

(sleep loop_dt_s)
}))

(trap (image-save))
(main)