26 : Super(ObjectInitializer)
28 PrimaryActorTick.bCanEverTick =
true;
30 RandomEngine = CreateDefaultSubobject<URandomEngine>(TEXT(
"RandomEngine"));
32 TraceParams = FCollisionQueryParams(FName(TEXT(
"Laser_Trace")),
true,
this);
83 #if defined(WITH_ROS2)
85 if (ROS2->IsEnabled())
87 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"ROS2 Send");
89 AActor* ParentActor = GetAttachParentActor();
92 FTransform LocalTransformRelativeToParent = GetActorTransform().GetRelativeTransform(ParentActor->GetActorTransform());
93 ROS2->ProcessDataFromRadar(DataStream.GetSensorType(), StreamId, LocalTransformRelativeToParent,
RadarData,
this);
97 ROS2->ProcessDataFromRadar(DataStream.GetSensorType(), StreamId, DataStream.GetSensorTransform(),
RadarData,
this);
103 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"Send Stream");
104 DataStream.SerializeAndSend(*
this,
RadarData, DataStream.PopBufferFromPool());
118 constexpr float TO_METERS = 1e-2;
119 const FTransform& ActorTransform = GetActorTransform();
120 const FRotator& TransformRotator = ActorTransform.Rotator();
121 const FVector& RadarLocation = GetActorLocation();
122 const FVector& ForwardVector = GetActorForwardVector();
123 const FVector TransformXAxis = ActorTransform.GetUnitAxis(EAxis::X);
124 const FVector TransformYAxis = ActorTransform.GetUnitAxis(EAxis::Y);
125 const FVector TransformZAxis = ActorTransform.GetUnitAxis(EAxis::Z);
128 const float MaxRx = FMath::Tan(FMath::DegreesToRadians(
HorizontalFOV * 0.5f)) *
Range;
129 const float MaxRy = FMath::Tan(FMath::DegreesToRadians(
VerticalFOV * 0.5f)) *
Range;
134 Rays.resize(NumPoints);
135 for (
int i = 0; i <
Rays.size(); i++) {
138 Rays[i].Hitted =
false;
141 FCriticalSection Mutex;
142 GetWorld()->GetPhysicsScene()->GetPxScene()->lockRead();
144 TRACE_CPUPROFILER_EVENT_SCOPE(ParallelFor);
145 ParallelFor(NumPoints, [&](int32 idx) {
146 TRACE_CPUPROFILER_EVENT_SCOPE(ParallelForTask);
147 FHitResult OutHit(ForceInit);
148 const float Radius =
Rays[idx].Radius;
149 const float Angle =
Rays[idx].Angle;
152 FMath::SinCos(&Sin, &Cos, Angle);
154 const FVector EndLocation = RadarLocation + TransformRotator.RotateVector({
156 MaxRx * Radius * Cos,
160 const bool Hitted = GetWorld()->ParallelLineTraceSingleByChannel(
164 ECC_GameTraceChannel2,
166 FCollisionResponseParams::DefaultResponseParam
169 const TWeakObjectPtr<AActor> HittedActor = OutHit.Actor;
170 if (Hitted && HittedActor.Get()) {
171 Rays[idx].Hitted =
true;
175 Rays[idx].AzimuthAndElevation = FMath::GetAzimuthAndElevation (
176 (EndLocation - RadarLocation).GetSafeNormal() *
Range,
182 Rays[idx].Distance = OutHit.Distance * TO_METERS;
186 GetWorld()->GetPhysicsScene()->GetPxScene()->unlockRead();
189 for (
auto& ray :
Rays) {
192 ray.RelativeVelocity,
193 ray.AzimuthAndElevation.X,
194 ray.AzimuthAndElevation.Y,
204 constexpr float TO_METERS = 1e-2;
206 const TWeakObjectPtr<AActor> HittedActor = OutHit.Actor;
207 const FVector TargetVelocity = HittedActor->GetVelocity();
208 const FVector TargetLocation = OutHit.ImpactPoint;
209 const FVector Direction = (TargetLocation - RadarLocation).GetSafeNormal();
211 const float V = TO_METERS * FVector::DotProduct(DeltaVelocity, Direction);