CARLA
client/Client.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 
10 #include "carla/client/World.h"
11 #include "carla/PythonUtil.h"
13 
14 namespace carla {
15 namespace client {
16 
17  using namespace carla::traffic_manager;
18 
19  class Client {
20  public:
21 
22  /// Construct a carla client.
23  ///
24  /// @param host IP address of the host machine running the simulator.
25  /// @param port TCP port to connect with the simulator.
26  /// @param worker_threads number of asynchronous threads to use, or 0 to use
27  /// all available hardware concurrency.
28  explicit Client(
29  const std::string &host,
30  uint16_t port,
31  size_t worker_threads = 0u);
32 
33  /// Set a timeout for networking operations. If set, any networking
34  /// operation taking longer than @a timeout throws rpc::timeout.
35  void SetTimeout(time_duration timeout) {
36  _simulator->SetNetworkingTimeout(timeout);
37  }
38 
40  return _simulator->GetNetworkingTimeout();
41  }
42 
43  /// Return the version string of this client API.
44  std::string GetClientVersion() const {
45  return _simulator->GetClientVersion();
46  }
47 
48  /// Return the version string of the simulator we are connected to.
49  std::string GetServerVersion() const {
50  return _simulator->GetServerVersion();
51  }
52 
53  std::vector<std::string> GetAvailableMaps() const {
54  return _simulator->GetAvailableMaps();
55  }
56 
57  World ReloadWorld(bool reset_settings = true) const {
58  return World{_simulator->ReloadEpisode(reset_settings)};
59  }
60 
62  std::string map_name,
63  bool reset_settings = true,
64  rpc::MapLayer map_layers = rpc::MapLayer::All) const {
65  return World{_simulator->LoadEpisode(std::move(map_name), reset_settings, map_layers)};
66  }
67 
69  std::string opendrive,
71  bool reset_settings = true) const {
72  return World{_simulator->LoadOpenDriveEpisode(
73  std::move(opendrive), params, reset_settings)};
74  }
75 
76  /// Return an instance of the world currently active in the simulator.
77  World GetWorld() const {
78  return World{_simulator->GetCurrentEpisode()};
79  }
80 
81  /// Return an instance of the TrafficManager currently active in the simulator.
82  TrafficManager GetInstanceTM(uint16_t port = TM_DEFAULT_PORT) const {
83  return TrafficManager(_simulator->GetCurrentEpisode(), port);
84  }
85 
86  /// Return an instance of the Episode currently active in the simulator.
88  return _simulator->GetCurrentEpisode();
89  }
90 
91  std::string StartRecorder(std::string name, bool additional_data = false) {
92  return _simulator->StartRecorder(name, additional_data);
93  }
94 
95  void StopRecorder(void) {
96  _simulator->StopRecorder();
97  }
98 
99  std::string ShowRecorderFileInfo(std::string name, bool show_all) {
100  return _simulator->ShowRecorderFileInfo(name, show_all);
101  }
102 
103  std::string ShowRecorderCollisions(std::string name, char type1, char type2) {
104  return _simulator->ShowRecorderCollisions(name, type1, type2);
105  }
106 
107  std::string ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance) {
108  return _simulator->ShowRecorderActorsBlocked(name, min_time, min_distance);
109  }
110 
111  std::string ReplayFile(std::string name, double start, double duration, uint32_t follow_id) {
112  return _simulator->ReplayFile(name, start, duration, follow_id);
113  }
114 
115  void StopReplayer(bool keep_actors) {
116  _simulator->StopReplayer(keep_actors);
117  }
118 
119  void SetReplayerTimeFactor(double time_factor) {
120  _simulator->SetReplayerTimeFactor(time_factor);
121  }
122 
123  void SetReplayerIgnoreHero(bool ignore_hero) {
124  _simulator->SetReplayerIgnoreHero(ignore_hero);
125  }
126 
128  std::vector<rpc::Command> commands,
129  bool do_tick_cue = false) const {
130  _simulator->ApplyBatch(std::move(commands), do_tick_cue);
131  }
132 
133  std::vector<rpc::CommandResponse> ApplyBatchSync(
134  std::vector<rpc::Command> commands,
135  bool do_tick_cue = false) const {
136  return _simulator->ApplyBatchSync(std::move(commands), do_tick_cue);
137  }
138 
139  private:
140 
141  std::shared_ptr<detail::Simulator> _simulator;
142 
143  };
144 
146  const std::string &host,
147  uint16_t port,
148  size_t worker_threads)
149  : _simulator(
150  new detail::Simulator(host, port, worker_threads),
151  PythonUtil::ReleaseGILDeleter()) {}
152 
153 } // namespace client
154 } // namespace carla
World ReloadWorld(bool reset_settings=true) const
Definition: client/Client.h:57
Seting for map generation from opendrive without additional geometry.
std::vector< rpc::CommandResponse > ApplyBatchSync(std::vector< rpc::Command > commands, bool do_tick_cue=false) const
void SetReplayerIgnoreHero(bool ignore_hero)
void SetReplayerTimeFactor(double time_factor)
static const unsigned short TM_DEFAULT_PORT
Definition: Constants.h:20
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
std::vector< std::string > GetAvailableMaps() const
Definition: client/Client.h:53
World GetWorld() const
Return an instance of the world currently active in the simulator.
Definition: client/Client.h:77
std::string ShowRecorderCollisions(std::string name, char type1, char type2)
std::string GetClientVersion() const
Return the version string of this client API.
Definition: client/Client.h:44
std::string StartRecorder(std::string name, bool additional_data=false)
Definition: client/Client.h:91
std::shared_ptr< detail::Simulator > _simulator
std::string ReplayFile(std::string name, double start, double duration, uint32_t follow_id)
This class integrates all the various stages of the traffic manager appropriately using messengers...
Client(const std::string &host, uint16_t port, size_t worker_threads=0u)
Construct a carla client.
World GenerateOpenDriveWorld(std::string opendrive, const rpc::OpendriveGenerationParameters &params, bool reset_settings=true) const
Definition: client/Client.h:68
std::string ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance)
World LoadWorld(std::string map_name, bool reset_settings=true, rpc::MapLayer map_layers=rpc::MapLayer::All) const
Definition: client/Client.h:61
carla::client::detail::EpisodeProxy GetCurrentEpisode() const
Return an instance of the Episode currently active in the simulator.
Definition: client/Client.h:87
TrafficManager GetInstanceTM(uint16_t port=TM_DEFAULT_PORT) const
Return an instance of the TrafficManager currently active in the simulator.
Definition: client/Client.h:82
Positive time duration up to milliseconds resolution.
Definition: Time.h:19
std::string GetServerVersion() const
Return the version string of the simulator we are connected to.
Definition: client/Client.h:49
std::string ShowRecorderFileInfo(std::string name, bool show_all)
Definition: client/Client.h:99
void SetTimeout(time_duration timeout)
Set a timeout for networking operations.
Definition: client/Client.h:35
void StopReplayer(bool keep_actors)
void ApplyBatch(std::vector< rpc::Command > commands, bool do_tick_cue=false) const
time_duration GetTimeout()
Definition: client/Client.h:39