From f1c29ed71806f39b55b1a2a926bb36926cea00f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=93=81=E9=94=A4?= Date: Tue, 11 Aug 2026 18:22:44 +0800 Subject: [PATCH] fix(example): J-key voice command ack protocol to stop stale repeats - Edge-triggered voice commands: only execute on new command (None/'' -> command), so repeated identical commands (e.g. consecutive "forward") trigger again - Ack protocol with App: device returns J:1 on receipt, executes the action, then returns J:0 when done so the App clears the pending command - Fixes: voice command repeating the last recognition result forever - Bump version to 0.0.4, add CHANGELOG and README notes --- CHANGELOG.md | 13 +++++++++++++ README.md | 10 ++++++++++ examples/picarx_control.py | 20 ++++++++++++++------ sunfounder_controller/version.py | 2 +- 4 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6d19d7c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,13 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## [0.0.4] - 2026-08-11 + +- Fix voice control (J key) repeating the last recognition result in `picarx_control.py` +- Add J-key ack protocol: device returns `1` on receipt (ack), then `0` when the action completes, so the App clears the pending command and repeated identical commands (e.g. consecutive "forward") trigger again +- Edge-triggered voice command execution (empty/None -> command) + +## [0.0.2] - 2020-06-12 + +- New Release diff --git a/README.md b/README.md index 58b53dc..e1b3137 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,16 @@ - set(key='A_region', value=None) send value +## Voice control (J key) + +In `picarx_control.py`, the J key uses an ack protocol with the App: + +1. Device receives a voice command (`J`) → sends `J: 1` (ack, action in progress) +2. Device executes the action (~0.3s, adjustable via `ack_ts` threshold) +3. Device sends `J: 0` (action done) → App clears the pending command + +This prevents the last voice command from repeating forever and allows repeated identical commands to trigger again (edge-triggered). + Quick Links: diff --git a/examples/picarx_control.py b/examples/picarx_control.py index bd0d228..2fa6a39 100644 --- a/examples/picarx_control.py +++ b/examples/picarx_control.py @@ -3,6 +3,7 @@ from robot_hat import utils, Music from vilib import Vilib import os +import time from time import sleep utils.reset_mcu() @@ -85,6 +86,7 @@ def main(): Vilib.camera_start(vflip=False,hflip=False) Vilib.display(local=False, web=True) speak = None + ack_ts = 0 while True: # sleep(0.2) @@ -101,12 +103,18 @@ def main(): # sc.set("L", [0,distance]) sc.set("F", distance) - # if sc.get('J') == True: - # horn() - - # print(sc.get('J'), type(sc.get('J')), speak) - if sc.get('J') != None: - speak=sc.get('J') + # ---- J-key voice protocol: receive → ack(1) → execute → done(0, App clears) ---- + j = sc.get('J') + if j not in (None, ''): # voice command present + if j != speak: # edge-trigger: only run on new command (repeat allowed) + speak = j + sc.set("J", 1) # ① ack: tell App we're handling it + ack_ts = time.time() + else: + if speak is not None and time.time() - ack_ts > 0.3: # ② ack(1) sent long enough for App to receive + sc.set("J", 0) # ③ done: App clears the send value + speak = None # ④ reset, ready for next command + # ---- if speak == "forward": px.forward(speed) elif speak == "backward": diff --git a/sunfounder_controller/version.py b/sunfounder_controller/version.py index a0235ce..221ce5d 100644 --- a/sunfounder_controller/version.py +++ b/sunfounder_controller/version.py @@ -1 +1 @@ -__version__ = "0.0.2" \ No newline at end of file +__version__ = "0.0.4" \ No newline at end of file