Exemple #1
0
        static double  Test2(Driver Driver, double ObstaclePosition)
        {
            CarPhisics Car1 = new CarPhisics();


            double t  = 0;
            double dt = 0.01;

            do
            {
                t += dt;
                Driver.DistanceToObstacle = ObstaclePosition - Car1.PositionX;
                Driver.Update();
                Car1.AcceleratorCommand = Driver.AcceleratorCMD;
                Car1.BrakeCommand       = Driver.BrakeCMD;
                Car1.UpdateStatus(dt);
            } while (Car1.Speed > 0);
            //Console.Write("Time: {0}\tPosition: {1}",t,Car1.PositionX);
            return(Car1.PositionX);
        }
Exemple #2
0
        static void Test1()
        {
            CarPhisics Car1   = new CarPhisics();
            Driver     Driver = new Driver();

            StreamWriter sw = new StreamWriter("output.csv");

            sw.WriteLine("Time" + '\t' + Car1.CSVHeader('\t'));
            double t        = 0;
            double dt       = 0.1;
            double AccelCMD = 0;
            double brakeCMD = 0;
            double MaxSpeed = 0;

            sw.WriteLine(t.ToString() + '\t' + Car1.toCSVString('\t'));
            while (t < 10)
            {
                if (t < 7)
                {
                    AccelCMD = 1;
                    brakeCMD = 0;
                }
                else
                {
                    AccelCMD = 0;
                    brakeCMD = 1;
                }
                Car1.AcceleratorCommand = MathUtils.Bound(AccelCMD, 0, 1);
                Car1.UpdateStatus(dt);

                MaxSpeed = Car1.Speed > MaxSpeed ? Car1.Speed : MaxSpeed;

                t += dt;
                sw.WriteLine(t.ToString() + '\t' + Car1.toCSVString('\t'));
            }
            Console.WriteLine((MaxSpeed * 3.6).ToString() + "kmh");
            //Console.ReadLine();
            sw.Close();
        }