Vehicle Manager

File: vehicle_manager.py
Author: Marcelo Jacinto (marcelo.jacinto@tecnico.ulisboa.pt)
License: BSD-3-Clause. Copyright (c) 2023, Marcelo Jacinto. All rights reserved.
Description: Definition of the VehicleManager class - a singleton used to manage the vehiles that are spawned in the simulation world

Classes:

VehicleManager

The VehicleManager class is implemented following a singleton pattern.

class pegasus.simulator.logic.vehicle_manager.VehicleManager

Bases: object

The VehicleManager class is implemented following a singleton pattern. This means that once a vehicle is spawned on the world or an instance of the VehicleManager is created, no either will be running at the same time.

This class keeps track of all the vehicles that are spawned in the simulation world, either trough the extension UI or via Python script. Every time a new vehicle object is created, the ‘add_vehicle’ method is invoked. Additionally, a vehicle is removed, i.e. ‘remove_vehicle’ gets invoked, every time the ‘__del__’ function of the “Vehicle” object gets invoked.

Methods:

__del__()

Destructor for the object

__init__()

Constructor for the vehicle manager class.

__new__(cls)

Method that allocated memory for a new vehicle_manager.

add_vehicle(stage_prefix, vehicle)

Method that adds the vehicles to the vehicle manager.

get_vehicle(stage_prefix)

Method that returns the vehicle object given its stage prefix.

get_vehicle_manager()

Method that returns the current vehicle manager.

remove_all_vehicles()

Method that will delete all the vehicles that were spawned from the vehicle manager.

remove_vehicle(stage_prefix)

Method that deletes a vehicle from the vehicle manager.

Attributes:

vehicles

Returns: (list) List of vehicles that were spawned.

__del__()

Destructor for the object

__init__()

Constructor for the vehicle manager class.

static __new__(cls)

Method that allocated memory for a new vehicle_manager. Since the VehicleManager follows a singleton pattern, only one instance of VehicleManger object can be in memory at any time.

Returns:

the single instance of the VehicleManager class.

Return type:

VehicleManger

add_vehicle(stage_prefix, vehicle)

Method that adds the vehicles to the vehicle manager.

Parameters:
  • stage_prefix (str) – A string with the name that the vehicle is spawned in the simulator

  • vehicle (Vehicle) – The vehicle object being added to the vehicle manager.

get_vehicle(stage_prefix)

Method that returns the vehicle object given its stage prefix. Returns None if there is no vehicle associated with that stage prefix

Parameters:

stage_prefix (str) – A string with the name that the vehicle is spawned in the simulator

Returns:

The vehicle object associated with the stage_prefix

Return type:

Vehicle

static get_vehicle_manager()

Method that returns the current vehicle manager.

remove_all_vehicles()

Method that will delete all the vehicles that were spawned from the vehicle manager.

remove_vehicle(stage_prefix)

Method that deletes a vehicle from the vehicle manager.

Parameters:

stage_prefix (str) – A string with the name that the vehicle is spawned in the simulator.

property vehicles

Returns: (list) List of vehicles that were spawned.