Skip to content
This repository has been archived by the owner on Feb 24, 2022. It is now read-only.

Commit

Permalink
feat + fix: Increased speed of car in controls projects to 200 MPH,
Browse files Browse the repository at this point in the history
updated menu to show EKF and UKF use same scene and Run Away Car is a
Bonus Challenge, fixed timing issue in PF so that no matter what the
delay, the accuracy result doesnt change also added timing constraint of
100 seconds to finish to pass.
  • Loading branch information
awbrown90 committed May 24, 2017
1 parent b41bbc4 commit 60c8577
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 30 deletions.
78 changes: 78 additions & 0 deletions Assets/1_SelfDrivingCar/Scenes/project_3/particle_filter_v2.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,7 @@ MonoBehaviour:
- {fileID: 2039399158}
run_button: {fileID: 323763175}
time: {fileID: 1046353007}
system_time: {fileID: 1792479840}
status: {fileID: 1242085451}
average_error: {fileID: 801420254}
map_data: {fileID: 4900000, guid: 76bf173f65b03954ab091848e5a087c7, type: 3}
Expand Down Expand Up @@ -5957,6 +5958,7 @@ RectTransform:
- {fileID: 801420253}
- {fileID: 1242085450}
- {fileID: 1046353006}
- {fileID: 1792479839}
m_Father: {fileID: 610982329}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -7360,6 +7362,82 @@ Transform:
m_Father: {fileID: 614215526}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 90}
--- !u!1 &1792479838
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1792479839}
- component: {fileID: 1792479841}
- component: {fileID: 1792479840}
m_Layer: 5
m_Name: time_system
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1792479839
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1792479838}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1.0000113, y: 1.0000113, z: 1.0000113}
m_Children: []
m_Father: {fileID: 1095899312}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -504, y: 193}
m_SizeDelta: {x: -1150, y: -679}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1792479840
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1792479838}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0, b: 0, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 26
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 2
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: 'System Time: 2000
'
--- !u!222 &1792479841
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1792479838}
--- !u!1 &1844053175
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2059,12 +2059,16 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 11400002, guid: 0e7ee4df08df88c4880f43398f9ad2c2, type: 2}
propertyPath: m_Topspeed
value: 100
value: 200
objectReference: {fileID: 0}
- target: {fileID: 100042, guid: 0e7ee4df08df88c4880f43398f9ad2c2, type: 2}
propertyPath: m_Name
value: Car
objectReference: {fileID: 0}
- target: {fileID: 11400002, guid: 0e7ee4df08df88c4880f43398f9ad2c2, type: 2}
propertyPath: m_Downforce
value: 100
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 0e7ee4df08df88c4880f43398f9ad2c2, type: 2}
m_IsPrefabParent: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 11400002, guid: 0e7ee4df08df88c4880f43398f9ad2c2, type: 2}
propertyPath: m_Topspeed
value: 100
value: 200
objectReference: {fileID: 0}
- target: {fileID: 100042, guid: 0e7ee4df08df88c4880f43398f9ad2c2, type: 2}
propertyPath: m_Name
Expand Down
10 changes: 5 additions & 5 deletions Assets/1_SelfDrivingCar/Scripts/MenuOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MenuOptions : MonoBehaviour
public void Start ()
{
project = 0;
project_name.text = "Project 1: Bicycle Tracker with EKF";
project_name.text = "Project 1/2: EKF and UKF";
project_image.sprite = project_1;
}

Expand Down Expand Up @@ -59,12 +59,12 @@ public void Next()

if(project == 0)
{
project_name.text = "Project 1: Bicycle Tracker with EKF";
project_name.text = "Project 1/2: EKF and UKF";
project_image.sprite = project_1;
}
else if(project == 1)
{
project_name.text = "Project 2: Run Away Robot with UKF";
project_name.text = "Bonus Challenge: Catch the Run Away Car";
project_image.sprite = project_2;
}
else if(project == 2)
Expand Down Expand Up @@ -97,12 +97,12 @@ public void Previous()

if(project == 0)
{
project_name.text = "Project 1: Bicycle Tracker with EKF";
project_name.text = "Project 1/2: EKF and UKF";
project_image.sprite = project_1;
}
else if(project == 1)
{
project_name.text = "Project 2: Run Away Robot with UKF";
project_name.text = "Bonus Challenge: Catch the Run Away Car";
project_image.sprite = project_2;
}
else if(project == 2)
Expand Down
15 changes: 7 additions & 8 deletions Assets/1_SelfDrivingCar/Scripts/project_3/CommandServer_pf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ void Start()

particle_filter = car.GetComponent<particle_filter_v2> ();
}

// Update is called once per frame
void Update()
{
}


void OnOpen(SocketIOEvent obj)
{
Expand Down Expand Up @@ -68,6 +64,8 @@ void BestParticle(SocketIOEvent obj)

particle_filter.SenseParticleDistance (associations, sense_x, sense_y);

particle_filter.setSimulatorProcess();

}

EmitTelemetry(obj);
Expand All @@ -82,14 +80,14 @@ void EmitTelemetry(SocketIOEvent obj)

//print("Attempting to Send...");
// send only if robot is moving
if (!particle_filter.isRunning() || !particle_filter.isReadyProcess()) {
if (!particle_filter.isRunning() || !particle_filter.isServerProcess()) {

_socket.Emit("telemetry", new JSONObject());
}
else {

particle_filter.Processed();
particle_filter.ServerPause();

// Collect Data from the robot's sensors
Dictionary<string, string> data = new Dictionary<string, string>();
data["sense_x"] = particle_filter.Sense_x().ToString("N4");
Expand All @@ -103,6 +101,7 @@ void EmitTelemetry(SocketIOEvent obj)
data["sense_observations_y"] = particle_filter.Sense_Obsy();

_socket.Emit("telemetry", new JSONObject(data));

}
});
}
Expand Down
64 changes: 49 additions & 15 deletions Assets/1_SelfDrivingCar/Scripts/project_3/particle_filter_v2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class particle_filter_v2 : MonoBehaviour {

private double scale = .1;
private int time_step;
private int time_system;
private double current_time;

private float x_cum;
private float y_cum;
Expand All @@ -50,12 +52,13 @@ public class particle_filter_v2 : MonoBehaviour {
// UI
public Text run_button;
public Text time;
public Text system_time;
public Text status;
public Text average_error;
private bool status_check;

//if there is new data to process
private bool process_data;
private bool simulator_process;
private bool server_process;
private bool script_running = false;

public TextAsset map_data;
Expand All @@ -81,8 +84,12 @@ void Start () {
status.text = "";
status_check = false;

current_time = 0;

time_step = 0;
time_system = 0;
time.text = "Time Step: "+time_step.ToString ();
system_time.text = "System Time: "+time_step.ToString ();

//Clear landmarks if restarting
if (map != null)
Expand Down Expand Up @@ -131,21 +138,24 @@ void Start () {
ResetParticleSensors ();

//flag new data is ready to process
process_data = true;
simulator_process = false;
server_process = true;

}

// Update is called once per frame
void FixedUpdate () {

//dont run past time interval and dont run until last data was processed
if (running && time_step < x_positions.Count-1 && (!process_data||!script_running))
if (running && time_step < x_positions.Count-1 && (simulator_process||!script_running))
{


simulator_process = false;


time_step++;
time.text = "Time Step: "+time_step.ToString ();

time.text = "Time Step: " + (time_step).ToString ("N2");
transform.position = new Vector3 (x_positions [time_step], y_positions [time_step], 0);
transform.rotation = Quaternion.AngleAxis (t_positions [time_step] * Mathf.Rad2Deg, Vector3.forward);

Expand All @@ -158,16 +168,26 @@ void FixedUpdate () {
ResetSensors ();
SenseDistance ();

//flag new data is ready to process
process_data = true;

server_process = true;

}


if (running)
{
time_system++;
current_time = (time_system * Time.deltaTime);
system_time.text = "System Time: " + (current_time).ToString ("N2");
}


if (running && time_step >= x_positions.Count-1) {

if (!status_check && script_running)
{
status.text = "Success! Your particle filter passed!";
status_check = true;

}
ToggleRunning();
}
Expand Down Expand Up @@ -199,15 +219,23 @@ public bool isRunning()
{
return running;
}
public bool isReadyProcess()


public bool isServerProcess()
{
return server_process;
}
public void ServerPause()
{
return process_data;
server_process = false;
}
public void Processed()
public void setSimulatorProcess()
{
process_data = false;
simulator_process = true;
}



public float normrand(float mean, float stdDev)
{
float u1 = 1.0f-Random.Range (0.0f, 1.0f); //uniform(0,1] random doubles
Expand All @@ -219,6 +247,7 @@ public float normrand(float mean, float stdDev)

public void Estimate(float estimate_x, float estimate_y, float estimate_theta)
{

particle.transform.position = new Vector3 ((float)(estimate_x*scale), (float)(estimate_y*scale), 0);
particle.transform.rotation = Quaternion.AngleAxis (estimate_theta * Mathf.Rad2Deg, Vector3.forward);

Expand Down Expand Up @@ -512,7 +541,12 @@ public void SetError(int time_step, int max_time, float x, float y, float yaw)

if (time_step > 100 & !status_check)
{
if (x > 1)
if ((current_time) > 100.0)
{
status.text = "You ran out of time ";
status_check = true;
}
else if (x > 1)
{
status.text = "Your x error is larger than the max";
status_check = true;
Expand Down

0 comments on commit 60c8577

Please sign in to comment.