9#include <boost/algorithm/clamp.hpp>
17 static const float lower = 0.0;
18 static const float upper = 163.82;
25 else if (vel >= lower)
37 std::chrono::system_clock::time_point start_Point = std::chrono::system_clock::now();
39 std::chrono::system_clock::time_point ref_point = std::chrono::system_clock::from_time_t(1072915200);
41 mGenerationDelta0 = std::chrono::duration_cast<std::chrono::milliseconds>(start_Point - ref_point);
46 UE_LOG(LogCarla, Warning, TEXT(
"CaService:SetOwner function called"));
58 mVehicle = Cast<ACarlaWheeledVehicle>(Owner);
62 UE_LOG(LogCarla, Warning, TEXT(
"CaService:Initialize Vehicle type"));
82 UE_LOG(LogCarla, Warning, TEXT(
"CaService:Initialize RSU type"));
92 UE_LOG(LogCarla, Warning, TEXT(
"CaService:SetParams function called"));
145 if (T_elapsed >= T_GenCamDcc)
157 T_GenCam = std::min(T_elapsed, T_GenCamMax);
161 else if (T_elapsed >= T_GenCam)
166 T_GenCam = T_GenCamMax;
192 if (DeltaSpeed > 0.5)
202 double Dot = a.X * b.X + a.Y * b.Y + a.Z * b.Z;
203 return std::acos(Dot / (a.Size() * b.Size()));
225 return static_cast<long>(stationType);
231 case crp::CityObjectLabel::None:
234 case crp::CityObjectLabel::Pedestrians:
237 case crp::CityObjectLabel::Bicycle:
240 case crp::CityObjectLabel::Motorcycle:
243 case crp::CityObjectLabel::Car:
246 case crp::CityObjectLabel::Bus:
250 case crp::CityObjectLabel::Truck:
253 case crp::CityObjectLabel::Buildings:
254 case crp::CityObjectLabel::Walls:
255 case crp::CityObjectLabel::Fences:
256 case crp::CityObjectLabel::Poles:
257 case crp::CityObjectLabel::TrafficLight:
258 case crp::CityObjectLabel::TrafficSigns:
261 case crp::CityObjectLabel::Train:
275 if (special_type.compare(
"emergency") == 0)
281 return static_cast<long>(stationType);
307 RefPos.Y = Longitude;
315 const FVector CarlaNorthVector = FVector(0.0f, -1.0f, 0.0f);
316 const FVector ForwVect =
mActorOwner->GetActorForwardVector().GetSafeNormal2D();
317 const float DotProd = FVector::DotProduct(CarlaNorthVector, ForwVect);
320 if (DotProd >= 1.00f)
323 float Heading = std::acos(DotProd);
325 if (FVector::CrossProduct(CarlaNorthVector, ForwVect).Z < 0.0f)
326 Heading = carla::geom::Math::Pi2<float>() - Heading;
439 const float noise_lon_stddev,
440 const float noise_alt_stddev,
441 const float noise_head_stddev,
442 const float noise_lat_bias,
443 const float noise_lon_bias,
444 const float noise_alt_bias,
445 const float noise_head_bias)
483 float length = bb.Extent.X * 2.0;
484 float width = bb.Extent.Y * 2.0;
493 const double lonAccelValue = Accel.
x * 10.0;
495 if (lonAccelValue >= -160.0 && lonAccelValue <= 161.0)
520 const double latAccelValue = Accel.
y * 10.0;
521 if (latAccelValue >= -160.0 && latAccelValue <= 161.0)
532 const double vertAccelValue = Accel.
z * 10.0;
533 if (vertAccelValue >= -160.0 && vertAccelValue <= 161.0)
552 const FVector &Accelerometer)
557 constexpr float Mean = 0.0f;
565 const float DeltaTime)
568 constexpr float TO_METERS = 1e-2;
570 constexpr float GRAVITY = 9.81f;
575 const FVector CurrentLocation =
mVehicle->GetActorLocation();
579 const FVector Y0 = CurrentLocation;
580 const float H1 = DeltaTime;
583 const float H1AndH2 = H2 + H1;
584 const FVector A = Y1 / (H1 * H2);
585 const FVector B = Y2 / (H2 * (H1AndH2));
586 const FVector C = Y0 / (H1 * (H1AndH2));
587 FVector FVectorAccelerometer = TO_METERS * -2.0f * (A - B - C);
595 FVectorAccelerometer.Z += GRAVITY;
597 FQuat ImuRotation =
mActorOwner->GetRootComponent()->GetComponentTransform().GetRotation();
598 FVectorAccelerometer = ImuRotation.UnrotateVector(FVectorAccelerometer);
605 return Accelerometer;
617 constexpr float Mean = 0.0f;
624 const FVector AngularVelocity =
627 const FQuat SensorLocalRotation =
628 mActorOwner->GetRootComponent()->GetRelativeTransform().GetRotation();
630 const FVector FVectorGyroscope =
631 SensorLocalRotation.RotateVector(AngularVelocity);
642 const FVector &Gyroscope)
648 constexpr float Mean = 0.0f;
655 std::tm epoch_time = {};
656 epoch_time = {0, 0, 0, 1, 0, 104};
659 std::chrono::system_clock::time_point epoch = std::chrono::system_clock::from_time_t(std::mktime(&epoch_time));
662 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
665 std::chrono::milliseconds duration = std::chrono::duration_cast<std::chrono::milliseconds>(now - epoch);
668 return duration.count();
677 uint8_t ProtectedZoneDataLength = 16;
679 for (uint8_t i = 0; i <= ProtectedZoneDataLength; ++i)
724 if (LightStateData.
Fog)
740 if (HeadingDelta > 4.0)
static const float scLowFrequencyContainerInterval
long millisecondsSince2004()
static FVector FIMU_GetActorAngularVelocityInRadians(AActor &Actor)
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)
const carla::geom::Vector3D ComputeAccelerometerNoise(const FVector &Accelerometer)
FVector GetReferencePosition()
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)
float mGenerationInterval
const long mProtocolVersion
void SetOwner(UWorld *world, AActor *Owner)
bool Trigger(float DeltaSeconds)
void SetAccelerationStandardDeviation(const FVector &Vec)
void SetYawrateDeviation(const float noise_yawrate_stddev, const float noise_yawrate_bias)
unsigned int mGenCamLowDynamicsCounter
bool CheckHeadingDelta(float DeltaSeconds)
carla::geom::Vector3D ComputeAccelerometer(const float DeltaTime)
ITSContainer::StationType_t GetStationType()
std::array< FVector, 2 > PrevLocation
Used to compute the acceleration
std::chrono::milliseconds mGenerationDelta0
FVector StdDevAccel
Standard deviation for acceleration settings.
CaService(URandomEngine *random_engine)
FCarlaActor * mCarlaActor
unsigned int mGenCamLowDynamicsLimit
carla::geom::GeoLocation CurrentGeoReference
bool CheckPositionDelta(float DeltaSeconds)
void AddLowFrequencyContainer(CAMContainer::LowFrequencyContainer_t &lfc)
void AddBasicVehicleContainerHighFrequency(CAMContainer::HighFrequencyContainer_t &hfc, float DeltaTime)
URandomEngine * mRandomEngine
ITSContainer::SpeedValue_t BuildSpeedValue(const float vel)
void GenerateCamMessage(float DeltaTime)
bool CheckSpeedDelta(float DeltaSeconds)
ACarlaWheeledVehicle * mVehicle
const float ComputeYawNoise(const FVector &Gyroscope)
float PrevDeltaTime
Used to compute the acceleration
void SetParams(const float GenCamMin, const float GenCamMax, const bool FixedRate)
void AddRSUContainerHighFrequency(CAMContainer::HighFrequencyContainer_t &hfc)
double GetFVectorAngle(const FVector &a, const FVector &b)
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::GeoLocation & GetGeoReference() const
Return the GeoLocation point of the map loaded
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
static UCarlaEpisode * GetCurrentEpisode(const UObject *WorldContextObject)
float GetNormalDistribution(float Mean, float StandardDeviation)
GeoLocation Transform(const Location &location) const
Transform the given location to a GeoLocation using this as geo-reference.
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
long ProtectedCommunicationZoneCount
std::vector< ProtectedCommunicationZone_t > list
PosConfidenceEllipse_t positionConfidenceEllipse
VehicleLengthConfidenceIndication_t vehicleLengthConfidenceIndication
VehicleLengthValue_t vehicleLengthValue
VerticalAccelerationValue_t verticalAccelerationValue
AccelerationConfidence_t verticalAccelerationConfidence
YawRateConfidence_t yawRateConfidence
YawRateValue_t yawRateValue
SpeedConfidence_t speedConfidence