CARLA
 
载入中...
搜索中...
未找到
GnssSensor.cpp
浏览该文件的文档.
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"
13
15#include "carla/geom/Vector3D.h"
16#include "carla/ros2/ROS2.h"
18
19AGnssSensor::AGnssSensor(const FObjectInitializer &ObjectInitializer)
20 : Super(ObjectInitializer)
21{
22 PrimaryActorTick.bCanEverTick = true;
23 RandomEngine = CreateDefaultSubobject<URandomEngine>(TEXT("RandomEngine"));
24}
25
30
31void AGnssSensor::Set(const FActorDescription &ActorDescription)
32{
33 Super::Set(ActorDescription);
34 UActorBlueprintFunctionLibrary::SetGnss(ActorDescription, this);
35}
36
37void AGnssSensor::PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
38{
39 TRACE_CPUPROFILER_EVENT_SCOPE(AGnssSensor::PostPhysTick);
40
41 FVector ActorLocation = GetActorLocation();
43 if (LargeMap)
44 {
45 ActorLocation = LargeMap->LocalToGlobalLocation(ActorLocation);
46 }
47 carla::geom::Location Location = ActorLocation;
48 carla::geom::GeoLocation CurrentLocation = CurrentGeoReference.Transform(Location);
49
50 // Compute the noise for the sensor
51 const float LatError = RandomEngine->GetNormalDistribution(0.0f, LatitudeDeviation);
52 const float LonError = RandomEngine->GetNormalDistribution(0.0f, LongitudeDeviation);
53 const float AltError = RandomEngine->GetNormalDistribution(0.0f, AltitudeDeviation);
54
55 // Apply the noise to the sensor
56 double Latitude = CurrentLocation.latitude + LatitudeBias + LatError;
57 double Longitude = CurrentLocation.longitude + LongitudeBias + LonError;
58 double Altitude = CurrentLocation.altitude + AltitudeBias + AltError;
59
60 auto Stream = GetDataStream(*this);
61
62 // ROS2
63 #if defined(WITH_ROS2)
65 if (ROS2->IsEnabled())
66 {
67 TRACE_CPUPROFILER_EVENT_SCOPE_STR("ROS2 Send");
69 AActor* ParentActor = GetAttachParentActor();
70 if (ParentActor)
71 {
72 FTransform LocalTransformRelativeToParent = GetActorTransform().GetRelativeTransform(ParentActor->GetActorTransform());
73 ROS2->ProcessDataFromGNSS(Stream.GetSensorType(), StreamId, LocalTransformRelativeToParent, carla::geom::GeoLocation{Latitude, Longitude, Altitude}, this);
74 }
75 else
76 {
77 ROS2->ProcessDataFromGNSS(Stream.GetSensorType(), StreamId, Stream.GetSensorTransform(), carla::geom::GeoLocation{Latitude, Longitude, Altitude}, this);
78 }
79 }
80 #endif
81 {
82 TRACE_CPUPROFILER_EVENT_SCOPE_STR("AGnssSensor Stream Send");
83 Stream.SerializeAndSend(*this, carla::geom::GeoLocation{Latitude, Longitude, Altitude});
84 }
85}
86
88{
89 LatitudeDeviation = Value;
90}
91
93{
94 LongitudeDeviation = Value;
95}
96
98{
99 AltitudeDeviation = Value;
100}
101
103{
104 LatitudeBias = Value;
105}
106
108{
109 LongitudeBias = Value;
110}
111
113{
114 AltitudeBias = Value;
115}
116
118{
119 return LatitudeDeviation;
120}
122{
123 return LongitudeDeviation;
124}
126{
127 return AltitudeDeviation;
128}
129
131{
132 return LatitudeBias;
133}
135{
136 return LongitudeBias;
137}
139{
140 return AltitudeBias;
141}
142
144{
145 Super::BeginPlay();
146
147 const UCarlaEpisode* episode = UCarlaStatics::GetCurrentEpisode(GetWorld());
149}
float GetLongitudeDeviation() const
carla::geom::GeoLocation CurrentGeoReference
Definition GnssSensor.h:60
float GetAltitudeBias() const
float LongitudeBias
Definition GnssSensor.h:67
void SetLatitudeDeviation(float Value)
float GetAltitudeDeviation() const
void SetLongitudeBias(float Value)
virtual void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds) override
float LatitudeBias
Definition GnssSensor.h:66
float LatitudeDeviation
Definition GnssSensor.h:62
void SetLongitudeDeviation(float Value)
void SetAltitudeDeviation(float Value)
float AltitudeBias
Definition GnssSensor.h:68
float GetLatitudeDeviation() const
float GetLongitudeBias() const
void Set(const FActorDescription &ActorDescription)
float GetLatitudeBias() const
void SetAltitudeBias(float Value)
float AltitudeDeviation
Definition GnssSensor.h:64
void SetLatitudeBias(float Value)
virtual void BeginPlay() override
float LongitudeDeviation
Definition GnssSensor.h:63
static FActorDefinition GetSensorDefinition()
AGnssSensor(const FObjectInitializer &ObjectInitializer)
FVector LocalToGlobalLocation(const FVector &InLocation) 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.
uint64_t GetSensorType()
Definition DataStream.h:58
static void SetGnss(const FActorDescription &Description, AGnssSensor *Gnss)
A simulation episode.
const carla::geom::GeoLocation & GetGeoReference() const
Return the GeoLocation point of the map loaded
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
static UCarlaEpisode * GetCurrentEpisode(const UObject *WorldContextObject)
float GetNormalDistribution(float Mean, float StandardDeviation)
GeoLocation Transform(const Location &location) const
Transform the given location to a GeoLocation using this as geo-reference.
static std::shared_ptr< ROS2 > GetInstance()
Definition ROS2.h:51
Serializes a stream endpoint.
A definition of a Carla Actor with all the variation and attributes.
A description of a Carla Actor with all its variation.