Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change AI throttle Multiplier on the joystick #943

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
21 changes: 21 additions & 0 deletions donkeycar/parts/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ def __init__(self, poll_delay=0.0,
throttle_scale=1.0,
steering_scale=1.0,
throttle_dir=-1.0,
ai_scale = 1.0,
dev_fn='/dev/input/js0',
auto_record_on_throttle=True):

Expand All @@ -833,6 +834,7 @@ def __init__(self, poll_delay=0.0,
self.last_throttle_axis_val = 0
self.throttle_scale = throttle_scale
self.steering_scale = steering_scale
self.ai_scale = ai_scale
self.throttle_dir = throttle_dir
self.recording = False
self.constant_throttle = False
Expand Down Expand Up @@ -1044,6 +1046,22 @@ def decrease_max_throttle(self):

print('throttle_scale:', self.throttle_scale)

def increase_ai_throttle(self):
'''
increase AI throttle scale setting
'''
self.ai_scale = round(min(2.0, self.ai_scale + 0.01), 3)

print('AI scale :', self.ai_scale)

def decrease_ai_throttle(self):
'''
decrrease AI throttle scale setting
'''
self.ai_scale = round(max(0.0, self.ai_scale - 0.01), 2)

print('AI Scale:', self.ai_scale)


def toggle_constant_throttle(self):
'''
Expand Down Expand Up @@ -1193,6 +1211,8 @@ def init_trigger_maps(self):
'cross' : self.emergency_stop,
'dpad_up' : self.increase_max_throttle,
'dpad_down' : self.decrease_max_throttle,
'dpad_left' : self.decrease_ai_throttle,
'dpad_right' : self.increase_ai_throttle,
'start' : self.toggle_constant_throttle,
"R1" : self.chaos_monkey_on_right,
"L1" : self.chaos_monkey_on_left,
Expand Down Expand Up @@ -1681,6 +1701,7 @@ def get_js_controller(cfg):
ctr = cont_class(throttle_dir=cfg.JOYSTICK_THROTTLE_DIR,
throttle_scale=cfg.JOYSTICK_MAX_THROTTLE,
steering_scale=cfg.JOYSTICK_STEERING_SCALE,
ai_scale = cfg.AI_THROTTLE_MULT,
auto_record_on_throttle=cfg.AUTO_RECORD_ON_THROTTLE,
dev_fn=cfg.JOYSTICK_DEVICE_FILE)

Expand Down
6 changes: 5 additions & 1 deletion donkeycar/templates/complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def drive(cfg, model_path=None, use_joystick=False, model_type=None,
throttle_dir=cfg.JOYSTICK_THROTTLE_DIR,
throttle_scale=cfg.JOYSTICK_MAX_THROTTLE,
steering_scale=cfg.JOYSTICK_STEERING_SCALE,
ai_scale = cfg.AI_THROTTLE_MULT,
auto_record_on_throttle=cfg.AUTO_RECORD_ON_THROTTLE)
ctr.set_deadzone(cfg.JOYSTICK_DEADZONE)
elif cfg.CONTROLLER_TYPE == "MM1":
Expand Down Expand Up @@ -488,6 +489,9 @@ class DriveMode:
def run(self, mode,
user_angle, user_throttle,
pilot_angle, pilot_throttle):

mul = ctr.ai_scale
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this expected to work if ctr != MyJoyStickController?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this expected to work if ctr != MyJoyStickController?


if mode == 'user':
return user_angle, user_throttle

Expand All @@ -496,7 +500,7 @@ def run(self, mode,

else:
return pilot_angle if pilot_angle else 0.0, \
pilot_throttle * cfg.AI_THROTTLE_MULT \
pilot_throttle * mul \
if pilot_throttle else 0.0

V.add(DriveMode(),
Expand Down