16#include "Components/PrimitiveComponent.h"
18#include <boost/algorithm/clamp.hpp>
25 static const float lower = 0.0;
26 static const float upper = 163.82;
33 else if (vel >= lower)
45 std::chrono::system_clock::time_point start_Point = std::chrono::system_clock::now();
47 std::chrono::system_clock::time_point ref_point = std::chrono::system_clock::from_time_t(1072915200);
49 mGenerationDelta0 = std::chrono::duration_cast<std::chrono::milliseconds>(start_Point - ref_point);
78 mVehicle = Cast<ACarlaWheeledVehicle>(Owner);
79 UE_LOG(LogCarla, Verbose, TEXT(
"CaService:Initialize Vehicle type"));
98 PrevLocation = {FVector::ZeroVector, FVector::ZeroVector};
107 UE_LOG(LogCarla, Verbose, TEXT(
"CaService:Initialize RSU type"));
113 UE_LOG(LogCarla, Verbose, TEXT(
"CaService:Initialize station type %i"),
mStationType);
118 UE_LOG(LogCarla, Verbose, TEXT(
"CaService:SetParams function called"));
171 if (T_elapsed >= T_GenCamDcc)
183 T_GenCam = std::min(T_elapsed, T_GenCamMax);
187 else if (T_elapsed >= T_GenCam)
192 T_GenCam = T_GenCamMax;
221 if (DeltaSpeed > 0.5)
231 double Dot = a.X * b.X + a.Y * b.Y + a.Z * b.Z;
232 return std::acos(Dot / (a.Size() * b.Size()));
237 UE_LOG(LogCarla, VeryVerbose, TEXT(
"V2XSensor: generating cam message"));
253 return static_cast<long>(stationType);
261 case crp::CityObjectLabel::None:
264 case crp::CityObjectLabel::Pedestrians:
267 case crp::CityObjectLabel::Bicycle:
270 case crp::CityObjectLabel::Motorcycle:
273 case crp::CityObjectLabel::Car:
276 case crp::CityObjectLabel::Bus:
280 case crp::CityObjectLabel::Truck:
283 case crp::CityObjectLabel::Buildings:
284 case crp::CityObjectLabel::Walls:
285 case crp::CityObjectLabel::Fences:
286 case crp::CityObjectLabel::Poles:
287 case crp::CityObjectLabel::TrafficLight:
288 case crp::CityObjectLabel::TrafficSigns:
291 case crp::CityObjectLabel::Train:
305 if (special_type.compare(
"emergency") == 0)
317 return static_cast<long>(stationType);
343 RefPos.Y = Longitude;
351 const FVector CarlaNorthVector = FVector(0.0f, -1.0f, 0.0f);
352 const FVector ForwVect =
mActorOwner->GetActorForwardVector().GetSafeNormal2D();
353 const float DotProd = FVector::DotProduct(CarlaNorthVector, ForwVect);
356 if (DotProd >= 1.00f)
359 float Heading = std::acos(DotProd);
361 if (FVector::CrossProduct(CarlaNorthVector, ForwVect).Z < 0.0f)
362 Heading = carla::geom::Math::Pi2<float>() - Heading;
474 const float noise_lon_stddev,
475 const float noise_alt_stddev,
476 const float noise_head_stddev,
477 const float noise_lat_bias,
478 const float noise_lon_bias,
479 const float noise_alt_bias,
480 const float noise_head_bias)
522 float length = bb.Extent.X * 2.0;
523 float width = bb.Extent.Y * 2.0;
532 const double lonAccelValue = Accel.
x * 10.0;
534 if (lonAccelValue >= -160.0 && lonAccelValue <= 161.0)
559 const double latAccelValue = Accel.
y * 10.0;
560 if (latAccelValue >= -160.0 && latAccelValue <= 161.0)
571 const double vertAccelValue = Accel.
z * 10.0;
572 if (vertAccelValue >= -160.0 && vertAccelValue <= 161.0)
591 const FVector &Accelerometer)
const
596 constexpr float Mean = 0.0f;
604 const float DeltaTime)
610 constexpr float TO_METERS = 1e-2;
612 constexpr float GRAVITY = 9.81f;
617 const FVector CurrentLocation =
mVehicle->GetActorLocation();
621 const FVector Y0 = CurrentLocation;
622 const float H1 = DeltaTime;
625 const float H1AndH2 = H2 + H1;
626 const FVector A = Y1 / (H1 * H2);
627 const FVector B = Y2 / (H2 * (H1AndH2));
628 const FVector C = Y0 / (H1 * (H1AndH2));
629 FVector FVectorAccelerometer = TO_METERS * -2.0f * (A - B - C);
637 FVectorAccelerometer.Z += GRAVITY;
639 FQuat ImuRotation =
mActorOwner->GetRootComponent()->GetComponentTransform().GetRotation();
640 FVectorAccelerometer = ImuRotation.UnrotateVector(FVectorAccelerometer);
646 return Accelerometer;
659 constexpr float Mean = 0.0f;
670 FVector AngularVelocity = FVector::ZeroVector;
671 if (
const auto *RootComponent = Cast<UPrimitiveComponent>(
mActorOwner->GetRootComponent()))
673 const FQuat ActorGlobalRotation = RootComponent->GetComponentTransform().GetRotation();
675 AngularVelocity = ActorGlobalRotation.UnrotateVector(GlobalAngularVelocity);
678 const FQuat SensorLocalRotation =
679 mActorOwner->GetRootComponent()->GetRelativeTransform().GetRotation();
681 const FVector FVectorGyroscope =
682 SensorLocalRotation.RotateVector(AngularVelocity);
693 const FVector &Gyroscope)
const
699 constexpr float Mean = 0.0f;
706 std::tm epoch_time = {};
707 epoch_time = {0, 0, 0, 1, 0, 104};
710 std::chrono::system_clock::time_point epoch = std::chrono::system_clock::from_time_t(std::mktime(&epoch_time));
713 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
716 std::chrono::milliseconds duration = std::chrono::duration_cast<std::chrono::milliseconds>(now - epoch);
719 return duration.count();
730 for (uint8_t i = 0; i < ProtectedZoneDataLength; ++i)
779 if (LightStateData.
Fog)
796 if (HeadingDelta > 4.0)
static const float scLowFrequencyContainerInterval
long millisecondsSince2004()
FVector CarlaGetActorAngularVelocityInRadians(const AActor &Actor)
Angular velocity of Actor in the world frame, in rad/s: on a Multi-GPU secondary the primary's (a mir...
FVehicleLightState GetVehicleLightState() const
FVector GetVehicleOrientation() const
Orientation vector of the vehicle, pointing forward.
float GetVehicleForwardSpeed() const
Forward speed in cm/s. Might be negative if goes backwards.
FVector LocalToGlobalLocation(const FVector &InLocation) const
static crp::CityObjectLabel GetTagOfTaggedComponent(const UPrimitiveComponent &Component)
Retrieve the tag of an already tagged component.
@ GenerationDeltaTime_oneMilliSec
@ HighFrequencyContainer_PR_basicVehicleContainerHighFrequency
@ HighFrequencyContainer_PR_rsuContainerHighFrequency
@ LowFrequencyContainer_PR_basicVehicleContainerLowFrequency
@ LowFrequencyContainer_PR_NOTHING
void CreateITSPduHeader(CAM_t &message)
carla::geom::GeoProjection CurrentGeoProjection
float ComputeSpeed() const
void SetGNSSDeviation(const float noise_lat_stddev, const float noise_lon_stddev, const float noise_alt_stddev, const float noise_head_stddev, const float noise_lat_bias, const float noise_lon_bias, const float noise_alt_bias, const float noise_head_bias)
UCarlaEpisode * mCarlaEpisode
void SetVelDeviation(const float noise_vel_stddev_x)
long GetVehicleRole() const
float mGenerationInterval
ITSContainer::SpeedValue_t BuildSpeedValue(const float vel) const
const long mProtocolVersion
bool Trigger(float DeltaSeconds)
void SetAccelerationStandardDeviation(const FVector &Vec)
const carla::geom::Vector3D ComputeAccelerometerNoise(const FVector &Accelerometer) const
float ComputeYawRate() const
void SetYawrateDeviation(const float noise_yawrate_stddev, const float noise_yawrate_bias)
unsigned int mGenCamLowDynamicsCounter
bool CheckHeadingDelta(float DeltaSeconds)
void SetActor(UWorld *world, AActor *Owner)
carla::geom::Vector3D ComputeAccelerometer(const float DeltaTime)
std::array< FVector, 2 > PrevLocation
Used to compute the acceleration.
CAM_t GetCamMessage() const
std::chrono::milliseconds mGenerationDelta0
FVector StdDevAccel
Standard deviation for acceleration settings.
CaService(URandomEngine *random_engine)
FCarlaActor * mCarlaActor
unsigned int mGenCamLowDynamicsLimit
const float ComputeYawNoise(const FVector &Gyroscope) const
bool CheckPositionDelta(float DeltaSeconds)
void AddLowFrequencyContainer(CAMContainer::LowFrequencyContainer_t &lfc)
double GetFVectorAngle(const FVector &a, const FVector &b) const
ITSContainer::StationType_t GetStationType() const
void AddBasicVehicleContainerHighFrequency(CAMContainer::HighFrequencyContainer_t &hfc, float DeltaTime)
URandomEngine * mRandomEngine
FVector GetReferencePosition() const
void GenerateCamMessage(float DeltaTime)
bool CheckSpeedDelta(float DeltaSeconds)
ACarlaWheeledVehicle * mVehicle
float PrevDeltaTime
Used to compute the acceleration.
void SetParams(const float GenCamMin, const float GenCamMax, const bool FixedRate)
void AddRSUContainerHighFrequency(CAMContainer::HighFrequencyContainer_t &hfc)
CAM_t CreateCooperativeAwarenessMessage(float DeltaTime)
bool CheckTriggeringConditions(float DeltaSeconds)
float mLastLowCamTimeStamp
void AddCooperativeAwarenessMessage(CAMContainer::CoopAwareness_t &CoopAwarenessMessage, float DeltaTime)
void AddBasicContainer(CAMContainer::BasicContainer_t &BasicContainer)
ActorType GetActorType() const
const FActorInfo * GetActorInfo() const
IdType GetActorId() const
@ YawRateConfidence_unavailable
@ ProtectedZoneType_cenDsrcTolling
@ LateralAccelerationValue_unavailable
@ LateralAccelerationValue_pointOneMeterPerSecSquaredToLeft
@ AltitudeConfidence_unavailable
@ LongitudinalAccelerationValue_pointOneMeterPerSecSquaredForward
@ LongitudinalAccelerationValue_unavailable
@ AltitudeValue_oneCentimeter
@ YawRateValue_unavailable
@ YawRateValue_degSec_000_01ToLeft
@ DriveDirection_backward
@ SemiAxisLength_unavailable
@ Longitude_oneMicroDegreeEast
@ Latitude_oneMicroDegreeNorth
@ StationType_passengerCar
@ StationType_specialVehicles
@ StationType_roadSideUnit
@ ExteriorLights_reverseLightOn
@ ExteriorLights_highBeamHeadlightsOn
@ ExteriorLights_lowBeamHeadlightsOn
@ ExteriorLights_leftTurnSignalOn
@ ExteriorLights_rightTurnSignalOn
@ ExteriorLights_parkingLightsOn
@ ExteriorLights_fogLightOn
@ CurvatureCalculationMode_yarRateUsed
@ VehicleRole_publicTransport
@ CurvatureValue_unavailable
@ VerticalAccelerationValue_unavailable
@ VerticalAccelerationValue_pointOneMeterPerSecSquaredUp
@ AccelerationConfidence_unavailable
@ VehicleLengthConfidenceIndication_unavailable
@ HeadingValue_unavailable
@ HeadingConfidence_equalOrWithinOneDegree
@ SpeedValue_oneCentimeterPerSec
@ SpeedConfidence_equalOrWithInOneCentimerterPerSec
@ CurvatureConfidence_unavailable
static FBoundingBox GetActorBoundingBox(const AActor *Actor, uint8 InTagQueried=0xFF)
Compute the bounding box of the given Carla actor.
FCarlaActor * FindCarlaActor(FCarlaActor::IdType ActorId)
Find a Carla actor by id.
double GetElapsedGameTime() const
Game seconds since the start of this episode.
const carla::geom::GeoProjection & GetGeoProjection() const
Return the geo projection of the map loaded.
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
static UCarlaEpisode * GetCurrentEpisode(const UObject *WorldContextObject)
float GetNormalDistribution(float Mean, float StandardDeviation)
static constexpr T ToDegrees(T rad)
ITSContainer::ReferencePosition_t referencePosition
ITSContainer::StationType_t stationType
ITSContainer::VehicleLength_t vehicleLength
ITSContainer::LateralAcceleration_t lateralAcceleration
ITSContainer::VehicleWidth_t vehicleWidth
ITSContainer::Speed_t speed
OptionalStructAvailable_t lateralAccelerationAvailable
ITSContainer::CurvatureCalculationMode_t curvatureCalculationMode
OptionalStructAvailable_t verticalAccelerationAvailable
OptionalStructAvailable_t performanceClassAvailable
ITSContainer::Heading_t heading
ITSContainer::YawRate_t yawRate
OptionalStructAvailable_t lanePositionAvailable
ITSContainer::DriveDirection_t driveDirection
OptionalStructAvailable_t accelerationControlAvailable
OptionalStructAvailable_t steeringWheelAngleAvailable
ITSContainer::Curvature_t curvature
ITSContainer::VerticalAcceleration_t verticalAcceleration
OptionalStructAvailable_t cenDsrcTollingZoneAvailable
ITSContainer::LongitudinalAcceleration_t longitudinalAcceleration
ITSContainer::ExteriorLights_t exteriorLights
ITSContainer::PathHistory_t pathHistory
ITSContainer::VehicleRole_t vehicleRole
HighFrequencyContainer_t highFrequencyContainer
BasicContainer_t basicContainer
LowFrequencyContainer_t lowFrequencyContainer
GenerationDeltaTime_t generationDeltaTime
CamParameters_t camParameters
RSUContainerHighFrequency_t rsuContainerHighFrequency
BasicVehicleContainerHighFrequency_t basicVehicleContainerHighFrequency
HighFrequencyContainer_PR present
BasicVehicleContainerLowFrequency_t basicVehicleContainerLowFrequency
LowFrequencyContainer_PR present
ITSContainer::ProtectedCommunicationZonesRSU_t protectedCommunicationZonesRSU
CAMContainer::CoopAwareness_t cam
ITSContainer::ItsPduHeader_t header
TMap< FString, FActorAttribute > Variations
User selected variations of the actor.
FActorDescription Description
AltitudeValue_t altitudeValue
AltitudeConfidence_t altitudeConfidence
CurvatureValue_t curvatureValue
CurvatureConfidence_t curvatureConfidence
HeadingValue_t headingValue
HeadingConfidence_t headingConfidence
LateralAccelerationValue_t lateralAccelerationValue
AccelerationConfidence_t lateralAccelerationConfidence
LongitudinalAccelerationValue_t longitudinalAccelerationValue
AccelerationConfidence_t longitudinalAccelerationConfidence
SemiAxisLength_t semiMinorConfidence
HeadingValue_t semiMajorOrientation
SemiAxisLength_t semiMajorConfidence
Latitude_t protectedZoneLatitude
OptionalValueAvailable_t protectedZoneRadiusAvailable
OptionalValueAvailable_t protectedZoneIDAvailable
Longitude_t protectedZoneLongitude
ProtectedZoneType_t protectedZoneType
OptionalValueAvailable_t expiryTimeAvailable
std::array< ProtectedCommunicationZone_t, 16u > data
long ProtectedCommunicationZoneCount
PosConfidenceEllipse_t positionConfidenceEllipse
VehicleLengthConfidenceIndication_t vehicleLengthConfidenceIndication
VehicleLengthValue_t vehicleLengthValue
VerticalAccelerationValue_t verticalAccelerationValue
AccelerationConfidence_t verticalAccelerationConfidence
YawRateConfidence_t yawRateConfidence
YawRateValue_t yawRateValue
SpeedConfidence_t speedConfidence
GeoLocation TransformToGeoLocation(const Location &location) const
Transform the given geo location to a location.