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

Commit

Permalink
Fix+Feat: Ajusted the timing scripts for the kalman filter and change…
Browse files Browse the repository at this point in the history
…d its

dataset features
  • Loading branch information
awbrown90 committed May 3, 2017
1 parent e6e13cf commit c5f0db9
Show file tree
Hide file tree
Showing 12 changed files with 1,087 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Assets/1_SelfDrivingCar/Scenes/project_1/EKF_project.unity
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,8 @@ MonoBehaviour:
rmse_y: {fileID: 1651981976}
rmse_vx: {fileID: 1924886836}
rmse_vy: {fileID: 683751068}
data1: {fileID: 4900000, guid: 18f9d9f438398d64f97ac602cbe9feff, type: 3}
data2: {fileID: 4900000, guid: ca83b5854287abd42878e32812c50ef3, type: 3}
data1: {fileID: 4900000, guid: 7fb552bc7e36779438384ff22ecbb35e, type: 3}
data2: {fileID: 4900000, guid: f01a3ffe785a721418c016e2f9ab50dd, type: 3}
--- !u!50 &614215528
Rigidbody2D:
serializedVersion: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ void Update()
void OnOpen(SocketIOEvent obj)
{
Debug.Log("Connection Open");
kalman_filter.OpenScript ();
EmitTelemetry(obj);
}

void OnClose(SocketIOEvent obj)
{
Debug.Log("Connection Closed");
kalman_filter.CloseScript ();
}

void onManual(SocketIOEvent obj)
Expand Down Expand Up @@ -77,11 +79,13 @@ void EmitTelemetry(SocketIOEvent obj)
//print("Attempting to Send...");
// send only if robot is moving
if (!kalman_filter.isRunning()) {
if (!kalman_filter.isRunning() || !kalman_filter.isReadyProcess()) {
_socket.Emit("telemetry", new JSONObject());
}
else {
kalman_filter.Processed();
// Collect Data from the robot's sensors
Dictionary<string, string> data = new Dictionary<string, string>();
Expand Down
Binary file modified Assets/1_SelfDrivingCar/Scripts/project_1/camera_follow_ekf.cs
Binary file not shown.
65 changes: 61 additions & 4 deletions Assets/1_SelfDrivingCar/Scripts/project_1/ekf_generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class ekf_generator : MonoBehaviour {
public TextAsset data1;
public TextAsset data2;

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

// Use this for initialization
void Start () {

Expand Down Expand Up @@ -93,6 +97,9 @@ void Start () {

sensor_markers[time_step].GetComponent<SpriteRenderer>().enabled = true;

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

}

public string sensor_Measure()
Expand All @@ -102,6 +109,7 @@ public string sensor_Measure()

public void Estimate(float est_x, float est_y)
{
Debug.Log("estimate "+est_x+" "+est_y);
GameObject get_estimate_marker = (GameObject)Instantiate (estimate_marker);
get_estimate_marker.GetComponent<SpriteRenderer>().enabled = true;
get_estimate_marker.transform.position = new Vector3 ((float)(est_x*scale), (float)(est_y*scale), 0);
Expand All @@ -119,7 +127,7 @@ public void SetRmse(float x, float y, float vx, float vy)
// Update is called once per delta time
void FixedUpdate () {

if (running && time_step < x_positions.Count-1)
if (running && time_step < x_positions.Count-1 && (!process_data||!script_running))
{

time_step++;
Expand All @@ -130,6 +138,9 @@ void FixedUpdate () {

sensor_markers[time_step].GetComponent<SpriteRenderer>().enabled = true;

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

}
if (running && time_step >= sensors.Count - 1) {
ToggleRunning();
Expand Down Expand Up @@ -177,7 +188,10 @@ private void Load(TextAsset data)
var arrayString = data.text.Split ('\n');
foreach (var line in arrayString)
{
CreateAttributes(line);
if (!String.IsNullOrEmpty (line))
{
CreateAttributes (line);
}
}
}

Expand Down Expand Up @@ -214,7 +228,20 @@ private void CreateAttributes(string line)

sensor_markers.Add (get_radar_marker);

string radar_packet = entries[0]+" "+entries[1]+" "+entries[2]+" "+entries[3]+" "+entries[4]+" "+entries[5]+" "+entries[6]+" "+entries[7]+" "+(entries [8].Remove (entries [8].Length-1, 1)).ToString();
string radar_packet = "";
for (int i = 0; i < entries.Length; i++)
{
if (i != entries.Length - 1)
{
radar_packet += entries[i]+" ";
}
else
{
radar_packet += (entries [i].Remove (entries [i].Length - 1, 1)).ToString ();
}
}

//string radar_packet = entries[0]+" "+entries[1]+" "+entries[2]+" "+entries[3]+" "+entries[4]+" "+entries[5]+" "+entries[6]+" "+entries[7]+" "+(entries [8].Remove (entries [8].Length-1, 1)).ToString();

sensors.Add (radar_packet);
}
Expand Down Expand Up @@ -242,19 +269,49 @@ private void CreateAttributes(string line)

sensor_markers.Add (get_lidar_marker);

string lidar_packet = entries[0]+" "+entries[1]+" "+entries[2]+" "+entries[3]+" "+entries[4]+" "+entries[5]+" "+entries[6]+" "+(entries [7].Remove (entries [7].Length-1, 1)).ToString();
string lidar_packet = "";
for (int i = 0; i < entries.Length; i++)
{
if (i != entries.Length - 1)
{
lidar_packet += entries[i]+" ";
}
else
{
lidar_packet += (entries [i].Remove (entries [i].Length - 1, 1)).ToString ();
}
}

//string lidar_packet = entries[0]+" "+entries[1]+" "+entries[2]+" "+entries[3]+" "+entries[4]+" "+entries[5]+" "+entries[6]+" "+(entries [7].Remove (entries [7].Length-1, 1)).ToString();

sensors.Add (lidar_packet);
}
else
{
Debug.Log ("recived an unexpected data line");
Debug.Log (line);
}


}

}
public bool isReadyProcess()
{
return process_data;
}
public void Processed()
{
process_data = false;
}
public void OpenScript()
{
script_running = true;
}
public void CloseScript()
{
script_running = false;
}


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void EmitTelemetry(SocketIOEvent obj)
//print("Attempting to Send...");
// send only if robot is moving
if (!sensor.Status()) {
if (!sensor.Status() ) {
_socket.Emit("telemetry", new JSONObject());
}
Expand Down
1 change: 1 addition & 0 deletions Assets/1_SelfDrivingCar/Scripts/project_2/robot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ void FixedUpdate () {
timestamp += (int)(Time.deltaTime*1e6);
frame_counter++;
checkStatus ();

}
else
{
Expand Down
Binary file modified Assets/1_SelfDrivingCar/Scripts/project_3/camera_follow_pf.cs
Binary file not shown.
Loading

0 comments on commit c5f0db9

Please sign in to comment.