コード例 #1
0
ファイル: ControlActor.cpp プロジェクト: whiteted/AI_racing
///The main function: Ticking.
///Whether this runs before or after the car's ticking shouldn't matter.
void AControlActor::RaceTick(float DeltaTime) {

	if (raceActive || logAIsensors) {
		timeElapsed += DeltaTime;

		/// ============ Set Variables such as speed, currCurvature, etc. ===========
		currTrackPos = GetTrackPos(car->GetActorLocation());
		velocity = ReadVelocity();
		edgeDist = GetEdgeDist();

		currSection = GetSection(0);
		nextSection = GetSection(1);
		distToCurrSectionEnd = currSection.length - currTrackPos.distThrough;
		float r = distToCurrSectionEnd / currSection.length;
		currCurvature = r*currSection.initCurvature + (1 - r)*currSection.finalCurvature;

		// currSteeringAngle set each time the user sets it
	}

	if (logAIsensors) {
		/// =============== [Debug] Log all the things ============
		UE_LOG(ControlActor, Log, TEXT(""));
		UE_LOG(ControlActor, Log, TEXT("============================================="));

		UE_LOG(ControlActor, Log, TEXT("Time elapsed: %f"), timeElapsed);
		UE_LOG(ControlActor, Log, TEXT("Current section: %d"), currTrackPos.currSectionI);
		UE_LOG(ControlActor, Log, TEXT("Distance through section: %f"), currTrackPos.distThrough);
		UE_LOG(ControlActor, Log, TEXT("Total distancce: %f"), trackSplineDist);
		UE_LOG(ControlActor, Log, TEXT(""));

		UE_LOG(ControlActor, Log, TEXT("Velocity forward: %f"), velocity.ahead);
		UE_LOG(ControlActor, Log, TEXT("Velocity right: %f"), velocity.right);
		UE_LOG(ControlActor, Log, TEXT("Speed: %f"), velocity.speed);
		UE_LOG(ControlActor, Log, TEXT("Angle to ahead: %f"), velocity.angleToAhead);
		UE_LOG(ControlActor, Log, TEXT(""));

		UE_LOG(ControlActor, Log, TEXT("Left edge dist: %f"), edgeDist.left);
		UE_LOG(ControlActor, Log, TEXT("Right edge dist: %f"), edgeDist.right);
	}

	/// ============ Run the AI! ==========
	if (raceActive) {
		ExecuteAIscript();
	}
	else {
		if (!car->userInControl) {
			Accelerate(0);
			SetSteeringAngle(0);
		}
	}
}
コード例 #2
0
ファイル: Parallel.c プロジェクト: CalPolyRobotics/IGVC
// Sloppy psuedo code
// Make cart parallel to left wall
// Assuming it's far enough from the wall
// that the front bumper won't bump into the wall
int main (void) {

	//if side sensors aren't too close to wall
	//nose near wall = 90 - degree
	//back near wall = 90 + degree
	SideAngleToWall = angle

	SetSteeringAngle(SideAngleToWall)
}