Skip to content
Merged
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
20 changes: 20 additions & 0 deletions README1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# OpenPilot Custom Modifications

This repository contains custom modifications to OpenPilot(steering and accelaration), including updates to the keyboard and joystick control files.

## Modified Files

1. **Keyboard Control File:**
- File: `tools/lib/keyboard_ctrl.py`
- Description: Custom changes to the keyboard control logic to integrate with the new GUI button.
- Path in Repository: [tools/lib/keyboard_ctrl.py](https://github.com/Sage-A/openpilot/blob/ADbranch/tools/lib/keyboard_ctrl.py)

2. **Joystick Control File:**
- File: `tools/sim/joystick_control.py`
- Description: Modifications to the joystick control to handle new input methods, including GUI-based control.
- Path in Repository: [tools/sim/joystick_control.py](https://github.com/Sage-A/openpilot/blob/ADbranch/tools/sim/joystick_control.py)

## How to Set Up

Find instructions on how to set up/build Openpilot in the README.md file in openpilot/tools.
Find instructions on how to run MetaSim in the README.md file in openpilot/tools/sim.
10 changes: 6 additions & 4 deletions tools/joystick/joystick_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

class Keyboard:
def __init__(self):
managed_processes['ui'].w.customWindow.accelDown.connect(self.GUI_ACCEL)
managed_processes['ui'].w.customWindow.accelRelease.connect(self.GUI_ACCEL)
self.kb = KBHit()
self.axis_increment = 0.05 # 5% of full actuation each key press
self.axes_map = {'b': 'gb', 's': 'gb',
self.axes_map = {'GUI_ACCEL': 'gb', 's': 'gb',
'a': 'steer', 'd': 'steer'}
self.axes_values = {'gb': 0., 'steer': 0.}
self.axes_order = ['gb', 'steer']
Expand All @@ -33,7 +35,7 @@ def update(self):
self.cancel = True
elif key in self.axes_map:
axis = self.axes_map[key]
incr = self.axis_increment if key in ['b', 'a'] else -self.axis_increment
incr = self.axis_increment if key in ['GUI_ACCEL', 'a'] else -self.axis_increment
self.axes_values[axis] = float(np.clip(self.axes_values[axis] + incr, -1, 1))
else:
return False
Expand All @@ -42,7 +44,7 @@ def update(self):
class SteeringGUI:
def __init__(self, steer_slider):
# Refers to the acceleration and steering inputs
self.accel_axis = 'GUI_ACCEL'
self.accel_axis = 'b'
self.steer_axis = 'GUI_STEER'

# Acceleration and steering both range from -1.0 to 1.0
Expand Down Expand Up @@ -192,7 +194,7 @@ def main():
if args.gui:
print('Using GUI for control (slider + throttle inputs).')
elif args.keyboard:
print('Gas/brake control: `B` and `S` keys')
print('Gas/brake control: `GUI_ACCEL` and `S` keys')
print('Steering control: `A` and `D` keys')
print('Buttons')
print('- `R`: Resets axes')
Expand Down
4 changes: 2 additions & 2 deletions tools/sim/lib/keyboard_ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
| r | Reset Simulation |
| i | Toggle Ignition |
| q | Exit all |
| basd | Control manually |
| GUI_ACCELasd | Control manually |
"""


Expand Down Expand Up @@ -66,7 +66,7 @@ def keyboard_poll_thread(q: 'Queue[QueueMessage]'):
q.put(control_cmd_gen("cruise_down"))
elif c == '3':
q.put(control_cmd_gen("cruise_cancel"))
elif c == 'b':
elif c == 'GUI_ACCEL':
q.put(control_cmd_gen(f"throttle_{100.0}"))
elif c == 'a':
q.put(control_cmd_gen(f"steer_{-0.15}"))
Expand Down
Loading