Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
daviduhm committed Apr 24, 2020
0 parents commit 177750a
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
74 changes: 74 additions & 0 deletions LaneFollowingSensor.cs
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)
{
//
}
}
}
11 changes: 11 additions & 0 deletions LaneFollowingSensor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions LaneFollowingSensor.prefab
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:
7 changes: 7 additions & 0 deletions LaneFollowingSensor.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 177750a

Please sign in to comment.