コード例 #1
0
void PerformanceTesting::TestStoppingDistance(bool abs, std::ostream & info_output, std::ostream & error_output)
{
	info_output << "Testing stopping distance" << std::endl;

	float maxtime = 300.0;
	float t = 0.;
	float dt = 1/90.0;
	int i = 0;

	float stopthreshold = 0.1; //if the speed (in m/s) is less than this value, discontinue the testing
	btVector3 stopstart; //where the stopping starts
	float brakestartspeed = 26.82; //speed at which to start braking, in m/s (26.82 m/s is 60 mph)

	bool accelerating = true; //switches to false once 60 mph is reached

	ResetCar();

	car.SetABS(abs);

	while (t < maxtime)
	{
		if (accelerating)
		{
			carinput[CarInput::THROTTLE] = 1.0f;
			carinput[CarInput::BRAKE] = 0.0f;
		}
		else
		{
			carinput[CarInput::THROTTLE] = 0.0f;
			carinput[CarInput::BRAKE] = 1.0f;
		}

		car.Update(carinput);

		world.update(dt);

		float car_speed = car.GetSpeed();

		if (car_speed >= brakestartspeed && accelerating) //stop accelerating and hit the brakes
		{
			accelerating = false;
			stopstart = car.GetWheelPosition(WheelPosition(0));
			//std::cout << "hitting the brakes at " << t << ", " << car_speed << std::endl;
		}

		if (!accelerating && car_speed < stopthreshold)
		{
			break;
		}

		if (!car.GetEngine().GetCombustion())
		{
			error_output << "Car stalled during launch, t=" << t << std::endl;
			break;
		}

		if (i % (int)(1.0/dt) == 0) //every second
		{
			//std::cout << t << ", " << car.dynamics.GetSpeed() << ", " << car.GetGear() << ", " << car.GetEngineRPM() << std::endl;
		}

		t += dt;
		i++;
	}

	btVector3 stopend = car.GetWheelPosition(WheelPosition(0));

	info_output << "60-0 stopping distance ";
	if (abs)
		info_output << "(ABS)";
	else
		info_output << "(no ABS)";
	info_output << ": " << ConvertToFeet((stopend-stopstart).length()) << " ft" << std::endl;
}
コード例 #2
0
void PERFORMANCE_TESTING::TestStoppingDistance(bool abs, std::ostream & info_output, std::ostream & error_output)
{
	info_output << "Testing stopping distance" << std::endl;

	ResetCar();
	car.dynamics.SetABS(abs);

	double maxtime = 300.0;
	double t = 0.;
	double dt = .004;
	int i = 0;

	std::vector <float> inputs(CARINPUT::INVALID, 0.0);

	inputs[CARINPUT::THROTTLE] = 1.0;

	float stopthreshold = 0.1; //if the speed (in m/s) is less than this value, discontinue the testing
	btVector3 stopstart; //where the stopping starts
	float brakestartspeed = 26.82; //speed at which to start braking, in m/s (26.82 m/s is 60 mph)

	bool accelerating = true; //switches to false once 60 mph is reached
	while (t < maxtime)
	{
		if (accelerating)
		{
			inputs[CARINPUT::THROTTLE] = 1.0;
			inputs[CARINPUT::BRAKE] = 0.0;
		}
		else
		{
			inputs[CARINPUT::THROTTLE] = 0.0;
			inputs[CARINPUT::BRAKE] = 1.0;
			inputs[CARINPUT::NEUTRAL] = 1.0;
		}

		car.HandleInputs(inputs);

		world.update(dt);

		if (car.dynamics.GetSpeed() >= brakestartspeed && accelerating) //stop accelerating and hit the brakes
		{
			accelerating = false;
			stopstart = car.dynamics.GetWheelPosition(WHEEL_POSITION(0));
			//std::cout << "hitting the brakes at " << t << ", " << car.dynamics.GetSpeed() << std::endl;
		}

		if (!accelerating && car.dynamics.GetSpeed() < stopthreshold)
		{
			break;
		}

		if (car.GetEngineRPM() < 1)
		{
			error_output << "Car stalled during launch, t=" << t << std::endl;
			break;
		}

		if (i % (int)(1.0/dt) == 0) //every second
		{
			//std::cout << t << ", " << car.dynamics.GetSpeed() << ", " << car.GetGear() << ", " << car.GetEngineRPM() << std::endl;
		}

		t += dt;
		i++;
	}

	btVector3 stopend = car.dynamics.GetWheelPosition(WHEEL_POSITION(0));

	info_output << "60-0 stopping distance ";
	if (abs)
		info_output << "(ABS)";
	else
		info_output << "(no ABS)";
	info_output << ": " << ConvertToFeet((stopend-stopstart).length()) << " ft" << std::endl;
}
コード例 #3
0
ファイル: performance_testing.cpp プロジェクト: Timo6/vdrift
void PerformanceTesting::TestStoppingDistance(bool abs, std::ostream & info_output, std::ostream & error_output)
{
	info_output << "Testing stopping distance" << std::endl;

	float maxtime = 300;
	float t = 0.;
	float dt = 1/90.0;
	int i = 0;

	float stopthreshold = 0.1; //if the speed (in m/s) is less than this value, discontinue the testing
	btVector3 stopstart; //where the stopping starts
	float brakestartspeed = 26.82; //speed at which to start braking, in m/s (26.82 m/s is 60 mph)

	// wheel lockup speeds during braking
	float front_lockup_speed = 0.0f;
	float rear_lockup_speed = 0.0f;

	bool accelerating = true; //switches to false once 60 mph is reached

	ResetCar();

	car.SetABS(abs);

	while (t < maxtime)
	{
		if (accelerating && car.GetTransmission().GetGear() == 1 &&
			car.GetEngine().GetRPM() > 0.8f * car.GetEngine().GetRedline())
		{
			carinput[CarInput::BRAKE] = 0;
			carinput[CarInput::CLUTCH] = 0;
		}

		car.Update(carinput);

		world.update(dt);

		float car_speed = car.GetSpeed();

		if (car_speed >= brakestartspeed && accelerating) //stop accelerating and hit the brakes
		{
			stopstart = car.GetWheelPosition(WheelPosition(0));

			carinput[CarInput::THROTTLE] = 0;
			carinput[CarInput::BRAKE] = 1;
			accelerating = false;

			//info_output << "hitting the brakes at " << t << ", " << car_speed << std::endl;
		}

		if (!accelerating && car_speed < stopthreshold)
		{
			break;
		}

		if (!accelerating)
		{
			if (!(front_lockup_speed > 0) && car.GetWheel(WheelPosition(0)).GetRPM() < 0.001f)
			{
				front_lockup_speed = car_speed;
			}
			if (!(rear_lockup_speed > 0) && car.GetWheel(WheelPosition(3)).GetRPM() < 0.001f)
			{
				rear_lockup_speed = car_speed;
			}
		}

		if (t > 0 && !car.GetEngine().GetCombustion())
		{
			error_output << "Car stalled during launch, t=" << t << std::endl;
		}

		if (i % (int)(1/dt) == 0) //every second
		{
			//info_output << t
			//	<< ", " << car_speed
			//	<< ", " << car.GetWheel(WheelPosition(0)).GetAngularVelocity()
			//	<< ", " << car.GetBrake(WheelPosition(0)).GetBrakeFactor()
			//	<< std::endl;
		}

		t += dt;
		i++;
	}

	btVector3 stopend = car.GetWheelPosition(WheelPosition(0));

	info_output << "60-0 stopping distance ";
	if (abs)
		info_output << "(ABS)";
	else
		info_output << "(no ABS)";
	info_output << ": " << ConvertToFeet((stopend-stopstart).length()) << " ft\n"
		<< "Wheel lockup speed " << ConvertToMPH(front_lockup_speed)
		<< ", " << ConvertToMPH(rear_lockup_speed) << std::endl;
}