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;
108 constexpr
float GRAVITY = 9.81f;
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 FActorDefinition GetSensorDefinition()
auto GetToken() const
Return the token that allows subscribing to this sensor's stream.
float ComputeCompass()
Magnetometer: orientation with respect to the North in rad.
FVector StdDevGyro
Standard deviation for gyroscope settings.
const carla::geom::Vector3D ComputeGyroscopeNoise(const FVector &Gyroscope)
void SetOwner(AActor *Owner) override
A definition of a Carla Actor with all the variation and attributes.
const FVector & GetGyroscopeBias() const
void BeginPlay() override
const FVector & GetAccelerationStandardDeviation() const
static void SetIMU(const FActorDescription &Description, AInertialMeasurementUnit *IMU)
std::array< FVector, 2 > PrevLocation
Used to compute the acceleration.
carla::geom::Vector3D ComputeGyroscope()
Gyroscope: measures angular velocity in rad/sec.
FVector BiasGyro
Bias for gyroscope settings.
carla::SharedPtr< cc::Actor > Actor
virtual void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaTime) override
void Set(const FActorDescription &ActorDescription) override
A description of a Carla Actor with all its variation.
float PrevDeltaTime
Used to compute the acceleration.
void SetGyroscopeBias(const FVector &Vec)
static FActorDefinition MakeIMUDefinition()
const auto & get_stream_id() const
const FVector & GetGyroscopeStandardDeviation() const
const carla::geom::Vector3D ComputeAccelerometerNoise(const FVector &Accelerometer)
void SetGyroscopeStandardDeviation(const FVector &Vec)
FAsyncDataStream GetDataStream(const SensorT &Self)
Return the FDataStream associated with this sensor.
static const FVector CarlaNorthVector
Based on OpenDRIVE's lon and lat, North is in (0.0f, -1.0f, 0.0f)
static std::shared_ptr< ROS2 > GetInstance()
void SetAccelerationStandardDeviation(const FVector &Vec)
float GetNormalDistribution(float Mean, float StandardDeviation)
FVector StdDevAccel
Standard deviation for acceleration settings.
static FVector FIMU_GetActorAngularVelocityInRadians(AActor &Actor)
carla::streaming::detail::token_type token_type
carla::geom::Vector3D ComputeAccelerometer(const float DeltaTime)
Accelerometer: measures linear acceleration in m/s^2.
static const float GRAVITY
AInertialMeasurementUnit(const FObjectInitializer &ObjectInitializer)
URandomEngine * RandomEngine
Random Engine used to provide noise for sensor output.