Skip to content

Commit

Permalink
add: park gear shortcut
Browse files Browse the repository at this point in the history
Signed-off-by: Alptuğ Cırıt <[email protected]>
  • Loading branch information
mozhoku committed Sep 23, 2024
1 parent 45ac96b commit c4ab134
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Assets/AWSIM/Resources/Hotkeys.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"hotkeys": [
{
"key": "W / Up Arrow",
"description": "Throttle"
"description": "Forward"
},
{
"key": "S / Down Arrow",
"description": "Brake"
"description": "Brake & Reverse"
},
{
"key": "A / Left Arrow",
Expand All @@ -35,6 +35,10 @@
"key": "N",
"description": "Neutral Gear"
},
{
"key": "P",
"description": "Park Gear"
},
{
"key": "Left Alt",
"description": "Change Gear Mode"
Expand Down
14 changes: 14 additions & 0 deletions Assets/AWSIM/Scripts/UI/Toggle/UIKeyboardControlToggle.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
using AWSIM.Scripts.Vehicles.VPP_Integration;
using AWSIM.Scripts.Vehicles.VPP_Integration.Enums;
using UnityEngine;
using VehiclePhysics;

namespace AWSIM.Scripts.UI.Toggle
{
public class UIKeyboardControlToggle : MonoBehaviour
{
private GameObject _egoVehicle;
private AutowareVPPAdapter _adapter;
private VPVehicleController _controller;

private void Start()
{
_egoVehicle = GameObject.FindWithTag("Ego");
_adapter = _egoVehicle.GetComponent<AutowareVPPAdapter>();
_controller = _egoVehicle.GetComponent<VPVehicleController>();

// Set the toggle to the current state of the keyboard control mode
GetComponent<UnityEngine.UI.Toggle>().isOn = _adapter.ControlModeInput != VPPControlMode.Autonomous;
Expand All @@ -24,6 +27,17 @@ public void Activate()
Start();
}

private void Update()
{
if (_adapter.ControlModeInput == VPPControlMode.Manual)
{
if (Input.GetKeyDown(KeyCode.P))
{
_controller.data.bus[Channel.Input][InputData.AutomaticGear] = (int)Gearbox.AutomaticGear.P;
}
}
}

// Toggle the keyboard control
public void OnClick(bool isOn)
{
Expand Down
6 changes: 4 additions & 2 deletions docs/ProjectGuide/HotkeyList/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

| Key | Feature |
|:-----------------------|:------------------|
| W / Up Arrow | Throttle. |
| S / Down Arrow | Brake. |
| W / Up Arrow | Forward. |
| S / Down Arrow | Brake & Reverse. |
| A / Left Arrow | Steer Left. |
| D / Right Arrow | Steer Right. |
| Space | Handbrake. |
| Left Shift / Left Ctrl | Change Gear +/-. |
| R | Reverse Gear. |
| N | Neutral Gear. |
| P | Park Gear. |
| Left Alt | Change Gear Mode. |


### [VPPVehicleSignalHandler.cs](https://github.com/autowarefoundation/AWSIM-Labs/blob/main/Assets/AWSIM/Scripts/Vehicles/VPP%20Integration/VPPVehicleSignalHandler.cs)

| Key | Feature |
Expand Down

0 comments on commit c4ab134

Please sign in to comment.