14namespace traffic_manager {
17 const std::pair<std::string, uint16_t> &_serverTM,
19 : client(_serverTM.first, _serverTM.second),
20 episodeProxyTM(episodeProxy) {
34 std::thread _thread = std::thread([
this] () {
35 std::chrono::milliseconds wait_time(TM_TIMEOUT);
38 std::this_thread::sleep_for(wait_time);
40 client.HealthCheckRemoteTM();
46 std::string rhost(
"");
49 client.getServerDetails(rhost, rport);
51 std::string strtmserver(rhost +
":" + std::to_string(rport));
55 "Trying to connect rpc server of traffic manager; "
56 "but the system failed to connect at " + strtmserver);
73 std::unique_lock<std::mutex> lock(
_mutex);
74 std::chrono::milliseconds wait_time(TM_TIMEOUT + 1000);
75 _cv.wait_for(lock, wait_time);
93 std::vector<carla::rpc::Actor> actor_list;
94 for (
auto &&actor : _actor_list) {
95 actor_list.emplace_back(actor->Serialize());
97 client.RegisterVehicle(actor_list);
101 std::vector<carla::rpc::Actor> actor_list;
102 for (
auto &&actor : _actor_list) {
103 actor_list.emplace_back(actor->Serialize());
105 client.UnregisterVehicle(actor_list);
111 client.SetPercentageSpeedDifference(actor, percentage);
117 client.SetDesiredSpeed(actor, value);
121 client.SetGlobalPercentageSpeedDifference(percentage);
127 client.SetLaneOffset(actor, offset);
131 client.SetGlobalLaneOffset(offset);
137 client.SetUpdateVehicleLights(actor, do_update);
144 client.SetCollisionDetection(reference_actor, other_actor, detect_collision);
150 client.SetForceLaneChange(actor, direction);
156 client.SetAutoLaneChange(actor, enable);
162 client.SetDistanceToLeadingVehicle(actor, distance);
166 client.SetGlobalDistanceToLeadingVehicle(distance);
173 client.SetPercentageIgnoreWalkers(actor, percentage);
179 client.SetPercentageIgnoreVehicles(actor, percentage);
185 client.SetPercentageRunningLight(actor, percentage);
191 client.SetPercentageRunningSign(actor, percentage);
197 client.SetKeepRightPercentage(actor, percentage);
203 client.SetRandomLeftLaneChangePercentage(actor, percentage);
209 client.SetRandomRightLaneChangePercentage(actor, percentage);
213 client.SetHybridPhysicsMode(mode_switch);
217 client.SetHybridPhysicsRadius(radius);
221 client.SetOSMMode(mode_switch);
227 client.SetCustomPath(actor, path, empty_buffer);
231 client.RemoveUploadPath(actor_id, remove_path);
235 client.UpdateUploadPath(actor_id, path);
241 client.SetImportedRoute(actor, route, empty_buffer);
245 client.RemoveImportedRoute(actor_id, remove_path);
249 client.UpdateImportedRoute(actor_id, route);
253 client.SetRespawnDormantVehicles(mode_switch);
257 client.SetBoundariesRespawnDormantVehicles(lower_bound, upper_bound);
261 client.SetMaxBoundaries(lower, upper);
269 client.SetSynchronousMode(mode);
273 client.SetSynchronousModeTimeOutInMiliSecond(time);
277 return client.GetNextAction(actor_id);
281 return client.GetActionBuffer(actor_id);
289 client.HealthCheckRemoteTM();
297 client.SetRandomDeviceSeed(seed);
SharedPtrType Lock() const
Same as TryLock but never return nullptr.
void SetPercentageIgnoreVehicles(const ActorPtr &actor, const float perc)
Method to specify the % chance of ignoring collisions with any vehicle.
carla::client::detail::EpisodeProxy & GetEpisodeProxy()
Get CARLA episode information.
void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update)
Method to set the automatic management of the vehicle lights
void Start()
To start the TrafficManager.
void SetGlobalPercentageSpeedDifference(float const percentage)
Method to set a global % decrease in velocity with respect to the speed limit.
void RemoveUploadPath(const ActorId &actor_id, const bool remove_path)
Method to remove a path.
carla::client::detail::EpisodeProxy episodeProxyTM
CARLA client connection object.
void SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision)
Method to set collision detection rules between vehicles.
void SetKeepRightPercentage(const ActorPtr &actor, const float percentage)
Method to set % to keep on the right lane.
bool SynchronousTick()
Method to provide synchronous tick
void UpdateUploadPath(const ActorId &actor_id, const Path path)
Method to update an already set path.
void SetGlobalLaneOffset(float const offset)
Method to set a global lane offset displacement from the center line.
void UnregisterVehicles(const std::vector< ActorPtr > &actor_list)
This method unregisters a vehicle from traffic manager.
std::condition_variable _cv
void SetHybridPhysicsMode(const bool mode_switch)
Method to set hybrid physics mode.
void RemoveImportedRoute(const ActorId &actor_id, const bool remove_path)
Method to remove a route.
void RegisterVehicles(const std::vector< ActorPtr > &actor_list)
This method registers a vehicle with the traffic manager.
void SetCustomPath(const ActorPtr &actor, const Path path, const bool empty_buffer)
Method to set our own imported path.
void SetDesiredSpeed(const ActorPtr &actor, const float value)
Set a vehicle's exact desired velocity.
void SetLaneOffset(const ActorPtr &actor, const float offset)
Method to set a lane offset displacement from the center line.
void SetOSMMode(const bool mode_switch)
Method to set Open Street Map mode.
void Stop()
To stop the TrafficManager.
void SetRandomDeviceSeed(const uint64_t seed)
Method to set randomization seed.
void UpdateImportedRoute(const ActorId &actor_id, const Route route)
Method to update an already set route.
void SetGlobalDistanceToLeadingVehicle(const float distance)
Method to specify Global Distance
void SetRandomRightLaneChangePercentage(const ActorPtr &actor, const float percentage)
Method to set % to randomly do a right lane change.
virtual ~TrafficManagerRemote()
Destructor.
void SetRespawnDormantVehicles(const bool mode_switch)
Method to set automatic respawn of dormant vehicles.
void SetAutoLaneChange(const ActorPtr &actor, const bool enable)
Enable/disable automatic lane change on a vehicle.
void SetBoundariesRespawnDormantVehicles(const float lower_bound, const float upper_bound)
Method to set boundaries for respawning vehicles.
void SetImportedRoute(const ActorPtr &actor, const Route route, const bool empty_buffer)
Method to set our own imported route.
void SetPercentageIgnoreWalkers(const ActorPtr &actor, const float perc)
Method to specify the % chance of ignoring collisions with any walker.
Action GetNextAction(const ActorId &actor_id)
Method to get the vehicle's next action.
void SetPercentageRunningLight(const ActorPtr &actor, const float perc)
Method to specify the % chance of running any traffic light
void SetSynchronousModeTimeOutInMiliSecond(double time)
Method to set Tick timeout for synchronous execution.
ActionBuffer GetActionBuffer(const ActorId &actor_id)
Method to get the vehicle's action buffer.
void Reset()
To reset the traffic manager.
void SetRandomLeftLaneChangePercentage(const ActorPtr &actor, const float percentage)
Method to set % to randomly do a left lane change.
void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage)
Method to set a vehicle's % decrease in velocity with respect to the speed limit.
TrafficManagerRemote(const std::pair< std::string, uint16_t > &_serverTM, carla::client::detail::EpisodeProxy &episodeProxy)
Constructor store remote location information.
void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance)
Method to specify how much distance a vehicle should maintain to the leading vehicle.
void HealthCheckRemoteTM()
Method to check server is alive or not.
void SetPercentageRunningSign(const ActorPtr &actor, const float perc)
Method to specify the % chance of running any traffic sign
void SetSynchronousMode(bool mode)
Method to switch traffic manager into synchronous execution.
void SetForceLaneChange(const ActorPtr &actor, const bool direction)
Method to force lane change on a vehicle.
void SetHybridPhysicsRadius(const float radius)
Method to set hybrid physics radius.
void Release()
To release the traffic manager.
void SetMaxBoundaries(const float lower, const float upper)
Method to set limits for boundaries when respawning vehicles.
carla::SharedPtr< cc::Actor > ActorPtr
std::vector< uint8_t > Route
std::vector< cg::Location > Path
std::vector< Action > ActionBuffer
std::pair< RoadOption, WaypointPtr > Action
This file contains definitions of common data structures used in traffic manager.