Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla TrafficManagerRemote

From Leeroopedia
Knowledge Sources
Domains Traffic_Management, Autonomous_Driving
Last Updated 2026-02-15 05:00 GMT

Overview

The TrafficManagerRemote class is the remote proxy implementation of the Traffic Manager that delegates all traffic management operations to a remote TrafficManagerServer via an RPC client.

Description

TrafficManagerRemote extends TrafficManagerBase and acts as a thin proxy layer that forwards all API calls to a remote Traffic Manager instance running on a different process or machine. It is used when a CARLA client connects to an already-running traffic manager server. Key features include:

  • RPC Communication: Contains a TrafficManagerClient instance that handles all RPC communication with the remote server. All Set* and Get* methods serialize their arguments (converting ActorPtr to carla::rpc::Actor via Serialize()) and forward them through the client.
  • Health Check Thread: On Start(), spawns a detached background thread that periodically calls client.HealthCheckRemoteTM() at intervals of TM_TIMEOUT milliseconds. If the health check fails (connection lost), it records a pending exception on the episode proxy and terminates the monitoring thread.
  • Lifecycle Management:
    • Start(): Begins the health check monitoring thread.
    • Stop(): Sets _keep_alive to false and waits (with timeout) for the monitoring thread to terminate via a condition variable.
    • Release(): Calls Stop().
    • Reset(): Stops the current connection, re-obtains the episode proxy for the current episode, and calls Start() to reconnect.
  • Vehicle Registration: RegisterVehicles and UnregisterVehicles convert ActorPtr vectors to carla::rpc::Actor vectors before forwarding to the client.
  • Parameter Forwarding: All parameter methods (SetPercentageSpeedDifference, SetLaneOffset, SetDesiredSpeed, SetCollisionDetection, SetForceLaneChange, SetAutoLaneChange, SetDistanceToLeadingVehicle, SetHybridPhysicsMode, SetSynchronousMode, etc.) perform actor serialization and delegate to the TrafficManagerClient.

Usage

TrafficManagerRemote is created by the TrafficManager facade when it detects that a traffic manager server is already running on the requested port. It provides the same API as TrafficManagerLocal but routes all operations over the network.

Code Reference

Source Location

  • Repository: CARLA
  • File: LibCarla/source/carla/trafficmanager/TrafficManagerRemote.cpp
  • Header: LibCarla/source/carla/trafficmanager/TrafficManagerRemote.h

Signature

class TrafficManagerRemote : public TrafficManagerBase {
public:
  TrafficManagerRemote(
    const std::pair<std::string, uint16_t> &_serverTM,
    carla::client::detail::EpisodeProxy &episodeProxy);

  virtual ~TrafficManagerRemote();

  void Start();
  void Stop();
  void Release();
  void Reset();

  void RegisterVehicles(const std::vector<ActorPtr> &actor_list);
  void UnregisterVehicles(const std::vector<ActorPtr> &actor_list);

  void SetPercentageSpeedDifference(const ActorPtr &actor, const float percentage);
  void SetLaneOffset(const ActorPtr &actor, const float offset);
  void SetDesiredSpeed(const ActorPtr &actor, const float value);
  void SetGlobalPercentageSpeedDifference(float const percentage);
  void SetGlobalLaneOffset(float const offset);
  void SetUpdateVehicleLights(const ActorPtr &actor, const bool do_update);
  void SetCollisionDetection(const ActorPtr &reference_actor, const ActorPtr &other_actor, const bool detect_collision);
  void SetForceLaneChange(const ActorPtr &actor, const bool direction);
  void SetAutoLaneChange(const ActorPtr &actor, const bool enable);
  void SetDistanceToLeadingVehicle(const ActorPtr &actor, const float distance);
  void SetHybridPhysicsMode(const bool mode_switch);
  void SetSynchronousMode(bool mode);
  bool SynchronousTick();
  // ... all TrafficManagerBase overrides

private:
  TrafficManagerClient client;
  carla::client::detail::EpisodeProxy episodeProxyTM;
  bool _keep_alive;
  std::mutex _mutex;
  std::condition_variable _cv;
};

Import

#include "carla/trafficmanager/TrafficManagerRemote.h"

I/O Contract

Inputs

Name Type Required Description
_serverTM const std::pair<std::string, uint16_t>& Yes Remote server hostname and port as a pair
episodeProxy carla::client::detail::EpisodeProxy& Yes Proxy to the current CARLA simulation episode
actor / actor_list ActorPtr / std::vector<ActorPtr> Varies Vehicle actor(s) for registration and per-vehicle configuration
percentage / value / distance float Varies Numeric parameters for behavior configuration
mode_switch / enable bool Varies Boolean toggles for mode switches

Outputs

Name Type Description
SynchronousTick() bool Return value from remote synchronous tick
RPC calls Network All operations forwarded as RPC calls to the remote TrafficManagerServer

Usage Examples

// TrafficManagerRemote is created internally by the TrafficManager facade
// when a remote TM server already exists:
auto server_info = std::make_pair(std::string("192.168.1.100"), uint16_t(8000));
auto tm_remote = new TrafficManagerRemote(server_info, episode_proxy);

// Register vehicles (serializes actors over RPC):
tm_remote->RegisterVehicles(vehicle_list);

// Configure speed (forwarded to remote server):
tm_remote->SetPercentageSpeedDifference(vehicle, -15.0f);

// Synchronous tick via remote:
bool success = tm_remote->SynchronousTick();

// Cleanup:
tm_remote->Release();

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment