fixed spaces
This commit is contained in:
parent
967e6fe19c
commit
4561d4a333
|
@ -315,7 +315,6 @@ class CarlaGame(object):
|
|||
)
|
||||
self._display.blit(surface, (10, 10))
|
||||
|
||||
|
||||
if self._map_view is not None:
|
||||
array = self._map_view
|
||||
array = array[:, :, :3]
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
// Sets default values
|
||||
ALidar::ALidar()
|
||||
{
|
||||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
auto MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("CamMesh0"));
|
||||
MeshComp->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
|
||||
|
@ -24,12 +24,12 @@ ALidar::ALidar()
|
|||
void ALidar::Set(const FLidarDescription &LidarDescription)
|
||||
{
|
||||
Channels = LidarDescription.Channels;
|
||||
Range = LidarDescription.Range;
|
||||
PointsPerSecond = LidarDescription.PointsPerSecond;
|
||||
RotationFrequency = LidarDescription.RotationFrequency;
|
||||
UpperFovLimit = LidarDescription.UpperFovLimit;
|
||||
LowerFovLimit = LidarDescription.LowerFovLimit;
|
||||
ShowDebugPoints = LidarDescription.ShowDebugPoints;
|
||||
Range = LidarDescription.Range;
|
||||
PointsPerSecond = LidarDescription.PointsPerSecond;
|
||||
RotationFrequency = LidarDescription.RotationFrequency;
|
||||
UpperFovLimit = LidarDescription.UpperFovLimit;
|
||||
LowerFovLimit = LidarDescription.LowerFovLimit;
|
||||
ShowDebugPoints = LidarDescription.ShowDebugPoints;
|
||||
CreateLasers();
|
||||
}
|
||||
|
||||
|
@ -38,45 +38,45 @@ void ALidar::CreateLasers()
|
|||
float dAngle = (UpperFovLimit - LowerFovLimit) / (Channels - 1);
|
||||
|
||||
Lasers.Empty();
|
||||
for(int i=0; i<Channels; i++)
|
||||
{
|
||||
Lasers.Emplace(i, UpperFovLimit - i * dAngle);
|
||||
}
|
||||
for(int i=0; i<Channels; i++)
|
||||
{
|
||||
Lasers.Emplace(i, UpperFovLimit - i * dAngle);
|
||||
}
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ALidar::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
void ALidar::ReadPoints(float DeltaTime, FCapturedLidarSegment& LidarSegmentData)
|
||||
{
|
||||
int PointsToScanWithOneLaser = int(FMath::RoundHalfFromZero(PointsPerSecond * DeltaTime / float(Channels)));
|
||||
int PointsToScanWithOneLaser = int(FMath::RoundHalfFromZero(PointsPerSecond * DeltaTime / float(Channels)));
|
||||
|
||||
float AngleDistanceOfTick = RotationFrequency * 360 * DeltaTime;
|
||||
float AngleDistanceOfLaserMeasure = AngleDistanceOfTick / PointsToScanWithOneLaser;
|
||||
float AngleDistanceOfTick = RotationFrequency * 360 * DeltaTime;
|
||||
float AngleDistanceOfLaserMeasure = AngleDistanceOfTick / PointsToScanWithOneLaser;
|
||||
|
||||
LidarSegmentData.LidarLasersSegments.Empty();
|
||||
LidarSegmentData.LidarLasersSegments.Empty();
|
||||
|
||||
auto NumOfLasers = Lasers.Num();
|
||||
LidarSegmentData.LidarLasersSegments.AddDefaulted(NumOfLasers);
|
||||
for (int li=0; li<NumOfLasers; li++)
|
||||
{
|
||||
auto& Laser = Lasers[li];
|
||||
auto& LaserPoints = LidarSegmentData.LidarLasersSegments[li].Points;
|
||||
LaserPoints.AddDefaulted(PointsToScanWithOneLaser);
|
||||
for (int i=0; i<PointsToScanWithOneLaser; i++)
|
||||
{
|
||||
Laser.Measure(
|
||||
this,
|
||||
CurrentHorizontalAngle + AngleDistanceOfLaserMeasure * i,
|
||||
LaserPoints[i],
|
||||
ShowDebugPoints
|
||||
);
|
||||
}
|
||||
}
|
||||
auto NumOfLasers = Lasers.Num();
|
||||
LidarSegmentData.LidarLasersSegments.AddDefaulted(NumOfLasers);
|
||||
for (int li=0; li<NumOfLasers; li++)
|
||||
{
|
||||
auto& Laser = Lasers[li];
|
||||
auto& LaserPoints = LidarSegmentData.LidarLasersSegments[li].Points;
|
||||
LaserPoints.AddDefaulted(PointsToScanWithOneLaser);
|
||||
for (int i=0; i<PointsToScanWithOneLaser; i++)
|
||||
{
|
||||
Laser.Measure(
|
||||
this,
|
||||
CurrentHorizontalAngle + AngleDistanceOfLaserMeasure * i,
|
||||
LaserPoints[i],
|
||||
ShowDebugPoints
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
CurrentHorizontalAngle = fmod(CurrentHorizontalAngle + AngleDistanceOfTick, 360.0f);
|
||||
LidarSegmentData.HorizontalAngle = CurrentHorizontalAngle;
|
||||
CurrentHorizontalAngle = fmod(CurrentHorizontalAngle + AngleDistanceOfTick, 360.0f);
|
||||
LidarSegmentData.HorizontalAngle = CurrentHorizontalAngle;
|
||||
}
|
||||
|
|
|
@ -12,20 +12,20 @@
|
|||
UCLASS()
|
||||
class CARLA_API ALidar : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
ALidar();
|
||||
// Sets default values for this actor's properties
|
||||
ALidar();
|
||||
|
||||
void Set(const FLidarDescription &LidarDescription);
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
TArray<LidarLaser> Lasers;
|
||||
float CurrentHorizontalAngle = 0;
|
||||
TArray<LidarLaser> Lasers;
|
||||
float CurrentHorizontalAngle = 0;
|
||||
|
||||
void CreateLasers();
|
||||
|
||||
|
@ -35,37 +35,37 @@ public:
|
|||
void ReadPoints(float DeltaTime, FCapturedLidarSegment& LidarSegmentData);
|
||||
|
||||
/** Number of lasers */
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
int Channels = 32;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
int Channels = 32;
|
||||
|
||||
/** Measure distance */
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float Range = 5000;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float Range = 5000;
|
||||
|
||||
/** Points generated by all lasers per second */
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float PointsPerSecond = 56000;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float PointsPerSecond = 56000;
|
||||
|
||||
/** Lidar rotation frequency */
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float RotationFrequency = 10;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float RotationFrequency = 10;
|
||||
|
||||
/**
|
||||
Upper laser angle, counts from horizontal,
|
||||
positive values means above horizontal line
|
||||
*/
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float UpperFovLimit = 10;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float UpperFovLimit = 10;
|
||||
|
||||
/**
|
||||
Lower laser angle, counts from horizontal,
|
||||
negative values means under horizontal line
|
||||
*/
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float LowerFovLimit = -30;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float LowerFovLimit = -30;
|
||||
|
||||
/** wether to show debug points of laser hits in simulator */
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
bool ShowDebugPoints = false;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
bool ShowDebugPoints = false;
|
||||
|
||||
};
|
||||
|
|
|
@ -8,47 +8,47 @@
|
|||
|
||||
int LidarLaser::GetId()
|
||||
{
|
||||
return Id;
|
||||
return Id;
|
||||
}
|
||||
|
||||
bool LidarLaser::Measure(ALidar* Lidar, float HorizontalAngle, FVector& XYZ, bool Debug)
|
||||
{
|
||||
FCollisionQueryParams TraceParams = FCollisionQueryParams(FName(TEXT("Laser_Trace")), true, Lidar);
|
||||
TraceParams.bTraceComplex = true;
|
||||
TraceParams.bReturnPhysicalMaterial = false;
|
||||
FCollisionQueryParams TraceParams = FCollisionQueryParams(FName(TEXT("Laser_Trace")), true, Lidar);
|
||||
TraceParams.bTraceComplex = true;
|
||||
TraceParams.bReturnPhysicalMaterial = false;
|
||||
|
||||
FHitResult HitInfo(ForceInit);
|
||||
FHitResult HitInfo(ForceInit);
|
||||
|
||||
FVector LidarBodyLoc = Lidar->GetActorLocation();
|
||||
FVector LidarBodyLoc = Lidar->GetActorLocation();
|
||||
FRotator LidarBodyRot = Lidar->GetActorRotation();
|
||||
FRotator LaserRot (VerticalAngle, HorizontalAngle, 0); // float InPitch, float InYaw, float InRoll
|
||||
FRotator LaserRot (VerticalAngle, HorizontalAngle, 0); // float InPitch, float InYaw, float InRoll
|
||||
FRotator ResultRot = UKismetMathLibrary::ComposeRotators(
|
||||
LaserRot,
|
||||
LidarBodyRot
|
||||
);
|
||||
FVector EndTrace = Lidar->Range * UKismetMathLibrary::GetForwardVector(ResultRot) + LidarBodyLoc;
|
||||
FVector EndTrace = Lidar->Range * UKismetMathLibrary::GetForwardVector(ResultRot) + LidarBodyLoc;
|
||||
|
||||
Lidar->GetWorld()->LineTraceSingleByChannel(
|
||||
HitInfo,
|
||||
LidarBodyLoc,
|
||||
EndTrace,
|
||||
ECC_MAX,
|
||||
TraceParams,
|
||||
FCollisionResponseParams::DefaultResponseParam
|
||||
);
|
||||
Lidar->GetWorld()->LineTraceSingleByChannel(
|
||||
HitInfo,
|
||||
LidarBodyLoc,
|
||||
EndTrace,
|
||||
ECC_MAX,
|
||||
TraceParams,
|
||||
FCollisionResponseParams::DefaultResponseParam
|
||||
);
|
||||
|
||||
if (HitInfo.bBlockingHit)
|
||||
{
|
||||
if (HitInfo.bBlockingHit)
|
||||
{
|
||||
if (Debug)
|
||||
{
|
||||
DrawDebugPoint(
|
||||
Lidar->GetWorld(),
|
||||
HitInfo.ImpactPoint,
|
||||
10, //size
|
||||
FColor(255,0,255),
|
||||
false, //persistent (never goes away)
|
||||
0.1 //point leaves a trail on moving object
|
||||
);
|
||||
DrawDebugPoint(
|
||||
Lidar->GetWorld(),
|
||||
HitInfo.ImpactPoint,
|
||||
10, //size
|
||||
FColor(255,0,255),
|
||||
false, //persistent (never goes away)
|
||||
0.1 //point leaves a trail on moving object
|
||||
);
|
||||
}
|
||||
|
||||
XYZ = LidarBodyLoc - HitInfo.ImpactPoint;
|
||||
|
@ -58,9 +58,9 @@ bool LidarLaser::Measure(ALidar* Lidar, float HorizontalAngle, FVector& XYZ, boo
|
|||
FVector(0, 0, 1)
|
||||
);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return true;
|
||||
} else {
|
||||
XYZ = FVector(0, 0, 0);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,17 +10,17 @@ class CARLA_API LidarLaser
|
|||
{
|
||||
public:
|
||||
|
||||
LidarLaser(int Id, float VerticalAngle) :
|
||||
Id(Id),
|
||||
VerticalAngle(VerticalAngle)
|
||||
{}
|
||||
LidarLaser(int Id, float VerticalAngle) :
|
||||
Id(Id),
|
||||
VerticalAngle(VerticalAngle)
|
||||
{}
|
||||
|
||||
int GetId();
|
||||
bool Measure(ALidar* Lidar, float HorizontalAngle, FVector& XYZ, bool Debug = false);
|
||||
int GetId();
|
||||
bool Measure(ALidar* Lidar, float HorizontalAngle, FVector& XYZ, bool Debug = false);
|
||||
|
||||
private:
|
||||
|
||||
int Id;
|
||||
float VerticalAngle;
|
||||
int Id;
|
||||
float VerticalAngle;
|
||||
|
||||
};
|
||||
|
|
|
@ -10,38 +10,38 @@ struct FLidarDescription
|
|||
GENERATED_USTRUCT_BODY()
|
||||
|
||||
/** Number of lasers */
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
int Channels = 32;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
int Channels = 32;
|
||||
|
||||
/** Measure distance */
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float Range = 5000;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float Range = 5000;
|
||||
|
||||
/** Points generated by all lasers per second */
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float PointsPerSecond = 56000;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float PointsPerSecond = 56000;
|
||||
|
||||
/** Lidar rotation frequency */
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float RotationFrequency = 10;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float RotationFrequency = 10;
|
||||
|
||||
/**
|
||||
Upper laser angle, counts from horizontal,
|
||||
positive values means above horizontal line
|
||||
*/
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float UpperFovLimit = 10;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float UpperFovLimit = 10;
|
||||
|
||||
/**
|
||||
Lower laser angle, counts from horizontal,
|
||||
negative values means under horizontal line
|
||||
*/
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float LowerFovLimit = -30;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
float LowerFovLimit = -30;
|
||||
|
||||
/** wether to show debug points of laser hits in simulator */
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
bool ShowDebugPoints = false;
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
|
||||
bool ShowDebugPoints = false;
|
||||
|
||||
/** Position relative to the player. */
|
||||
UPROPERTY(Category = "Lidar Description", EditDefaultsOnly)
|
||||
|
|
Loading…
Reference in New Issue