コード例 #1
1
    public static void TestPlaneConstructor()
    {
        PlaneAttributes atts = new PlaneAttributes("badger50", 1, 5, 3, 7, 2000);
        Plane p = new Plane("acas-1200-badger50", atts);

        //A plane should have anything assigned to it in the constructor reflected in it immediately.
        p.attributes.maxHeight.ShouldBe(2000);
        p.attributes.planeModelGUID.ShouldBe("badger50");
        p.attributes.planeHeight.ShouldBe(3);
        p.attributes.planeWidth.ShouldBe(5);
        p.attributes.planeLength.ShouldBe(7);
        p.attributes.planeClass.ShouldBe(1);

        //A new plane should have no position data within it.
        p.GetPositionCount().ShouldBe(0);

        //A new plane with no position data should have a 'zero' velocity
        p.IsClass(p.attributes.planeClass).ShouldBe(true);
        Vector3d vel = p.GetVelocity();
        vel.x.ShouldBe(0, .01);
        vel.y.ShouldBe(0, .01);
        vel.z.ShouldBe(0, .01);

        //Getting position from a newly constructed plane (with no position data)
        //should cause a NotSupportedException
        Exception ex = null;
        try {
            Vector3d pos = p.GetPosition();
        } catch (Exception e) {
            ex = e;
        }
        ex.ShouldNotBeNull();
        ex.GetType().ShouldBe(typeof(NotSupportedException));
    }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: chiloschista/FunCub
 public PlaneAttributes(PlaneAttributes values)
 {
     aileron  = values.aileron;
     elevator = values.elevator;
     rudder   = values.rudder;
     throttle = values.throttle;
     aux      = values.aux;
 }
コード例 #3
0
    //Method for Initializing an array of planes for testing
    public static Plane[][] createTestSet()
    {
        //TBD: Add some plane data for 'successful' collisions tests here
        //The test data needs to be pretty precise (down to the .001 lat/long and a number of entries over a few seconds)
        PlaneAttributes atts = new PlaneAttributes("default", 1, 150, 150, 150, 3000);
        long zeroTime = 0x7000000010000000;
        double denverLat = 39.7392;
        double denverLong = 104.9903;

        double sydneyLat = -33.8830555556;
        double sydneyLong = 151.216666667;

        double moscowLat = 55.7522222;
        double moscowLong = 37.6155556;

        //head on collision
        Plane a = new Plane("a", atts);
        Plane aa = new Plane("aa", atts);

        for (int i = 0; i < 100; i++) {
            a.AddPosition(new GPSData(denverLat, denverLong + .0223 - i * .0001, 2000, zeroTime + 1000 * i));
            aa.AddPosition(new GPSData(denverLat, denverLong - .0223 + i * .0001, 2000, zeroTime + 1000 * i));
        }

        Console.WriteLine(a.GetPosition() + " : " +  a.GetVelocity());
        Console.WriteLine(aa.GetPosition() + " : " +  aa.GetVelocity());

        //right angle collision
        Plane b = new Plane("b", atts);
        Plane bb = new Plane("bb", atts);

        for (int i = 0; i < 100; i++) {
            b.AddPosition(new GPSData(sydneyLat - .0223 + i * .0001, sydneyLong, 2000, zeroTime + 1000 * i));
            bb.AddPosition(new GPSData(sydneyLat, sydneyLong - .0223 + i * .0001, 2000, zeroTime + 1000 * i));
        }

        //Collision from behind
        Plane c = new Plane("c", atts);
        Plane cc = new Plane("cc", atts);

        for (int i = 0; i < 100; i++) {
            c.AddPosition(new GPSData(moscowLat, moscowLong - .0200 + i * .0002, 2000, zeroTime + 1000 * i));
            cc.AddPosition(new GPSData(moscowLat, moscowLong - .0400 + i * .00035, 2000, zeroTime + 1000 * i));
        }

        Plane[][] planeArray = new Plane[][] {
            new Plane[] { a, aa },
            new Plane[] { b, bb },
            new Plane[] { c, cc }
        };

        return planeArray;
    }
コード例 #4
0
    public static void MockDBTest()
    {
        Dictionary<string, PlaneAttributes> database = PlaneDB.MakeDB(test_plane_data);
        //Count should be 2 not 3 because of the bad data in wrongPlane.
        database.Count.ShouldBe(2);

        PlaneAttributes planeA = new PlaneAttributes("bigPlane", 5, 120, 50, 150, 7000);

        PlaneAttributes smallPlane = database["smallPlane"];
        //Plane Width attribute for smallPlane within the database should be 12.
        smallPlane.planeWidth.ShouldBe(12);

        //wrongPlane should be thorwn out (bad data).
        database.ShouldNotContainKey("wrongPlane");

        //planeA attributes should be the same as 'bigPlane' attributes within the database.
        planeA.ShouldBe(database["bigPlane"]);
    }
コード例 #5
0
    //Method for initializing an array of planes for fail tests
    private static Plane[][] createFailTestSet()
    {
        //Add some plane data for fail tests here
        //The test data needs to be pretty precise (down to the .001 lat/long and a number of entries over a few seconds)
        PlaneAttributes atts = new PlaneAttributes("default", 1, 150, 150, 150, 3000);
        long zeroTime = 0x7000000010000000;
        double denverLat = 39.7392;
        double denverLong = 104.9903;

        Plane a = new Plane("a", atts);
        Plane aa = new Plane("aa", atts);
        Plane b = new Plane("b", atts);
        Plane bb = new Plane("bb", atts);
        Plane c = new Plane("c", atts);
        Plane cc = new Plane("cc", atts);

        for (int i = 0; i < 100; i++) {
            //Running somewhat parralel on different latitudes
            a.AddPosition(new GPSData(denverLat+.0050, denverLong + .0223 + i * .0001, 2000, zeroTime + 1000 * i));
            aa.AddPosition(new GPSData(denverLat, denverLong + .0213 + i * .0001, 2000, zeroTime + 1000 * i));

            //Running parralel on same latitude and different altitudes
            b.AddPosition(new GPSData(denverLat, denverLong + .0223 + i * .0001, 2500, zeroTime + 1000 * i));
            bb.AddPosition(new GPSData(denverLat, denverLong + .0223 + i * .0001, 2000, zeroTime + 1000 * i));

            //cross at different times
            c.AddPosition(new GPSData(denverLat + i * .0001, denverLong + .0213 + i * .0001, 2500, zeroTime + 1000 * i));
            cc.AddPosition(new GPSData(denverLat + i * .0001, denverLong + .0223 - i * .0001, 2000, zeroTime + 1000 * i));
        }

        Plane[][] failPlaneArray = new Plane[][] {
            new Plane[] { a, aa },
            new Plane[] { b, bb },
            new Plane[] { c, cc }
        };

        return failPlaneArray;
    }
コード例 #6
0
    public static Dictionary<string, PlaneAttributes> MakeDB(string database)
    {
        //create a variable db that is a Dictionary with parameters string and PlaneAttributes.
        var db = new Dictionary<string, PlaneAttributes> ();

        //create a string array called 'lines' that splits the database by each line.
        string[] lines = database.Split('\n');

        /*for every line within the database, split on the '|' character and
         store in a new array called 'content'*/
        foreach (string line in lines){
            string[] content = line.Split('|');

            /*declare plane model GUID as a string and make sure content at index 0 is our planeModelGUID,
             * which is our key for the dictionary and use Trim() to remove the whitespace around the GUID */
            string planeModelGUID = content[0].Trim();

            //declare plane class as an integer, and plane width, height, length and max height as doubles.
            int planeClass;
            double planeWidth, planeHeight, planeLength, maxHeight;

            //see if planeClass data is an integer, if not skip it.
            if (!int.TryParse(content[1], out planeClass)) {
                continue;
            }
            //see if plane class is less than 0 or greater than 6, if so skip it.
            if (planeClass <= 0 || planeClass >= 6) {
                continue;
            }

            //see if planeWidth is a double, if not skip it.
            if (!double.TryParse(content[2], out planeWidth)) {
                continue;
            }

            //see if planeWidth is greater than 0 and less than 1000, if not skip it.
            if (planeWidth <= 0 || planeWidth >= 1000) {
                continue;
            }

            //see if planeHeight is a double, if not skip it.
            if (!double.TryParse(content [3], out planeHeight)) {
                continue;
            }

            //see if planeHeight is greater than 0 and less than 1000, if not skip it.
            if (planeHeight <= 0 || planeHeight >= 1000) {
                continue;
            }

            //see if planeLength is a double, if not skip it.
            if (!double.TryParse(content[4], out planeLength)) {
                continue;
            }

            //see if planeHeight is greater than 0 and less than 1000, if not skip it.
            if (planeLength <= 0 || planeLength >= 1000) {
                continue;
            }

            //see if maxHeight is a double, if not skip it.
            if (!double.TryParse (content [5], out maxHeight)) {
                continue;
            }

            //see if maxHeight is greater than 0 and less than 18000, if not skip it.
            if (maxHeight <= 0 || maxHeight >= 18000) {
                continue;
            }

            //if a '#' character is found at the beginning of a GUID skip it.
            if (planeModelGUID[0] == '#') {
                continue;
            }

            //if a planeModelGUID is already found in the db, so the data are a duplicate, skip it.
            if (db.ContainsKey(planeModelGUID)) {
                continue;
            }

            //create new set of PlaneAttributes called 'att'.
            PlaneAttributes att = new PlaneAttributes (planeModelGUID, planeClass, planeWidth, planeHeight, planeLength, maxHeight);

            //when all if statements pass for a certain plane model GUID add that plane model GUID to the db.
            db [planeModelGUID] = att;

        }

        return db;
    }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: kd0aij/MatrixPilot
 public PlaneAttributes(PlaneAttributes values)
 {
     aileron = values.aileron;
     elevator = values.elevator;
     rudder = values.rudder;
     throttle = values.throttle;
     aux = values.aux;
 }
コード例 #8
0
ファイル: MainForm.cs プロジェクト: kd0aij/MatrixPilot
        public PlaneAttributes ReassignJystValues(JoystickState joyState)
        {
            PlaneAttributes planeAttrib = new PlaneAttributes();

            switch (MapAileron_comboBox.SelectedIndex)
            {
                case 0: planeAttrib.aileron = joyState.X; break; // X
                case 1: planeAttrib.aileron = joyState.Y; break;// Y
                case 2: planeAttrib.aileron = joyState.Z; break;// Z
                case 3: planeAttrib.aileron = joyState.GetSlider()[0]; break;// Slider1
                case 4: planeAttrib.aileron = joyState.GetSlider()[1]; break;// Slider2
                default:
                    break;
            }

            switch (MapElevator_comboBox.SelectedIndex)
            {
                case 0: planeAttrib.elevator = joyState.X; break; // X
                case 1: planeAttrib.elevator = joyState.Y; break;// Y
                case 2: planeAttrib.elevator = joyState.Z; break;// Z
                case 3: planeAttrib.elevator = joyState.GetSlider()[0]; break;// Slider1
                case 4: planeAttrib.elevator = joyState.GetSlider()[1]; break;// Slider2
                default:
                    break;
            }

            switch (MapRudder_comboBox.SelectedIndex)
            {
                case 0: planeAttrib.rudder = joyState.X; break; // X
                case 1: planeAttrib.rudder = joyState.Y; break;// Y
                case 2: planeAttrib.rudder = joyState.Z; break;// Z
                case 3: planeAttrib.rudder = joyState.GetSlider()[0]; break;// Slider1
                case 4: planeAttrib.rudder = joyState.GetSlider()[1]; break;// Slider2
                default:
                    break;
            }

            switch (MapThrottle_comboBox.SelectedIndex)
            {
                case 0: planeAttrib.throttle = joyState.X; break; // X
                case 1: planeAttrib.throttle = joyState.Y; break;// Y
                case 2: planeAttrib.throttle = joyState.Z; break;// Z
                case 3: planeAttrib.throttle = joyState.GetSlider()[0]; break;// Slider1
                case 4: planeAttrib.throttle = joyState.GetSlider()[1]; break;// Slider2
                default:
                    break;
            }

            return planeAttrib;
        }
コード例 #9
0
ファイル: MainForm.cs プロジェクト: chiloschista/FunCub
        public PlaneAttributes ReassignJystValues(JoystickState joyState)
        {
            PlaneAttributes planeAttrib = new PlaneAttributes();

            switch (MapAileron_comboBox.SelectedIndex)
            {
            case 0: planeAttrib.aileron = joyState.X; break;              // X

            case 1: planeAttrib.aileron = joyState.Y; break;              // Y

            case 2: planeAttrib.aileron = joyState.Z; break;              // Z

            case 3: planeAttrib.aileron = joyState.GetSlider()[0]; break; // Slider1

            case 4: planeAttrib.aileron = joyState.GetSlider()[1]; break; // Slider2

            default:
                break;
            }

            switch (MapElevator_comboBox.SelectedIndex)
            {
            case 0: planeAttrib.elevator = joyState.X; break;              // X

            case 1: planeAttrib.elevator = joyState.Y; break;              // Y

            case 2: planeAttrib.elevator = joyState.Z; break;              // Z

            case 3: planeAttrib.elevator = joyState.GetSlider()[0]; break; // Slider1

            case 4: planeAttrib.elevator = joyState.GetSlider()[1]; break; // Slider2

            default:
                break;
            }

            switch (MapRudder_comboBox.SelectedIndex)
            {
            case 0: planeAttrib.rudder = joyState.X; break;              // X

            case 1: planeAttrib.rudder = joyState.Y; break;              // Y

            case 2: planeAttrib.rudder = joyState.Z; break;              // Z

            case 3: planeAttrib.rudder = joyState.GetSlider()[0]; break; // Slider1

            case 4: planeAttrib.rudder = joyState.GetSlider()[1]; break; // Slider2

            default:
                break;
            }

            switch (MapThrottle_comboBox.SelectedIndex)
            {
            case 0: planeAttrib.throttle = joyState.X; break;              // X

            case 1: planeAttrib.throttle = joyState.Y; break;              // Y

            case 2: planeAttrib.throttle = joyState.Z; break;              // Z

            case 3: planeAttrib.throttle = joyState.GetSlider()[0]; break; // Slider1

            case 4: planeAttrib.throttle = joyState.GetSlider()[1]; break; // Slider2

            default:
                break;
            }

            return(planeAttrib);
        }
コード例 #10
0
ファイル: MainForm.cs プロジェクト: chiloschista/FunCub
        private void Joystick_timer_Tick(object sender, EventArgs e)
        {
            if (joystickComboBox.SelectedIndex < 0)
            {
                // No joystick available, nothing to do.
                return;
            }

            jyst.Poll();
            if (doCalibartion)
            {
                doCalibartion       = false;
                jystHandler.CenterX = jyst.state.X;
                jystHandler.CenterY = jyst.state.Y;
            }

            PlaneAttributes planeAttrib = ReassignJystValues(jyst.state);

            JoystickHandler.FbW_Data PwmData = new JoystickHandler.FbW_Data();


            // write joystick to the UI
            if (OverrideAileron_checkBox.Checked)
            {
                PwmData.aileron = Aileron_trackBar.Value;
            }
            else
            {
                PwmData.aileron = jystHandler.ConvertForUI(planeAttrib.aileron,
                                                           AileronScalar_numericUpDown.Value,
                                                           AileronTrim_numericUpDown.Value,
                                                           InvertAileron_checkBox.Checked);
                Aileron_trackBar.Value = MainForm.Clip(PwmData.aileron, PWMminValue, PWMmaxValue);
            }
            Aileron_label.Text = "Aileron\r" + PwmData.aileron.ToString();


            if (OverrideElevator_checkBox.Checked)
            {
                PwmData.elevator = Elevator_trackBar.Value;
            }
            else
            {
                PwmData.elevator = jystHandler.ConvertForUI(planeAttrib.elevator,
                                                            ElevatorScalar_numericUpDown.Value,
                                                            ElevatorTrim_numericUpDown.Value,
                                                            InvertElevator_checkBox.Checked);
                Elevator_trackBar.Value = MainForm.Clip(PwmData.elevator, PWMminValue, PWMmaxValue);
            }
            Elevator_label.Text = "Elevator\r" + PwmData.elevator.ToString();


            if (OverrideRudder_checkBox.Checked)
            {
                PwmData.rudder = Rudder_trackBar.Value;
            }
            else
            {
                PwmData.rudder = jystHandler.ConvertForUI(planeAttrib.rudder,
                                                          RudderScalar_numericUpDown.Value,
                                                          RudderTrim_numericUpDown.Value,
                                                          InvertRudder_checkBox.Checked);
                Rudder_trackBar.Value = MainForm.Clip(PwmData.rudder, PWMminValue, PWMmaxValue);
            }
            Rudder_label.Text = "Rudder\r" + PwmData.rudder.ToString();


            if (OverrideThrottle_checkBox.Checked)
            {
                PwmData.throttle = Throttle_trackBar.Value;
            }
            else
            {
                PwmData.throttle = jystHandler.ConvertForUI(planeAttrib.throttle,
                                                            ThrottleScalar_numericUpDown.Value,
                                                            ThrottleTrim_numericUpDown.Value,
                                                            InvertThrottle_checkBox.Checked);
                Throttle_trackBar.Value = MainForm.Clip(PwmData.throttle, PWMminValue, PWMmaxValue);
            }
            Throttle_label.Text = "Throttle\r" + PwmData.throttle.ToString();


            switch (Mode_comboBox.SelectedIndex)
            {
            default:
            case 0: PwmData.mode = PWMminValue; break;     // Manual

            case 1: PwmData.mode = PWMmidValue; break;     // Stabilized

            case 2: PwmData.mode = PWMmaxValue; break;     // WayPoint
            }

            byte[] packet = JoystickHandler.CreateTxPacket(PwmData);
            Send(packet);
        }
コード例 #11
0
 //Basic Constructor for Plane()
 public Plane(string guid, PlaneAttributes atts)
 {
     acasGUID = guid;
     attributes = atts;
     positions = new LinkedList<GPSData>();
 }