forked from lgsvl/LaneFollowingSensor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 177750a
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Copyright (c) 2020 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 Simulator.Bridge.Ros; | ||
using System.Collections.Generic; | ||
|
||
namespace Simulator.Sensors | ||
{ | ||
[SensorType("Lane Following", new System.Type[] { })] | ||
public class LaneFollowingSensor : SensorBase, IVehicleInputs | ||
{ | ||
private float ADSteerInput = 0f; | ||
private double LastControlUpdate = 0f; | ||
|
||
public float SteerInput { get; private set; } = 0f; | ||
public float AccelInput { get; private set; } = 0f; | ||
public float BrakeInput { get; private set; } = 0f; | ||
|
||
private void Awake() | ||
{ | ||
LastControlUpdate = SimulatorManager.Instance.CurrentTime; | ||
} | ||
|
||
public override void OnBridgeSetup(IBridge bridge) | ||
{ | ||
bridge.AddReader<TwistStamped>(Topic, data => | ||
{ | ||
LastControlUpdate = SimulatorManager.Instance.CurrentTime; | ||
ADSteerInput = (float)data.twist.angular.x; | ||
}); | ||
} | ||
|
||
public void Update() | ||
{ | ||
if (SimulatorManager.Instance.CurrentTime - LastControlUpdate >= 0.5) | ||
{ | ||
ADSteerInput = SteerInput = 0f; | ||
} | ||
} | ||
|
||
private void FixedUpdate() | ||
{ | ||
if (SimulatorManager.Instance.CurrentTime - LastControlUpdate < 0.5f) | ||
{ | ||
SteerInput = ADSteerInput; | ||
} | ||
} | ||
|
||
public override void OnVisualize(Visualizer visualizer) | ||
{ | ||
Debug.Assert(visualizer != null); | ||
var graphData = new Dictionary<string, object>() | ||
{ | ||
{"AD Steer Input", ADSteerInput}, | ||
{"Last Control Update", LastControlUpdate}, | ||
}; | ||
|
||
visualizer.UpdateGraphValues(graphData); | ||
} | ||
|
||
public override void OnVisualizeToggle(bool state) | ||
{ | ||
// | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!1 &7421421382082150271 | ||
GameObject: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
serializedVersion: 6 | ||
m_Component: | ||
- component: {fileID: 2562287667199667010} | ||
- component: {fileID: 5791120669988743586} | ||
m_Layer: 0 | ||
m_Name: LaneFollowingSensor | ||
m_TagString: Untagged | ||
m_Icon: {fileID: 0} | ||
m_NavMeshLayer: 0 | ||
m_StaticEditorFlags: 0 | ||
m_IsActive: 1 | ||
--- !u!4 &2562287667199667010 | ||
Transform: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 7421421382082150271} | ||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} | ||
m_LocalPosition: {x: 0, y: 0, z: 0} | ||
m_LocalScale: {x: 1, y: 1, z: 1} | ||
m_Children: [] | ||
m_Father: {fileID: 0} | ||
m_RootOrder: 0 | ||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
--- !u!114 &5791120669988743586 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 7421421382082150271} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: d82409b4466fbf38eaab962e12c22546, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
Name: Lane Following | ||
Topic: | ||
Frame: |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.