19 namespace traffic_manager {
22 using Path = std::vector<cg::Location>;
23 using Route = std::vector<uint8_t>;
25 using namespace constants::Networking;
49 server = new ::rpc::server(RPCPort);
51 }
catch(std::exception) {
54 std::this_thread::sleep_for(500ms);
58 if(server !=
nullptr) {
65 if(server ==
nullptr) {
68 "trying to create rpc server for traffic manager; " 69 "but the system failed to create because of bind error."));
73 server->bind(
"register_vehicle", [=](std :: vector <carla::rpc::Actor> _actor_list) {
74 std::vector<ActorPtr> actor_list;
75 for (
auto &&actor : _actor_list) {
83 server->bind(
"unregister_vehicle", [=](std :: vector <carla::rpc::Actor> _actor_list) {
84 std::vector<ActorPtr> actor_list;
85 for (
auto &&actor : _actor_list) {
93 server->bind(
"set_percentage_speed_difference", [=](
carla::rpc::Actor actor,
const float percentage) {
99 server->bind(
"set_lane_offset", [=](
carla::rpc::Actor actor,
const float offset) {
104 server->bind(
"set_desired_speed", [=](
carla::rpc::Actor actor,
const float value) {
109 server->bind(
"update_vehicle_lights", [=](
carla::rpc::Actor actor,
const bool do_update) {
115 server->bind(
"set_global_percentage_speed_difference", [=](
const float percentage) {
121 server->bind(
"set_global_lane_offset", [=](
const float offset) {
135 server->bind(
"set_force_lane_change", [=](
carla::rpc::Actor actor,
const bool direction) {
140 server->bind(
"set_auto_lane_change", [=](
carla::rpc::Actor actor,
const bool enable) {
146 server->bind(
"set_distance_to_leading_vehicle", [=](
carla::rpc::Actor actor,
const float distance) {
152 server->bind(
"set_global_distance_to_leading_vehicle", [=](
const float distance) {
157 server->bind(
"set_percentage_running_light", [=](
carla::rpc::Actor actor,
const float percentage) {
162 server->bind(
"set_percentage_running_sign", [=](
carla::rpc::Actor actor,
const float percentage) {
167 server->bind(
"set_percentage_ignore_walkers", [=](
carla::rpc::Actor actor,
const float percentage) {
172 server->bind(
"set_percentage_ignore_vehicles", [=](
carla::rpc::Actor actor,
const float percentage) {
177 server->bind(
"set_percentage_keep_right_rule", [=](
carla::rpc::Actor actor,
const float percentage) {
182 server->bind(
"set_percentage_random_left_lanechange", [=](
carla::rpc::Actor actor,
const float percentage) {
187 server->bind(
"set_percentage_random_right_lanechange", [=](
carla::rpc::Actor actor,
const float percentage) {
192 server->bind(
"set_hybrid_physics_mode", [=](
const bool mode_switch) {
197 server->bind(
"set_hybrid_physics_radius", [=](
const float radius) {
202 server->bind(
"set_osm_mode", [=](
const bool mode_switch) {
212 server->bind(
"remove_custom_path", [=](
const ActorId actor_id,
const bool remove_path) {
217 server->bind(
"update_custom_path", [=](
const ActorId actor_id,
const Path path) {
222 server->bind(
"set_imported_route", [=](
carla::rpc::Actor actor,
const Route route,
const bool empty_buffer) {
227 server->bind(
"remove_imported_route", [=](
const ActorId actor_id,
const bool remove_path) {
232 server->bind(
"update_imported_route", [=](
const ActorId actor_id,
const Route route) {
237 server->bind(
"set_respawn_dormant_vehicles", [=](
const bool mode_switch) {
242 server->bind(
"set_boundaries_respawn_dormant_vehicles", [=](
const float lower_bound,
const float upper_bound) {
247 server->bind(
"get_next_action", [=](
const ActorId actor_id) {
252 server->bind(
"get_all_actions", [=](
const ActorId actor_id) {
256 server->bind(
"shut_down", [=]() {
261 server->bind(
"set_synchronous_mode", [=](
const bool mode) {
266 server->bind(
"set_synchronous_mode_timeout_in_milisecond", [=](
const double time) {
271 server->bind(
"set_random_device_seed", [=](
const uint64_t seed) {
276 server->bind(
"synchronous_tick", [=]() ->
bool {
281 server->bind(
"health_check_remote_TM", [=](){});
308 ::rpc::server *server =
nullptr;
virtual void SetHybridPhysicsMode(const bool mode_switch)=0
Method to set hybrid physics mode.
virtual void SetAutoLaneChange(const ActorPtr &actor, const bool enable)=0
Enable/disable automatic lane change on a vehicle.
virtual void SetForceLaneChange(const ActorPtr &actor, const bool direction)=0
Method to force lane change on a vehicle.
virtual bool SynchronousTick()=0
Method to provide synchronous tick.
carla::SharedPtr< cc::Actor > ActorPtr
virtual void SetGlobalDistanceToLeadingVehicle(const float dist)=0
Method to set Global Distance to Leading Vehicle.
void throw_exception(const std::exception &e)
Holds an Actor, but only instantiates it when needed.
virtual void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc)=0
Method to specify the % chance of ignoring collisions with any walker.
virtual void Release()=0
To release the traffic manager.
std::vector< cg::Location > Path
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
This file contains definitions of common data structures used in traffic manager. ...
virtual void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage)=0
Set a vehicle's % decrease in velocity with respect to the speed limit.
uint16_t _RPCPort
Traffic manager server RPC port.
virtual void UnregisterVehicles(const std::vector< ActorPtr > &actor_list)=0
This method unregisters a vehicle from traffic manager.
static T Get(carla::rpc::Response< T > &response)
TrafficManagerServer(uint16_t &RPCPort, carla::traffic_manager::TrafficManagerBase *tm)
Here RPCPort is the traffic manager local instance RPC server port where it can listen to remote traf...
virtual Action GetNextAction(const ActorId &actor_id)=0
Method to get the vehicle's next action.
virtual void SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage)=0
Method to set % to randomly do a left lane change.
virtual void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path)=0
Method to remove a route.
static const uint64_t MIN_TRY_COUNT
virtual void SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer)=0
Method to set our own imported route.
virtual void SetOSMMode(const bool mode_switch)=0
Method to set Open Street Map mode.
virtual void RemoveUploadPath(const ActorId &actor_id, const bool remove_path)=0
Method to remove a path.
virtual void SetGlobalPercentageSpeedDifference(float const percentage)=0
Set a global % decrease in velocity with respect to the speed limit.
virtual void SetKeepRightPercentage(const ActorPtr &actor, const float percentage)=0
Method to set % to keep on the right lane.
The function of this class is to integrate all the various stages of the traffic manager appropriatel...
virtual void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance)=0
Method to specify how much distance a vehicle should maintain to the leading vehicle.
virtual void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update)=0
Method to set the automatic management of the vehicle lights.
virtual void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc)=0
Method to specify the % chance of ignoring collisions with any vehicle.
virtual void SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer)=0
Method to set our own imported path.
virtual void SetGlobalLaneOffset(float const offset)=0
Method to set a global lane offset displacement from the center line.
std::vector< uint8_t > Route
virtual void SetRespawnDormantVehicles(const bool mode_switch)=0
Method to set automatic respawn of dormant vehicles.
virtual void UpdateUploadPath(const ActorId &actor_id, const Path path)=0
Method to update an already set path.
virtual void SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision)=0
Method to set collision detection rules between vehicles.
virtual void SetPercentageRunningLight(const ActorPtr &actor, const float perc)=0
Method to specify the % chance of running any traffic light.
SharedPtr< client::Actor > Get(EpisodeProxy episode) const
virtual void UpdateImportedRoute(const ActorId &actor_id, const Route route)=0
Method to update an already set route.
virtual void SetHybridPhysicsRadius(const float radius)=0
Method to set hybrid physics radius.
virtual void SetLaneOffset(const ActorPtr &actor, const float offset)=0
Method to set a lane offset displacement from the center line.
virtual void SetRandomDeviceSeed(const uint64_t seed)=0
Method to set randomization seed.
virtual void SetDesiredSpeed(const ActorPtr &actor, const float value)=0
Set a vehicle's exact desired velocity.
virtual void SetSynchronousModeTimeOutInMiliSecond(double time)=0
Method to set Tick timeout for synchronous execution.
virtual void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound)=0
Method to set boundaries for respawning vehicles.
virtual void SetPercentageRunningSign(const ActorPtr &actor, const float perc)=0
Method to specify the % chance of running any traffic sign.
virtual ActionBuffer GetActionBuffer(const ActorId &actor_id)=0
Method to get the vehicle's action buffer.
virtual void SetSynchronousMode(bool mode)=0
Method to switch traffic manager into synchronous execution.
virtual void RegisterVehicles(const std::vector< ActorPtr > &actor_list)=0
This method registers a vehicle with the traffic manager.
virtual void SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage)=0
Method to set % to randomly do a right lane change.
virtual carla::client::detail::EpisodeProxy & GetEpisodeProxy()=0
Get carla episode information.