Skip to content

Commit

Permalink
Added wall obstacle, fixed seed in results, fixed (!) physics, fixed …
Browse files Browse the repository at this point in the history
…start timeout
  • Loading branch information
noahzemlin committed Apr 12, 2020
1 parent 44ccd66 commit 01e4248
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 21 deletions.
126 changes: 126 additions & 0 deletions Unity/Assets/Prefabs/WallObstacle.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &263655742314861756
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 9049140628315696784}
- component: {fileID: 5164920174710020469}
- component: {fileID: 7430368685364654574}
- component: {fileID: 3856744250248823490}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &9049140628315696784
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 263655742314861756}
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: 235087896767986407}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &5164920174710020469
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 263655742314861756}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &7430368685364654574
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 263655742314861756}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: d66d47edfafaae64097082a5baaf9f3d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!65 &3856744250248823490
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 263655742314861756}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &3099440550098806083
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 235087896767986407}
m_Layer: 0
m_Name: WallObstacle
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 4294967295
m_IsActive: 1
--- !u!4 &235087896767986407
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3099440550098806083}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: 0}
m_LocalScale: {x: 2.5, y: 2, z: 1}
m_Children:
- {fileID: 9049140628315696784}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
7 changes: 7 additions & 0 deletions Unity/Assets/Prefabs/WallObstacle.prefab.meta

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

17 changes: 14 additions & 3 deletions Unity/Assets/RosSharpModules/ControlSubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ControlSubscriber : UnitySubscriber<Control>

private bool firstMessage = true;
private bool begingame = false;
private float startTime = 100000;

protected override void Start()
{
Expand All @@ -31,14 +32,24 @@ protected override void Start()

base.Start();
car = GetComponent<AckermannController>();
startTime = Time.realtimeSinceStartup;

if (!ConfigLoader.simulator.CompetitionMode) {
// Don't care about the stopsim stuff
begingame = false;
firstMessage = false;
GameManager.instance.StartSim();
}
}

private void Update()
{
private void FixedUpdate() {
if (begingame)
{
GameManager.instance.StartSim();
begingame = false;
GameManager.instance.StartSim();
}
if (firstMessage && !begingame && Time.realtimeSinceStartup - startTime >= 30) {
GameManager.instance.StopSim("Did not start in 30 seconds!");
}
}

Expand Down
8 changes: 3 additions & 5 deletions Unity/Assets/Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ MonoBehaviour:
- {fileID: 1923489091770420782, guid: 206c202f5305ed547acd125cc0ff283b, type: 3}
- {fileID: 3099440550098806083, guid: 38e6276f7bdfc8a4f97f931161c8351d, type: 3}
- {fileID: 510538099432521406, guid: d11cee11ba864484fb0f8e57b8efc5b5, type: 3}
- {fileID: 3099440550098806083, guid: 1db2593c3c7bc054886d1d97877d85ab, type: 3}
waypointPrefab: {fileID: 5216091860525757151, guid: ff26faa179beeaf43b9361021ef297a9,
type: 3}
height: 66
Expand Down Expand Up @@ -724,9 +725,6 @@ MonoBehaviour:
rightWheel: {fileID: 1857142558}
frontAxleTf: {fileID: 360597449}
robotCamera: {fileID: 1822220454}
drag: 0.85
L: 0.3
T: 0.26
ManualTopSpeed: 1
CntrlAngle: 0
CntrlPower: 0
Expand Down Expand Up @@ -824,14 +822,14 @@ Rigidbody:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 829615084}
serializedVersion: 2
m_Mass: 5
m_Mass: 2
m_Drag: 0
m_AngularDrag: 0
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 1
m_Constraints: 0
m_CollisionDetection: 0
m_CollisionDetection: 3
--- !u!153 &829615094
ConfigurableJoint:
m_ObjectHideFlags: 0
Expand Down
15 changes: 10 additions & 5 deletions Unity/Assets/Scripts/AckermannController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class AckermannController : MonoBehaviour
public GameObject robotCamera;

[Range(0.0F, 1.0F)]
public float drag = 0.85f;
private float drag = 0.85f;

public float L = 0.7f;
public float T = 0.6f;
private float L = 0.3f;
private float T = 0.26f;

[Range(0.0F, 10.0F)]
public float ManualTopSpeed = 1.0f;
Expand Down Expand Up @@ -55,6 +55,9 @@ void Start()
}

rb = GetComponent<Rigidbody>();
rb.centerOfMass = new Vector3(0,0,0);
rb.inertiaTensorRotation = Quaternion.identity;
rb.maxAngularVelocity = 100f;
}

// Update is called once per frame
Expand Down Expand Up @@ -92,9 +95,11 @@ private void FixedUpdate()
accel = (new_linear_vel - linear_vel) / Time.fixedDeltaTime;

linear_vel = new_linear_vel;
transform.Translate(linear_vel * Time.fixedDeltaTime, Space.World);
//transform.Translate(linear_vel * Time.fixedDeltaTime, Space.World);
rb.velocity = linear_vel;

angular_vel = new Vector3(0, Power / L * Mathf.Tan(radAngle), 0);
transform.Rotate(angular_vel * Mathf.Rad2Deg * Time.fixedDeltaTime, Space.World);
// transform.Rotate(angular_vel * Mathf.Rad2Deg * Time.fixedDeltaTime, Space.World);
rb.angularVelocity = angular_vel;
}
}
4 changes: 4 additions & 0 deletions Unity/Assets/Scripts/ConfigLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public static void LoadConfig()
simulator.ManualControl = false;
}

if (simulator.Seed == -1) {
simulator.Seed = UnityEngine.Random.Range(0, int.MaxValue);
}

// Load competition.cfg
try
{
Expand Down
5 changes: 2 additions & 3 deletions Unity/Assets/Scripts/FieldBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ public class FieldBuilder : MonoBehaviour
void Start()
{

GameObject waypointHolder = new GameObject("Waypoints");;
GameObject waypointHolder = new GameObject("Waypoints");

bool[,] maze;
HashSet<(int, int)> frontier;

if (ConfigLoader.simulator.Seed != -1)
Random.InitState(ConfigLoader.simulator.Seed);
Random.InitState(ConfigLoader.simulator.Seed);

Vector2[] waypoints = GameManager.instance.GetWaypoints();

Expand Down
9 changes: 5 additions & 4 deletions Unity/Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ void Initalize()

waypoints.Add(new Vector2(-37, 0)); // Start Pos

if (ConfigLoader.simulator.Seed != -1)
Random.InitState(ConfigLoader.simulator.Seed);
Random.InitState(ConfigLoader.simulator.Seed);

waypoints.Add(new Vector2(Random.Range(-20, -5), Random.Range(-10, 10)));
waypoints.Add(new Vector2(Random.Range(0, 15), Random.Range(-20, 20)));
Expand All @@ -98,7 +97,6 @@ private void FixedUpdate() {
{
if (ConfigLoader.simulator.CompetitionMode) {
StopSim("Connection to RosBridge lost!");
State = GameState.QUITTING;
} else {
ReloadSim();
}
Expand All @@ -115,7 +113,6 @@ private void FixedUpdate() {
if (State == GameState.PLAYING && ConfigLoader.simulator.CompetitionMode && Time.time - startTime >= maxTime)
{
StopSim(null);
State = GameState.QUITTING;
}
}

Expand Down Expand Up @@ -177,6 +174,10 @@ public void UpdateRoot() {

public void StopSim(string error)
{
if (State == GameState.QUITTING) {
return; // Already quitting
}
State = GameState.QUITTING;
float finalTime = Time.time - startTime;

if (finalTime > maxTime) {
Expand Down
2 changes: 1 addition & 1 deletion Unity/ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 2.0
bundleVersion: 3.0
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand Down

0 comments on commit 01e4248

Please sign in to comment.