CARLA
Loading...
Searching...
No Matches
carla::traffic_manager::TrafficManager Class Reference

This class integrates all the various stages of the traffic manager appropriately using messengers. More...

#include <TrafficManager.h>

Public Member Functions

ActionBuffer GetActionBuffer (const ActorId &actor_id)
 Method to get the action buffer.
Action GetNextAction (const ActorId &actor_id)
 Method to get the next action.
bool IsValidPort () const
TrafficManager & operator= (const TrafficManager &)=default
TrafficManager & operator= (TrafficManager &&)=default
uint16_t Port () const
void RegisterVehicles (const std::vector< ActorPtr > &actor_list)
 This method registers a vehicle with the traffic manager.
void RemoveImportedRoute (const ActorId &actor_id, const bool remove_path)
 Method to remove a route.
void RemoveUploadPath (const ActorId &actor_id, const bool remove_path)
 Method to remove a path.
void SetAutoLaneChange (const ActorPtr &actor, const bool enable)
 Enable/disable automatic lane change on a vehicle.
void SetCollisionDetection (const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision)
 Method to set collision detection rules between vehicles.
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 SetDistanceToLeadingVehicle (const ActorPtr &actor, const float distance)
 Method to specify how much distance a vehicle should maintain to the leading vehicle.
void SetForceLaneChange (const ActorPtr &actor, const bool direction)
 Method to force lane change on a vehicle.
void SetGlobalDistanceToLeadingVehicle (const float distance)
 Method to Set Global distance to Leading vehicle.
void SetGlobalLaneOffset (float const offset)
 Method to set a global lane offset displacement from the center line.
void SetGlobalLargeVehicleWideTurn (const bool enable)
 Method to enable/disable the wide-turn manoeuvre globally for large vehicles.
void SetGlobalPercentageSpeedDifference (float const percentage)
 Set a global % decrease in velocity with respect to the speed limit.
void SetHybridPhysicsMode (const bool mode_switch)
 This method sets the hybrid physics mode.
void SetHybridPhysicsRadius (const float radius)
 This method sets the hybrid physics radius.
void SetImportedRoute (const ActorPtr &actor, const Route route, const bool empty_buffer)
 Method to set our own imported route.
void SetKeepSlowLanePercentage (const ActorPtr &actor, const float percentage)
 Method to set % to keep on the slow lane.
void SetLaneOffset (const ActorPtr &actor, const float offset)
 Method to set a lane offset displacement from the center line.
void SetLargeVehicleWideTurn (const ActorPtr &actor, const bool enable)
 Method to enable/disable the wide-turn manoeuvre for a single large vehicle.
void SetOSMMode (const bool mode_switch)
 Method to set Open Street Map mode.
void SetPercentageIgnoreVehicles (const ActorPtr &actor, const float perc)
 Method to specify the % chance of ignoring collisions with any vehicle.
void SetPercentageIgnoreWalkers (const ActorPtr &actor, const float perc)
 Method to specify the % chance of ignoring collisions with any walker.
void SetPercentageRunningLight (const ActorPtr &actor, const float perc)
 Method to specify the % chance of running a light.
void SetPercentageRunningSign (const ActorPtr &actor, const float perc)
 Method to specify the % chance of running a sign.
void SetPercentageSpeedDifference (const ActorPtr &actor, const float percentage)
 Set a vehicle's % decrease in velocity with respect to the speed limit.
void SetRandomDeviceSeed (const uint64_t seed)
 Method to set randomization seed.
void SetRandomLeftLaneChangePercentage (const ActorPtr &actor, const float percentage)
 Method to set % to randomly do a left lane change.
void SetRandomRightLaneChangePercentage (const ActorPtr &actor, const float percentage)
 Method to set % to randomly do a right lane change.
void SetSynchronousMode (bool mode)
 Method to switch traffic manager into synchronous execution.
void SetSynchronousModeTimeOutInMiliSecond (double time)
 Method to set tick timeout for synchronous execution.
void SetUpdateVehicleLights (const ActorPtr &actor, const bool do_update)
 Set the automatic management of the vehicle lights.
void ShutDown ()
bool SynchronousTick ()
 Method to provide synchronous tick.
 TrafficManager ()
 TrafficManager (carla::client::detail::EpisodeProxy episode_proxy, uint16_t port=TM_DEFAULT_PORT)
 Public constructor for singleton life cycle management.
 TrafficManager (const TrafficManager &other)
 TrafficManager (TrafficManager &&)=default
void UnregisterVehicles (const std::vector< ActorPtr > &actor_list)
 This method unregisters a vehicle from traffic manager.
void UpdateImportedRoute (const ActorId &actor_id, const Route route)
 Method to update an already set route.
void UpdateUploadPath (const ActorId &actor_id, const Path path)
 Method to update an already set path.

Static Public Member Functions

static void Release ()
static void RequestReset (uint64_t episode_id, std::function< void()> on_done)
 Non-blocking: reset all TMs once per episode on the reset thread, then call on_done.
static void Reset (uint64_t episode_id)
static void Tick ()

Private Member Functions

bool CreateTrafficManagerClient (carla::client::detail::EpisodeProxy episode_proxy, uint16_t port)
void CreateTrafficManagerServer (carla::client::detail::EpisodeProxy episode_proxy, uint16_t port)
TrafficManagerBase * GetTM (uint16_t port) const

Private Attributes

uint16_t _port = 0

Static Private Attributes

static std::mutex _mutex
static std::map< uint16_t, TrafficManagerBase * > _tm_map

Detailed Description

This class integrates all the various stages of the traffic manager appropriately using messengers.

Definition at line 27 of file TrafficManager.h.

Constructor & Destructor Documentation

◆ TrafficManager() [1/4]

carla::traffic_manager::TrafficManager::TrafficManager ( carla::client::detail::EpisodeProxy episode_proxy,
uint16_t port = TM_DEFAULT_PORT )
explicit

Public constructor for singleton life cycle management.

Definition at line 43 of file TrafficManager.cpp.

References _port, CreateTrafficManagerClient(), CreateTrafficManagerServer(), and GetTM().

Referenced by operator=(), operator=(), TrafficManager(), and TrafficManager().

◆ TrafficManager() [2/4]

carla::traffic_manager::TrafficManager::TrafficManager ( const TrafficManager & other)
inline

Definition at line 35 of file TrafficManager.h.

References _port, and TrafficManager().

◆ TrafficManager() [3/4]

carla::traffic_manager::TrafficManager::TrafficManager ( )
inline

Definition at line 39 of file TrafficManager.h.

Referenced by carla::client::Client::GetInstanceTM().

◆ TrafficManager() [4/4]

carla::traffic_manager::TrafficManager::TrafficManager ( TrafficManager && )
default

References TrafficManager().

Member Function Documentation

◆ CreateTrafficManagerClient()

bool carla::traffic_manager::TrafficManager::CreateTrafficManagerClient ( carla::client::detail::EpisodeProxy episode_proxy,
uint16_t port )
private

Get TM server info (Remote IP & PORT)

Set remote TM server IP and port

Try to connect to remote TM server

Check memory allocated or not

Try to reset all traffic lights

Set the pointer of the instance

If Connection error occurred

Clear previously allocated memory

Definition at line 292 of file TrafficManager.cpp.

References _tm_map, carla::traffic_manager::TrafficManagerRemote::HealthCheckRemoteTM(), carla::client::detail::EpisodeProxyImpl< PointerT >::Lock(), and carla::traffic_manager::TrafficManagerRemote::TrafficManagerRemote().

Referenced by TrafficManager().

◆ CreateTrafficManagerServer()

void carla::traffic_manager::TrafficManager::CreateTrafficManagerServer ( carla::client::detail::EpisodeProxy episode_proxy,
uint16_t port )
private

Define local constants

Create local instance of TM

Get TM server info (Local IP & PORT)

Set this client as the TM to server

Set the pointer of the instance

Definition at line 198 of file TrafficManager.cpp.

References _tm_map, IP_DATA_BUFFER_SIZE, carla::client::detail::EpisodeProxyImpl< PointerT >::Lock(), SOCK_INVALID_INDEX, and carla::traffic_manager::TrafficManagerLocal::TrafficManagerLocal().

Referenced by TrafficManager().

◆ GetActionBuffer()

ActionBuffer carla::traffic_manager::TrafficManager::GetActionBuffer ( const ActorId & actor_id)
inline

Method to get the action buffer.

Definition at line 367 of file TrafficManager.h.

References _port, carla::traffic_manager::TrafficManagerBase::GetActionBuffer(), and GetTM().

◆ GetNextAction()

Action carla::traffic_manager::TrafficManager::GetNextAction ( const ActorId & actor_id)
inline

Method to get the next action.

Definition at line 356 of file TrafficManager.h.

References _port, carla::traffic_manager::TrafficManagerBase::GetNextAction(), and GetTM().

◆ GetTM()

◆ IsValidPort()

bool carla::traffic_manager::TrafficManager::IsValidPort ( ) const
inline

Definition at line 59 of file TrafficManager.h.

References _port.

◆ operator=() [1/2]

TrafficManager & carla::traffic_manager::TrafficManager::operator= ( const TrafficManager & )
default

References TrafficManager().

◆ operator=() [2/2]

TrafficManager & carla::traffic_manager::TrafficManager::operator= ( TrafficManager && )
default

◆ Port()

uint16_t carla::traffic_manager::TrafficManager::Port ( ) const
inline

Definition at line 55 of file TrafficManager.h.

References _port.

◆ RegisterVehicles()

void carla::traffic_manager::TrafficManager::RegisterVehicles ( const std::vector< ActorPtr > & actor_list)
inline

This method registers a vehicle with the traffic manager.

Definition at line 137 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::RegisterVehicles().

Referenced by carla::client::Vehicle::SetAutopilot().

◆ Release()

void carla::traffic_manager::TrafficManager::Release ( )
static

◆ RemoveImportedRoute()

void carla::traffic_manager::TrafficManager::RemoveImportedRoute ( const ActorId & actor_id,
const bool remove_path )
inline

Method to remove a route.

Definition at line 105 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::RemoveImportedRoute().

◆ RemoveUploadPath()

void carla::traffic_manager::TrafficManager::RemoveUploadPath ( const ActorId & actor_id,
const bool remove_path )
inline

Method to remove a path.

Definition at line 81 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::RemoveUploadPath().

◆ RequestReset()

void carla::traffic_manager::TrafficManager::RequestReset ( uint64_t episode_id,
std::function< void()> on_done )
static

Non-blocking: reset all TMs once per episode on the reset thread, then call on_done.

Definition at line 194 of file TrafficManager.cpp.

Referenced by carla::client::detail::Episode::OnEpisodeChanged(), and operator=().

◆ Reset()

void carla::traffic_manager::TrafficManager::Reset ( uint64_t episode_id)
static

Definition at line 83 of file TrafficManager.cpp.

References _mutex, _tm_map, and carla::traffic_manager::AppendReleased().

Referenced by operator=().

◆ SetAutoLaneChange()

void carla::traffic_manager::TrafficManager::SetAutoLaneChange ( const ActorPtr & actor,
const bool enable )
inline

Enable/disable automatic lane change on a vehicle.

Definition at line 238 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetAutoLaneChange().

◆ SetCollisionDetection()

void carla::traffic_manager::TrafficManager::SetCollisionDetection ( const ActorPtr & reference_actor,
const ActorPtr & other_actor,
const bool detect_collision )
inline

Method to set collision detection rules between vehicles.

Definition at line 221 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetCollisionDetection().

◆ SetCustomPath()

void carla::traffic_manager::TrafficManager::SetCustomPath ( const ActorPtr & actor,
const Path path,
const bool empty_buffer )
inline

Method to set our own imported path.

Definition at line 73 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetCustomPath().

◆ SetDesiredSpeed()

void carla::traffic_manager::TrafficManager::SetDesiredSpeed ( const ActorPtr & actor,
const float value )
inline

Set a vehicle's exact desired velocity.

Definition at line 171 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetDesiredSpeed().

◆ SetDistanceToLeadingVehicle()

void carla::traffic_manager::TrafficManager::SetDistanceToLeadingVehicle ( const ActorPtr & actor,
const float distance )
inline

Method to specify how much distance a vehicle should maintain to the leading vehicle.

Definition at line 247 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetDistanceToLeadingVehicle().

◆ SetForceLaneChange()

void carla::traffic_manager::TrafficManager::SetForceLaneChange ( const ActorPtr & actor,
const bool direction )
inline

Method to force lane change on a vehicle.

Direction flag can be set to true for left and false for right.

Definition at line 230 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetForceLaneChange().

◆ SetGlobalDistanceToLeadingVehicle()

void carla::traffic_manager::TrafficManager::SetGlobalDistanceToLeadingVehicle ( const float distance)
inline

Method to Set Global distance to Leading vehicle.

Definition at line 314 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetGlobalDistanceToLeadingVehicle().

◆ SetGlobalLaneOffset()

void carla::traffic_manager::TrafficManager::SetGlobalLaneOffset ( float const offset)
inline

Method to set a global lane offset displacement from the center line.

Positive values imply a right offset while negative ones mean a left one.

Definition at line 189 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetGlobalLaneOffset().

◆ SetGlobalLargeVehicleWideTurn()

void carla::traffic_manager::TrafficManager::SetGlobalLargeVehicleWideTurn ( const bool enable)
inline

Method to enable/disable the wide-turn manoeuvre globally for large vehicles.

Definition at line 205 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetGlobalLargeVehicleWideTurn().

◆ SetGlobalPercentageSpeedDifference()

void carla::traffic_manager::TrafficManager::SetGlobalPercentageSpeedDifference ( float const percentage)
inline

Set a global % decrease in velocity with respect to the speed limit.

If less than 0, it's a % increase.

Definition at line 180 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetGlobalPercentageSpeedDifference().

◆ SetHybridPhysicsMode()

void carla::traffic_manager::TrafficManager::SetHybridPhysicsMode ( const bool mode_switch)
inline

This method sets the hybrid physics mode.

Definition at line 121 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetHybridPhysicsMode().

◆ SetHybridPhysicsRadius()

void carla::traffic_manager::TrafficManager::SetHybridPhysicsRadius ( const float radius)
inline

This method sets the hybrid physics radius.

Definition at line 129 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetHybridPhysicsRadius().

◆ SetImportedRoute()

void carla::traffic_manager::TrafficManager::SetImportedRoute ( const ActorPtr & actor,
const Route route,
const bool empty_buffer )
inline

Method to set our own imported route.

Definition at line 97 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetImportedRoute().

◆ SetKeepSlowLanePercentage()

void carla::traffic_manager::TrafficManager::SetKeepSlowLanePercentage ( const ActorPtr & actor,
const float percentage )
inline

Method to set % to keep on the slow lane.

Definition at line 322 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetKeepSlowLanePercentage().

◆ SetLaneOffset()

void carla::traffic_manager::TrafficManager::SetLaneOffset ( const ActorPtr & actor,
const float offset )
inline

Method to set a lane offset displacement from the center line.

Positive values imply a right offset while negative ones mean a left one.

Definition at line 163 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetLaneOffset().

◆ SetLargeVehicleWideTurn()

void carla::traffic_manager::TrafficManager::SetLargeVehicleWideTurn ( const ActorPtr & actor,
const bool enable )
inline

Method to enable/disable the wide-turn manoeuvre for a single large vehicle.

Definition at line 197 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetLargeVehicleWideTurn().

◆ SetOSMMode()

void carla::traffic_manager::TrafficManager::SetOSMMode ( const bool mode_switch)
inline

Method to set Open Street Map mode.

Definition at line 65 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetOSMMode().

◆ SetPercentageIgnoreVehicles()

void carla::traffic_manager::TrafficManager::SetPercentageIgnoreVehicles ( const ActorPtr & actor,
const float perc )
inline

Method to specify the % chance of ignoring collisions with any vehicle.

Definition at line 263 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetPercentageIgnoreVehicles().

◆ SetPercentageIgnoreWalkers()

void carla::traffic_manager::TrafficManager::SetPercentageIgnoreWalkers ( const ActorPtr & actor,
const float perc )
inline

Method to specify the % chance of ignoring collisions with any walker.

Definition at line 255 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetPercentageIgnoreWalkers().

◆ SetPercentageRunningLight()

void carla::traffic_manager::TrafficManager::SetPercentageRunningLight ( const ActorPtr & actor,
const float perc )
inline

Method to specify the % chance of running a light.

Definition at line 279 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetPercentageRunningLight().

◆ SetPercentageRunningSign()

void carla::traffic_manager::TrafficManager::SetPercentageRunningSign ( const ActorPtr & actor,
const float perc )
inline

Method to specify the % chance of running a sign.

Definition at line 271 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetPercentageRunningSign().

◆ SetPercentageSpeedDifference()

void carla::traffic_manager::TrafficManager::SetPercentageSpeedDifference ( const ActorPtr & actor,
const float percentage )
inline

Set a vehicle's % decrease in velocity with respect to the speed limit.

If less than 0, it's a % increase.

Definition at line 154 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetPercentageSpeedDifference().

◆ SetRandomDeviceSeed()

void carla::traffic_manager::TrafficManager::SetRandomDeviceSeed ( const uint64_t seed)
inline

Method to set randomization seed.

Definition at line 346 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetRandomDeviceSeed().

◆ SetRandomLeftLaneChangePercentage()

void carla::traffic_manager::TrafficManager::SetRandomLeftLaneChangePercentage ( const ActorPtr & actor,
const float percentage )
inline

Method to set % to randomly do a left lane change.

Definition at line 330 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetRandomLeftLaneChangePercentage().

◆ SetRandomRightLaneChangePercentage()

void carla::traffic_manager::TrafficManager::SetRandomRightLaneChangePercentage ( const ActorPtr & actor,
const float percentage )
inline

Method to set % to randomly do a right lane change.

Definition at line 338 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetRandomRightLaneChangePercentage().

◆ SetSynchronousMode()

void carla::traffic_manager::TrafficManager::SetSynchronousMode ( bool mode)
inline

Method to switch traffic manager into synchronous execution.

Definition at line 287 of file TrafficManager.h.

References _mutex, _port, and _tm_map.

◆ SetSynchronousModeTimeOutInMiliSecond()

void carla::traffic_manager::TrafficManager::SetSynchronousModeTimeOutInMiliSecond ( double time)
inline

Method to set tick timeout for synchronous execution.

Definition at line 297 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetSynchronousModeTimeOutInMiliSecond().

◆ SetUpdateVehicleLights()

void carla::traffic_manager::TrafficManager::SetUpdateVehicleLights ( const ActorPtr & actor,
const bool do_update )
inline

Set the automatic management of the vehicle lights.

Definition at line 213 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SetUpdateVehicleLights().

◆ ShutDown()

void carla::traffic_manager::TrafficManager::ShutDown ( )

◆ SynchronousTick()

bool carla::traffic_manager::TrafficManager::SynchronousTick ( )
inline

Method to provide synchronous tick.

Definition at line 305 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::SynchronousTick().

◆ Tick()

void carla::traffic_manager::TrafficManager::Tick ( )
static

◆ UnregisterVehicles()

void carla::traffic_manager::TrafficManager::UnregisterVehicles ( const std::vector< ActorPtr > & actor_list)
inline

This method unregisters a vehicle from traffic manager.

Definition at line 145 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::UnregisterVehicles().

Referenced by carla::client::Vehicle::SetAutopilot().

◆ UpdateImportedRoute()

void carla::traffic_manager::TrafficManager::UpdateImportedRoute ( const ActorId & actor_id,
const Route route )
inline

Method to update an already set route.

Definition at line 113 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::UpdateImportedRoute().

◆ UpdateUploadPath()

void carla::traffic_manager::TrafficManager::UpdateUploadPath ( const ActorId & actor_id,
const Path path )
inline

Method to update an already set path.

Definition at line 89 of file TrafficManager.h.

References _port, GetTM(), and carla::traffic_manager::TrafficManagerBase::UpdateUploadPath().

Member Data Documentation

◆ _mutex

std::mutex carla::traffic_manager::TrafficManager::_mutex
staticprivate

Definition at line 398 of file TrafficManager.h.

Referenced by GetTM(), Release(), Reset(), SetSynchronousMode(), ShutDown(), and Tick().

◆ _port

◆ _tm_map

std::map< uint16_t, TrafficManagerBase * > carla::traffic_manager::TrafficManager::_tm_map
staticprivate

The documentation for this class was generated from the following files: