Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4c8c7d9
WIP bus servo management
danic85 Jul 12, 2025
d18189c
Update config
danic85 Jul 12, 2025
60d524a
Added SC servo examples + compatibility
danic85 Jul 13, 2025
3e4dfc0
Configure initial positions
danic85 Jul 14, 2025
0be65a3
Allow other poses to be stored and accessed
danic85 Jul 14, 2025
91fac95
Added change_id script
danic85 Aug 3, 2025
69f2d7c
Calibrate servos on boot
danic85 Oct 4, 2025
9a57f8a
adjustments
danic85 Oct 4, 2025
0cf906e
Dynamic servo calibration + center on change_id
danic85 Oct 5, 2025
8d62b54
Controller support and WIP recording
danic85 Dec 13, 2025
f02d0db
Working with Pi
danic85 Dec 13, 2025
b052ed0
Adjust config
danic85 Dec 13, 2025
6841f63
Cleanup
danic85 Dec 14, 2025
c1ed384
Working input recorder
danic85 Dec 14, 2025
5e503e5
Support servo control (WIP - calibration needed)
danic85 Dec 14, 2025
008c369
Callibration + allow modules to be disabled on test environments
danic85 Dec 15, 2025
af0fdb2
Disable test
danic85 Dec 15, 2025
40040c8
Add documentation and tests
danic85 Dec 16, 2025
f645caa
Fix test
danic85 Dec 16, 2025
8a22781
Timeout controller connection after 30 seconds
danic85 Dec 16, 2025
d81c07c
Enable on robot
danic85 Dec 16, 2025
6a84d43
Fix for environment input to resolve pi issue
danic85 Dec 17, 2025
4803d58
Calibrate new leg position
danic85 Dec 17, 2025
dc4cb27
Improvements to gamepad controller modules. Temperature alert in disp…
danic85 Dec 18, 2025
d48ccd8
Fix tests
danic85 Dec 18, 2025
4a5a0ee
Fixes and improvements to loop and temperature management
danic85 Dec 21, 2025
5349956
Fix tests
danic85 Dec 21, 2025
cd4331b
Resolve PR comments
danic85 Dec 21, 2025
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
Prev Previous commit
Next Next commit
Adjust config
  • Loading branch information
danic85 committed Dec 13, 2025
commit b052ed0d833246de91a3c422ad6f08fe29b33123
18 changes: 11 additions & 7 deletions config/controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ controller:
args: {}
BTN_A:
- topic: 'tts'
msg: 'Test Default'
args: {
msg: 'Test Default'
}
BTN_X:
- topic: 'eye/blink'
args: {}
Expand All @@ -44,17 +46,17 @@ controller:
BTN_B:
- topic: ''
args: {}
ABS_RX:
ABS_RZ:
- topic: 'servo:pan:mv'
args: {}
deadzone: 200
modifier:
scale: 1.0
ABS_RY:
scale: 0.01
ABS_RX:
- topic: 'servo:tilt:mv'
args: {}
modifier:
scale: 1.0
scale: -0.01
ABS_X:
- topic: 'eye/move'
args: {axis: 'y'}
Expand All @@ -68,13 +70,15 @@ controller:
ABS_Z: # Left trigger
- topic: ''
args: {}
ABS_RZ: # Right trigger
ABS_RY: # Right trigger
- topic: ''
args: {}
BTN_TR:
BTN_A:
- topic: 'tts'
msg: 'Left Shoulder Held'
args: {
msg: 'Left Shoulder Held'
}
ABS_X:
- topic: 'servo:leg_l_ankle:mv'
modifier:
Expand Down
81 changes: 5 additions & 76 deletions modules/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def handle_js_event(self, time_ms, value, type_, number):
JS_EVENT_BUTTON = 1
JS_EVENT_AXIS = 0x02
JS_EVENT_INIT = 0x80

topic = None
args = {}

is_init = (type_ & JS_EVENT_INIT) != 0
event_type = type_ & ~JS_EVENT_INIT
Expand All @@ -68,7 +71,6 @@ def handle_js_event(self, time_ms, value, type_, number):
if event_type == JS_EVENT_BUTTON:
# self.log(f"JS Button Event: number={number} value={value} (init={is_init})")
button = button_names.get(number, f'BTN_{number}')
self.log(f"Button event: {button} value={value} (jsdev)")
# value: 1=pressed, 0=released
if value == 1:
self.pressed_buttons.add(button)
Expand All @@ -77,10 +79,7 @@ def handle_js_event(self, time_ms, value, type_, number):

active_mods = sorted([b for b in self.pressed_buttons if b in self.modifier_buttons])
mapping_key = '+'.join(active_mods) if active_mods else 'default'
self.log(f"Active modifiers: {active_mods} (jsdev)")
button_map = self.button_action_map.get(mapping_key, self.button_action_map.get('default', {}))

self.log(button)
if button in button_map and value == 1:
actions = button_map[button]
for mapping in actions:
Expand All @@ -99,7 +98,6 @@ def handle_js_event(self, time_ms, value, type_, number):
active_mods = sorted([b for b in self.pressed_buttons if b in self.modifier_buttons])
mapping_key = '+'.join(active_mods) if active_mods else 'default'
button_map = self.button_action_map.get(mapping_key, self.button_action_map.get('default', {}))
self.log(f"Active modifiers: {active_mods} (jsdev)")

if axis in button_map:
actions = button_map[axis]
Expand All @@ -122,6 +120,7 @@ def handle_js_event(self, time_ms, value, type_, number):

topic = mapping.get('topic')
if not topic:
self.log(f"Empty topic for axis {axis} mapping, skipping.", level='warning')
continue # Skip empty topic
args = dict(mapping.get('args', {})) # Copy to avoid mutation
modifier = mapping.get('modifier', None)
Expand All @@ -131,77 +130,7 @@ def handle_js_event(self, time_ms, value, type_, number):
# self.log(f"Axis {axis} moved to {args.get('delta', value)} (jsdev)")
self.publish(topic, **args)
self.log(f"Published to topic {topic} with args {args} (jsdev)")

def handle_event(self, event):
# if event.code == 'ABS_Y':
# self.log(f"Event: {event.ev_type} {event.code} {event.state}")
event.modifier_buttons = list(self.pressed_buttons)

# Track pressed/released buttons for modifiers
if event.ev_type == 'Key':
if event.state == 1:
self.pressed_buttons.add(event.code)
elif event.state == 0 and event.code in self.pressed_buttons:
self.pressed_buttons.remove(event.code)

# Determine current mapping set
mapping_key = None
# Only consider modifier buttons for mapping key
active_mods = sorted([b for b in self.pressed_buttons if b in self.modifier_buttons])
if active_mods:
mapping_key = '+'.join(active_mods)
else:
mapping_key = 'default'
button_map = self.button_action_map.get(mapping_key, self.button_action_map.get('default', {}))

# Handle digital button press (use dynamic mapping)
if (event.ev_type == 'Key' or event.code.startswith('ABS_HAT')) and (event.state == 1 or event.state == -1):
self.log(f"Button {event.code} pressed")
button = event.code
if button in button_map:
actions = button_map[button]
for mapping in actions:
topic = mapping.get('topic')
args = mapping.get('args', {})

self.publish(topic, **args)
event.topic = topic
event.args = args
# Handle analog stick/trigger movement (use dynamic mapping)
elif event.ev_type == 'Absolute':
axis = event.code
value = event.state
if axis in button_map:
actions = button_map[axis]
for mapping in actions:
deadzone = mapping.get('deadzone', self.global_deadzone)
if deadzone > abs(value):
continue # Skip if within deadzone

debounce = mapping.get('debounce', self.global_debounce) # debounce in ms
now = int(time.time() * 1000) # current time in ms
last_time = self.axis_last_time.get(axis, None)

# Only allow if enough time has passed
if last_time is not None and (now - last_time) < debounce:
continue # Skip if within debounce interval
self.axis_last_time[axis] = now
last_value = self.axis_last_value.get(axis, 0)
delta = value - last_value
self.axis_last_value[axis] = value


topic = mapping.get('topic')
args = dict(mapping.get('args', {})) # Copy to avoid mutation
modifier = mapping.get('modifier', None)
if modifier is not None:
scale = modifier.get('scale', 1.0)
args['delta'] = delta * scale
self.log(f"Axis {axis} moved to {args['delta']}")
self.publish(topic, **args)
event.topic = topic
event.args = args
self.publish('controller/event', event=event)
self.publish('controller/event', event=(time_ms, value, type_, number, topic, args))

def stop(self):
self.running = False
Expand Down