Please enter the commit message for your changes. Lines starting
with '#' will be ignored, and an empty message aborts the commit. On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) Changes to be committed: modified: .gitignore modified: README.md new file: bashes/auto-wifi-connect.service new file: bashes/auto-wifi-connect.sh deleted: keyboard_control.py new file: my_model/image.png new file: path_follower_demo.py new file: scripts/PIDtracking.py new file: scripts/__pycache__/publish_sine_path.cpython-310.pyc new file: scripts/publish_sine_path.py modified: src/gc_navigation2_slamtoolbox/params/gc_navigation_slam.yaml modified: src/gc_navigation2_slamtoolbox/params/gc_navigation_slam.yaml.bak new file: src/gc_navigation2_slamtoolbox/params/gc_navigation_slam.yaml.bak2 modified: src/origincar_base/config/ekf.yaml new file: src/origincar_base/config/ekf.yaml.bak modified: src/origincar_base/launch/base_serial.launch.py new file: src/origincar_base/launch/base_serial.launch.py.bak modified: src/origincar_base/launch/origincar_bringup.launch.py new file: src/past_control/CMakeLists.txt new file: src/past_control/config/past_control.yaml new file: src/past_control/include/past_control/tools.h new file: src/past_control/launch/past_control.launch.py new file: src/past_control/msg/Obstacle.msg new file: src/past_control/msg/ObstacleArray.msg new file: src/past_control/package.xml new file: src/past_control/src/lane_follower_node.cpp new file: src/past_control/src/obstacle_detector_node.cpp new file: src/past_control/src/racing_orchestrator.cpp new file: src/planner/CMakeLists.txt new file: src/planner/config/planner.yaml new file: src/planner/launch/planner.launch.py new file: src/planner/package.xml new file: src/planner/src/planner_version.cpp modified: src/qr_detection/src/qr_dete_depth.cpp new file: src/racing_control/CMakeLists.txt new file: src/racing_control/include/racing_control/racing_control.hpp new file: src/racing_control/package.xml new file: src/racing_control/src/racing_control.cpp modified: src/vlm_detect/setup.py new file: src/vlm_detect/vlm_detect/__pycache__/__init__.cpython-310.pyc new file: src/vlm_detect/vlm_detect/__pycache__/tts_node.cpython-310.pyc new file: src/vlm_detect/vlm_detect/test_publisher.py new file: src/vlm_detect/vlm_detect/tts_node.py modified: src/vlm_detect/vlm_detect/vlm_node.py new file: tools/measure_turning_radius.py new file: tools/set_volume.py new file: tools/udp_to_cmdvel.py new file: tools/windows_keyboard_control.py new file: vlm_server.py new file: "\350\260\203\350\257\225\350\256\260\345\275\225.Assets/1.png" renamed: "\350\260\203\350\257\225\350\256\260\345\275\225.log" -> "\350\260\203\350\257\225\350\256\260\345\275\225.md"
This commit is contained in:
137
tools/windows_keyboard_control.py
Normal file
137
tools/windows_keyboard_control.py
Normal file
@@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Windows keyboard control → UDP → RDKx5
|
||||
Simultaneous keys supported (W+A = forward-left, etc.)
|
||||
|
||||
Usage:
|
||||
1. pip install keyboard
|
||||
2. Run this script on Windows
|
||||
3. RDKx5 must be running udp_to_cmdvel node
|
||||
|
||||
Controls:
|
||||
W/S : forward / backward
|
||||
A/D : turn left / right
|
||||
Q/E : left-forward / right-forward (single-key diagonal)
|
||||
Z/C : left-backward / right-backward
|
||||
Space : emergency stop
|
||||
I/K : linear speed +/-
|
||||
J/L : angular speed +/-
|
||||
Esc : quit
|
||||
"""
|
||||
|
||||
import keyboard
|
||||
import socket
|
||||
import struct
|
||||
import time
|
||||
import sys
|
||||
|
||||
# ========== CONFIG ==========
|
||||
ROBOT_IP = "192.168.10.210"
|
||||
UDP_PORT = 9999
|
||||
# ============================
|
||||
|
||||
HELP = """
|
||||
========================================
|
||||
Windows Keyboard Control → RDKx5
|
||||
========================================
|
||||
W/S : forward / backward
|
||||
A/D : turn left / right
|
||||
Q/E : left-forward / right-forward
|
||||
Z/C : left-backward / right-backward
|
||||
Space : STOP
|
||||
I/K : linear speed +/- (step 0.05)
|
||||
J/L : angular speed +/- (step 0.1)
|
||||
Esc : quit
|
||||
========================================
|
||||
Current: lin=%.2f ang=%.2f
|
||||
"""
|
||||
|
||||
|
||||
def main():
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
lin_speed = 0.2
|
||||
ang_speed = 0.5
|
||||
lin_step = 0.05
|
||||
ang_step = 0.1
|
||||
|
||||
def print_help():
|
||||
print(HELP % (lin_speed, ang_speed))
|
||||
|
||||
print("Connecting to %s:%d ..." % (ROBOT_IP, UDP_PORT))
|
||||
print_help()
|
||||
|
||||
while True:
|
||||
if keyboard.is_pressed('esc'):
|
||||
sock.sendto(struct.pack('dd', 0.0, 0.0), (ROBOT_IP, UDP_PORT))
|
||||
print("\nQuit.")
|
||||
break
|
||||
|
||||
# Speed adjustments (one-shot, debounced by keyboard library)
|
||||
if keyboard.is_pressed('i'):
|
||||
lin_speed = round(lin_speed + lin_step, 2)
|
||||
print_help()
|
||||
time.sleep(0.15)
|
||||
continue
|
||||
if keyboard.is_pressed('k'):
|
||||
lin_speed = round(max(0.0, lin_speed - lin_step), 2)
|
||||
print_help()
|
||||
time.sleep(0.15)
|
||||
continue
|
||||
if keyboard.is_pressed('j'):
|
||||
ang_speed = round(ang_speed + ang_step, 2)
|
||||
print_help()
|
||||
time.sleep(0.15)
|
||||
continue
|
||||
if keyboard.is_pressed('l'):
|
||||
ang_speed = round(max(0.0, ang_speed - ang_step), 2)
|
||||
print_help()
|
||||
time.sleep(0.15)
|
||||
continue
|
||||
|
||||
# Emergency stop
|
||||
if keyboard.is_pressed('space'):
|
||||
sock.sendto(struct.pack('dd', 0.0, 0.0), (ROBOT_IP, UDP_PORT))
|
||||
print("*** STOP ***")
|
||||
time.sleep(0.05)
|
||||
continue
|
||||
|
||||
# Combined movement: multi-key support
|
||||
lin = 0.0
|
||||
ang = 0.0
|
||||
|
||||
if keyboard.is_pressed('w'):
|
||||
lin += lin_speed
|
||||
if keyboard.is_pressed('s'):
|
||||
lin -= lin_speed
|
||||
if keyboard.is_pressed('a'):
|
||||
ang += ang_speed
|
||||
if keyboard.is_pressed('d'):
|
||||
ang -= ang_speed
|
||||
|
||||
# Single-key diagonals (override if used)
|
||||
if keyboard.is_pressed('q'):
|
||||
lin, ang = lin_speed, ang_speed
|
||||
if keyboard.is_pressed('e'):
|
||||
lin, ang = lin_speed, -ang_speed
|
||||
if keyboard.is_pressed('z'):
|
||||
lin, ang = -lin_speed, ang_speed
|
||||
if keyboard.is_pressed('c'):
|
||||
lin, ang = -lin_speed, -ang_speed
|
||||
|
||||
sock.sendto(struct.pack('dd', round(lin, 3), round(ang, 3)),
|
||||
(ROBOT_IP, UDP_PORT))
|
||||
|
||||
time.sleep(0.05) # 20Hz
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Installing keyboard library if needed...")
|
||||
try:
|
||||
import keyboard
|
||||
except ImportError:
|
||||
print("ERROR: 'keyboard' library not installed.")
|
||||
print("Run: pip install keyboard")
|
||||
sys.exit(1)
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user