def _determinePlatoonVType(self, mode): '''_determinePlatoonVType(PlatoonMode) -> string Returns the type ID corresponding to the given mode. Uses the vehicles vType and the global map PLATOON_VTYPES between original and platoon-vTypes. If the original vType is not mapped to any platoon-vtypes, the original vType is used for platooning as well ''' global WARNED_DEFAULT # original vType origVType = self._vTypes[PlatoonMode.NONE] if origVType not in cfg.PLATOON_VTYPES \ or mode not in cfg.PLATOON_VTYPES[origVType] \ or cfg.PLATOON_VTYPES[origVType][mode] is "": if "default" in cfg.PLATOON_VTYPES and mode in cfg.PLATOON_VTYPES["default"]: if rp.VERBOSITY >= 1 and not WARNED_DEFAULT[mode]: warn(("Using default vType '%s' for vehicle '%s' (PlatoonMode: '%s'). " + "This warning is issued only once.") % (cfg.PLATOON_VTYPES["default"][mode], self._ID, PlatoonMode(mode).name)) WARNED_DEFAULT[mode] = True return cfg.PLATOON_VTYPES["default"][mode] else: if rp.VERBOSITY >= 1 and not WARNED_DEFAULT[mode]: warn(("No vType specified for PlatoonMode '%s' for vehicle '%s'. Behavior within " + "platoon is NOT altered. This warning is issued only once.") % ( PlatoonMode(mode).name, self._ID)) WARNED_DEFAULT[mode] = True return origVType if rp.VERBOSITY >= 3: report("Using vType '%s' for vehicle '%s' (PlatoonMode: '%s')." % (cfg.PLATOON_VTYPES[origVType][mode], self._ID, PlatoonMode(mode).name)) return cfg.PLATOON_VTYPES[origVType][mode]
def setPlatoonMode(self, mode): '''setPlatoonMode(PlatoonMode) Assign this vehicle the vType corresponding to the given 'mode' 'mode' is from Globals.PlatoonMode Enum. (safety checks have to be done at caller site) ''' if self._currentPlatoonMode == mode: # do nothing mode is already chosen return if rp.VERBOSITY >= 3: report("Vehicle '%s': Setting PlatoonMode '%s'" % (self._ID, PlatoonMode(mode).name)) if self._vTypes[mode] != self._vTypes[self._currentPlatoonMode]: traci.vehicle.setType(self._ID, self._vTypes[mode]) # if self._speedFactors[mode] != self._speedFactors[self._currentPlatoonMode]: # Safer to call always since active speed factor mechanism may have changed # current speed factor from basic speedfactor traci.vehicle.setSpeedFactor(self._ID, self._speedFactors[mode]) if self._laneChangeModes[mode] != self._laneChangeModes[self._currentPlatoonMode]: traci.vehicle.setLaneChangeMode(self._ID, self._laneChangeModes[mode]) self.resetSplitCountDown() self._splitConditions = False self._currentPlatoonMode = mode