fixed spaces

This commit is contained in:
Anton Pechenko 2017-12-05 16:29:06 +03:00
parent 967e6fe19c
commit 4561d4a333
6 changed files with 109 additions and 110 deletions

View File

@ -315,7 +315,6 @@ class CarlaGame(object):
) )
self._display.blit(surface, (10, 10)) self._display.blit(surface, (10, 10))
if self._map_view is not None: if self._map_view is not None:
array = self._map_view array = self._map_view
array = array[:, :, :3] array = array[:, :, :3]

View File

@ -8,8 +8,8 @@
// Sets default values // Sets default values
ALidar::ALidar() ALidar::ALidar()
{ {
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. // 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; PrimaryActorTick.bCanEverTick = true;
auto MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("CamMesh0")); auto MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("CamMesh0"));
MeshComp->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName); MeshComp->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
@ -24,12 +24,12 @@ ALidar::ALidar()
void ALidar::Set(const FLidarDescription &LidarDescription) void ALidar::Set(const FLidarDescription &LidarDescription)
{ {
Channels = LidarDescription.Channels; Channels = LidarDescription.Channels;
Range = LidarDescription.Range; Range = LidarDescription.Range;
PointsPerSecond = LidarDescription.PointsPerSecond; PointsPerSecond = LidarDescription.PointsPerSecond;
RotationFrequency = LidarDescription.RotationFrequency; RotationFrequency = LidarDescription.RotationFrequency;
UpperFovLimit = LidarDescription.UpperFovLimit; UpperFovLimit = LidarDescription.UpperFovLimit;
LowerFovLimit = LidarDescription.LowerFovLimit; LowerFovLimit = LidarDescription.LowerFovLimit;
ShowDebugPoints = LidarDescription.ShowDebugPoints; ShowDebugPoints = LidarDescription.ShowDebugPoints;
CreateLasers(); CreateLasers();
} }
@ -38,45 +38,45 @@ void ALidar::CreateLasers()
float dAngle = (UpperFovLimit - LowerFovLimit) / (Channels - 1); float dAngle = (UpperFovLimit - LowerFovLimit) / (Channels - 1);
Lasers.Empty(); Lasers.Empty();
for(int i=0; i<Channels; i++) for(int i=0; i<Channels; i++)
{ {
Lasers.Emplace(i, UpperFovLimit - i * dAngle); Lasers.Emplace(i, UpperFovLimit - i * dAngle);
} }
} }
// Called when the game starts or when spawned // Called when the game starts or when spawned
void ALidar::BeginPlay() void ALidar::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
} }
void ALidar::ReadPoints(float DeltaTime, FCapturedLidarSegment& LidarSegmentData) 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 AngleDistanceOfTick = RotationFrequency * 360 * DeltaTime;
float AngleDistanceOfLaserMeasure = AngleDistanceOfTick / PointsToScanWithOneLaser; float AngleDistanceOfLaserMeasure = AngleDistanceOfTick / PointsToScanWithOneLaser;
LidarSegmentData.LidarLasersSegments.Empty(); LidarSegmentData.LidarLasersSegments.Empty();
auto NumOfLasers = Lasers.Num(); auto NumOfLasers = Lasers.Num();
LidarSegmentData.LidarLasersSegments.AddDefaulted(NumOfLasers); LidarSegmentData.LidarLasersSegments.AddDefaulted(NumOfLasers);
for (int li=0; li<NumOfLasers; li++) for (int li=0; li<NumOfLasers; li++)
{ {
auto& Laser = Lasers[li]; auto& Laser = Lasers[li];
auto& LaserPoints = LidarSegmentData.LidarLasersSegments[li].Points; auto& LaserPoints = LidarSegmentData.LidarLasersSegments[li].Points;
LaserPoints.AddDefaulted(PointsToScanWithOneLaser); LaserPoints.AddDefaulted(PointsToScanWithOneLaser);
for (int i=0; i<PointsToScanWithOneLaser; i++) for (int i=0; i<PointsToScanWithOneLaser; i++)
{ {
Laser.Measure( Laser.Measure(
this, this,
CurrentHorizontalAngle + AngleDistanceOfLaserMeasure * i, CurrentHorizontalAngle + AngleDistanceOfLaserMeasure * i,
LaserPoints[i], LaserPoints[i],
ShowDebugPoints ShowDebugPoints
); );
} }
} }
CurrentHorizontalAngle = fmod(CurrentHorizontalAngle + AngleDistanceOfTick, 360.0f); CurrentHorizontalAngle = fmod(CurrentHorizontalAngle + AngleDistanceOfTick, 360.0f);
LidarSegmentData.HorizontalAngle = CurrentHorizontalAngle; LidarSegmentData.HorizontalAngle = CurrentHorizontalAngle;
} }

View File

@ -12,20 +12,20 @@
UCLASS() UCLASS()
class CARLA_API ALidar : public AActor class CARLA_API ALidar : public AActor
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
// Sets default values for this actor's properties // Sets default values for this actor's properties
ALidar(); ALidar();
void Set(const FLidarDescription &LidarDescription); void Set(const FLidarDescription &LidarDescription);
protected: protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
virtual void BeginPlay() override; virtual void BeginPlay() override;
TArray<LidarLaser> Lasers; TArray<LidarLaser> Lasers;
float CurrentHorizontalAngle = 0; float CurrentHorizontalAngle = 0;
void CreateLasers(); void CreateLasers();
@ -35,37 +35,37 @@ public:
void ReadPoints(float DeltaTime, FCapturedLidarSegment& LidarSegmentData); void ReadPoints(float DeltaTime, FCapturedLidarSegment& LidarSegmentData);
/** Number of lasers */ /** Number of lasers */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
int Channels = 32; int Channels = 32;
/** Measure distance */ /** Measure distance */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
float Range = 5000; float Range = 5000;
/** Points generated by all lasers per second */ /** Points generated by all lasers per second */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
float PointsPerSecond = 56000; float PointsPerSecond = 56000;
/** Lidar rotation frequency */ /** Lidar rotation frequency */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
float RotationFrequency = 10; float RotationFrequency = 10;
/** /**
Upper laser angle, counts from horizontal, Upper laser angle, counts from horizontal,
positive values means above horizontal line positive values means above horizontal line
*/ */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
float UpperFovLimit = 10; float UpperFovLimit = 10;
/** /**
Lower laser angle, counts from horizontal, Lower laser angle, counts from horizontal,
negative values means under horizontal line negative values means under horizontal line
*/ */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
float LowerFovLimit = -30; float LowerFovLimit = -30;
/** wether to show debug points of laser hits in simulator */ /** wether to show debug points of laser hits in simulator */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
bool ShowDebugPoints = false; bool ShowDebugPoints = false;
}; };

View File

@ -8,47 +8,47 @@
int LidarLaser::GetId() int LidarLaser::GetId()
{ {
return Id; return Id;
} }
bool LidarLaser::Measure(ALidar* Lidar, float HorizontalAngle, FVector& XYZ, bool Debug) bool LidarLaser::Measure(ALidar* Lidar, float HorizontalAngle, FVector& XYZ, bool Debug)
{ {
FCollisionQueryParams TraceParams = FCollisionQueryParams(FName(TEXT("Laser_Trace")), true, Lidar); FCollisionQueryParams TraceParams = FCollisionQueryParams(FName(TEXT("Laser_Trace")), true, Lidar);
TraceParams.bTraceComplex = true; TraceParams.bTraceComplex = true;
TraceParams.bReturnPhysicalMaterial = false; TraceParams.bReturnPhysicalMaterial = false;
FHitResult HitInfo(ForceInit); FHitResult HitInfo(ForceInit);
FVector LidarBodyLoc = Lidar->GetActorLocation(); FVector LidarBodyLoc = Lidar->GetActorLocation();
FRotator LidarBodyRot = Lidar->GetActorRotation(); 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( FRotator ResultRot = UKismetMathLibrary::ComposeRotators(
LaserRot, LaserRot,
LidarBodyRot LidarBodyRot
); );
FVector EndTrace = Lidar->Range * UKismetMathLibrary::GetForwardVector(ResultRot) + LidarBodyLoc; FVector EndTrace = Lidar->Range * UKismetMathLibrary::GetForwardVector(ResultRot) + LidarBodyLoc;
Lidar->GetWorld()->LineTraceSingleByChannel( Lidar->GetWorld()->LineTraceSingleByChannel(
HitInfo, HitInfo,
LidarBodyLoc, LidarBodyLoc,
EndTrace, EndTrace,
ECC_MAX, ECC_MAX,
TraceParams, TraceParams,
FCollisionResponseParams::DefaultResponseParam FCollisionResponseParams::DefaultResponseParam
); );
if (HitInfo.bBlockingHit) if (HitInfo.bBlockingHit)
{ {
if (Debug) if (Debug)
{ {
DrawDebugPoint( DrawDebugPoint(
Lidar->GetWorld(), Lidar->GetWorld(),
HitInfo.ImpactPoint, HitInfo.ImpactPoint,
10, //size 10, //size
FColor(255,0,255), FColor(255,0,255),
false, //persistent (never goes away) false, //persistent (never goes away)
0.1 //point leaves a trail on moving object 0.1 //point leaves a trail on moving object
); );
} }
XYZ = LidarBodyLoc - HitInfo.ImpactPoint; XYZ = LidarBodyLoc - HitInfo.ImpactPoint;
@ -58,9 +58,9 @@ bool LidarLaser::Measure(ALidar* Lidar, float HorizontalAngle, FVector& XYZ, boo
FVector(0, 0, 1) FVector(0, 0, 1)
); );
return true; return true;
} else { } else {
XYZ = FVector(0, 0, 0); XYZ = FVector(0, 0, 0);
return false; return false;
} }
} }

View File

@ -10,17 +10,17 @@ class CARLA_API LidarLaser
{ {
public: public:
LidarLaser(int Id, float VerticalAngle) : LidarLaser(int Id, float VerticalAngle) :
Id(Id), Id(Id),
VerticalAngle(VerticalAngle) VerticalAngle(VerticalAngle)
{} {}
int GetId(); int GetId();
bool Measure(ALidar* Lidar, float HorizontalAngle, FVector& XYZ, bool Debug = false); bool Measure(ALidar* Lidar, float HorizontalAngle, FVector& XYZ, bool Debug = false);
private: private:
int Id; int Id;
float VerticalAngle; float VerticalAngle;
}; };

View File

@ -10,38 +10,38 @@ struct FLidarDescription
GENERATED_USTRUCT_BODY() GENERATED_USTRUCT_BODY()
/** Number of lasers */ /** Number of lasers */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
int Channels = 32; int Channels = 32;
/** Measure distance */ /** Measure distance */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
float Range = 5000; float Range = 5000;
/** Points generated by all lasers per second */ /** Points generated by all lasers per second */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
float PointsPerSecond = 56000; float PointsPerSecond = 56000;
/** Lidar rotation frequency */ /** Lidar rotation frequency */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
float RotationFrequency = 10; float RotationFrequency = 10;
/** /**
Upper laser angle, counts from horizontal, Upper laser angle, counts from horizontal,
positive values means above horizontal line positive values means above horizontal line
*/ */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
float UpperFovLimit = 10; float UpperFovLimit = 10;
/** /**
Lower laser angle, counts from horizontal, Lower laser angle, counts from horizontal,
negative values means under horizontal line negative values means under horizontal line
*/ */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
float LowerFovLimit = -30; float LowerFovLimit = -30;
/** wether to show debug points of laser hits in simulator */ /** wether to show debug points of laser hits in simulator */
UPROPERTY(EditDefaultsOnly, Category = "Lidar Description") UPROPERTY(EditDefaultsOnly, Category = "Lidar Description")
bool ShowDebugPoints = false; bool ShowDebugPoints = false;
/** Position relative to the player. */ /** Position relative to the player. */
UPROPERTY(Category = "Lidar Description", EditDefaultsOnly) UPROPERTY(Category = "Lidar Description", EditDefaultsOnly)