Changed Radar's API naming

This commit is contained in:
Marc Garcia Puig 2019-12-09 13:02:25 +01:00
parent 158b5ed2cc
commit d682577169
4 changed files with 46 additions and 50 deletions

View File

@ -744,37 +744,35 @@ void UActorBlueprintFunctionLibrary::MakeRadarDefinition(
FillIdAndTags(Definition, TEXT("sensor"), TEXT("other"), TEXT("radar"));
AddVariationsForSensor(Definition);
FActorVariation FOV;
FOV.Id = TEXT("fov");
FOV.Type = EActorAttributeType::Float;
FOV.RecommendedValues = { TEXT("30") };
FOV.bRestrictToRecommended = false;
FActorVariation HorizontalFOV;
HorizontalFOV.Id = TEXT("horizontal_fov");
HorizontalFOV.Type = EActorAttributeType::Float;
HorizontalFOV.RecommendedValues = { TEXT("30") };
HorizontalFOV.bRestrictToRecommended = false;
FActorVariation Steps;
Steps.Id = TEXT("steps");
Steps.Type = EActorAttributeType::Int;
Steps.RecommendedValues = { TEXT("10") };
Steps.bRestrictToRecommended = false;
FActorVariation VerticalFOV;
VerticalFOV.Id = TEXT("vertical_fov");
VerticalFOV.Type = EActorAttributeType::Float;
VerticalFOV.RecommendedValues = { TEXT("30") };
VerticalFOV.bRestrictToRecommended = false;
FActorVariation Far;
Far.Id = TEXT("far");
Far.Type = EActorAttributeType::Float;
Far.RecommendedValues = { TEXT("100") };
Far.bRestrictToRecommended = false;
FActorVariation Range;
Range.Id = TEXT("range");
Range.Type = EActorAttributeType::Float;
Range.RecommendedValues = { TEXT("100") };
Range.bRestrictToRecommended = false;
FActorVariation Aperture;
Aperture.Id = TEXT("aperture");
Aperture.Type = EActorAttributeType::Int;
Aperture.RecommendedValues = { TEXT("10") };
Aperture.bRestrictToRecommended = false;
FActorVariation PointsPerSecond;
PointsPerSecond.Id = TEXT("points_per_second");
PointsPerSecond.Type = EActorAttributeType::Int;
PointsPerSecond.RecommendedValues = { TEXT("1500") };
PointsPerSecond.bRestrictToRecommended = false;
FActorVariation PointLossPercentage;
PointLossPercentage.Id = TEXT("point_loss_percentage");
PointLossPercentage.Type = EActorAttributeType::Float;
PointLossPercentage.RecommendedValues = { TEXT("0.95") };
PointLossPercentage.bRestrictToRecommended = false;
Definition.Variations.Append({FOV, Steps, Far, Aperture, PointLossPercentage});
Definition.Variations.Append({
HorizontalFOV,
VerticalFOV,
Range,
PointsPerSecond});
Success = CheckActorDefinition(Definition);
}
@ -1493,15 +1491,14 @@ void UActorBlueprintFunctionLibrary::SetRadar(
CARLA_ABFL_CHECK_ACTOR(Radar);
constexpr float TO_CENTIMETERS = 1e2;
Radar->SetFOVAndSteps(
RetrieveActorAttributeToFloat("fov", Description.Variations, 30.0f),
RetrieveActorAttributeToInt("steps", Description.Variations, 10));
Radar->SetDistance(
RetrieveActorAttributeToFloat("far", Description.Variations, 100.0f) * TO_CENTIMETERS);
Radar->SetAperture(
RetrieveActorAttributeToInt("aperture", Description.Variations, 10));
Radar->SetPointLossPercentage(
RetrieveActorAttributeToFloat("point_loss_percentage", Description.Variations, 0.95));
Radar->SetHorizontalFOV(
RetrieveActorAttributeToFloat("horizontal_fov", Description.Variations, 30.0f));
Radar->SetVerticalFOV(
RetrieveActorAttributeToFloat("vertical_fov", Description.Variations, 30.0f));
Radar->SetRange(
RetrieveActorAttributeToFloat("range", Description.Variations, 100.0f) * TO_CENTIMETERS);
Radar->SetPointsPerSecond(
RetrieveActorAttributeToInt("points_per_second", Description.Variations, 1500));
}
#undef CARLA_ABFL_CHECK_ACTOR

View File

@ -219,6 +219,4 @@ public:
static void SetIMU(const FActorDescription &Description, AInertialMeasurementUnit *IMU);
static void SetRadar(const FActorDescription &Description, ARadar *Radar);
/// @}
};

View File

@ -9,6 +9,8 @@
#include "Carla/Actor/ActorBlueprintFunctionLibrary.h"
#include "Kismet/KismetMathLibrary.h"
#include "carla/geom/Math.h"
FActorDefinition ARadar::GetSensorDefinition()
{
return UActorBlueprintFunctionLibrary::MakeRadarDefinition();
@ -45,12 +47,12 @@ void ARadar::SetVerticalFOV(float NewVerticalFOV)
VerticalFOV = NewVerticalFOV;
}
void ARadar::SetDistance(float NewDistance)
void ARadar::SetRange(float NewRange)
{
Distance = NewDistance;
Range = NewRange;
}
void ARadar::SetPointsPerSecond(float NewPointsPerSecond)
void ARadar::SetPointsPerSecond(int NewPointsPerSecond)
{
PointsPerSecond = NewPointsPerSecond;
RadarData.SetResolution(PointsPerSecond);
@ -99,13 +101,13 @@ void ARadar::SendLineTraces()
const FVector TransformZAxis = ActorTransform.GetUnitAxis(EAxis::Z);
// Maximun radar radius in horizontal and vertical direction
const float MaxRx = FMath::Tan(FMath::DegreesToRadians(HorizontalFOV * 0.5f)) * Distance;
const float MaxRy = FMath::Tan(FMath::DegreesToRadians(VerticalFOV * 0.5f)) * Distance;
const float MaxRx = FMath::Tan(FMath::DegreesToRadians(HorizontalFOV * 0.5f)) * Range;
const float MaxRy = FMath::Tan(FMath::DegreesToRadians(VerticalFOV * 0.5f)) * Range;
for (int i = 0; i < NumPoints; i++)
for (int i = 0; i < PointsPerSecond; i++)
{
float Radius = RandomEngine->GetUniformFloat();
float Angle = RandomEngine->GetUniformFloatInRange(0.0f, 2.0f * Math.PI);
float Angle = RandomEngine->GetUniformFloatInRange(0.0f, carla::geom::Math::Pi2<float>());
float Sin, Cos;
FMath::SinCos(&Sin, &Cos, Angle);
FVector Rotation = TransformRotator.RotateVector({
@ -113,7 +115,7 @@ void ARadar::SendLineTraces()
MaxRx * Radius * Cos,
MaxRy * Radius * Sin
});
FVector EndLocation = Rotation * Distance;
FVector EndLocation = Rotation * Range;
bool Hitted = World->LineTraceSingleByChannel(
OutHit,
@ -130,7 +132,7 @@ void ARadar::SendLineTraces()
const float RelativeVelocity = CalculateRelativeVelocity(OutHit, RadarLocation, ForwardVector);
FVector2D AzimuthAndElevation = FMath::GetAzimuthAndElevation (
(EndLocation - RadarLocation).GetSafeNormal() * Distance,
(EndLocation - RadarLocation).GetSafeNormal() * Range,
TransformXAxis,
TransformYAxis,
TransformZAxis
@ -144,7 +146,6 @@ void ARadar::SendLineTraces()
});
}
}
}
float ARadar::CalculateRelativeVelocity(const FHitResult& OutHit, const FVector& RadarLocation, const FVector& ForwardVector)

View File

@ -39,7 +39,7 @@ public:
void SetVerticalFOV(float NewVerticalFOV);
UFUNCTION(BlueprintCallable, Category = "Radar")
void SetDistance(float NewDistance);
void SetRange(float NewRange);
UFUNCTION(BlueprintCallable, Category = "Radar")
void SetPointsPerSecond(int NewPointsPerSecond);
@ -51,7 +51,7 @@ protected:
virtual void Tick(float DeltaTime) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Detection")
float Distance;
float Range;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Detection")
float HorizontalFOV;