CARLA
GnssSensor.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #include "Carla.h"
12 
14 #include "carla/geom/Vector3D.h"
16 
17 AGnssSensor::AGnssSensor(const FObjectInitializer &ObjectInitializer)
18  : Super(ObjectInitializer)
19 {
20  PrimaryActorTick.bCanEverTick = true;
21  RandomEngine = CreateDefaultSubobject<URandomEngine>(TEXT("RandomEngine"));
22 }
23 
25 {
27 }
28 
29 void AGnssSensor::Set(const FActorDescription &ActorDescription)
30 {
31  Super::Set(ActorDescription);
32  UActorBlueprintFunctionLibrary::SetGnss(ActorDescription, this);
33 }
34 
35 void AGnssSensor::PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
36 {
37  TRACE_CPUPROFILER_EVENT_SCOPE(AGnssSensor::PostPhysTick);
38 
39  FVector ActorLocation = GetActorLocation();
40  ALargeMapManager * LargeMap = UCarlaStatics::GetLargeMapManager(GetWorld());
41  if (LargeMap)
42  {
43  ActorLocation = LargeMap->LocalToGlobalLocation(ActorLocation);
44  }
45  carla::geom::Location Location = ActorLocation;
46  carla::geom::GeoLocation CurrentLocation = CurrentGeoReference.Transform(Location);
47 
48  // Compute the noise for the sensor
49  const float LatError = RandomEngine->GetNormalDistribution(0.0f, LatitudeDeviation);
50  const float LonError = RandomEngine->GetNormalDistribution(0.0f, LongitudeDeviation);
51  const float AltError = RandomEngine->GetNormalDistribution(0.0f, AltitudeDeviation);
52 
53  // Apply the noise to the sensor
54  double Latitude = CurrentLocation.latitude + LatitudeBias + LatError;
55  double Longitude = CurrentLocation.longitude + LongitudeBias + LonError;
56  double Altitude = CurrentLocation.altitude + AltitudeBias + AltError;
57 
58  {
59  TRACE_CPUPROFILER_EVENT_SCOPE_STR("AGnssSensor Stream Send");
60  auto Stream = GetDataStream(*this);
61  Stream.Send(*this, carla::geom::GeoLocation{Latitude, Longitude, Altitude});
62  }
63 }
64 
66 {
67  LatitudeDeviation = Value;
68 }
69 
71 {
72  LongitudeDeviation = Value;
73 }
74 
76 {
77  AltitudeDeviation = Value;
78 }
79 
81 {
82  LatitudeBias = Value;
83 }
84 
86 {
87  LongitudeBias = Value;
88 }
89 
91 {
92  AltitudeBias = Value;
93 }
94 
96 {
97  return LatitudeDeviation;
98 }
100 {
101  return LongitudeDeviation;
102 }
104 {
105  return AltitudeDeviation;
106 }
107 
109 {
110  return LatitudeBias;
111 }
113 {
114  return LongitudeBias;
115 }
117 {
118  return AltitudeBias;
119 }
120 
122 {
123  Super::BeginPlay();
124 
125  const UCarlaEpisode* episode = UCarlaStatics::GetCurrentEpisode(GetWorld());
127 }
virtual void BeginPlay() override
Definition: GnssSensor.cpp:121
static FActorDefinition GetSensorDefinition()
Definition: GnssSensor.cpp:24
void SetLatitudeBias(float Value)
Definition: GnssSensor.cpp:80
float GetLongitudeBias() const
Definition: GnssSensor.cpp:112
virtual void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds) override
Definition: GnssSensor.cpp:35
float GetLatitudeBias() const
Definition: GnssSensor.cpp:108
A definition of a Carla Actor with all the variation and attributes.
carla::geom::GeoLocation CurrentGeoReference
Definition: GnssSensor.h:60
void SetAltitudeDeviation(float Value)
Definition: GnssSensor.cpp:75
float GetAltitudeDeviation() const
Definition: GnssSensor.cpp:103
GeoLocation Transform(const Location &location) const
Transform the given location to a GeoLocation using this as geo-reference.
Definition: GeoLocation.cpp:66
geom::Location Location
Definition: rpc/Location.h:14
float LatitudeDeviation
Definition: GnssSensor.h:62
void SetLongitudeBias(float Value)
Definition: GnssSensor.cpp:85
void SetAltitudeBias(float Value)
Definition: GnssSensor.cpp:90
float LongitudeBias
Definition: GnssSensor.h:67
A simulation episode.
Definition: CarlaEpisode.h:34
float GetLongitudeDeviation() const
Definition: GnssSensor.cpp:99
static void SetGnss(const FActorDescription &Description, AGnssSensor *Gnss)
float AltitudeDeviation
Definition: GnssSensor.h:64
A description of a Carla Actor with all its variation.
float GetAltitudeBias() const
Definition: GnssSensor.cpp:116
void SetLongitudeDeviation(float Value)
Definition: GnssSensor.cpp:70
FAsyncDataStream GetDataStream(const SensorT &Self)
Return the FDataStream associated with this sensor.
AGnssSensor(const FObjectInitializer &ObjectInitializer)
Definition: GnssSensor.cpp:17
float AltitudeBias
Definition: GnssSensor.h:68
static UCarlaEpisode * GetCurrentEpisode(const UObject *WorldContextObject)
Definition: CarlaStatics.h:68
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
Definition: CarlaStatics.h:100
void SetLatitudeDeviation(float Value)
Definition: GnssSensor.cpp:65
const carla::geom::GeoLocation & GetGeoReference() const
Return the GeoLocation point of the map loaded.
Definition: CarlaEpisode.h:113
float LongitudeDeviation
Definition: GnssSensor.h:63
void Set(const FActorDescription &ActorDescription)
Definition: GnssSensor.cpp:29
float GetNormalDistribution(float Mean, float StandardDeviation)
Definition: RandomEngine.h:110
float LatitudeBias
Definition: GnssSensor.h:66
FVector LocalToGlobalLocation(const FVector &InLocation) const
float GetLatitudeDeviation() const
Definition: GnssSensor.cpp:95
URandomEngine * RandomEngine
Random Engine used to provide noise for sensor output.