25 FVector(0.0f, -1.0f, 0.0f);
28 const FObjectInitializer &ObjectInitializer)
29 : Super(ObjectInitializer)
31 PrimaryActorTick.bCanEverTick =
true;
32 PrimaryActorTick.TickGroup = TG_PostPhysics;
33 RandomEngine = CreateDefaultSubobject<URandomEngine>(TEXT(
"RandomEngine"));
34 PrevLocation = { FVector::ZeroVector, FVector::ZeroVector };
47 Super::Set(ActorDescription);
53 Super::SetOwner(OwningActor);
60 const auto RootComponent = Cast<UPrimitiveComponent>(Actor.GetRootComponent());
62 FVector AngularVelocity;
64 if (RootComponent !=
nullptr) {
65 const FQuat ActorGlobalRotation = RootComponent->GetComponentTransform().GetRotation();
68 AngularVelocity = ActorGlobalRotation.UnrotateVector(GlobalAngularVelocity);
70 AngularVelocity = FVector::ZeroVector;
73 return AngularVelocity;
77 const FVector &Accelerometer)
82 constexpr float Mean = 0.0f;
92 const FVector &Gyroscope)
98 constexpr float Mean = 0.0f;
108 const float DeltaTime)
111 constexpr float TO_METERS = 1e-2;
115 const float GRAVITY = (GameMode !=
nullptr) ? GameMode->
IMUSensorGravity : 9.81f;
120 const FVector CurrentLocation = GetActorLocation();
124 const FVector Y0 = CurrentLocation;
125 const float H1 = DeltaTime;
128 const float H1AndH2 = H2 + H1;
129 const FVector A = Y1 / ( H1 * H2 );
130 const FVector B = Y2 / ( H2 * (H1AndH2) );
131 const FVector C = Y0 / ( H1 * (H1AndH2) );
132 FVector FVectorAccelerometer = TO_METERS * -2.0f * ( A - B - C );
140 FVectorAccelerometer.Z += GRAVITY;
143 GetRootComponent()->GetComponentTransform().GetRotation();
144 FVectorAccelerometer = ImuRotation.UnrotateVector(FVectorAccelerometer);
151 return Accelerometer;
156 check(GetOwner() !=
nullptr);
157 const FVector AngularVelocity =
164 RootComponent->GetRelativeTransform().GetRotation();
166 const FVector FVectorGyroscope =
167 SensorLocalRotation.RotateVector(AngularVelocity);
180 const FVector ForwVect = GetActorForwardVector().GetSafeNormal2D();
184 if (DotProd >= 1.00f)
187 const float Compass = std::acos(DotProd);
190 return carla::geom::Math::Pi2<float>() - Compass;
202 if (GetOwner() ==
nullptr)
213 #if defined(WITH_ROS2)
215 if (ROS2->IsEnabled())
217 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"ROS2 Send");
219 AActor* ParentActor = GetAttachParentActor();
222 FTransform LocalTransformRelativeToParent = GetActorTransform().GetRelativeTransform(ParentActor->GetActorTransform());
233 TRACE_CPUPROFILER_EVENT_SCOPE(AInertialMeasurementUnit::SerializeAndSend);
294 return {World.X, World.Y, World.Z};
299 const FVector Location(World[0], World[1], World[2]);
314 State.imu_history = History;
315 const FQuat LocalRotation = RootComponent->GetRelativeTransform().GetRotation();
316 State.imu_local_rotation = std::array<double, 4>{LocalRotation.X, LocalRotation.Y, LocalRotation.Z, LocalRotation.W};
325 if (
State.imu_history)
331 if (
State.imu_local_rotation)
333 const auto &Rotation = *
State.imu_local_rotation;
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...
static std::array< double, 3 > FIMU_ToWorld(const AActor &Sensor, const FVector &Local)
World-frame location, the same on every server (a large map rebases each server's local origin on its...
static FVector FIMU_ToLocal(const AActor &Sensor, const std::array< double, 3 > &World)
static FVector FIMU_GetActorAngularVelocityInRadians(AActor &Actor)
Base class for the CARLA Game Mode.
float IMUSensorGravity
Gravitational acceleration used by IMU sensors.
float ComputeCompass()
Magnetometer: orientation with respect to the North in rad.
const carla::geom::Vector3D & GetGyroscopeValue() const
carla::geom::Vector3D GyroscopeValue
Gyroscope value calculated after each PostPhysTick.
void GetMirrorState(carla::multigpu::SensorState &State) const override
Multi-GPU: the runtime state this sensor starts its next tick from (noise generator,...
void SetMirrorState(const carla::multigpu::SensorState &State) override
carla::geom::Vector3D AccelerometerValue
Accelerometer value calculated after each PostPhysTick.
void BeginPlay() override
float CompassValue
Magnetometer value calculated after each PostPhysTick.
float GetCompassValue() const
const FVector & GetAccelerationStandardDeviation() const
AInertialMeasurementUnit(const FObjectInitializer &ObjectInitializer)
const carla::geom::Vector3D ComputeGyroscopeNoise(const FVector &Gyroscope)
FVector StdDevAccel
Standard deviation for acceleration settings.
const carla::geom::Vector3D ComputeAccelerometerNoise(const FVector &Accelerometer)
void SetGyroscopeBias(const FVector &Vec)
void SetOwner(AActor *Owner) override
const carla::geom::Vector3D & GetAccelerometerValue() const
static const FVector CarlaNorthVector
Based on OpenDRIVE's lon and lat, North is in (0.0f, -1.0f, 0.0f)
FVector BiasGyro
Bias for gyroscope settings.
carla::geom::Vector3D ComputeGyroscope()
Gyroscope: measures angular velocity in rad/sec.
virtual void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaTime) override
FVector StdDevGyro
Standard deviation for gyroscope settings.
static FActorDefinition GetSensorDefinition()
TOptional< FQuat > MirroredLocalRotation
Multi-GPU secondary: the primary IMU's rotation relative to its parent.
void Set(const FActorDescription &ActorDescription) override
const FVector & GetGyroscopeBias() const
float PrevDeltaTime
Used to compute the acceleration.
void SetAccelerationStandardDeviation(const FVector &Vec)
carla::geom::Vector3D ComputeAccelerometer(const float DeltaTime)
Accelerometer: measures linear acceleration in m/s^2.
void SetGyroscopeStandardDeviation(const FVector &Vec)
std::array< FVector, 2 > PrevLocation
Used to compute the acceleration.
const FVector & GetGyroscopeStandardDeviation() const
FVector GlobalToLocalLocation(const FVector &InLocation) const
FVector LocalToGlobalLocation(const FVector &InLocation) const
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.
static FActorDefinition MakeIMUDefinition()
static void SetIMU(const FActorDescription &Description, AInertialMeasurementUnit *IMU)
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
static ACarlaGameModeBase * GetGameMode(const UObject *WorldContextObject)
uint32 GetState() const
The engine's state, to continue its exact sequence elsewhere (a Multi-GPU secondary's mirror of a sen...
float GetNormalDistribution(float Mean, float StandardDeviation)
void SetState(uint32 State)
Continue from State, as GetState returned it; an impossible value is ignored.
static std::shared_ptr< ROS2 > GetInstance()
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.
An IMU's history: its two previous locations (world, cm) and the delta between them; its acceleromete...
std::array< double, 3 > last_location
std::array< double, 3 > older_location
One record of frame data packet 27: the runtime state a sensor of the primary starts this frame's tic...