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

[Car] Add control to change use mode when ai driving #302

Open
wants to merge 2 commits 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
2 changes: 1 addition & 1 deletion ansible/roles/donkeycar/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
dest: /home/pi/projects/
force: yes
single_branch: yes
version: main
version: eedd7eddbfb209006066bb716eb8e68d5d68d3a5

- name: Create python3 virtual environment & install tensorflow
become: yes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def run_threaded(self,
controller_x_pressed: Optional[bool]=False,
inverted: Optional[bool]=False,
scale: Optional[float]=0.5,
cam_image_array: Optional[Any] = None
cam_image_array: Optional[Any] = None,
use_pilot_angle: Optional[bool] = None
) -> Tuple[float, str, bool, bool, float, float, str]:
"""
:param user_throttle: User throttle value
Expand Down Expand Up @@ -143,7 +144,8 @@ def run_threaded(self,
laptimer_last_lap_end_date_time,
laptimer_laps_total,
controller_x_pressed,
cam_image_array
cam_image_array,
use_pilot_angle
)
return res

Expand Down
3 changes: 2 additions & 1 deletion ansible/roles/mycar/files/custom/car/services/jobs/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def run_threaded(self,
laptimer_last_lap_end_date_time: Optional[datetime] = None,
laptimer_laps_total: Optional[int] = None,
controller_x_pressed: Optional[bool] = False,
cam_image_array: Optional[Any] = None
cam_image_array: Optional[Any] = None,
use_pilot_angle: Optional[bool] = None
) -> Tuple[float, str, bool, bool]:
"""
Part run threaded, is call with all donekcarmanacer I/O.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def run_threaded(self,
laptimer_last_lap_end_date_time: Optional[datetime] = None,
laptimer_laps_total: Optional[int] = None,
controller_x_pressed: Optional[bool] = False,
cam_image_array: Optional[Any] = None
cam_image_array: Optional[Any] = None,
use_pilot_angle: Optional[bool] = None
) -> Tuple[float, str, bool]:
"""
Part run_threaded call.
Expand All @@ -104,7 +105,8 @@ def run_threaded(self,
laptimer_last_lap_end_date_time,
laptimer_laps_total,
controller_x_pressed,
cam_image_array)
cam_image_array,
use_pilot_angle)

# Default values
user_throttle = 0.0
Expand All @@ -113,7 +115,7 @@ def run_threaded(self,
recording_state = False
pilot_angle = 0
pilote_throttle = 0
user_mode = 'auto_pilote'
user_mode = 'local_angle' if use_pilot_angle else 'local'

if self.drive_stage == JobAiAssistedStage.MODEL_DRIVING:
laptimer_reset_all = self.race_service.handle_laptimer_outputs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def run_threaded(self,
laptimer_last_lap_end_date_time: Optional[datetime] = None,
laptimer_laps_total: Optional[int] = None,
controller_x_pressed: Optional[bool] = False,
cam_image_array: Optional[Any] = None
cam_image_array: Optional[Any] = None,
use_pilot_angle: Optional[bool] = None
) -> Tuple[float, str, bool]:
"""
Part run_threaded call.
Expand All @@ -81,7 +82,8 @@ def run_threaded(self,
laptimer_last_lap_end_date_time,
laptimer_laps_total,
controller_x_pressed,
cam_image_array)
cam_image_array,
use_pilot_angle)
laptimer_reset_all = True

if self.drive_stage == JobDriveStage.USER_NOT_CONFIRMED: # user not confirmed yet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def run_threaded(self,
laptimer_last_lap_end_date_time: Optional[datetime] = None,
laptimer_laps_total: Optional[int] = None,
controller_x_pressed: Optional[bool] = False,
cam_image_array: Optional[Any] = None
cam_image_array: Optional[Any] = None,
use_pilot_angle: Optional[bool] = None
) -> Tuple[float, str, bool, bool]:
user_throttle, job_name, laptimer_reset_all, recording_state, pilote_angle, pilote_throttle, user_mode = super(JobRecord, self).run_threaded(
user_throttle,
Expand All @@ -117,7 +118,8 @@ def run_threaded(self,
laptimer_last_lap_end_date_time,
laptimer_laps_total,
controller_x_pressed,
cam_image_array)
cam_image_array,
use_pilot_angle)
job_name = 'RECORD'
user_mode = 'user'

Expand Down
6 changes: 4 additions & 2 deletions ansible/roles/mycar/files/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def drive(cfg, model_path=None, use_joystick=False, model_type=None,
'recording',
'controller/x_pressed',
'controller/inverted',
'controller/scale'
'controller/scale',
'controller/use_pilot_angle'
],
threaded=True)

Expand Down Expand Up @@ -302,7 +303,8 @@ def drive(cfg, model_path=None, use_joystick=False, model_type=None,
'controller/x_pressed',
'controller/inverted',
'controller/scale',
'cam/image_array'
'cam/image_array',
'controller/use_pilot_angle'
],
outputs=[
'user/throttle',
Expand Down
8 changes: 6 additions & 2 deletions ansible/roles/mycar/files/my_joystick.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def __init__(self, *args, **kwargs):
self.inverted = False
super(MyJoystickController, self).__init__(*args, **kwargs)
self.state_x_button = False
self.use_pilot_angle = False
self.js = None

def init_js(self):
Expand Down Expand Up @@ -191,6 +192,9 @@ def forward_throttle(self):
def throttle_stop(self):
self.set_throttle(0)

def toggle_use_pilot_angle(self):
self.use_pilot_angle = not self.use_pilot_angle

def init_trigger_maps(self):
"""
init set of mapping from buttons to function calls
Expand All @@ -200,7 +204,7 @@ def init_trigger_maps(self):
'b_button': self.go_easy_mode,
'a_button': self.invert_controls,
'x_button': self.x_button_pressed,
'y_button': self.emergency_stop,
'y_button': self.toggle_use_pilot_angle,
'right_shoulder': self.increase_max_throttle,
'left_shoulder': self.decrease_max_throttle,
'options': self.toggle_constant_throttle,
Expand Down Expand Up @@ -298,7 +302,7 @@ def run_threaded(self, img_arr=None, mode=None, recording=None, manager_job_name
if o_x_pressed:
self.state_x_button = False # resetting it for next turns

return o_angle, o_throttle, o_mode, o_recording, o_x_pressed, self.inverted, self.throttle_scale
return o_angle, o_throttle, o_mode, o_recording, o_x_pressed, self.inverted, self.throttle_scale, self.use_pilot_angle

def update(self):
while True:
Expand Down