-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCruiseControlSensor.cs
89 lines (73 loc) · 2.58 KB
/
CruiseControlSensor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Copyright (c) 2019-2021 LG Electronics, Inc.
*
* This software contains code licensed as described in LICENSE.
*
*/
using UnityEngine;
using Simulator.Bridge;
using Simulator.Utilities;
using Simulator.Sensors.UI;
using System.Collections.Generic;
namespace Simulator.Sensors
{
[SensorType("Cruise Control", new System.Type[] { })]
public class CruiseControlSensor : SensorBase, IVehicleInputs
{
[SensorParameter]
[Range(0.0f, 200f)]
public float CruiseSpeed = 0f;
private IVehicleDynamics Dynamics;
private IAgentController Controller;
public float SteerInput { get; private set; } = 0f;
public float AccelInput { get; private set; } = 0f;
public float BrakeInput { get; private set; } = 0f;
[AnalysisMeasurement(MeasurementType.Velocity)]
public float MaxSpeed = 0;
public override SensorDistributionType DistributionType => SensorDistributionType.MainOrClient;
public override float PerformanceLoad { get; } = 0.05f;
protected override void Initialize()
{
Dynamics = GetComponentInParent<IVehicleDynamics>();
Controller = GetComponentInParent<IAgentController>();
}
protected override void Deinitialize()
{
}
public void Update()
{
Debug.Assert(Dynamics != null);
if (Controller.AccelInput >= 0)
{
AccelInput = Dynamics.Velocity.magnitude < CruiseSpeed ? 1f : 0f;
}
MaxSpeed = Mathf.Max(MaxSpeed, Dynamics.Velocity.magnitude);
}
public override void OnBridgeSetup(BridgeInstance bridge)
{
// TODO new base class?
}
public override void OnVisualize(Visualizer visualizer)
{
Debug.Assert(visualizer != null);
var graphData = new Dictionary<string, object>()
{
{"Cruise Speed", CruiseSpeed},
{"Steer Input", SteerInput},
{"Accel Input", AccelInput},
{"Speed", Dynamics.Velocity.magnitude},
{"Hand Brake", Dynamics.HandBrake},
{"Ignition", Dynamics.CurrentIgnitionStatus},
{"Reverse", Dynamics.Reverse},
{"Gear", Dynamics.CurrentGear},
{"RPM", Dynamics.CurrentRPM},
{"Velocity", Dynamics.Velocity}
};
visualizer.UpdateGraphValues(graphData);
}
public override void OnVisualizeToggle(bool state)
{
//
}
}
}