10 #include "carla/Version.h" 27 #include <rpc/rpc_error.h> 37 return response.
Get();
51 Pimpl(
const std::string &host, uint16_t port,
size_t worker_threads)
57 worker_threads > 0u ? worker_threads : std::thread::hardware_concurrency());
60 template <
typename ... Args>
61 auto RawCall(
const std::string &
function, Args && ... args) {
64 }
catch (const ::rpc::timeout &) {
69 template <
typename T,
typename ... Args>
70 auto CallAndWait(
const std::string &
function, Args && ... args) {
71 auto object =
RawCall(
function, std::forward<Args>(args) ...);
73 auto response =
object.template as<R>();
74 if (response.HasError()) {
80 template <
typename ... Args>
81 void AsyncCall(
const std::string &
function, Args && ... args) {
104 const std::string &host,
106 const size_t worker_threads)
110 return _pimpl->CallAndWait<
bool>(
"is_traffic_manager_running", port);
114 return _pimpl->CallAndWait<std::pair<std::string, uint16_t>>(
"get_traffic_manager_running", port);
118 return _pimpl->CallAndWait<
bool>(
"add_traffic_manager_running", trafficManagerInfo);
122 _pimpl->AsyncCall(
"destroy_traffic_manager", port);
132 return _pimpl->GetTimeout();
140 return ::carla::version();
144 return _pimpl->CallAndWait<std::string>(
"version");
149 _pimpl->CallAndWait<
void>(
"load_new_episode", std::move(map_name), reset_settings, map_layer);
154 _pimpl->CallAndWait<
void>(
"load_map_layer", map_layer);
159 _pimpl->CallAndWait<
void>(
"unload_map_layer", map_layer);
164 _pimpl->CallAndWait<
void>(
"copy_opendrive_to_file", std::move(opendrive), params);
168 const std::vector<std::string> &objects_name,
171 _pimpl->CallAndWait<
void>(
"apply_color_texture_to_objects", objects_name, parameter, Texture);
175 const std::vector<std::string> &objects_name,
178 _pimpl->CallAndWait<
void>(
"apply_float_color_texture_to_objects", objects_name, parameter, Texture);
182 return _pimpl->CallAndWait<std::vector<std::string>>(
"get_names_of_all_objects");
194 return _pimpl->CallAndWait<std::string>(
"get_map_data");
198 return _pimpl->CallAndWait<std::vector<uint8_t>>(
"get_navigation_mesh");
207 auto requiredFiles =
_pimpl->CallAndWait<std::vector<std::string>>(
"get_required_files", folder);
212 for (
auto requiredFile : requiredFiles) {
215 log_info(
"Could not find the required file in cache, downloading... ", requiredFile);
217 log_info(
"Found the required file in cache! ", requiredFile);
221 return requiredFiles;
226 auto content =
_pimpl->CallAndWait<std::vector<uint8_t>>(
"request_file", name);
235 if (file.empty() && request_otherwise) {
243 return _pimpl->CallAndWait<std::vector<std::string>>(
"get_available_maps");
247 return _pimpl->CallAndWait<std::vector<rpc::ActorDefinition>>(
"get_actor_definitions");
259 return _pimpl->CallAndWait<uint64_t>(
"set_episode_settings", settings);
267 _pimpl->AsyncCall(
"set_weather_parameters", weather);
271 const std::vector<ActorId> &ids) {
272 using return_t = std::vector<rpc::Actor>;
273 return _pimpl->CallAndWait<return_t>(
"get_actors_by_id", ids);
289 return _pimpl->AsyncCall(
"apply_physics_control", vehicle, physics_control);
295 return _pimpl->AsyncCall(
"set_vehicle_light_state", vehicle, light_state);
301 return _pimpl->AsyncCall(
"open_vehicle_door", vehicle, door_idx);
307 return _pimpl->AsyncCall(
"close_vehicle_door", vehicle, door_idx);
313 float angle_in_deg) {
314 return _pimpl->AsyncCall(
"set_wheel_steer_direction", vehicle, vehicle_wheel, angle_in_deg);
320 return _pimpl->CallAndWait<
float>(
"get_wheel_steer_angle", vehicle, wheel_location);
326 return _pimpl->CallAndWait<
rpc::Actor>(
"spawn_actor", description, transform);
340 constexpr
float OneEps = 1.0f - std::numeric_limits<float>::epsilon();
342 std::cout <<
"WARNING: Transformations with translation only in the 'z' axis are ill-formed when \ 343 using SpringArm or SpringArmGhost attachment. Please, be careful with that." << std::endl;
356 return _pimpl->CallAndWait<
bool>(
"destroy_actor", actor);
357 }
catch (
const std::exception &e) {
358 log_error(
"failed to destroy actor", actor,
':', e.what());
364 _pimpl->AsyncCall(
"set_actor_location", actor, location);
368 _pimpl->AsyncCall(
"set_actor_transform", actor, transform);
372 _pimpl->AsyncCall(
"set_actor_target_velocity", actor, vector);
376 _pimpl->AsyncCall(
"set_actor_target_angular_velocity", actor, vector);
380 _pimpl->AsyncCall(
"enable_actor_constant_velocity", actor, vector);
384 _pimpl->AsyncCall(
"disable_actor_constant_velocity", actor);
388 _pimpl->AsyncCall(
"add_actor_impulse", actor, impulse);
392 _pimpl->AsyncCall(
"add_actor_impulse_at_location", actor, impulse, location);
396 _pimpl->AsyncCall(
"add_actor_force", actor, force);
400 _pimpl->AsyncCall(
"add_actor_force_at_location", actor, force, location);
404 _pimpl->AsyncCall(
"add_actor_angular_impulse", actor, vector);
408 _pimpl->AsyncCall(
"add_actor_torque", actor, vector);
412 _pimpl->CallAndWait<
void>(
"set_actor_simulate_physics", actor, enabled);
416 _pimpl->CallAndWait<
void>(
"set_actor_collisions", actor, enabled);
420 _pimpl->AsyncCall(
"set_actor_dead", actor);
424 _pimpl->AsyncCall(
"set_actor_enable_gravity", actor, enabled);
428 _pimpl->AsyncCall(
"set_actor_autopilot", vehicle, enabled);
432 _pimpl->AsyncCall(
"show_vehicle_debug_telemetry", vehicle, enabled);
436 _pimpl->AsyncCall(
"apply_control_to_vehicle", vehicle, control);
440 _pimpl->AsyncCall(
"apply_ackermann_control_to_vehicle", vehicle, control);
449 _pimpl->AsyncCall(
"apply_ackermann_controller_settings", vehicle, settings);
453 _pimpl->AsyncCall(
"enable_carsim", vehicle, simfile_path);
457 _pimpl->AsyncCall(
"use_carsim_road", vehicle, enabled);
462 uint64_t MaxSubsteps,
463 float MaxSubstepDeltaTime,
464 std::string VehicleJSON,
465 std::string PowertrainJSON,
466 std::string TireJSON,
467 std::string BaseJSONPath) {
468 _pimpl->AsyncCall(
"enable_chrono_physics",
479 _pimpl->AsyncCall(
"apply_control_to_walker", walker, control);
488 _pimpl->AsyncCall(
"set_bones_transform", walker, bones);
492 _pimpl->AsyncCall(
"blend_pose", walker, blend);
496 _pimpl->AsyncCall(
"get_pose_from_animation", walker);
502 _pimpl->AsyncCall(
"set_traffic_light_state", traffic_light, traffic_light_state);
506 _pimpl->AsyncCall(
"set_traffic_light_green_time", traffic_light, green_time);
510 _pimpl->AsyncCall(
"set_traffic_light_yellow_time", traffic_light, yellow_time);
514 _pimpl->AsyncCall(
"set_traffic_light_red_time", traffic_light, red_time);
518 _pimpl->AsyncCall(
"freeze_traffic_light", traffic_light, freeze);
522 _pimpl->AsyncCall(
"reset_traffic_light_group", traffic_light);
526 _pimpl->CallAndWait<
void>(
"reset_all_traffic_lights");
530 _pimpl->AsyncCall(
"freeze_all_traffic_lights", frozen);
534 using return_t = std::vector<geom::BoundingBox>;
535 return _pimpl->CallAndWait<return_t>(
"get_light_boxes", traffic_light);
539 return _pimpl->CallAndWait<std::vector<std::pair<carla::ActorId, uint32_t>>>(
"get_vehicle_light_states");
543 using return_t = std::vector<ActorId>;
544 return _pimpl->CallAndWait<return_t>(
"get_group_traffic_lights", traffic_light);
548 return _pimpl->CallAndWait<std::string>(
"start_recorder", name, additional_data);
552 return _pimpl->AsyncCall(
"stop_recorder");
556 return _pimpl->CallAndWait<std::string>(
"show_recorder_file_info", name, show_all);
560 return _pimpl->CallAndWait<std::string>(
"show_recorder_collisions", name, type1, type2);
564 return _pimpl->CallAndWait<std::string>(
"show_recorder_actors_blocked", name, min_time, min_distance);
568 uint32_t follow_id,
bool replay_sensors) {
569 return _pimpl->CallAndWait<std::string>(
"replay_file", name, start, duration,
570 follow_id, replay_sensors);
574 _pimpl->AsyncCall(
"stop_replayer", keep_actors);
578 _pimpl->AsyncCall(
"set_replayer_time_factor", time_factor);
582 _pimpl->AsyncCall(
"set_replayer_ignore_hero", ignore_hero);
586 _pimpl->AsyncCall(
"set_replayer_ignore_spectator", ignore_spectator);
591 std::function<
void(
Buffer)> callback) {
594 _pimpl->streaming_client.Subscribe(receivedToken, std::move(callback));
598 _pimpl->streaming_client.UnSubscribe(token);
619 std::function<
void(
Buffer)> callback)
621 std::vector<unsigned char> token_data =
_pimpl->CallAndWait<std::vector<unsigned char>>(
"get_gbuffer_token",
ActorId, GBufferId);
623 std::memcpy(&token.data[0u], token_data.data(), token_data.size());
624 _pimpl->streaming_client.Subscribe(token, std::move(callback));
631 std::vector<unsigned char> token_data =
_pimpl->CallAndWait<std::vector<unsigned char>>(
"get_gbuffer_token",
ActorId, GBufferId);
633 std::memcpy(&token.data[0u], token_data.data(), token_data.size());
634 _pimpl->streaming_client.UnSubscribe(token);
638 _pimpl->AsyncCall(
"draw_debug_shape", shape);
642 _pimpl->AsyncCall(
"apply_batch", std::move(commands), do_tick_cue);
646 std::vector<rpc::Command> commands,
648 auto result =
_pimpl->RawCall(
"apply_batch", std::move(commands), do_tick_cue);
649 return result.as<std::vector<rpc::CommandResponse>>();
653 return _pimpl->CallAndWait<uint64_t>(
"tick_cue");
657 using return_t = std::vector<rpc::LightState>;
658 return _pimpl->CallAndWait<return_t>(
"query_lights_state",
_pimpl->endpoint);
662 _pimpl->AsyncCall(
"update_lights_state",
_pimpl->endpoint, std::move(lights), discard_client);
666 _pimpl->AsyncCall(
"update_day_night_cycle",
_pimpl->endpoint, active);
670 using return_t = std::vector<geom::BoundingBox>;
671 return _pimpl->CallAndWait<return_t>(
"get_all_level_BBs", queried_tag);
675 using return_t = std::vector<rpc::EnvironmentObject>;
676 return _pimpl->CallAndWait<return_t>(
"get_environment_objects", queried_tag);
680 std::vector<uint64_t> env_objects_ids,
682 _pimpl->AsyncCall(
"enable_environment_objects", std::move(env_objects_ids), enable);
687 using return_t = std::pair<bool,rpc::LabelledPoint>;
688 return _pimpl->CallAndWait<return_t>(
"project_point", location, direction, search_distance);
693 using return_t = std::vector<rpc::LabelledPoint>;
694 return _pimpl->CallAndWait<return_t>(
"cast_ray", start_location, end_location);
void ApplyAckermannControllerSettings(rpc::ActorId vehicle, const rpc::AckermannControllerSettings &settings)
Seting for map generation from opendrive without additional geometry.
time_duration GetTimeout() const
static time_duration milliseconds(size_t timeout)
void SetLightStateToVehicle(rpc::ActorId vehicle, const rpc::VehicleLightState &light_state)
bool SetFilesBaseFolder(const std::string &path)
void AddActorTorque(rpc::ActorId actor, const geom::Vector3D &vector)
void SubscribeToGBuffer(rpc::ActorId ActorId, uint32_t GBufferId, std::function< void(Buffer)> callback)
void ApplyAckermannControlToVehicle(rpc::ActorId vehicle, const rpc::VehicleAckermannControl &control)
std::vector< uint8_t > GetNavigationMesh() const
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 set_timeout(int64_t value)
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)
std::vector< rpc::ActorDefinition > GetActorDefinitions()
std::string GetClientVersion()
void ShowVehicleDebugTelemetry(rpc::ActorId vehicle, bool enabled)
bool IsEnabledForROS(const streaming::Token &token)
time_duration GetTimeout() const
rpc::MapInfo GetMapInfo()
void CloseVehicleDoor(rpc::ActorId vehicle, const rpc::VehicleDoor door_idx)
void SetTrafficLightState(rpc::ActorId traffic_light, const rpc::TrafficLightState trafficLightState)
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)
void throw_exception(const std::exception &e)
void FreezeAllTrafficLights(bool frozen)
std::vector< std::string > GetNamesOfAllObjects() const
void SetActorCollisions(rpc::ActorId actor, bool enabled)
std::vector< ActorId > GetGroupTrafficLights(rpc::ActorId traffic_light)
void CopyOpenDriveToServer(std::string opendrive, const rpc::OpendriveGenerationParameters ¶ms)
rpc::AckermannControllerSettings GetAckermannControllerSettings(rpc::ActorId vehicle) const
void SetTrafficLightYellowTime(rpc::ActorId traffic_light, float yellow_time)
std::vector< uint8_t > GetCacheFile(const std::string &name, const bool request_otherwise=true) const
void OpenVehicleDoor(rpc::ActorId vehicle, const rpc::VehicleDoor door_idx)
void EnableActorConstantVelocity(rpc::ActorId actor, const geom::Vector3D &vector)
void async_call(const std::string &function, Args &&... args)
static void log_error(Args &&... args)
std::vector< std::pair< ActorId, VehicleLightState::flag_type > > VehicleLightStateList
This file contains definitions of common data structures used in traffic manager. ...
rpc::EpisodeSettings GetEpisodeSettings()
std::vector< std::string > GetRequiredFiles(const std::string &folder="", const bool download=true) const
void DrawDebugShape(const rpc::DebugShape &shape)
void SetActorDead(rpc::ActorId actor)
rpc::EpisodeInfo GetEpisodeInfo()
auto call(const std::string &function, Args &&... args)
std::string ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance)
void SetReplayerIgnoreSpectator(bool ignore_spectator)
void RequestFile(const std::string &name) const
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
void AddActorAngularImpulse(rpc::ActorId actor, const geom::Vector3D &vector)
void FreezeTrafficLight(rpc::ActorId traffic_light, bool freeze)
void SubscribeToStream(const streaming::Token &token, std::function< void(Buffer)> callback)
rpc::VehicleLightStateList GetVehiclesLightStates()
Returns a list of pairs where the firts element is the vehicle ID and the second one is the light sta...
void SetReplayerIgnoreHero(bool ignore_hero)
void ResetTrafficLightGroup(rpc::ActorId traffic_light)
bool IsTrafficManagerRunning(uint16_t port) const
Querry to know if a Traffic Manager is running on port.
void AsyncCall(const std::string &function, Args &&... args)
void ApplyControlToVehicle(rpc::ActorId vehicle, const rpc::VehicleControl &control)
static T Get(carla::rpc::Response< T > &response)
void LoadLevelLayer(rpc::MapLayer map_layer) const
static std::vector< uint8_t > ReadFile(std::string path)
void DisableForROS(const streaming::Token &token)
const std::unique_ptr< Pimpl > _pimpl
static bool WriteFile(std::string path, std::vector< uint8_t > content)
#define DEBUG_ASSERT(predicate)
std::vector< rpc::LabelledPoint > CastRay(geom::Location start_location, geom::Location end_location) const
void SetReplayerTimeFactor(double time_factor)
void ApplyColorTextureToObjects(const std::vector< std::string > &objects_name, const rpc::MaterialParameter ¶meter, const rpc::TextureColor &Texture)
void EnableForROS(const streaming::Token &token)
void SetActorAutopilot(rpc::ActorId vehicle, bool enabled)
rpc::VehiclePhysicsControl GetVehiclePhysicsControl(rpc::ActorId vehicle) const
auto CallAndWait(const std::string &function, Args &&... args)
std::string StartRecorder(std::string name, bool additional_data)
rpc::WeatherParameters GetWeatherParameters()
void AsyncRun(size_t worker_threads)
Serializes a stream endpoint.
void BlendPose(rpc::ActorId walker, float blend)
void LoadEpisode(std::string map_name, bool reset_settings=true, rpc::MapLayer map_layer=rpc::MapLayer::All)
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.
streaming::Client streaming_client
std::string GetServerVersion()
void EnableChronoPhysics(rpc::ActorId vehicle, uint64_t MaxSubsteps, float MaxSubstepDeltaTime, std::string VehicleJSON, std::string PowertrainJSON, std::string TireJSON, std::string BaseJSONPath)
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.
float GetWheelSteerAngle(rpc::ActorId vehicle, rpc::VehicleWheelLocation wheel_location)
void DestroyTrafficManager(uint16_t port) const
void AddActorImpulse(rpc::ActorId actor, const geom::Vector3D &impulse)
A token that uniquely identify a stream.
rpc::Actor GetSpectator()
std::vector< rpc::Actor > GetActorsById(const std::vector< ActorId > &ids)
std::vector< rpc::CommandResponse > ApplyBatchSync(std::vector< rpc::Command > commands, bool do_tick_cue)
std::string GetMapData() const
void ResetAllTrafficLights()
void SetTrafficLightRedTime(rpc::ActorId traffic_light, float red_time)
rpc::VehicleLightState GetVehicleLightState(rpc::ActorId vehicle) const
constexpr size_t milliseconds() const noexcept
Pimpl(const std::string &host, uint16_t port, size_t worker_threads)
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)
auto RawCall(const std::string &function, Args &&... args)
static void log_info(Args &&... args)
rpc::Actor SpawnActorWithParent(const rpc::ActorDescription &description, const geom::Transform &transform, rpc::ActorId parent, rpc::AttachmentType attachment_type)
void UpdateDayNightCycle(const bool active) const
A client able to subscribe to multiple streams.
const auto & get_stream_id() const
void UnloadLevelLayer(rpc::MapLayer map_layer) const
void SetActorSimulatePhysics(rpc::ActorId actor, bool enabled)
std::vector< rpc::LightState > QueryLightsStateToServer() const
void UseCarSimRoad(rpc::ActorId vehicle, bool enabled)
rpc::Actor SpawnActor(const rpc::ActorDescription &description, const geom::Transform &transform)
bool DestroyActor(rpc::ActorId actor)
void SetWeatherParameters(const rpc::WeatherParameters &weather)
static auto Dot(const Vector3D &a, const Vector3D &b)
Client(const std::string &host, uint16_t port, size_t worker_threads=0u)
rpc::WalkerBoneControlOut GetBonesTransform(rpc::ActorId walker)
Positive time duration up to milliseconds resolution.
std::vector< geom::BoundingBox > GetLightBoxes(rpc::ActorId traffic_light) const
void SetTrafficLightGreenTime(rpc::ActorId traffic_light, float green_time)
void StopReplayer(bool keep_actors)
void UnSubscribeFromStream(const streaming::Token &token)
std::string ShowRecorderCollisions(std::string name, char type1, char type2)
std::vector< rpc::EnvironmentObject > GetEnvironmentObjects(uint8_t queried_tag) const
void SetActorEnableGravity(rpc::ActorId actor, bool enabled)
void UnSubscribeFromGBuffer(rpc::ActorId ActorId, uint32_t GBufferId)
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)
void SetWheelSteerDirection(rpc::ActorId vehicle, rpc::VehicleWheelLocation vehicle_wheel, float angle_in_deg)
Vector3D MakeSafeUnitVector(const float epsilon) const
Defines the physical appearance of a vehicle whitch is obtained by the sensors.
void ApplyControlToWalker(rpc::ActorId walker, const rpc::WalkerControl &control)
const std::string GetEndpoint() const
static bool FileExists(std::string file)
void EnableEnvironmentObjects(std::vector< uint64_t > env_objects_ids, bool enable) const
const std::string endpoint
static bool SetFilesBaseFolder(const std::string &path)
void DisableActorConstantVelocity(rpc::ActorId actor)
std::vector< std::string > GetAvailableMaps()
uint64_t SetEpisodeSettings(const rpc::EpisodeSettings &settings)