Removing unnecessary comments
This commit is contained in:
parent
8cc6f132fc
commit
c82f9ffc9f
|
@ -14,7 +14,7 @@
|
||||||
FAckermannController::~FAckermannController() {}
|
FAckermannController::~FAckermannController() {}
|
||||||
|
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
// -- FAckermannController --------------------------------------------------------------
|
// -- FAckermannController -----------------------------------------------------
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
FAckermannControllerSettings FAckermannController::GetSettings() const {
|
FAckermannControllerSettings FAckermannController::GetSettings() const {
|
||||||
|
@ -59,25 +59,18 @@ void FAckermannController::Reset() {
|
||||||
// Reset control parameters
|
// Reset control parameters
|
||||||
Steer = 0.0f;
|
Steer = 0.0f;
|
||||||
|
|
||||||
//SpeedControlActivation = 0;
|
|
||||||
|
|
||||||
SpeedControlAccelDelta = 0.0f;
|
SpeedControlAccelDelta = 0.0f;
|
||||||
SpeedControlAccelTarget = 0.0f;
|
SpeedControlAccelTarget = 0.0f;
|
||||||
|
|
||||||
AccelControlPedalDelta = 0.0f;
|
AccelControlPedalDelta = 0.0f;
|
||||||
AccelControlPedalTarget = 0.0f;
|
AccelControlPedalTarget = 0.0f;
|
||||||
|
|
||||||
//ThrottleLowerBorder = 0.0f;
|
|
||||||
//BrakeUpperBorder = 0.0f;
|
|
||||||
|
|
||||||
// Reset vehicle state
|
// Reset vehicle state
|
||||||
VehicleSpeed = 0.0f;
|
VehicleSpeed = 0.0f;
|
||||||
VehicleAcceleration = 0.0f;
|
VehicleAcceleration = 0.0f;
|
||||||
//VehiclePitch = 0.0f;
|
|
||||||
|
|
||||||
LastVehicleSpeed = 0.0f;
|
LastVehicleSpeed = 0.0f;
|
||||||
LastVehicleAcceleration = 0.0f;
|
LastVehicleAcceleration = 0.0f;
|
||||||
//LastVehiclePitch = 0.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FAckermannController::RunLoop(FVehicleControl& Control) {
|
void FAckermannController::RunLoop(FVehicleControl& Control) {
|
||||||
|
@ -172,36 +165,20 @@ void FAckermannController::RunControlReverse() {
|
||||||
|
|
||||||
|
|
||||||
void FAckermannController::RunControlSpeed() {
|
void FAckermannController::RunControlSpeed() {
|
||||||
|
SpeedController.SetTargetPoint(TargetSpeed);
|
||||||
|
SpeedControlAccelDelta = SpeedController.Run(VehicleSpeed, DeltaTime);
|
||||||
|
|
||||||
// TODO(joel): Minimum acceleration 1.0f
|
// Clipping borders
|
||||||
//if (FMath::Abs(TargetAcceleration) < 1.0f) {
|
float ClippingLowerBorder = -FMath::Abs(TargetAcceleration);
|
||||||
// SpeedControlActivation = (SpeedControlActivation < 5) ? SpeedControlActivation + 1 : SpeedControlActivation;
|
float ClippingUpperBorder = FMath::Abs(TargetAcceleration);
|
||||||
//} else {
|
if (FMath::Abs(TargetAcceleration) < 0.0001f) {
|
||||||
// SpeedControlActivation = (SpeedControlActivation > 0) ? SpeedControlActivation - 1 : SpeedControlActivation;
|
// Per definition of AckermannDrive: if zero, then use max value
|
||||||
//}
|
ClippingLowerBorder = -MaxDecel;
|
||||||
|
ClippingUpperBorder = MaxAccel;
|
||||||
//if (SpeedControlActivation >= 5) {
|
}
|
||||||
//SpeedController.SetTargetPoint(FMath::Abs(TargetSpeed));
|
SpeedControlAccelTarget += SpeedControlAccelDelta;
|
||||||
//SpeedControlAccelDelta = SpeedController.Run(FMath::Abs(VehicleSpeed), DeltaTime);
|
SpeedControlAccelTarget = FMath::Clamp(SpeedControlAccelTarget,
|
||||||
SpeedController.SetTargetPoint(TargetSpeed);
|
ClippingLowerBorder, ClippingUpperBorder);
|
||||||
SpeedControlAccelDelta = SpeedController.Run(VehicleSpeed, DeltaTime);
|
|
||||||
|
|
||||||
// Clipping borders
|
|
||||||
float ClippingLowerBorder = -FMath::Abs(TargetAcceleration);
|
|
||||||
float ClippingUpperBorder = FMath::Abs(TargetAcceleration);
|
|
||||||
if (FMath::Abs(TargetAcceleration) < 0.0001f) {
|
|
||||||
// Per definition of AckermannDrive: if zero, then use max value
|
|
||||||
ClippingLowerBorder = -MaxDecel;
|
|
||||||
ClippingUpperBorder = MaxAccel;
|
|
||||||
}
|
|
||||||
SpeedControlAccelTarget += SpeedControlAccelDelta;
|
|
||||||
SpeedControlAccelTarget = FMath::Clamp(SpeedControlAccelTarget,
|
|
||||||
ClippingLowerBorder, ClippingUpperBorder);
|
|
||||||
|
|
||||||
//} else {
|
|
||||||
// SpeedControlAccelDelta = 0.0f;
|
|
||||||
// SpeedControlAccelTarget = TargetAcceleration;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FAckermannController::RunControlAcceleration() {
|
void FAckermannController::RunControlAcceleration() {
|
||||||
|
@ -210,86 +187,44 @@ void FAckermannController::RunControlAcceleration() {
|
||||||
|
|
||||||
// Clipping borders
|
// Clipping borders
|
||||||
AccelControlPedalTarget += AccelControlPedalDelta;
|
AccelControlPedalTarget += AccelControlPedalDelta;
|
||||||
//AccelControlPedalTarget = FMath::Clamp(AccelControlPedalTarget, -MaxPedal, MaxPedal);
|
|
||||||
AccelControlPedalTarget = FMath::Clamp(AccelControlPedalTarget, -1.0f, 1.0f);
|
AccelControlPedalTarget = FMath::Clamp(AccelControlPedalTarget, -1.0f, 1.0f);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FAckermannController::UpdateVehicleControlCommand() {
|
void FAckermannController::UpdateVehicleControlCommand() {
|
||||||
|
|
||||||
if (AccelControlPedalTarget < 0.0f) {
|
if (AccelControlPedalTarget < 0.0f) {
|
||||||
if (bReverse) {
|
if (bReverse) {
|
||||||
Throttle = FMath::Abs(AccelControlPedalTarget);
|
Throttle = FMath::Abs(AccelControlPedalTarget);
|
||||||
Brake = 0.0f;
|
Brake = 0.0f;
|
||||||
} else {
|
|
||||||
Throttle = 0.0f;
|
|
||||||
Brake = FMath::Abs(AccelControlPedalTarget);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (bReverse) {
|
Throttle = 0.0f;
|
||||||
Throttle = 0.0f;
|
Brake = FMath::Abs(AccelControlPedalTarget);
|
||||||
Brake = FMath::Abs(AccelControlPedalTarget);
|
|
||||||
} else {
|
|
||||||
Throttle = FMath::Abs(AccelControlPedalTarget);
|
|
||||||
Brake = 0.0f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// ThrottleLowerBorder = GetVehicleDrivingImpedanceAcceleration();
|
if (bReverse) {
|
||||||
// BrakeUpperBorder = ThrottleLowerBorder + GetVehicleLayOffEngineAcceleration();
|
Throttle = 0.0f;
|
||||||
|
Brake = FMath::Abs(AccelControlPedalTarget);
|
||||||
// if (AccelControlPedalTarget > ThrottleLowerBorder) {
|
} else {
|
||||||
// // Accelerating
|
Throttle = FMath::Abs(AccelControlPedalTarget);
|
||||||
// Throttle = (AccelControlPedalTarget - ThrottleLowerBorder) / MaxPedal;
|
Brake = 0.0f;
|
||||||
// Brake = 0.0f;
|
}
|
||||||
|
}
|
||||||
// } else if (AccelControlPedalTarget > BrakeUpperBorder) {
|
|
||||||
// // Coasting
|
|
||||||
// Throttle = 0.0f;
|
|
||||||
// Brake = 0.0f;
|
|
||||||
// } else {
|
|
||||||
// // Braking
|
|
||||||
// Throttle = 0.0f;
|
|
||||||
// Brake = (BrakeUpperBorder - AccelControlPedalTarget) / MaxPedal;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// float FAckermannController::GetVehicleLayOffEngineAcceleration() {
|
|
||||||
// float EngineBrakeForce = 500.0f; // [N]
|
|
||||||
// return -EngineBrakeForce / VehicleMass;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// float FAckermannController::GetVehicleDrivingImpedanceAcceleration() {
|
|
||||||
// float RollingResistanceForce = 0.01 * 9.81f * VehicleMass;
|
|
||||||
// float AirDensity = 1.25f;
|
|
||||||
// float AerodynamicDragForce = 0.5f * AirDensity * VehicleDragCoefficient * VehicleDragArea * (VehicleSpeed * VehicleSpeed);
|
|
||||||
// //float SlopeForce = 9.81f * VehicleMass * FMath::Sin(VehiclePitch);
|
|
||||||
// float SlopeForce = 0.0f;
|
|
||||||
|
|
||||||
// return -(RollingResistanceForce + AerodynamicDragForce + SlopeForce) / VehicleMass;
|
|
||||||
// }
|
|
||||||
|
|
||||||
void FAckermannController::UpdateVehicleState(const ACarlaWheeledVehicle* Vehicle) {
|
void FAckermannController::UpdateVehicleState(const ACarlaWheeledVehicle* Vehicle) {
|
||||||
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
|
TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
|
||||||
|
|
||||||
LastVehicleSpeed = VehicleSpeed;
|
LastVehicleSpeed = VehicleSpeed;
|
||||||
LastVehicleAcceleration = VehicleAcceleration;
|
LastVehicleAcceleration = VehicleAcceleration;
|
||||||
//LastVehiclePitch = VehiclePitch;
|
|
||||||
|
|
||||||
// Update simulation state
|
// Update simulation state
|
||||||
DeltaTime = Vehicle->GetWorld()->GetDeltaSeconds();
|
DeltaTime = Vehicle->GetWorld()->GetDeltaSeconds();
|
||||||
|
|
||||||
// Update Vehicle state
|
// Update Vehicle state
|
||||||
//VehicleSpeed = FMath::RoundToFloat((Vehicle->GetVehicleForwardSpeed() / 100.0f) * 10.0f) / 10.0f; // From cm/s to m/s
|
|
||||||
VehicleSpeed = Vehicle->GetVehicleForwardSpeed() / 100.0f; // From cm/s to m/s
|
VehicleSpeed = Vehicle->GetVehicleForwardSpeed() / 100.0f; // From cm/s to m/s
|
||||||
//VehicleSpeed = (4.0f*LastVehicleSpeed + CurrentSpeed) / 5.0f;
|
|
||||||
|
|
||||||
float CurrentAcceleration = (VehicleSpeed - LastVehicleSpeed) / DeltaTime;
|
float CurrentAcceleration = (VehicleSpeed - LastVehicleSpeed) / DeltaTime;
|
||||||
//CurrentAcceleration = FMath::RoundToFloat(CurrentAcceleration * 10.0f) / 10.0f;
|
|
||||||
VehicleAcceleration = (4.0f*LastVehicleAcceleration + CurrentAcceleration) / 5.0f;
|
VehicleAcceleration = (4.0f*LastVehicleAcceleration + CurrentAcceleration) / 5.0f;
|
||||||
//VehiclePitch = FMath::DegreesToRadians(
|
|
||||||
// Vehicle->GetVehicleTransform().GetRotation().Rotator().Pitch
|
|
||||||
//);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FAckermannController::UpdateVehiclePhysics(const ACarlaWheeledVehicle* Vehicle) {
|
void FAckermannController::UpdateVehiclePhysics(const ACarlaWheeledVehicle* Vehicle) {
|
||||||
|
@ -298,8 +233,5 @@ void FAckermannController::UpdateVehiclePhysics(const ACarlaWheeledVehicle* Vehi
|
||||||
check(Vehicle4W != nullptr);
|
check(Vehicle4W != nullptr);
|
||||||
|
|
||||||
// Update vehicle physics
|
// Update vehicle physics
|
||||||
//VehicleMass = Vehicle4W->Mass;
|
|
||||||
//VehicleDragArea = Vehicle4W->DragArea / (100.0f * 100.0f); // From cm2 to m2
|
|
||||||
//VehicleDragCoefficient = Vehicle4W->DragCoefficient;
|
|
||||||
VehicleMaxSteering = FMath::DegreesToRadians(Vehicle->GetMaximumSteerAngle());
|
VehicleMaxSteering = FMath::DegreesToRadians(Vehicle->GetMaximumSteerAngle());
|
||||||
}
|
}
|
|
@ -110,9 +110,6 @@ private:
|
||||||
void RunControlAcceleration();
|
void RunControlAcceleration();
|
||||||
void UpdateVehicleControlCommand();
|
void UpdateVehicleControlCommand();
|
||||||
|
|
||||||
//float GetVehicleDrivingImpedanceAcceleration();
|
|
||||||
//float GetVehicleLayOffEngineAcceleration();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
PID SpeedController = PID(0.15f, 0.0f, 0.25f);
|
PID SpeedController = PID(0.15f, 0.0f, 0.25f);
|
||||||
|
@ -130,8 +127,6 @@ private:
|
||||||
float MaxAccel = 3.0f; // [m/s2]
|
float MaxAccel = 3.0f; // [m/s2]
|
||||||
float MaxDecel = 8.0f; // [m/s2]
|
float MaxDecel = 8.0f; // [m/s2]
|
||||||
|
|
||||||
//float MaxPedal = 3.0f; // min(MaxAccel, MaxDecel)
|
|
||||||
|
|
||||||
// Control parameters
|
// Control parameters
|
||||||
float Steer = 0.0f;
|
float Steer = 0.0f;
|
||||||
float Throttle = 0.0f;
|
float Throttle = 0.0f;
|
||||||
|
@ -149,16 +144,11 @@ private:
|
||||||
float DeltaTime = 0.0f; // [s]
|
float DeltaTime = 0.0f; // [s]
|
||||||
|
|
||||||
// Vehicle state
|
// Vehicle state
|
||||||
//float VehicleMass = 0.0f; // [Kg]
|
|
||||||
float VehicleMaxSteering = 0.0f; // [rad]
|
float VehicleMaxSteering = 0.0f; // [rad]
|
||||||
//float VehicleDragArea = 0.0f; // [m2]
|
|
||||||
//float VehicleDragCoefficient = 0.0f; // [?]
|
|
||||||
|
|
||||||
float VehicleSpeed = 0.0f; // [m/s]
|
float VehicleSpeed = 0.0f; // [m/s]
|
||||||
float VehicleAcceleration = 0.0f; // [m/s2]
|
float VehicleAcceleration = 0.0f; // [m/s2]
|
||||||
//float VehiclePitch = 0.0f; // [rad]
|
|
||||||
|
|
||||||
float LastVehicleSpeed = 0.0f; // [m/s]
|
float LastVehicleSpeed = 0.0f; // [m/s]
|
||||||
float LastVehicleAcceleration = 0.0f; // [m/s2]
|
float LastVehicleAcceleration = 0.0f; // [m/s2]
|
||||||
//float LastVehiclePitch = 0.0f; // [rad]
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue