Making the result of radar deterministic
This commit is contained in:
parent
fcac0e5528
commit
9e7a132af2
|
@ -105,12 +105,21 @@ void ARadar::SendLineTraces(float DeltaTime)
|
|||
const float MaxRy = FMath::Tan(FMath::DegreesToRadians(VerticalFOV * 0.5f)) * Range;
|
||||
const int NumPoints = (int)(PointsPerSecond * DeltaTime);
|
||||
|
||||
// Generate the parameters of the rays in a deterministic way
|
||||
Rays.clear();
|
||||
Rays.resize(NumPoints);
|
||||
for (int i = 0; i < Rays.size(); i++) {
|
||||
Rays[i].Radius = RandomEngine->GetUniformFloat();
|
||||
Rays[i].Angle = RandomEngine->GetUniformFloatInRange(0.0f, carla::geom::Math::Pi2<float>());
|
||||
Rays[i].Hitted = false;
|
||||
}
|
||||
|
||||
FCriticalSection Mutex;
|
||||
GetWorld()->GetPhysicsScene()->GetPxScene()->lockRead();
|
||||
ParallelFor(NumPoints, [&](int32 idxChannel) {
|
||||
ParallelFor(NumPoints, [&](int32 idx) {
|
||||
FHitResult OutHit(ForceInit);
|
||||
const float Radius = RandomEngine->GetUniformFloat();
|
||||
const float Angle = RandomEngine->GetUniformFloatInRange(0.0f, carla::geom::Math::Pi2<float>());
|
||||
const float Radius = Rays[idx].Radius;
|
||||
const float Angle = Rays[idx].Angle;
|
||||
|
||||
float Sin, Cos;
|
||||
FMath::SinCos(&Sin, &Cos, Angle);
|
||||
|
@ -132,27 +141,34 @@ void ARadar::SendLineTraces(float DeltaTime)
|
|||
|
||||
const TWeakObjectPtr<AActor> HittedActor = OutHit.Actor;
|
||||
if (Hitted && HittedActor.Get()) {
|
||||
Rays[idx].Hitted = true;
|
||||
|
||||
const float RelativeVelocity = CalculateRelativeVelocity(OutHit, RadarLocation);
|
||||
Rays[idx].RelativeVelocity = CalculateRelativeVelocity(OutHit, RadarLocation);
|
||||
|
||||
const FVector2D AzimuthAndElevation = FMath::GetAzimuthAndElevation (
|
||||
Rays[idx].AzimuthAndElevation = FMath::GetAzimuthAndElevation (
|
||||
(EndLocation - RadarLocation).GetSafeNormal() * Range,
|
||||
TransformXAxis,
|
||||
TransformYAxis,
|
||||
TransformZAxis
|
||||
);
|
||||
|
||||
Mutex.Lock();
|
||||
RadarData.WriteDetection({
|
||||
RelativeVelocity,
|
||||
AzimuthAndElevation.X,
|
||||
AzimuthAndElevation.Y,
|
||||
OutHit.Distance * TO_METERS
|
||||
});
|
||||
Mutex.Unlock();
|
||||
Rays[idx].Distance = OutHit.Distance * TO_METERS;
|
||||
}
|
||||
});
|
||||
GetWorld()->GetPhysicsScene()->GetPxScene()->unlockRead();
|
||||
|
||||
// Write the detections in the output structure
|
||||
for (auto& ray : Rays) {
|
||||
if (ray.Hitted) {
|
||||
RadarData.WriteDetection({
|
||||
ray.RelativeVelocity,
|
||||
ray.AzimuthAndElevation.X,
|
||||
ray.AzimuthAndElevation.Y,
|
||||
ray.Distance
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float ARadar::CalculateRelativeVelocity(const FHitResult& OutHit, const FVector& RadarLocation)
|
||||
|
|
|
@ -81,4 +81,14 @@ private:
|
|||
|
||||
UWorld* World;
|
||||
|
||||
struct RayData {
|
||||
float Radius;
|
||||
float Angle;
|
||||
bool Hitted;
|
||||
float RelativeVelocity;
|
||||
FVector2D AzimuthAndElevation;
|
||||
float Distance;
|
||||
};
|
||||
|
||||
std::vector<RayData> Rays;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue