CARLA
Simulator.h
Go to the documentation of this file.
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/Debug.h"
10 #include "carla/Memory.h"
11 #include "carla/NonCopyable.h"
12 #include "carla/client/Actor.h"
15 #include "carla/client/Vehicle.h"
16 #include "carla/client/Walker.h"
28 #include "carla/rpc/Texture.h"
30 
31 #include <boost/optional.hpp>
32 
33 #include <memory>
34 
35 namespace carla {
36 namespace client {
37 
38  class ActorBlueprint;
39  class BlueprintLibrary;
40  class Map;
41  class Sensor;
42  class WalkerAIController;
43 
44 namespace detail {
45 
46  /// Connects and controls a CARLA Simulator.
47  class Simulator
48  : public std::enable_shared_from_this<Simulator>,
50  private NonCopyable {
51  public:
52 
53  // =========================================================================
54  /// @name Constructor
55  // =========================================================================
56  /// @{
57 
58  explicit Simulator(
59  const std::string &host,
60  uint16_t port,
61  size_t worker_threads = 0u,
62  bool enable_garbage_collection = false);
63 
64  /// @}
65  // =========================================================================
66  /// @name Load a new episode
67  // =========================================================================
68  /// @{
69 
70  EpisodeProxy ReloadEpisode(bool reset_settings = true) {
71  return LoadEpisode("", reset_settings);
72  }
73 
74  EpisodeProxy LoadEpisode(std::string map_name, bool reset_settings = true, rpc::MapLayer map_layers = rpc::MapLayer::All);
75 
76  void LoadLevelLayer(rpc::MapLayer map_layers) const {
77  _client.LoadLevelLayer(map_layers);
78  }
79 
80  void UnloadLevelLayer(rpc::MapLayer map_layers) const {
81  _client.UnloadLevelLayer(map_layers);
82  }
83 
85  std::string opendrive,
87  bool reset_settings = true);
88 
89  /// @}
90  // =========================================================================
91  /// @name Access to current episode
92  // =========================================================================
93  /// @{
94 
95  /// @pre Cannot be called previous to GetCurrentEpisode.
96  auto GetCurrentEpisodeId() const {
97  DEBUG_ASSERT(_episode != nullptr);
98  return _episode->GetId();
99  }
100 
102 
103  /// @}
104  // =========================================================================
105  /// @name World snapshot
106  // =========================================================================
107  /// @{
108 
110  DEBUG_ASSERT(_episode != nullptr);
111  return WorldSnapshot{_episode->GetState()};
112  }
113 
114  /// @}
115  // =========================================================================
116  /// @name Map related methods
117  // =========================================================================
118  /// @{
119 
121 
122  std::vector<std::string> GetAvailableMaps() {
123  return _client.GetAvailableMaps();
124  }
125 
126  /// @}
127  // =========================================================================
128  /// @name Required files related methods
129  // =========================================================================
130  /// @{
131 
132  bool SetFilesBaseFolder(const std::string &path);
133 
134  std::vector<std::string> GetRequiredFiles(const std::string &folder = "", const bool download = true) const;
135 
136  void RequestFile(const std::string &name) const;
137 
138  std::vector<uint8_t> GetCacheFile(const std::string &name, const bool request_otherwise) const;
139 
140  /// @}
141  // =========================================================================
142  /// @name Garbage collection policy
143  // =========================================================================
144  /// @{
145 
147  return _gc_policy;
148  }
149 
150  /// @}
151  // =========================================================================
152  /// @name Pure networking operations
153  // =========================================================================
154  /// @{
155 
157  _client.SetTimeout(timeout);
158  }
159 
161  return _client.GetTimeout();
162  }
163 
164  std::string GetClientVersion() {
165  return _client.GetClientVersion();
166  }
167 
168  std::string GetServerVersion() {
169  return _client.GetServerVersion();
170  }
171 
172  /// @}
173  // =========================================================================
174  /// @name Tick
175  // =========================================================================
176  /// @{
177 
179 
180  size_t RegisterOnTickEvent(std::function<void(WorldSnapshot)> callback) {
181  DEBUG_ASSERT(_episode != nullptr);
182  return _episode->RegisterOnTickEvent(std::move(callback));
183  }
184 
185  void RemoveOnTickEvent(size_t id) {
186  DEBUG_ASSERT(_episode != nullptr);
187  _episode->RemoveOnTickEvent(id);
188  }
189 
190  uint64_t Tick(time_duration timeout);
191 
192  /// @}
193  // =========================================================================
194  /// @name Access to global objects in the episode
195  // =========================================================================
196  /// @{
197 
198  std :: string GetEndpoint() {
199  return _client.GetEndpoint();
200  }
201 
202  /// Query to know if a Traffic Manager is running on port
203  bool IsTrafficManagerRunning(uint16_t port) const {
204  return _client.IsTrafficManagerRunning(port);
205  }
206 
207  /// Gets a pair filled with the <IP, port> of the Trafic Manager running on port.
208  /// If there is no Traffic Manager running the pair will be ("", 0)
209  std::pair<std::string, uint16_t> GetTrafficManagerRunning(uint16_t port) const {
210  return _client.GetTrafficManagerRunning(port);
211  }
212 
213  /// Informs that a Traffic Manager is running on <IP, port>
214  bool AddTrafficManagerRunning(std::pair<std::string, uint16_t> trafficManagerInfo) const {
215  return _client.AddTrafficManagerRunning(trafficManagerInfo);
216  }
217 
218  void DestroyTrafficManager(uint16_t port) const {
220  }
221 
222  void AddPendingException(std::string e) {
223  _episode->AddPendingException(e);
224  }
225 
227 
228  /// Returns a list of pairs where the firts element is the vehicle ID
229  /// and the second one is the light state
231 
233 
235  return _client.GetEpisodeSettings();
236  }
237 
238  uint64_t SetEpisodeSettings(const rpc::EpisodeSettings &settings);
239 
241  return _client.GetWeatherParameters();
242  }
243 
245  _client.SetWeatherParameters(weather);
246  }
247 
249  return _client.GetVehiclePhysicsControl(vehicle.GetId());
250  }
251 
253  return _client.GetVehicleLightState(vehicle.GetId());
254  }
255 
256  /// Returns all the BBs of all the elements of the level
257  std::vector<geom::BoundingBox> GetLevelBBs(uint8_t queried_tag) const {
258  return _client.GetLevelBBs(queried_tag);
259  }
260 
261  std::vector<rpc::EnvironmentObject> GetEnvironmentObjects(uint8_t queried_tag) const {
262  return _client.GetEnvironmentObjects(queried_tag);
263  }
264 
266  std::vector<uint64_t> env_objects_ids,
267  bool enable) const {
268  _client.EnableEnvironmentObjects(env_objects_ids, enable);
269  }
270 
271  std::pair<bool,rpc::LabelledPoint> ProjectPoint(
272  geom::Location location, geom::Vector3D direction, float search_distance) const {
273  return _client.ProjectPoint(location, direction, search_distance);
274  }
275 
276  std::vector<rpc::LabelledPoint> CastRay(
277  geom::Location start_location, geom::Location end_location) const {
278  return _client.CastRay(start_location, end_location);
279  }
280 
281  /// @}
282  // =========================================================================
283  /// @name AI
284  // =========================================================================
285  /// @{
286 
287  void RegisterAIController(const WalkerAIController &controller);
288 
289  void UnregisterAIController(const WalkerAIController &controller);
290 
291  boost::optional<geom::Location> GetRandomLocationFromNavigation();
292 
293  std::shared_ptr<WalkerNavigation> GetNavigation() {
294  return _episode->GetNavigation();
295  }
296 
297  void SetPedestriansCrossFactor(float percentage);
298 
299  void SetPedestriansSeed(unsigned int seed);
300 
301  /// @}
302  // =========================================================================
303  /// @name General operations with actors
304  // =========================================================================
305  /// @{
306 
307  boost::optional<rpc::Actor> GetActorById(ActorId id) const {
308  DEBUG_ASSERT(_episode != nullptr);
309  return _episode->GetActorById(id);
310  }
311 
312  std::vector<rpc::Actor> GetActorsById(const std::vector<ActorId> &actor_ids) const {
313  DEBUG_ASSERT(_episode != nullptr);
314  return _episode->GetActorsById(actor_ids);
315  }
316 
317  std::vector<rpc::Actor> GetAllTheActorsInTheEpisode() const {
318  DEBUG_ASSERT(_episode != nullptr);
319  return _episode->GetActors();
320  }
321 
322  /// Creates an actor instance out of a description of an existing actor.
323  /// Note that this does not spawn an actor.
324  ///
325  /// If @a gc is GarbageCollectionPolicy::Enabled, the shared pointer
326  /// returned is provided with a custom deleter that calls Destroy() on the
327  /// actor. This method does not support GarbageCollectionPolicy::Inherit.
329  rpc::Actor actor_description,
332  return ActorFactory::MakeActor(GetCurrentEpisode(), std::move(actor_description), gc);
333  }
334 
335  /// Spawns an actor into the simulation.
336  ///
337  /// If @a gc is GarbageCollectionPolicy::Enabled, the shared pointer
338  /// returned is provided with a custom deleter that calls Destroy() on the
339  /// actor. If @gc is GarbageCollectionPolicy::Inherit, the default garbage
340  /// collection policy is used.
342  const ActorBlueprint &blueprint,
343  const geom::Transform &transform,
344  Actor *parent = nullptr,
347 
348  bool DestroyActor(Actor &actor);
349 
351  DEBUG_ASSERT(_episode != nullptr);
352  return _episode->GetState()->GetActorSnapshot(actor_id);
353  }
354 
355  ActorSnapshot GetActorSnapshot(const Actor &actor) const {
356  return GetActorSnapshot(actor.GetId());
357  }
358 
359  rpc::ActorState GetActorState(const Actor &actor) const {
360  return GetActorSnapshot(actor).actor_state;
361  }
362 
363  geom::Location GetActorLocation(const Actor &actor) const {
364  return GetActorSnapshot(actor).transform.location;
365  }
366 
368  return GetActorSnapshot(actor).transform;
369  }
370 
371  geom::Vector3D GetActorVelocity(const Actor &actor) const {
372  return GetActorSnapshot(actor).velocity;
373  }
374 
375  void SetActorTargetVelocity(const Actor &actor, const geom::Vector3D &vector) {
376  _client.SetActorTargetVelocity(actor.GetId(), vector);
377  }
378 
380  return GetActorSnapshot(actor).angular_velocity;
381  }
382 
383  void SetActorTargetAngularVelocity(const Actor &actor, const geom::Vector3D &vector) {
385  }
386  void EnableActorConstantVelocity(const Actor &actor, const geom::Vector3D &vector) {
387  _client.EnableActorConstantVelocity(actor.GetId(), vector);
388  }
389 
390  void DisableActorConstantVelocity(const Actor &actor) {
392  }
393 
394  void AddActorImpulse(const Actor &actor, const geom::Vector3D &impulse) {
395  _client.AddActorImpulse(actor.GetId(), impulse);
396  }
397 
398  void AddActorImpulse(const Actor &actor, const geom::Vector3D &impulse, const geom::Vector3D &location) {
399  _client.AddActorImpulse(actor.GetId(), impulse, location);
400  }
401 
402  void AddActorForce(const Actor &actor, const geom::Vector3D &force) {
403  _client.AddActorForce(actor.GetId(), force);
404  }
405 
406  void AddActorForce(const Actor &actor, const geom::Vector3D &force, const geom::Vector3D &location) {
407  _client.AddActorForce(actor.GetId(), force, location);
408  }
409 
410  void AddActorAngularImpulse(const Actor &actor, const geom::Vector3D &vector) {
411  _client.AddActorAngularImpulse(actor.GetId(), vector);
412  }
413 
414  void AddActorTorque(const Actor &actor, const geom::Vector3D &torque) {
415  _client.AddActorAngularImpulse(actor.GetId(), torque);
416  }
417 
419  return GetActorSnapshot(actor).acceleration;
420  }
421 
422  void SetActorLocation(Actor &actor, const geom::Location &location) {
423  _client.SetActorLocation(actor.GetId(), location);
424  }
425 
426  void SetActorTransform(Actor &actor, const geom::Transform &transform) {
427  _client.SetActorTransform(actor.GetId(), transform);
428  }
429 
430  void SetActorSimulatePhysics(Actor &actor, bool enabled) {
431  _client.SetActorSimulatePhysics(actor.GetId(), enabled);
432  }
433 
434  void SetActorEnableGravity(Actor &actor, bool enabled) {
435  _client.SetActorEnableGravity(actor.GetId(), enabled);
436  }
437 
438  /// @}
439  // =========================================================================
440  /// @name Operations with vehicles
441  // =========================================================================
442  /// @{
443 
444  void SetVehicleAutopilot(Vehicle &vehicle, bool enabled = true) {
445  _client.SetActorAutopilot(vehicle.GetId(), enabled);
446  }
447 
448  void ShowVehicleDebugTelemetry(Vehicle &vehicle, bool enabled = true) {
449  _client.ShowVehicleDebugTelemetry(vehicle.GetId(), enabled);
450  }
451 
452  void SetLightsToVehicle(Vehicle &vehicle, const rpc::VehicleControl &control) {
453  _client.ApplyControlToVehicle(vehicle.GetId(), control);
454  }
455 
456  void ApplyControlToVehicle(Vehicle &vehicle, const rpc::VehicleControl &control) {
457  _client.ApplyControlToVehicle(vehicle.GetId(), control);
458  }
459 
460  void ApplyControlToWalker(Walker &walker, const rpc::WalkerControl &control) {
461  _client.ApplyControlToWalker(walker.GetId(), control);
462  }
463 
465  return _client.GetBonesTransform(walker.GetId());
466  }
467 
468  void SetBonesTransform(Walker &walker, const rpc::WalkerBoneControlIn &bones) {
469  return _client.SetBonesTransform(walker.GetId(), bones);
470  }
471 
472  void BlendPose(Walker &walker, float blend) {
473  return _client.BlendPose(walker.GetId(), blend);
474  }
475 
476  void GetPoseFromAnimation(Walker &walker) {
477  return _client.GetPoseFromAnimation(walker.GetId());
478  }
479 
480  void ApplyPhysicsControlToVehicle(Vehicle &vehicle, const rpc::VehiclePhysicsControl &physicsControl) {
481  _client.ApplyPhysicsControlToVehicle(vehicle.GetId(), physicsControl);
482  }
483 
484  void SetLightStateToVehicle(Vehicle &vehicle, const rpc::VehicleLightState light_state) {
485  _client.SetLightStateToVehicle(vehicle.GetId(), light_state);
486  }
487 
488  void OpenVehicleDoor(Vehicle &vehicle, const rpc::VehicleDoor door_idx) {
489  _client.OpenVehicleDoor(vehicle.GetId(), door_idx);
490  }
491 
492  void CloseVehicleDoor(Vehicle &vehicle, const rpc::VehicleDoor door_idx) {
493  _client.CloseVehicleDoor(vehicle.GetId(), door_idx);
494  }
495 
496  void SetWheelSteerDirection(Vehicle &vehicle, rpc::VehicleWheelLocation wheel_location, float angle_in_deg) {
497  _client.SetWheelSteerDirection(vehicle.GetId(), wheel_location, angle_in_deg);
498  }
499 
500  float GetWheelSteerAngle(Vehicle &vehicle, rpc::VehicleWheelLocation wheel_location) {
501  return _client.GetWheelSteerAngle(vehicle.GetId(), wheel_location);
502  }
503 
504  void EnableCarSim(Vehicle &vehicle, std::string simfile_path) {
505  _client.EnableCarSim(vehicle.GetId(), simfile_path);
506  }
507 
508  void UseCarSimRoad(Vehicle &vehicle, bool enabled) {
509  _client.UseCarSimRoad(vehicle.GetId(), enabled);
510  }
511 
513  uint64_t MaxSubsteps,
514  float MaxSubstepDeltaTime,
515  std::string VehicleJSON,
516  std::string PowertrainJSON,
517  std::string TireJSON,
518  std::string BaseJSONPath) {
520  MaxSubsteps,
521  MaxSubstepDeltaTime,
522  VehicleJSON,
523  PowertrainJSON,
524  TireJSON,
525  BaseJSONPath);
526  }
527 
528  /// @}
529  // =========================================================================
530  /// @name Operations with the recorder
531  // =========================================================================
532  /// @{
533 
534  std::string StartRecorder(std::string name, bool additional_data) {
535  return _client.StartRecorder(std::move(name), additional_data);
536  }
537 
538  void StopRecorder(void) {
540  }
541 
542  std::string ShowRecorderFileInfo(std::string name, bool show_all) {
543  return _client.ShowRecorderFileInfo(std::move(name), show_all);
544  }
545 
546  std::string ShowRecorderCollisions(std::string name, char type1, char type2) {
547  return _client.ShowRecorderCollisions(std::move(name), type1, type2);
548  }
549 
550  std::string ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance) {
551  return _client.ShowRecorderActorsBlocked(std::move(name), min_time, min_distance);
552  }
553 
554  std::string ReplayFile(std::string name, double start, double duration,
555  uint32_t follow_id, bool replay_sensors) {
556  return _client.ReplayFile(std::move(name), start, duration, follow_id, replay_sensors);
557  }
558 
559  void SetReplayerTimeFactor(double time_factor) {
560  _client.SetReplayerTimeFactor(time_factor);
561  }
562 
563  void SetReplayerIgnoreHero(bool ignore_hero) {
564  _client.SetReplayerIgnoreHero(ignore_hero);
565  }
566 
567  void StopReplayer(bool keep_actors) {
568  _client.StopReplayer(keep_actors);
569  }
570 
571  /// @}
572  // =========================================================================
573  /// @name Operations with sensors
574  // =========================================================================
575  /// @{
576 
577  void SubscribeToSensor(
578  const Sensor &sensor,
579  std::function<void(SharedPtr<sensor::SensorData>)> callback);
580 
581  void UnSubscribeFromSensor(const Sensor &sensor);
582 
583  /// @}
584  // =========================================================================
585  /// @name Operations with traffic lights
586  // =========================================================================
587  /// @{
588 
589  void SetTrafficLightState(TrafficLight &trafficLight, const rpc::TrafficLightState trafficLightState) {
590  _client.SetTrafficLightState(trafficLight.GetId(), trafficLightState);
591  }
592 
593  void SetTrafficLightGreenTime(TrafficLight &trafficLight, float greenTime) {
594  _client.SetTrafficLightGreenTime(trafficLight.GetId(), greenTime);
595  }
596 
597  void SetTrafficLightYellowTime(TrafficLight &trafficLight, float yellowTime) {
598  _client.SetTrafficLightYellowTime(trafficLight.GetId(), yellowTime);
599  }
600 
601  void SetTrafficLightRedTime(TrafficLight &trafficLight, float redTime) {
602  _client.SetTrafficLightRedTime(trafficLight.GetId(), redTime);
603  }
604 
605  void FreezeTrafficLight(TrafficLight &trafficLight, bool freeze) {
606  _client.FreezeTrafficLight(trafficLight.GetId(), freeze);
607  }
608 
609  void ResetTrafficLightGroup(TrafficLight &trafficLight) {
610  _client.ResetTrafficLightGroup(trafficLight.GetId());
611  }
612 
615  }
616 
617  std::vector<geom::BoundingBox> GetLightBoxes(const TrafficLight &trafficLight) const {
618  return _client.GetLightBoxes(trafficLight.GetId());
619  }
620 
621  std::vector<ActorId> GetGroupTrafficLights(TrafficLight &trafficLight) {
622  return _client.GetGroupTrafficLights(trafficLight.GetId());
623  }
624 
625  /// @}
626  // =========================================================================
627  /// @name Debug
628  // =========================================================================
629  /// @{
630 
631  void DrawDebugShape(const rpc::DebugShape &shape) {
632  _client.DrawDebugShape(shape);
633  }
634 
635  /// @}
636  // =========================================================================
637  /// @name Apply commands in batch
638  // =========================================================================
639  /// @{
640 
641  void ApplyBatch(std::vector<rpc::Command> commands, bool do_tick_cue) {
642  _client.ApplyBatch(std::move(commands), do_tick_cue);
643  }
644 
645  auto ApplyBatchSync(std::vector<rpc::Command> commands, bool do_tick_cue) {
646  return _client.ApplyBatchSync(std::move(commands), do_tick_cue);
647  }
648 
649  /// @}
650  // =========================================================================
651  /// @name Operations lights
652  // =========================================================================
653  /// @{
654 
656  return _light_manager;
657  }
658 
659  std::vector<rpc::LightState> QueryLightsStateToServer() const {
661  }
662 
664  std::vector<rpc::LightState>& lights,
665  bool discard_client = false) const {
666  _client.UpdateServerLightsState(lights, discard_client);
667  }
668 
669  size_t RegisterLightUpdateChangeEvent(std::function<void(WorldSnapshot)> callback) {
670  DEBUG_ASSERT(_episode != nullptr);
671  return _episode->RegisterLightUpdateChangeEvent(std::move(callback));
672  }
673 
675  DEBUG_ASSERT(_episode != nullptr);
676  _episode->RemoveLightUpdateChangeEvent(id);
677  }
678 
679  void FreezeAllTrafficLights(bool frozen);
680 
681  /// @}
682  // =========================================================================
683  /// @name Texture updating operations
684  // =========================================================================
685  /// @{
686 
688  const std::vector<std::string> &objects_name,
689  const rpc::MaterialParameter& parameter,
690  const rpc::TextureColor& Texture);
691 
693  const std::vector<std::string> &objects_name,
694  const rpc::MaterialParameter& parameter,
695  const rpc::TextureFloatColor& Texture);
696 
697  std::vector<std::string> GetNamesOfAllObjects() const;
698 
699  /// @}
700 
701  private:
702 
703  bool ShouldUpdateMap(rpc::MapInfo& map_info);
704 
706 
708 
709  std::shared_ptr<Episode> _episode;
710 
712 
714 
715  std::string _open_drive_file;
716  };
717 
718 } // namespace detail
719 } // namespace client
720 } // namespace carla
void DisableActorConstantVelocity(const Actor &actor)
Definition: Simulator.h:390
void SetVehicleAutopilot(Vehicle &vehicle, bool enabled=true)
Definition: Simulator.h:444
void EnableActorConstantVelocity(const Actor &actor, const geom::Vector3D &vector)
Definition: Simulator.h:386
rpc::VehicleLightStateList GetVehiclesLightStates()
Returns a list of pairs where the firts element is the vehicle ID and the second one is the light sta...
Definition: Simulator.cpp:232
std::vector< geom::BoundingBox > GetLightBoxes(const TrafficLight &trafficLight) const
Definition: Simulator.h:617
std::shared_ptr< Episode > _episode
Definition: Simulator.h:709
bool DestroyActor(Actor &actor)
Definition: Simulator.cpp:352
time_duration GetNetworkingTimeout()
Definition: Simulator.h:160
void AddPendingException(std::string e)
Definition: Simulator.h:222
boost::optional< rpc::Actor > GetActorById(ActorId id) const
Definition: Simulator.h:307
Seting for map generation from opendrive without additional geometry.
void SetLightStateToVehicle(rpc::ActorId vehicle, const rpc::VehicleLightState &light_state)
void AddActorImpulse(const Actor &actor, const geom::Vector3D &impulse)
Definition: Simulator.h:394
void EnableChronoPhysics(Vehicle &vehicle, uint64_t MaxSubsteps, float MaxSubstepDeltaTime, std::string VehicleJSON, std::string PowertrainJSON, std::string TireJSON, std::string BaseJSONPath)
Definition: Simulator.h:512
std::vector< rpc::LabelledPoint > CastRay(geom::Location start_location, geom::Location end_location) const
Definition: Simulator.h:276
std::vector< rpc::Actor > GetActorsById(const std::vector< ActorId > &actor_ids) const
Definition: Simulator.h:312
bool SetFilesBaseFolder(const std::string &path)
Definition: Simulator.cpp:184
void SetActorTargetVelocity(rpc::ActorId actor, const geom::Vector3D &vector)
void SetActorLocation(rpc::ActorId actor, const geom::Location &location)
bool AddTrafficManagerRunning(std::pair< std::string, uint16_t > trafficManagerInfo) const
Informs the server that a Traffic Manager is running on <IP, port>
void ApplyPhysicsControlToVehicle(rpc::ActorId vehicle, const rpc::VehiclePhysicsControl &physics_control)
void SetBonesTransform(rpc::ActorId walker, const rpc::WalkerBoneControlIn &bones)
std::string ShowRecorderFileInfo(std::string name, bool show_all)
void EnableCarSim(rpc::ActorId vehicle, std::string simfile_path)
bool AddTrafficManagerRunning(std::pair< std::string, uint16_t > trafficManagerInfo) const
Informs that a Traffic Manager is running on <IP, port>
Definition: Simulator.h:214
ActorSnapshot GetActorSnapshot(ActorId actor_id) const
Definition: Simulator.h:350
std::vector< rpc::LightState > QueryLightsStateToServer() const
Definition: Simulator.h:659
void ShowVehicleDebugTelemetry(rpc::ActorId vehicle, bool enabled)
void SetActorSimulatePhysics(Actor &actor, bool enabled)
Definition: Simulator.h:430
std::vector< std::string > GetAvailableMaps()
Definition: Simulator.h:122
void CloseVehicleDoor(rpc::ActorId vehicle, const rpc::VehicleDoor door_idx)
void SetTrafficLightState(rpc::ActorId traffic_light, const rpc::TrafficLightState trafficLightState)
void UpdateServerLightsState(std::vector< rpc::LightState > &lights, bool discard_client=false) const
Definition: Simulator.h:663
void SetTrafficLightState(TrafficLight &trafficLight, const rpc::TrafficLightState trafficLightState)
Definition: Simulator.h:589
rpc::VehiclePhysicsControl GetVehiclePhysicsControl(const Vehicle &vehicle) const
Definition: Simulator.h:248
void SetActorTransform(rpc::ActorId actor, const geom::Transform &transform)
void GetPoseFromAnimation(rpc::ActorId walker)
std::string ReplayFile(std::string name, double start, double duration, uint32_t follow_id, bool replay_sensors)
SharedPtr< LightManager > GetLightManager() const
Definition: Simulator.h:655
void ShowVehicleDebugTelemetry(Vehicle &vehicle, bool enabled=true)
Definition: Simulator.h:448
void ApplyControlToVehicle(Vehicle &vehicle, const rpc::VehicleControl &control)
Definition: Simulator.h:456
std::vector< ActorId > GetGroupTrafficLights(rpc::ActorId traffic_light)
float GetWheelSteerAngle(Vehicle &vehicle, rpc::VehicleWheelLocation wheel_location)
Definition: Simulator.h:500
std::vector< std::string > GetNamesOfAllObjects() const
Definition: Simulator.cpp:408
void SetTrafficLightYellowTime(rpc::ActorId traffic_light, float yellow_time)
std::vector< uint8_t > GetCacheFile(const std::string &name, const bool request_otherwise) const
Definition: Simulator.cpp:196
void OpenVehicleDoor(rpc::ActorId vehicle, const rpc::VehicleDoor door_idx)
void EnableActorConstantVelocity(rpc::ActorId actor, const geom::Vector3D &vector)
void SetTrafficLightGreenTime(TrafficLight &trafficLight, float greenTime)
Definition: Simulator.h:593
static SharedPtr< Actor > MakeActor(EpisodeProxy episode, rpc::Actor actor_description, GarbageCollectionPolicy garbage_collection_policy)
Create an Actor based on the provided actor_description.
std::vector< std::string > GetRequiredFiles(const std::string &folder="", const bool download=true) const
Definition: Simulator.cpp:188
void SetWeatherParameters(const rpc::WeatherParameters &weather)
Definition: Simulator.h:244
void SetLightsToVehicle(Vehicle &vehicle, const rpc::VehicleControl &control)
Definition: Simulator.h:452
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
SharedPtr< LightManager > _light_manager
Definition: Simulator.h:707
void FreezeTrafficLight(TrafficLight &trafficLight, bool freeze)
Definition: Simulator.h:605
std::vector< std::pair< ActorId, VehicleLightState::flag_type > > VehicleLightStateList
rpc::WalkerBoneControlOut GetBonesTransform(Walker &walker)
Definition: Simulator.h:464
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
const GarbageCollectionPolicy _gc_policy
Definition: Simulator.h:711
size_t RegisterOnTickEvent(std::function< void(WorldSnapshot)> callback)
Definition: Simulator.h:180
rpc::EpisodeSettings GetEpisodeSettings()
SharedPtr< Actor > GetSpectator()
Definition: Simulator.cpp:236
void DrawDebugShape(const rpc::DebugShape &shape)
boost::optional< geom::Location > GetRandomLocationFromNavigation()
Definition: Simulator.cpp:297
Simulator(const std::string &host, uint16_t port, size_t worker_threads=0u, bool enable_garbage_collection=false)
Definition: Simulator.cpp:71
std::string ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance)
std::vector< ActorId > GetGroupTrafficLights(TrafficLight &trafficLight)
Definition: Simulator.h:621
void AddActorAngularImpulse(rpc::ActorId actor, const geom::Vector3D &vector)
void FreezeTrafficLight(rpc::ActorId traffic_light, bool freeze)
void SetReplayerIgnoreHero(bool ignore_hero)
void ResetTrafficLightGroup(rpc::ActorId traffic_light)
void SetActorTargetAngularVelocity(const Actor &actor, const geom::Vector3D &vector)
Definition: Simulator.h:383
std::vector< rpc::EnvironmentObject > GetEnvironmentObjects(uint8_t queried_tag) const
Definition: Simulator.h:261
bool IsTrafficManagerRunning(uint16_t port) const
Querry to know if a Traffic Manager is running on port.
void AddActorAngularImpulse(const Actor &actor, const geom::Vector3D &vector)
Definition: Simulator.h:410
void RemoveOnTickEvent(size_t id)
Definition: Simulator.h:185
void ApplyControlToVehicle(rpc::ActorId vehicle, const rpc::VehicleControl &control)
void UnSubscribeFromSensor(const Sensor &sensor)
Definition: Simulator.cpp:382
void LoadLevelLayer(rpc::MapLayer map_layer) const
SharedPtr< Map > _cached_map
Definition: Simulator.h:713
void ApplyBatch(std::vector< rpc::Command > commands, bool do_tick_cue)
Definition: Simulator.h:641
void GetPoseFromAnimation(Walker &walker)
Definition: Simulator.h:476
void UseCarSimRoad(Vehicle &vehicle, bool enabled)
Definition: Simulator.h:508
void StopReplayer(bool keep_actors)
Definition: Simulator.h:567
void SetActorLocation(Actor &actor, const geom::Location &location)
Definition: Simulator.h:422
std::string ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance)
Definition: Simulator.h:550
uint64_t SetEpisodeSettings(const rpc::EpisodeSettings &settings)
Definition: Simulator.cpp:240
void DrawDebugShape(const rpc::DebugShape &shape)
Definition: Simulator.h:631
#define DEBUG_ASSERT(predicate)
Definition: Debug.h:66
rpc::EpisodeSettings GetEpisodeSettings()
Definition: Simulator.h:234
std::vector< rpc::LabelledPoint > CastRay(geom::Location start_location, geom::Location end_location) const
void RemoveLightUpdateChangeEvent(size_t id)
Definition: Simulator.h:674
void SetReplayerTimeFactor(double time_factor)
std::pair< bool, rpc::LabelledPoint > ProjectPoint(geom::Location location, geom::Vector3D direction, float search_distance) const
Definition: Simulator.h:271
void SetActorAutopilot(rpc::ActorId vehicle, bool enabled)
rpc::VehiclePhysicsControl GetVehiclePhysicsControl(rpc::ActorId vehicle) const
SharedPtr< Actor > SpawnActor(const ActorBlueprint &blueprint, const geom::Transform &transform, Actor *parent=nullptr, rpc::AttachmentType attachment_type=rpc::AttachmentType::Rigid, GarbageCollectionPolicy gc=GarbageCollectionPolicy::Inherit)
Spawns an actor into the simulation.
Definition: Simulator.cpp:322
std::string StartRecorder(std::string name, bool additional_data)
Connects and controls a CARLA Simulator.
Definition: Simulator.h:47
rpc::WeatherParameters GetWeatherParameters()
void BlendPose(Walker &walker, float blend)
Definition: Simulator.h:472
void SetTrafficLightRedTime(TrafficLight &trafficLight, float redTime)
Definition: Simulator.h:601
rpc::ActorState GetActorState(const Actor &actor) const
Definition: Simulator.h:359
void EnableCarSim(Vehicle &vehicle, std::string simfile_path)
Definition: Simulator.h:504
void FreezeAllTrafficLights(bool frozen)
Definition: Simulator.cpp:386
void EnableEnvironmentObjects(std::vector< uint64_t > env_objects_ids, bool enable) const
Definition: Simulator.h:265
void BlendPose(rpc::ActorId walker, float blend)
std::pair< std::string, uint16_t > GetTrafficManagerRunning(uint16_t port) const
Gets a pair filled with the <IP, port> of the Trafic Manager running on port.
void AddActorForce(const Actor &actor, const geom::Vector3D &force)
Definition: Simulator.h:402
EpisodeProxy LoadEpisode(std::string map_name, bool reset_settings=true, rpc::MapLayer map_layers=rpc::MapLayer::All)
Definition: Simulator.cpp:86
void ApplyColorTextureToObjects(const std::vector< std::string > &objects_name, const rpc::MaterialParameter &parameter, const rpc::TextureColor &Texture)
– Texture updating operations
Definition: Simulator.cpp:394
void EnableChronoPhysics(rpc::ActorId vehicle, uint64_t MaxSubsteps, float MaxSubstepDeltaTime, std::string VehicleJSON, std::string PowertrainJSON, std::string TireJSON, std::string BaseJSONPath)
#define RELEASE_ASSERT(pred)
Definition: Debug.h:84
void ApplyBatch(std::vector< rpc::Command > commands, bool do_tick_cue)
std::vector< geom::BoundingBox > GetLevelBBs(uint8_t queried_tag) const
Returns all the BBs of all the elements of the level.
void OpenVehicleDoor(Vehicle &vehicle, const rpc::VehicleDoor door_idx)
Definition: Simulator.h:488
float GetWheelSteerAngle(rpc::ActorId vehicle, rpc::VehicleWheelLocation wheel_location)
void DestroyTrafficManager(uint16_t port) const
carla::ActorId ActorId
EpisodeProxy ReloadEpisode(bool reset_settings=true)
Definition: Simulator.h:70
std::string ShowRecorderFileInfo(std::string name, bool show_all)
Definition: Simulator.h:542
void AddActorImpulse(rpc::ActorId actor, const geom::Vector3D &impulse)
std::string ShowRecorderCollisions(std::string name, char type1, char type2)
Definition: Simulator.h:546
void SubscribeToSensor(const Sensor &sensor, std::function< void(SharedPtr< sensor::SensorData >)> callback)
Definition: Simulator.cpp:369
void AddActorTorque(const Actor &actor, const geom::Vector3D &torque)
Definition: Simulator.h:414
void DestroyTrafficManager(uint16_t port) const
Definition: Simulator.h:218
std::vector< rpc::CommandResponse > ApplyBatchSync(std::vector< rpc::Command > commands, bool do_tick_cue)
rpc::VehicleLightState GetVehicleLightState(const Vehicle &vehicle) const
Definition: Simulator.h:252
void SetTrafficLightRedTime(rpc::ActorId traffic_light, float red_time)
rpc::VehicleLightState GetVehicleLightState(rpc::ActorId vehicle) const
geom::Vector3D GetActorAngularVelocity(const Actor &actor) const
Definition: Simulator.h:379
SharedPtr< Actor > MakeActor(rpc::Actor actor_description, GarbageCollectionPolicy gc=GarbageCollectionPolicy::Disabled)
Creates an actor instance out of a description of an existing actor.
Definition: Simulator.h:328
void UpdateServerLightsState(std::vector< rpc::LightState > &lights, bool discard_client=false) const
void SetTimeout(time_duration timeout)
void SetActorTargetAngularVelocity(rpc::ActorId actor, const geom::Vector3D &vector)
GarbageCollectionPolicy GetGarbageCollectionPolicy() const
Definition: Simulator.h:146
void SetActorEnableGravity(Actor &actor, bool enabled)
Definition: Simulator.h:434
Provides communication with the rpc and streaming servers of a CARLA simulator.
WorldSnapshot GetWorldSnapshot() const
Definition: Simulator.h:109
void SetNetworkingTimeout(time_duration timeout)
Definition: Simulator.h:156
std::string ReplayFile(std::string name, double start, double duration, uint32_t follow_id, bool replay_sensors)
Definition: Simulator.h:554
size_t RegisterLightUpdateChangeEvent(std::function< void(WorldSnapshot)> callback)
Definition: Simulator.h:669
void CloseVehicleDoor(Vehicle &vehicle, const rpc::VehicleDoor door_idx)
Definition: Simulator.h:492
void UnloadLevelLayer(rpc::MapLayer map_layer) const
void UnregisterAIController(const WalkerAIController &controller)
Definition: Simulator.cpp:285
void SetActorSimulatePhysics(rpc::ActorId actor, bool enabled)
std::vector< rpc::LightState > QueryLightsStateToServer() const
std::shared_ptr< WalkerNavigation > GetNavigation()
Definition: Simulator.h:293
void UseCarSimRoad(rpc::ActorId vehicle, bool enabled)
uint64_t Tick(time_duration timeout)
Definition: Simulator.cpp:213
SharedPtr< Map > GetCurrentMap()
Definition: Simulator.cpp:153
void SetWeatherParameters(const rpc::WeatherParameters &weather)
void ApplyControlToWalker(Walker &walker, const rpc::WalkerControl &control)
Definition: Simulator.h:460
EpisodeProxy LoadOpenDriveEpisode(std::string opendrive, const rpc::OpendriveGenerationParameters &params, bool reset_settings=true)
Definition: Simulator.cpp:114
Represents an actor in the simulation.
Definition: client/Actor.h:18
rpc::WalkerBoneControlOut GetBonesTransform(rpc::ActorId walker)
geom::Vector3D angular_velocity
Definition: ActorSnapshot.h:23
void SetReplayerIgnoreHero(bool ignore_hero)
Definition: Simulator.h:563
void SetLightStateToVehicle(Vehicle &vehicle, const rpc::VehicleLightState light_state)
Definition: Simulator.h:484
void RequestFile(const std::string &name) const
Definition: Simulator.cpp:192
std::pair< std::string, uint16_t > GetTrafficManagerRunning(uint16_t port) const
Gets a pair filled with the <IP, port> of the Trafic Manager running on port.
Definition: Simulator.h:209
Positive time duration up to milliseconds resolution.
Definition: Time.h:19
geom::Location GetActorLocation(const Actor &actor) const
Definition: Simulator.h:363
std::vector< geom::BoundingBox > GetLightBoxes(rpc::ActorId traffic_light) const
void SetTrafficLightYellowTime(TrafficLight &trafficLight, float yellowTime)
Definition: Simulator.h:597
void SetTrafficLightGreenTime(rpc::ActorId traffic_light, float green_time)
void SetActorTransform(Actor &actor, const geom::Transform &transform)
Definition: Simulator.h:426
void SetBonesTransform(Walker &walker, const rpc::WalkerBoneControlIn &bones)
Definition: Simulator.h:468
void SetWheelSteerDirection(Vehicle &vehicle, rpc::VehicleWheelLocation wheel_location, float angle_in_deg)
Definition: Simulator.h:496
std::string ShowRecorderCollisions(std::string name, char type1, char type2)
std::vector< rpc::EnvironmentObject > GetEnvironmentObjects(uint8_t queried_tag) const
std::vector< rpc::Actor > GetAllTheActorsInTheEpisode() const
Definition: Simulator.h:317
void UnloadLevelLayer(rpc::MapLayer map_layers) const
Definition: Simulator.h:80
Contains all the necessary information for spawning an Actor.
void RegisterAIController(const WalkerAIController &controller)
Definition: Simulator.cpp:273
geom::Vector3D GetActorAcceleration(const Actor &actor) const
Definition: Simulator.h:418
void SetActorEnableGravity(rpc::ActorId actor, bool enabled)
void AddActorImpulse(const Actor &actor, const geom::Vector3D &impulse, const geom::Vector3D &location)
Definition: Simulator.h:398
void SetPedestriansCrossFactor(float percentage)
Definition: Simulator.cpp:304
SharedPtr< BlueprintLibrary > GetBlueprintLibrary()
Definition: Simulator.cpp:227
std::pair< bool, rpc::LabelledPoint > ProjectPoint(geom::Location location, geom::Vector3D direction, float search_distance) const
void AddActorForce(rpc::ActorId actor, const geom::Vector3D &force)
ActorSnapshot GetActorSnapshot(const Actor &actor) const
Definition: Simulator.h:355
geom::Vector3D GetActorVelocity(const Actor &actor) const
Definition: Simulator.h:371
void SetWheelSteerDirection(rpc::ActorId vehicle, rpc::VehicleWheelLocation vehicle_wheel, float angle_in_deg)
auto ApplyBatchSync(std::vector< rpc::Command > commands, bool do_tick_cue)
Definition: Simulator.h:645
Inherit (privately) to suppress copy/move construction and assignment.
void AddActorForce(const Actor &actor, const geom::Vector3D &force, const geom::Vector3D &location)
Definition: Simulator.h:406
Defines the physical appearance of a vehicle whitch is obtained by the sensors.
void ApplyControlToWalker(rpc::ActorId walker, const rpc::WalkerControl &control)
bool ShouldUpdateMap(rpc::MapInfo &map_info)
Definition: Simulator.cpp:142
std::string StartRecorder(std::string name, bool additional_data)
Definition: Simulator.h:534
const std::string GetEndpoint() const
void ApplyPhysicsControlToVehicle(Vehicle &vehicle, const rpc::VehiclePhysicsControl &physicsControl)
Definition: Simulator.h:480
void EnableEnvironmentObjects(std::vector< uint64_t > env_objects_ids, bool enable) const
void SetActorTargetVelocity(const Actor &actor, const geom::Vector3D &vector)
Definition: Simulator.h:375
rpc::WeatherParameters GetWeatherParameters()
Definition: Simulator.h:240
void LoadLevelLayer(rpc::MapLayer map_layers) const
Definition: Simulator.h:76
void SetPedestriansSeed(unsigned int seed)
Definition: Simulator.cpp:311
void ResetTrafficLightGroup(TrafficLight &trafficLight)
Definition: Simulator.h:609
WorldSnapshot WaitForTick(time_duration timeout)
Definition: Simulator.cpp:204
bool IsTrafficManagerRunning(uint16_t port) const
Query to know if a Traffic Manager is running on port.
Definition: Simulator.h:203
void SetReplayerTimeFactor(double time_factor)
Definition: Simulator.h:559
void DisableActorConstantVelocity(rpc::ActorId actor)
std::vector< std::string > GetAvailableMaps()
std::vector< geom::BoundingBox > GetLevelBBs(uint8_t queried_tag) const
Returns all the BBs of all the elements of the level.
Definition: Simulator.h:257
geom::Transform GetActorTransform(const Actor &actor) const
Definition: Simulator.h:367