23 FVector(0.0f, -1.0f, 0.0f);
26 const FObjectInitializer &ObjectInitializer)
27 : Super(ObjectInitializer)
29 PrimaryActorTick.bCanEverTick =
true;
30 PrimaryActorTick.TickGroup = TG_PostPhysics;
31 RandomEngine = CreateDefaultSubobject<URandomEngine>(TEXT(
"RandomEngine"));
32 PrevLocation = { FVector::ZeroVector, FVector::ZeroVector };
45 Super::Set(ActorDescription);
51 Super::SetOwner(Owner);
58 const auto RootComponent = Cast<UPrimitiveComponent>(Actor.GetRootComponent());
60 FVector AngularVelocity;
62 if (RootComponent !=
nullptr) {
63 const FQuat ActorGlobalRotation = RootComponent->GetComponentTransform().GetRotation();
64 const FVector GlobalAngularVelocity = RootComponent->GetPhysicsAngularVelocityInRadians();
65 AngularVelocity = ActorGlobalRotation.UnrotateVector(GlobalAngularVelocity);
67 AngularVelocity = FVector::ZeroVector;
70 return AngularVelocity;
74 const FVector &Accelerometer)
79 constexpr float Mean = 0.0f;
88 const FVector &Gyroscope)
94 constexpr float Mean = 0.0f;
103 const float DeltaTime)
106 constexpr float TO_METERS = 1e-2;
113 const FVector CurrentLocation = GetActorLocation();
117 const FVector Y0 = CurrentLocation;
118 const float H1 = DeltaTime;
121 const float H1AndH2 = H2 + H1;
122 const FVector A = Y1 / ( H1 * H2 );
123 const FVector B = Y2 / ( H2 * (H1AndH2) );
124 const FVector C = Y0 / ( H1 * (H1AndH2) );
125 FVector FVectorAccelerometer = TO_METERS * -2.0f * ( A - B - C );
133 FVectorAccelerometer.Z += GRAVITY;
136 GetRootComponent()->GetComponentTransform().GetRotation();
137 FVectorAccelerometer = ImuRotation.UnrotateVector(FVectorAccelerometer);
144 return Accelerometer;
149 check(GetOwner() !=
nullptr);
150 const FVector AngularVelocity =
153 const FQuat SensorLocalRotation =
154 RootComponent->GetRelativeTransform().GetRotation();
156 const FVector FVectorGyroscope =
157 SensorLocalRotation.RotateVector(AngularVelocity);
170 const FVector ForwVect = GetActorForwardVector().GetSafeNormal2D();
174 if (DotProd >= 1.00f)
177 const float Compass = std::acos(DotProd);
180 return carla::geom::Math::Pi2<float>() - Compass;
194 #if defined(WITH_ROS2)
196 if (ROS2->IsEnabled())
198 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"ROS2 Send");
200 AActor* ParentActor = GetAttachParentActor();
203 FTransform LocalTransformRelativeToParent = GetActorTransform().GetRelativeTransform(ParentActor->GetActorTransform());
204 ROS2->ProcessDataFromIMU(
Stream.
GetSensorType(), StreamId, LocalTransformRelativeToParent, Accelerometer, Gyroscope, Compass,
this);
208 ROS2->ProcessDataFromIMU(
Stream.
GetSensorType(), StreamId,
Stream.GetSensorTransform(), Accelerometer, Gyroscope, Compass,
this);
215 Stream.SerializeAndSend(*
this, Accelerometer, Gyroscope, Compass);
static FVector FIMU_GetActorAngularVelocityInRadians(AActor &Actor)
float ComputeCompass()
Magnetometer: orientation with respect to the North in rad
void BeginPlay() override
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
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()
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
auto GetToken() const
Return the token that allows subscribing to this sensor's stream.
FAsyncDataStream GetDataStream(const SensorT &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 ACarlaGameModeBase * GetGameMode(const UObject *WorldContextObject)
float GetNormalDistribution(float Mean, float StandardDeviation)
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.