-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
Override input for vehicle
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
namespace AWSIM | ||
{ | ||
public class ControlModeUI : MonoBehaviour | ||
{ | ||
[SerializeField] VehicleOverrideInputManager vehicleOverrideInputManager; | ||
[SerializeField] Text text; | ||
|
||
void Update() | ||
{ | ||
text.text = vehicleOverrideInputManager.ControlMode.ToString(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using ROS2; | ||
|
||
namespace AWSIM | ||
{ | ||
/// <summary> | ||
/// Subscribe to the "/vehicle/engage" topic and change the vehicle's control mode to AUTONOMOUS. | ||
/// </summary> | ||
public class EngageSubscriber : MonoBehaviour | ||
{ | ||
[SerializeField] string engageTopic = "/vehicle/engage"; | ||
[SerializeField] QoSSettings qosSettings = new QoSSettings(); | ||
ISubscription<autoware_auto_vehicle_msgs.msg.Engage> engageSubscriber; | ||
|
||
[SerializeField] VehicleOverrideInputManager vehicleOverrideInputManager; | ||
void Reset() | ||
{ | ||
qosSettings.ReliabilityPolicy = ReliabilityPolicy.QOS_POLICY_RELIABILITY_RELIABLE; | ||
qosSettings.DurabilityPolicy = DurabilityPolicy.QOS_POLICY_DURABILITY_TRANSIENT_LOCAL; | ||
qosSettings.HistoryPolicy = HistoryPolicy.QOS_POLICY_HISTORY_KEEP_LAST; | ||
qosSettings.Depth = 1; | ||
} | ||
|
||
void OnEnable() | ||
{ | ||
var qos = qosSettings.GetQoSProfile(); | ||
|
||
engageSubscriber = SimulatorROS2Node.CreateSubscription<autoware_auto_vehicle_msgs.msg.Engage>( | ||
engageTopic, msg => | ||
{ | ||
if (msg.Engage_) | ||
{ | ||
vehicleOverrideInputManager.ChangeControlModeToAUTONOMOUS(); | ||
} | ||
}, qos); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace AWSIM | ||
{ | ||
/// <summary> | ||
/// C# enum for Autoware's ControlMode. (No dependency on ROS2) | ||
/// VehicleROS2Utility.UnityToRosControlMode() can be used to convert C# enum to ros msg. | ||
/// <see href="https://github.com/autowarefoundation/autoware_msgs/blob/main/autoware_vehicle_msgs/msg/ControlModeReport.msg"/> | ||
/// </summary> | ||
public enum VehicleControlMode | ||
{ | ||
// NO_COMMAND = 0, | ||
AUTONOMOUS = 1, | ||
// AUTONOMOUS_STEER_ONLY = 2, | ||
// AUTONOMOUS_VELOCITY_ONLY = 3, | ||
MANUAL = 4, | ||
// DISENGAGED = 5, | ||
// NOT_READY = 6 | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace AWSIM | ||
{ | ||
/// <summary> | ||
/// Input base class to the vehicle. | ||
/// By creating arbitrary input classes to the vehicle (keyboard, steering controller, etc.) | ||
/// that inherit from this class, you can reproduce actual vehicle input overrides. | ||
/// Actual vehicle input is performed by VehicleOverrideInputManager. | ||
/// </summary> | ||
[RequireComponent(typeof(VehicleOverrideInputManager))] | ||
public class VehicleInputBase : MonoBehaviour | ||
{ | ||
/// <summary> | ||
/// Acceleration(m/s^2) to be applied to Vehicle acquired from Input. | ||
/// </summary> | ||
public float AccelerationInput { get; protected set; } = 0; | ||
|
||
/// <summary> | ||
/// Steering to be applied to Vehicle acquired from Input. | ||
/// </summary> | ||
public float SteeringInput { get; protected set; } = 0; | ||
|
||
/// <summary> | ||
/// Shift to be applied to Vehicle acquired from Input. | ||
/// </summary> | ||
public Vehicle.Shift ShiftInput { get; protected set; } = Vehicle.Shift.PARKING; | ||
|
||
/// <summary> | ||
/// TurnSignal to be applied to Vehicle acquired from Input. | ||
/// </summary> | ||
public Vehicle.TurnSignal TurnSignalInput { get; protected set; } = Vehicle.TurnSignal.NONE; | ||
|
||
/// <summary> | ||
/// Is there an input override to the vehicle? | ||
/// </summary> | ||
public bool Overridden { get; protected set; } = false; | ||
|
||
/// <summary> | ||
/// New control mode when input override occurs. | ||
/// Used by VehicleOverrideInputManager class when Overridden property is true. | ||
/// </summary> | ||
public VehicleControlMode NewControlMode { get; protected set; } = VehicleControlMode.AUTONOMOUS; | ||
|
||
/// <summary> | ||
/// Instead of unity callback Update(), this method is overridden and used to get inputs. | ||
/// This method is called by the VehicleOverrideInputManager class. | ||
/// </summary> | ||
/// <param name="currentControlMode"></param> | ||
public virtual void OnUpdate(VehicleControlMode currentControlMode) | ||
{ | ||
// Override this method to get inputs! | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.