CARLA
 
载入中...
搜索中...
未找到
World.h
浏览该文件的文档.
1// Copyright (c) 2017 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#pragma once
8
9#include "carla/Memory.h"
10#include "carla/Time.h"
20#include "carla/rpc/Actor.h"
25#include "carla/rpc/MapLayer.h"
29#include "carla/rpc/Texture.h"
31
32#include <string>
33#include <boost/optional.hpp>
34
35namespace carla {
36namespace client {
37
38 class Actor;
39 class ActorBlueprint;
40 class ActorList;
41 class BlueprintLibrary;
42 class Map;
43 class TrafficLight;
44 class TrafficSign;
45
46 class World {
47 public:
48
49 explicit World(detail::EpisodeProxy episode) : _episode(std::move(episode)) {}
50
52
53 World(const World &) = default;
54 World(World &&) = default;
55
56 World &operator=(const World &) = default;
57 World &operator=(World &&) = default;
58
59 /// Get the id of the episode associated with this world.
60 uint64_t GetId() const {
61 return _episode.GetId();
62 }
63
64 /// Return the map that describes this world.
65 SharedPtr<Map> GetMap() const;
66
67 void LoadLevelLayer(rpc::MapLayer map_layers) const;
68
69 void UnloadLevelLayer(rpc::MapLayer map_layers) const;
70
71 /// Return the list of blueprints available in this world. This blueprints
72 /// can be used to spawning actor into the world.
74
75 /// Returns a list of pairs where the firts element is the vehicle ID
76 /// and the second one is the light state
78
79 /// Get a random location from the pedestrians navigation mesh
80 boost::optional<geom::Location> GetRandomLocationFromNavigation() const;
81
82 /// Return the spectator actor. The spectator controls the view in the
83 /// simulator window.
85
87
88 /// @return The id of the frame when the settings were applied.
89 uint64_t ApplySettings(const rpc::EpisodeSettings &settings, time_duration timeout);
90
91 /// Retrieve the weather parameters currently active in the world.
93
94 /// Change the weather in the simulation.
95 void SetWeather(const rpc::WeatherParameters &weather);
96
97 /// Get Gravity value used for IMUI Sensor accelerometer calculation
98 float GetIMUISensorGravity() const;
99
100 /// Set Gravity value used for IMUI Sensor accelerometer calculation
101 void SetIMUISensorGravity(float NewIMUISensorGravity);
102
103 /// Return a snapshot of the world at this moment.
105
106 /// Find actor by id, return nullptr if not found.
108
109 /// Return a list with all the actors currently present in the world.
111
112 /// Return a list with the actors requested by ActorId.
113 SharedPtr<ActorList> GetActors(const std::vector<ActorId> &actor_ids) const;
114
115 /// Spawn an actor into the world based on the @a blueprint provided at @a
116 /// transform. If a @a parent is provided, the actor is attached to
117 /// @a parent.
119 const ActorBlueprint &blueprint,
120 const geom::Transform &transform,
121 Actor *parent = nullptr,
123 const std::string& socket_name = "");
124
125 /// Same as SpawnActor but return nullptr on failure instead of throwing an
126 /// exception.
128 const ActorBlueprint &blueprint,
129 const geom::Transform &transform,
130 Actor *parent = nullptr,
132 const std::string& socket_name = "") noexcept;
133
134 /// Block calling thread until a world tick is received.
136
137 /// Register a @a callback to be called every time a world tick is received.
138 ///
139 /// @return ID of the callback, use it to remove the callback.
140 size_t OnTick(std::function<void(WorldSnapshot)> callback);
141
142 /// Remove a callback registered with OnTick.
143 void RemoveOnTick(size_t callback_id);
144
145 /// Signal the simulator to continue to next tick (only has effect on
146 /// synchronous mode).
147 ///
148 /// @return The id of the frame that this call started.
149 uint64_t Tick(time_duration timeout);
150
151 /// set the probability that an agent could cross the roads in its path following
152 /// percentage of 0.0f means no pedestrian can cross roads
153 /// percentage of 0.5f means 50% of all pedestrians can cross roads
154 /// percentage of 1.0f means all pedestrians can cross roads if needed
155 void SetPedestriansCrossFactor(float percentage);
156
157 /// set the seed to use with random numbers in the pedestrians module
158 void SetPedestriansSeed(unsigned int seed);
159
160 SharedPtr<Actor> GetTrafficSign(const Landmark& landmark) const;
161
162 SharedPtr<Actor> GetTrafficLight(const Landmark& landmark) const;
163
164 SharedPtr<Actor> GetTrafficLightFromOpenDRIVE(const road::SignId& sign_id) const;
165
167
169
171 return DebugHelper{_episode};
172 }
173
175 return _episode;
176 };
177
178 void FreezeAllTrafficLights(bool frozen);
179
180 /// Returns all the BBs of all the elements of the level
181 std::vector<geom::BoundingBox> GetLevelBBs(uint8_t queried_tag) const;
182
183 std::vector<rpc::EnvironmentObject> GetEnvironmentObjects(uint8_t queried_tag) const;
184
186 std::vector<uint64_t> env_objects_ids,
187 bool enable) const;
188
189 boost::optional<rpc::LabelledPoint> ProjectPoint(
190 geom::Location location, geom::Vector3D direction, float search_distance = 10000.f) const;
191
192 boost::optional<rpc::LabelledPoint> GroundProjection(
193 geom::Location location, float search_distance = 10000.0) const;
194
195 std::vector<rpc::LabelledPoint> CastRay(
196 geom::Location start_location, geom::Location end_location) const;
197
198 std::vector<SharedPtr<Actor>> GetTrafficLightsFromWaypoint(
199 const Waypoint& waypoint, double distance) const;
200
201 std::vector<SharedPtr<Actor>> GetTrafficLightsInJunction(
202 const road::JuncId junc_id) const;
203
204 // std::vector<std::string> GetObjectNameList();
205
207 const std::string &actor_name,
208 const rpc::MaterialParameter& parameter,
209 const rpc::TextureColor& Texture);
210
212 const std::vector<std::string> &objects_names,
213 const rpc::MaterialParameter& parameter,
214 const rpc::TextureColor& Texture);
215
217 const std::string &actor_name,
218 const rpc::MaterialParameter& parameter,
219 const rpc::TextureFloatColor& Texture);
220
222 const std::vector<std::string> &objects_names,
223 const rpc::MaterialParameter& parameter,
224 const rpc::TextureFloatColor& Texture);
225
227 const std::string &actor_name,
228 const rpc::TextureColor& diffuse_texture,
229 const rpc::TextureFloatColor& emissive_texture,
230 const rpc::TextureFloatColor& normal_texture,
231 const rpc::TextureFloatColor& ao_roughness_metallic_emissive_texture);
232
234 const std::vector<std::string> &objects_names,
235 const rpc::TextureColor& diffuse_texture,
236 const rpc::TextureFloatColor& emissive_texture,
237 const rpc::TextureFloatColor& normal_texture,
238 const rpc::TextureFloatColor& ao_roughness_metallic_emissive_texture);
239
240 std::vector<std::string> GetNamesOfAllObjects() const;
241
242 private:
243
245 };
246
247} // namespace client
248} // namespace carla
Contains all the necessary information for spawning an Actor.
Represents an actor in the simulation.
Class containing a reference to RoadInfoSignal
Definition Landmark.h:22
SharedPtr< ActorList > GetActors() const
Return a list with all the actors currently present in the world.
Definition World.cpp:115
void ApplyColorTextureToObject(const std::string &actor_name, const rpc::MaterialParameter &parameter, const rpc::TextureColor &Texture)
Definition World.cpp:309
std::vector< geom::BoundingBox > GetLevelBBs(uint8_t queried_tag) const
Returns all the BBs of all the elements of the level
Definition World.cpp:237
void LoadLevelLayer(rpc::MapLayer map_layers) const
Definition World.cpp:28
SharedPtr< BlueprintLibrary > GetBlueprintLibrary() const
Return the list of blueprints available in this world.
Definition World.cpp:36
World(const World &)=default
void EnableEnvironmentObjects(std::vector< uint64_t > env_objects_ids, bool enable) const
Definition World.cpp:245
void FreezeAllTrafficLights(bool frozen)
Definition World.cpp:233
boost::optional< rpc::LabelledPoint > GroundProjection(geom::Location location, float search_distance=10000.0) const
Definition World.cpp:260
WorldSnapshot GetSnapshot() const
Return a snapshot of the world at this moment.
Definition World.cpp:103
DebugHelper MakeDebugHelper() const
Definition World.h:170
void ResetAllTrafficLights()
Definition World.cpp:225
World & operator=(const World &)=default
rpc::WeatherParameters GetWeather() const
Retrieve the weather parameters currently active in the world.
Definition World.cpp:86
SharedPtr< Actor > GetSpectator() const
Return the spectator actor.
Definition World.cpp:48
uint64_t GetId() const
Get the id of the episode associated with this world.
Definition World.h:60
rpc::VehicleLightStateList GetVehiclesLightStates() const
Returns a list of pairs where the firts element is the vehicle ID and the second one is the light sta...
Definition World.cpp:40
SharedPtr< Actor > GetActor(ActorId id) const
Find actor by id, return nullptr if not found.
Definition World.cpp:107
SharedPtr< Actor > GetTrafficLight(const Landmark &landmark) const
Definition World.cpp:194
World & operator=(World &&)=default
void SetPedestriansCrossFactor(float percentage)
set the probability that an agent could cross the roads in its path following percentage of 0....
Definition World.cpp:170
World(World &&)=default
uint64_t Tick(time_duration timeout)
Signal the simulator to continue to next tick (only has effect on synchronous mode).
Definition World.cpp:164
detail::EpisodeProxy _episode
Definition World.h:244
SharedPtr< Actor > TrySpawnActor(const ActorBlueprint &blueprint, const geom::Transform &transform, Actor *parent=nullptr, rpc::AttachmentType attachment_type=rpc::AttachmentType::Rigid, const std::string &socket_name="") noexcept
Same as SpawnActor but return nullptr on failure instead of throwing an exception.
Definition World.cpp:136
boost::optional< rpc::LabelledPoint > ProjectPoint(geom::Location location, geom::Vector3D direction, float search_distance=10000.f) const
Definition World.cpp:251
detail::EpisodeProxy GetEpisode() const
Definition World.h:174
World(detail::EpisodeProxy episode)
Definition World.h:49
WorldSnapshot WaitForTick(time_duration timeout) const
Block calling thread until a world tick is received.
Definition World.cpp:149
std::vector< SharedPtr< Actor > > GetTrafficLightsInJunction(const road::JuncId junc_id) const
Definition World.cpp:291
void SetIMUISensorGravity(float NewIMUISensorGravity)
Set Gravity value used for IMUI Sensor accelerometer calculation
Definition World.cpp:98
void ApplyTexturesToObject(const std::string &actor_name, const rpc::TextureColor &diffuse_texture, const rpc::TextureFloatColor &emissive_texture, const rpc::TextureFloatColor &normal_texture, const rpc::TextureFloatColor &ao_roughness_metallic_emissive_texture)
Definition World.cpp:341
std::vector< std::string > GetNamesOfAllObjects() const
Definition World.cpp:337
uint64_t ApplySettings(const rpc::EpisodeSettings &settings, time_duration timeout)
Definition World.cpp:56
boost::optional< geom::Location > GetRandomLocationFromNavigation() const
Get a random location from the pedestrians navigation mesh
Definition World.cpp:44
std::vector< rpc::EnvironmentObject > GetEnvironmentObjects(uint8_t queried_tag) const
Definition World.cpp:241
SharedPtr< Map > GetMap() const
Return the map that describes this world.
Definition World.cpp:24
std::vector< rpc::LabelledPoint > CastRay(geom::Location start_location, geom::Location end_location) const
Definition World.cpp:266
std::vector< SharedPtr< Actor > > GetTrafficLightsFromWaypoint(const Waypoint &waypoint, double distance) const
Definition World.cpp:271
void ApplyColorTextureToObjects(const std::vector< std::string > &objects_names, const rpc::MaterialParameter &parameter, const rpc::TextureColor &Texture)
Definition World.cpp:316
void ApplyFloatColorTextureToObjects(const std::vector< std::string > &objects_names, const rpc::MaterialParameter &parameter, const rpc::TextureFloatColor &Texture)
Definition World.cpp:330
void SetPedestriansSeed(unsigned int seed)
set the seed to use with random numbers in the pedestrians module
Definition World.cpp:174
void ApplyTexturesToObjects(const std::vector< std::string > &objects_names, const rpc::TextureColor &diffuse_texture, const rpc::TextureFloatColor &emissive_texture, const rpc::TextureFloatColor &normal_texture, const rpc::TextureFloatColor &ao_roughness_metallic_emissive_texture)
Definition World.cpp:369
SharedPtr< LightManager > GetLightManager() const
Definition World.cpp:229
SharedPtr< Actor > SpawnActor(const ActorBlueprint &blueprint, const geom::Transform &transform, Actor *parent=nullptr, rpc::AttachmentType attachment_type=rpc::AttachmentType::Rigid, const std::string &socket_name="")
Spawn an actor into the world based on the blueprint provided at transform.
Definition World.cpp:127
SharedPtr< Actor > GetTrafficSign(const Landmark &landmark) const
Definition World.cpp:178
void ApplyFloatColorTextureToObject(const std::string &actor_name, const rpc::MaterialParameter &parameter, const rpc::TextureFloatColor &Texture)
Definition World.cpp:323
void RemoveOnTick(size_t callback_id)
Remove a callback registered with OnTick.
Definition World.cpp:160
SharedPtr< Actor > GetTrafficLightFromOpenDRIVE(const road::SignId &sign_id) const
Definition World.cpp:210
size_t OnTick(std::function< void(WorldSnapshot)> callback)
Register a callback to be called every time a world tick is received.
Definition World.cpp:156
float GetIMUISensorGravity() const
Get Gravity value used for IMUI Sensor accelerometer calculation
Definition World.cpp:94
void SetWeather(const rpc::WeatherParameters &weather)
Change the weather in the simulation.
Definition World.cpp:90
rpc::EpisodeSettings GetSettings() const
Definition World.cpp:52
void UnloadLevelLayer(rpc::MapLayer map_layers) const
Definition World.cpp:32
Positive time duration up to milliseconds resolution.
Definition Time.h:19
int32_t JuncId
Definition RoadTypes.h:17
std::vector< std::pair< ActorId, VehicleLightState::flag_type > > VehicleLightStateList
carla::SharedPtr< cc::Actor > Actor
carla::SharedPtr< cc::ActorList > ActorList
Definition ALSM.h:33
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
Definition Memory.h:20