diff --git a/carma_messenger_vehicle_plugin/src/msger_veh_cfg.py b/carma_messenger_vehicle_plugin/src/msger_veh_cfg.py index 45cde379..7da9bcc0 100644 --- a/carma_messenger_vehicle_plugin/src/msger_veh_cfg.py +++ b/carma_messenger_vehicle_plugin/src/msger_veh_cfg.py @@ -14,6 +14,13 @@ import json import logging +from enum import Enum + +class VehicleState(Enum): + NOT_CREATED = 0 + CREATED_AND_DRIVING = 1 + FINISHED_AND_DESTROYED = 2 + class MsgerVehicleCfg: @@ -57,7 +64,7 @@ def __init__(self, cfg_path, log_level='INFO'): "lcm": veh["lcm"], "cfm": veh["cfm"] } - self._veh_state_dict[veh_id] = 0 + self._veh_state_dict[veh_id] = VehicleState.NOT_CREATED logging.info("Vehicle configuration loaded successfully.") except FileNotFoundError: logging.error("Configuration file not found. Please check the file path.") @@ -147,13 +154,11 @@ def set_veh_state(self, veh_id, state): Parameters: - veh_id: The ID of the vehicle. - state: The new state to set for the vehicle. - * 0: vehicle not created - * 1: vehicle is created and is driving in the scene - * 2: vehicle is created but finish the route and destroyed type: int """ if veh_id in self._veh_state_dict: self._veh_state_dict[veh_id] = state + logging.info("Set vehicle " + str(veh_id) + " state to " + state.name) else: logging.warning(f"Attempted to set state for a non-existent vehicle ID: {veh_id}") diff --git a/carma_messenger_vehicle_plugin/src/msger_veh_wrapper.py b/carma_messenger_vehicle_plugin/src/msger_veh_wrapper.py index a4b9f23b..0c1a3661 100644 --- a/carma_messenger_vehicle_plugin/src/msger_veh_wrapper.py +++ b/carma_messenger_vehicle_plugin/src/msger_veh_wrapper.py @@ -16,6 +16,7 @@ import logging from sumo_connector import SumoConnector from msger_veh_cfg import MsgerVehicleCfg +from msger_veh_cfg import VehicleState def setup_logging(level): numeric_level = getattr(logging, level.upper(), None) @@ -44,7 +45,7 @@ def run(args): for msg_veh_id in msg_veh_ids: if msg_veh_id not in sumo_veh_ids and \ - msger_veh_cfg.get_veh_state(msg_veh_id) == 0 and \ + msger_veh_cfg.get_veh_state(msg_veh_id) == VehicleState.NOT_CREATED and \ msger_veh_cfg.get_veh_departure_time(msg_veh_id) <= sumo_connector.get_sim_time(): ### Init logging.info("Adding new vehicle with ID: " + msg_veh_id) @@ -53,10 +54,10 @@ def run(args): sumo_connector.set_veh_speed(msg_veh_id, msger_veh_cfg.get_veh_speed(msg_veh_id)) sumo_connector.set_veh_lcm(msg_veh_id, msger_veh_cfg.get_veh_lcm(msg_veh_id)) sumo_connector.set_veh_type(msg_veh_id, msger_veh_cfg.get_veh_cfm(msg_veh_id)) - msger_veh_cfg.set_veh_state(msg_veh_id, 1) - elif msg_veh_id not in sumo_veh_ids and msger_veh_cfg.get_veh_state(msg_veh_id) == 1: + msger_veh_cfg.set_veh_state(msg_veh_id, VehicleState.CREATED_AND_DRIVING) + elif msg_veh_id not in sumo_veh_ids and msger_veh_cfg.get_veh_state(msg_veh_id) == VehicleState.CREATED_AND_DRIVING: ### Remove - msger_veh_cfg.set_veh_state(msg_veh_id, 2) + msger_veh_cfg.set_veh_state(msg_veh_id, VehicleState.FINISHED_AND_DESTROYED) logging.info("Vehicle " + msg_veh_id + " finished route.") ## TODO