17#include <util/ue-header-guard-begin.h>
18#include "DrawDebugHelpers.h"
19#include "Engine/CollisionProfile.h"
20#include "Kismet/KismetMathLibrary.h"
21#include <util/ue-header-guard-end.h>
32 : Super(ObjectInitializer) {
34 RandomEngine = CreateDefaultSubobject<URandomEngine>(TEXT(
"RandomEngine"));
43 Set(LidarDescription);
64 auto SensorTransform = DataStream.GetSensorTransform();
67 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"Send Stream");
68 DataStream.SerializeAndSend(*
this,
LidarData, DataStream.PopBufferFromPool());
71 #if defined(WITH_ROS2)
73 if (ROS2->IsEnabled())
75 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"ROS2 Send");
77 AActor* ParentActor = GetAttachParentActor();
83 FTransform LocalTransformRelativeToParent = GetActorTransform().GetRelativeTransform(ParentActor->GetActorTransform());
84 ROS2->ProcessDataFromLidar(DataStream.GetSensorType(), StreamId, LocalTransformRelativeToParent,
89 ROS2->ProcessDataFromLidar(DataStream.GetSensorType(), StreamId, SensorTransform,
99 const float Distance = HitPoint.
Length();
102 const float AbsAtm = exp(-AttenAtm * Distance);
104 const float IntRec = AbsAtm;
112 const FVector HitPoint = HitInfo.ImpactPoint;
113 Detection.
point = InverseSensorTransform.TransformPosition(HitPoint);
118 const float AbsAtm = exp(-AttenAtm * Distance);
120 const float IntRec = AbsAtm;
128 Super::PreprocessRays(Channels, MaxPointsPerChannel);
135 for (
auto ch = 0u; ch < Channels; ch++) {
136 for (
auto p = 0u; p < MaxPointsPerChannel; p++) {
147 Detection.
point += Noise;
150 const float Intensity = Detection.
intensity;
169 TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
172 [
this](
FDetection& Detection) { return PostprocessDetection(Detection); });
#define DEBUG_ASSERT(predicate)
void ResetDetections(uint32_t Channels, uint32_t MaxPointsPerChannel) override
Clear the per-channel detection buffers.
carla::sensor::data::LidarData FLidarData
TArray< float > PointCloudLidarData
static FActorDefinition GetSensorDefinition()
FDetection ComputeDetection(const FHitResult &HitInfo, const FTransform &InverseSensorTransform) const
float ComputeIntensity(const FSemanticDetection &RawDetection) const
Compute the received intensity of the point.
void WriteDetectionAsync(uint32_t Channel, const FHitResult &HitInfo, const FTransform &InverseSensorTransform, const FVector &SensorLocation) override
Computes the detection of a hit inside the raycast ParallelFor.
bool PostprocessDetection(FDetection &Detection) const
void PreprocessRays(uint32_t Channels, uint32_t MaxPointsPerChannel) override
Method that allow to preprocess if the rays will be traced.
float DropOffAlpha
Slope for the intensity dropoff of lidar points, it is calculated throught the dropoff limit and the ...
virtual void Set(const FActorDescription &Description) override
bool DropOffGenActive
Enable/Disable general dropoff of lidar points.
ARayCastLidar(const FObjectInitializer &ObjectInitializer)
virtual void SendData(const float DeltaTime) override
std::vector< std::vector< FDetection > > Detections
void ComputeAndSaveDetections(const FTransform &SensorTransform) override
Copies the per-channel detections into the LidarData structure.
std::vector< uint32_t > PointsPerChannel
static void CompactAndWriteDetections(std::vector< std::vector< DetectionT > > &Detections, std::vector< uint32_t > &OutPointsPerChannel, uint32_t Channels, LidarDataT &LidarData, PostprocessT &&Postprocess)
Post-processes the detections channel by channel, drops the rejected ones and writes the rest to Lida...
void CreateLasers()
Creates a Laser for each channel.
static void ResetChannelDetections(std::vector< std::vector< DetectionT > > &Detections, uint32_t Channels, uint32_t MaxPointsPerChannel)
Clears every channel buffer and reserves room for a full scan.
static void CopyDetectionsToPointCloud(const std::vector< std::vector< DetectionT > > &Detections, const std::vector< uint32_t > &InPointsPerChannel, TArray< float > &PointCloud)
Copies the kept detections into a flat x, y, z, intensity array (editor debug point cloud).
std::vector< std::vector< bool > > RayPreprocessCondition
FLidarDescription Description
virtual void Set(const FActorDescription &Description)
auto GetToken() const
Return the token that allows subscribing to this sensor's stream.
FAsyncDataStream GetDataStream(SensorType &&Self)
Return the FDataStream associated with this sensor.
URandomEngine * RandomEngine
Random Engine used to provide noise for sensor output.
void SetSeed(int32 InSeed)
static void SetLidar(const FActorDescription &Description, FLidarDescription &Lidar)
static FActorDefinition MakeLidarDefinition(const FString &Id)
float GetNormalDistribution(float Mean, float StandardDeviation)
static std::shared_ptr< ROS2 > GetInstance()
Helper class to store and serialize the data generated by a Lidar.
Helper class to store and serialize the data generated by a RawLidar.
Serializes a stream endpoint.
const auto & get_stream_id() const
A definition of a Carla Actor with all the variation and attributes.
A description of a Carla Actor with all its variation.
float DropOffAtZeroIntensity
General drop off rate.
int RandomSeed
Random seed for the noise/dropoff used by this sensor.
float LowerFovLimit
Lower laser angle, counts from horizontal, negative values means under horizontal line.
float DropOffGenRate
General drop off rate.
uint32 Channels
Number of lasers.
float DropOffIntensityLimit
General drop off rate.
float AtmospAttenRate
Attenuation Rate in the atmosphere in m^-1.
float UpperFovLimit
Upper laser angle, counts from horizontal, positive values means above horizontal line.
Vector3D MakeUnitVector(const float epsilon=2.0f *std::numeric_limits< float >::epsilon()) const
Return a unit-length copy of this vector.