public Boolean AircraftDidEnterRadarRangeEventTest(Aircraft intruder) { //TODO: case for updateRadarScreen call UpdateRadarScreen(); return true; }
public void Aircraft2String() { Aircraft ac = new Aircraft ("ABCDE1", Vector<double>.Build.DenseOfArray(new double[3]{-5, 0, 0})); string acstring = ac.ToString (); Assert.True (acstring.Contains("Identifier: ABCDE1")); }
//This doesn't work yet, math isnt quite right. Need starting coordinate as well as vector //to make any since. Must of missed something in my notes - Stephen public double Intersection(Aircraft aircraft1, Aircraft aircraft2, double radius) { //Positions Vector<double> c1 = Vector<double>.Build.DenseOfArray(new double[3]{aircraft1.DataBuffer[0][0], aircraft1.DataBuffer[0][1], aircraft1.DataBuffer[0][2]}); Vector<double> c2 = Vector<double>.Build.DenseOfArray(new double[3]{aircraft2.DataBuffer[0][0], aircraft2.DataBuffer[0][1], aircraft2.DataBuffer[0][2]}); //Velocities Vector<double> v1 = aircraft1.Velocity; Vector<double> v2 = aircraft2.Velocity; Vector<double> d = c1.Subtract (c2); Vector<double> w = v1.Subtract (v2); double dDotW = (d.DotProduct (w)); double wDotW = (w.DotProduct (w)); double dDotD = (d.DotProduct (d)); double decider = Math.Pow(dDotW, 2) - (wDotW * (dDotD - Math.Pow(radius, 2))); if (decider < 0) { //No intersection if negative return -1; } //double plusResult = -1 * dDotW + Math.Sqrt(decider) / wDotW; double minusResult = -1 * dDotW - Math.Sqrt(decider) / wDotW; //I believe this is when they first touch, the plus result is when they exit. if (minusResult < 0) { return -1; //No intersection } else { return minusResult; } }
/** * Add a new intruder to the list */ private void AddNewIntruder(TransponderData data) { if(WithinRadarRange(data)){ Aircraft newIntruder = new Aircraft (data.Icao); Intruders.Add (newIntruder); UpdateAircraftFromData (data, newIntruder); } }
public void AircraftCreation() { Aircraft ac = new Aircraft ("Fred1", Vector<double>.Build.DenseOfArray(new double[3]{-5, 0, 0})); Assert.AreEqual ( "Fred1", ac.Identifier); Assert.AreEqual ( -5, ac.Velocity[0]); Assert.AreEqual ( 0, ac.Velocity[1]); Assert.AreEqual ( 0, ac.Velocity[2]); }
public void AircraftDidEnterRadarRangeEventTestLong() { RadarHandler rh = new RadarHandler (); Aircraft us = new Aircraft ("1", Vector<double>.Build.DenseOfArray(new double[3]{.002, 0, 0})); us.DataBuffer.Add(Vector<double>.Build.DenseOfArray(new double[3]{40,-89,3000})); Aircraft them = new Aircraft ("2", Vector<double>.Build.DenseOfArray(new double[3]{.002, 0, 0})); them.DataBuffer.Add(Vector<double>.Build.DenseOfArray(new double[3]{40,-89.09053,3000})); //test one, should be about 4.6nm appart, true since it is in the 6nm radius, longitude test Assert.AreEqual (true, rh.AircraftDidEnterRadarRangeEventTest (them)); }
public void FasterAircraftCollision() { IMathCalcUtility mathUtil = new MathCalcUtility (); Aircraft fasterAircraft = new Aircraft ("1", Vector<double>.Build.DenseOfArray(new double[3]{-5, 0, 0})); fasterAircraft.DataBuffer.Add(Vector<double>.Build.DenseOfArray(new double[3]{50, 0, 0})); Aircraft thisAircraft = new Aircraft ("2", Vector<double>.Build.DenseOfArray(new double[3]{1, 0, 0})); thisAircraft.DataBuffer.Add(Vector<double>.Build.DenseOfArray(new double[3]{0, 0, 0})); double intersection = mathUtil.Intersection (thisAircraft, fasterAircraft, 1); Assert.AreEqual (Math.Sign(1), Math.Sign(intersection)); //should be an intersection // }
public void AircraftDidEnterRadarRangeEventTestLat() { DataProcessor dp = new DataProcessor (); RadarHandler rh = new RadarHandler (); Aircraft us = new Aircraft ("1", Vector<double>.Build.DenseOfArray(new double[3]{.002, 0, 0})); us.DataBuffer.Add(Vector<double>.Build.DenseOfArray(new double[3]{40.037919,-89,3000})); Aircraft them = new Aircraft ("2", Vector<double>.Build.DenseOfArray(new double[3]{.002, 0, 0})); them.DataBuffer.Add(Vector<double>.Build.DenseOfArray(new double[3]{39.962085,-89,3000})); //test one, should be about 4.5nm appart on radar, true since it is in the 6nm radius, latitude test Assert.AreEqual (true, rh.AircraftDidEnterRadarRangeEventTest (them)); }
public void FasterAircraftInFront() { IMathCalcUtility mathUtil = new MathCalcUtility (); Aircraft fasterAircraft = new Aircraft ("1", Vector<double>.Build.DenseOfArray(new double[3]{5, 0, 0})); fasterAircraft.DataBuffer.Add(Vector<double>.Build.DenseOfArray(new double[3]{5, 0, 0})); Aircraft thisAircraft = new Aircraft ("2", Vector<double>.Build.DenseOfArray(new double[3]{1, 0, 0})); thisAircraft.DataBuffer.Add(Vector<double>.Build.DenseOfArray(new double[3]{1, 0, 0})); double intersection = mathUtil.Intersection (fasterAircraft, thisAircraft, 1); Assert.AreEqual (-1.0, intersection); //should be no intersection }
public void NoMovementAtAllTest() { IMathCalcUtility mathUtil = new MathCalcUtility (); Aircraft tetheredBalloon = new Aircraft ("1", Vector<double>.Build.DenseOfArray(new double[3]{0, 0, 0})); tetheredBalloon.DataBuffer.Add(Vector<double>.Build.DenseOfArray(new double[3]{0, 0, 0})); Aircraft thisAircraft = new Aircraft ("2", Vector<double>.Build.DenseOfArray(new double[3]{1, 0, 0})); thisAircraft.DataBuffer.Add(Vector<double>.Build.DenseOfArray(new double[3]{1, 0, 0})); double intersection = mathUtil.Intersection (tetheredBalloon, thisAircraft, 1); Assert.AreEqual (-1.0, intersection); //should be no intersection since tetheredBalloon isn't moving thisAircraft.Velocity = Vector<double>.Build.DenseOfArray (new double[3]{ 1, 2, 0 }); intersection = mathUtil.Intersection (tetheredBalloon, thisAircraft, 1); Assert.AreEqual (-1.0, intersection); //still no intersection after thisAircraft changed course }
//MathCalcUtility to determine proximity of our aircraft to another private void DetermineProximityOfIntruder(Aircraft intruder) { //If in proximity... //Calculate time... var timeUntilIntersection = MathUtility.Intersection (ThisAircraft, intruder, 0.0822894); //radius of 500 feet (in NM) if (timeUntilIntersection > 0) { Console.WriteLine ("time until intersection: " + timeUntilIntersection); if (intruder.DataBuffer [0] [2] > ThisAircraft.DataBuffer [0] [2]) { AircraftWillIntersectInTimeEvent (timeUntilIntersection, Position.Above); } else { AircraftWillIntersectInTimeEvent (timeUntilIntersection, Position.Below); } } //If in radar range... if(WithinRadarRange(intruder)){ AircraftDidEnterRadarRangeEvent(intruder); } }
public void IntersectionTest() { //Test1 MathCalcUtility utility = new MathCalcUtility (); Vector<double> plane1DataFrom = Vector<double>.Build.DenseOfArray(new double[3]{0, -1, 0}); Vector<double> plane1DataTo = Vector<double>.Build.DenseOfArray(new double[3]{1, 0, 0}); Vector<double> plane2DataFrom = Vector<double>.Build.DenseOfArray(new double[3]{6, -1, 0}); Vector<double> plane2DataTo = Vector<double>.Build.DenseOfArray(new double[3]{5, 0, 0}); Vector<double> plane1vec = utility.CalculateVector (plane1DataFrom, plane1DataTo); Vector<double> plane2vec = utility.CalculateVector (plane2DataFrom, plane2DataTo); Aircraft aircraft1 = new Aircraft ("1", plane1vec); aircraft1.DataBuffer.Add (plane1DataTo); Aircraft aircraft2 = new Aircraft ("2", plane2vec); aircraft2.DataBuffer.Add (plane2DataTo); double time = utility.Intersection (aircraft1, aircraft2, 1f); Assert.AreEqual (1.0, time); }
public void StopMovementTest() { IMathCalcUtility mathUtil = new MathCalcUtility (); Aircraft stoppingAircraft = new Aircraft ("1", Vector<double>.Build.DenseOfArray(new double[3]{-5, 0, 0})); stoppingAircraft.DataBuffer.Add(Vector<double>.Build.DenseOfArray(new double[3]{50, 0, 0})); Aircraft thisAircraft = new Aircraft ("2", Vector<double>.Build.DenseOfArray(new double[3]{1, 0, 0})); thisAircraft.DataBuffer.Add(Vector<double>.Build.DenseOfArray(new double[3]{0, 0, 0})); double intersection = mathUtil.Intersection (thisAircraft, stoppingAircraft, 1); Assert.AreEqual (Math.Sign(1), Math.Sign(intersection)); //On collision course stoppingAircraft.Velocity = Vector<double>.Build.DenseOfArray (new double[3]{ 0, 0, 0 }); // stoppingAircraft has stopped moving completely intersection = mathUtil.Intersection (stoppingAircraft, thisAircraft, 1); Assert.AreEqual (Math.Sign(1), Math.Sign(intersection)); //Still collision thisAircraft.Velocity = Vector<double>.Build.DenseOfArray (new double[3]{ 1, -10, 0 }); intersection = mathUtil.Intersection (stoppingAircraft, thisAircraft, 1); Assert.AreEqual (-1.0, intersection); //No intersection after thisAircraft changed course }
// convert to cordinates // look for air craft and list and update if in list, else create new private void UpdateAircraftFromData(TransponderData data, Aircraft aircraft) { var coordinate = MathUtility.CalculateCoordinate (data.Latitude, data.Longitude, data.Altitude); aircraft.DataBuffer.Insert (0, coordinate); if (aircraft.DataBuffer.Count > 1) { aircraft.Velocity = MathUtility.CalculateVector (aircraft.DataBuffer [1], aircraft.DataBuffer [0]); } //remove the last data entry if (aircraft.DataBuffer.Count > 20) { aircraft.DataBuffer.RemoveAt (aircraft.DataBuffer.Count - 1); } // if (aircraft != ThisAircraft && aircraft.Velocity != null) { // Console.WriteLine("our aircraft: " + ThisAircraft ); // Console.WriteLine("intruder aircraft" + aircraft); // DetermineProximityOfIntruder (aircraft); // } }
//method for testing public Boolean AircraftDidEnterRadarRangeEventTest (Aircraft intruder) { UpdateRadarScreen(intruder.Identifier); return true; }
//if intruder is 6 nm in range add to radar screen public void AircraftDidEnterRadarRangeEvent(Aircraft intruder) { //case for updateRadarScreen call throw new NotImplementedException(); }
public DataProcessor () { Intruders = new List<Aircraft> (); ThisAircraft = new Aircraft ("B1E24F", Vector<double>.Build.Dense(3)); //Vector in R^3 MathUtility = new MathCalcUtility(); }
/** * Check Altitude Difference between aircrafts * to determine instruction to give */ private void CheckAltitudeDifference (Aircraft intruder, double timeUntilIntersection){ if (intruder.DataBuffer [0].L2Norm () > ThisAircraft.DataBuffer [0].L2Norm ()) { AircraftWillIntersectInTimeEvent (timeUntilIntersection, Position.Above); } else { AircraftWillIntersectInTimeEvent (timeUntilIntersection, Position.Below); } }
/** * Determine Proximity of given Intruder aircraft * */ private void DetermineProximityOfIntruder (Aircraft intruder) { //Calculate time until intersection, 0.0822894 is radius of 250 ft in Nautical Miles var timeUntilIntersection = MathUtility.Intersection (ThisAircraft, intruder, 0.0822894); Trace.WriteLine ("Time until intersection: " + timeUntilIntersection); //if > 0, then we are on trajectory to intersect. if (timeUntilIntersection > 0) { CheckAltitudeDifference (intruder, timeUntilIntersection); } /* otherwise time until intersection is negative (actually -1) and we overlapped. Here we want to continue to give instructions to the pilot until the distance between the planes begins to increase. Once we exit the critical range of .0822894 nm (taking into account our sphere bubble) we will no longer report from here */ else { if (ThisAircraft.DataBuffer.Count > 1 && intruder.DataBuffer.Count > 1) { if ((MathUtility.Distance (ThisAircraft.DataBuffer [1], intruder.DataBuffer [1]) > MathUtility.Distance (ThisAircraft.DataBuffer [0], intruder.DataBuffer [0])) && (MathUtility.Distance (ThisAircraft.DataBuffer [0], intruder.DataBuffer [0]) < .0822894)) { CheckAltitudeDifference (intruder, timeUntilIntersection); } } } //If in radar range... if(WithinRadarRange(intruder)){ AircraftDidEnterRadarRangeEvent(intruder); } }
/** * Update Aircrafts with newest data */ private void UpdateAircraftFromData (TransponderData data, Aircraft aircraft) { // convert tdata to cordinates var coordinate = MathUtility.CalculateCoordinate (data.Latitude, data.Longitude, data.Altitude); aircraft.DataBuffer.Insert (0, coordinate); //calc velocity if (aircraft.DataBuffer.Count > 1) { aircraft.Velocity = MathUtility.CalculateVector (aircraft.DataBuffer [1], aircraft.DataBuffer [0]); } //remove the last data entry (clean up old data) if (aircraft.DataBuffer.Count > 20) { aircraft.DataBuffer.RemoveAt (aircraft.DataBuffer.Count - 1); } }
/** * Determine if given aircraft is within radar range * return true if it is, else false. */ private bool WithinRadarRange(Aircraft aircraft){ if (ThisAircraft.DataBuffer.Count > 0) { var distance = MathUtility.Distance (aircraft.DataBuffer[0], ThisAircraft.DataBuffer [0]); //if distance is less than 6.1 NM return true Trace.WriteLine("Distance to aircraft " + aircraft.Identifier + ": " + distance); if (distance < RADAR_RANGE_NM) { return true; } } return false; }
//if intruder is 6 nm in range add to radar screen public void AircraftDidEnterRadarRangeEvent(Aircraft intruder) { AircraftDidEnterRadarRangeEventTest (intruder); }
//if intruder is 6 nm in range add to radar screen public void AircraftDidEnterRadarRangeEvent(Aircraft intruder) { //case for updateRadarScreen call throw new NotImplementedException (); }