IMU: Fix some weird cases when the imu gives nan values
This commit is contained in:
parent
12e4148def
commit
051a33c505
|
@ -167,13 +167,16 @@ float AInertialMeasurementUnit::ComputeCompass()
|
|||
{
|
||||
// Magnetometer: orientation with respect to the North in rad
|
||||
const FVector ForwVect = GetActorForwardVector().GetSafeNormal2D();
|
||||
float Compass = std::acos(FVector::DotProduct(CarlaNorthVector, ForwVect));
|
||||
const float DotProd = FVector::DotProduct(CarlaNorthVector, ForwVect)
|
||||
|
||||
// We check if the dot product is higher than 1.0 due to numerical error
|
||||
if (DotProd >= 1.00f)
|
||||
return 0.0f;
|
||||
|
||||
const float Compass = std::acos(DotProd);
|
||||
// Keep the angle between [0, 2pi)
|
||||
if (FVector::CrossProduct(CarlaNorthVector, ForwVect).Z < 0.0f)
|
||||
{
|
||||
Compass = carla::geom::Math::Pi2<float>() - Compass;
|
||||
}
|
||||
return carla::geom::Math::Pi2<float>() - Compass;
|
||||
|
||||
return Compass;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue