Beispiel #1
0
        public virtual void drive(double dt)
        {
            double f   = 0.5 * 1.225 * dragArea * myCarState.velocity * myCarState.velocity;
            double acc = Physics1D.compute_acceleration(engineForce - f, mass);
            double vel = Physics1D.compute_velocity(myCarState.velocity, acc, dt);
            double pos = Physics1D.compute_position(myCarState.position, vel, dt);
            double t   = myCarState.time + dt;


            myCarState.set(pos, vel, acc, t);
        }
Beispiel #2
0
        public override void drive(double dt)
        {
            Console.WriteLine("myCarState={0}", myCarState.velocity);
            double f = 0.5 * 1.225 * dragArea * myCarState.velocity * myCarState.velocity;
            double a = Physics1D.compute_acceleration(engineForce - f, mass);
            double v = Physics1D.compute_velocity(myCarState.velocity, a, dt);

            Console.WriteLine("v={0} ", v);
            v += random.Next(50);
            Console.WriteLine("v={0} ", v);
            double p = Physics1D.compute_position(myCarState.position, v, dt);
            double t = myCarState.time + dt;

            myCarState.set(p, v, a, t);
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            // read in car mass
            Console.WriteLine("Enter the mass of the car (kg): ");
            double mass;

            mass = Convert.ToDouble(Console.ReadLine());

            // read in engine force
            Console.WriteLine("Enter the net force of the engine (N): ");
            double engine_force;

            engine_force = Convert.ToDouble(Console.ReadLine());

            // read in drag area coefficient
            Console.WriteLine("Enter the car's drag area (m^2): ");
            double drag_area;

            drag_area = Convert.ToDouble(Console.ReadLine());

            // read in time step
            Console.WriteLine("Enter the simulation time step (s): ");
            double dt;

            dt = Convert.ToDouble(Console.ReadLine());

            // read in total number of simulation steps
            Console.WriteLine("Enter the number of time steps (int): ");
            int N;

            N = Convert.ToInt32(Console.ReadLine());

            // initialize the car's state
            double x0 = 0; // initial position
            double v  = 0; // initial velocity
            double t  = 0; // initial time
            double fd;     // drag force and secondary position and acceleration
            double x1;
            double a;



            // run the simulation
            for (int i = 0; i < N; ++i)
            {
                // TODO: COMPUTE UPDATED STATE HERE


                fd = 0.5 * 1.225 * drag_area * v * v;
                //Console.Write("fd=");
                //Console.WriteLine(fd);
                double f = engine_force - fd;
                a = Physics1D.compute_acceleration(f, mass);

                v = Physics1D.compute_velocity(v, a, dt);
                //Console.Write("v=");
                //Console.WriteLine(v);

                x1 = Physics1D.compute_position(x0, v, dt);

                x0 = x1;

                t += dt;  // increment time

                // print the time and current state
                Console.WriteLine("t:{0}, a:{1}, v:{2}, x1:{3}, fd:{4} ", t, a, v, x1, fd);
            }
        }