Class TrafficLightGroupUnit
- java.lang.Object
-
- org.eclipse.mosaic.fed.application.ambassador.simulation.AbstractSimulationUnit
-
- org.eclipse.mosaic.fed.application.ambassador.simulation.TrafficLightGroupUnit
-
- All Implemented Interfaces:
CommunicationModuleOwner
,AdHocCommunicative
,CellCommunicative
,Locatable
,OperatingSystem
,TrafficLightOperatingSystem
,EventProcessor
public class TrafficLightGroupUnit extends AbstractSimulationUnit implements TrafficLightOperatingSystem
Simulation unit that represents a traffic light group.
-
-
Constructor Summary
Constructors Constructor Description TrafficLightGroupUnit(String simulationUnitId, GeoPoint trafficLightPosition, TrafficLightGroup trafficLightGroup)
Creates a new traffic light group simulation unit.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CamBuilder
assembleCamMessage(CamBuilder camBuilder)
Assembles aCamBuilder
(Cooperative Awareness Message) using the givenMessageRouting
and the units' status information.Collection<TrafficLightProgram>
getAllPrograms()
Returns all traffic light programs that are registered for a traffic light group using this operating system.List<TrafficLight>
getAllTrafficLights()
Returns all traffic lights a traffic light group using this operating system.Collection<String>
getControlledLanes()
Returns a collection of incoming lanes controlled by this traffic light group.TrafficLightProgramPhase
getCurrentPhase()
Returns the traffic light program phase that is currently running on a traffic light group using this operating system.TrafficLightProgram
getCurrentProgram()
Returns the traffic light program that is currently running on a traffic light group using this operating system.GeoPoint
getInitialPosition()
This data element provides an absolute geographical longitude and latitude in a WGS84 coordinate system.GeoPoint
getPosition()
This data element provides an absolute geographical longitude and latitude in a WGS84 coordinate system.Collection<TrafficLightState>
getSignalSequence(String trafficLightProgramId, int trafficLightId)
Returns a sequence of states for a certain traffic light, where each state represents a state of the traffic light during a phase within a traffic light program.TrafficLightGroup
getTrafficLightGroup()
Getter for the traffic light group.void
processEvent(Event event)
Processes the given event.void
setRemainingDurationOfCurrentPhase(long remainingDuration)
Set the remaining duration of the current traffic light program phase of this traffic light group.void
switchToCustomState(List<TrafficLightState> stateList)
Switches all traffic lights which belong to this group to the given state.void
switchToPhaseIndex(int newPhaseId)
Switches the phase in the current traffic light program to the phase with the given id.void
switchToProgram(String newProgramId)
Sets a new traffic light program, identified by the givennewProgramId
, to this traffic light group.void
switchToProgramAndPhase(String newProgramId, int phaseId)
Sets a new traffic light program with the given id to this traffic light group and also sets the wanted phase for the new program.-
Methods inherited from class org.eclipse.mosaic.fed.application.ambassador.simulation.AbstractSimulationUnit
cleanPastEnvironmentEvents, getAdHocModule, getApplications, getApplicationsIterator, getCellModule, getConfigurationPath, getEventManager, getGroup, getId, getOsLog, getSimulationTime, getStateOfEnvironmentSensor, loadApplications, preProcessEvent, processSumoTraciMessage, putEnvironmentEvent, sendInteractionToRti, sendItefLogTuple, sendSumoTraciRequest, setGroup, setUp, tearDown, triggerOnSendMessage
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.mosaic.fed.application.app.api.os.modules.AdHocCommunicative
getAdHocModule
-
Methods inherited from interface org.eclipse.mosaic.fed.application.app.api.os.modules.CellCommunicative
getCellModule
-
Methods inherited from interface org.eclipse.mosaic.lib.util.scheduling.EventProcessor
canProcessEvent
-
Methods inherited from interface org.eclipse.mosaic.fed.application.app.api.os.OperatingSystem
getApplications, getApplicationsIterator, getConfigurationPath, getEventManager, getGroup, getId, getSimulationTime, getSimulationTimeMs, getStateOfEnvironmentSensor, sendInteractionToRti, sendItefLogTuple, sendSumoTraciRequest
-
-
-
-
Constructor Detail
-
TrafficLightGroupUnit
public TrafficLightGroupUnit(String simulationUnitId, GeoPoint trafficLightPosition, TrafficLightGroup trafficLightGroup)
Creates a new traffic light group simulation unit.- Parameters:
simulationUnitId
- internal traffic light group identifiertrafficLightPosition
- traffic light positiontrafficLightGroup
- traffic light group identifier
-
-
Method Detail
-
getPosition
public GeoPoint getPosition()
Description copied from interface:Locatable
This data element provides an absolute geographical longitude and latitude in a WGS84 coordinate system.- Specified by:
getPosition
in interfaceLocatable
- Returns:
- the position.
-
getInitialPosition
public GeoPoint getInitialPosition()
Description copied from interface:Locatable
This data element provides an absolute geographical longitude and latitude in a WGS84 coordinate system.- Specified by:
getInitialPosition
in interfaceLocatable
- Overrides:
getInitialPosition
in classAbstractSimulationUnit
- Returns:
- the position.
-
processEvent
public void processEvent(@Nonnull Event event) throws Exception
Description copied from interface:EventProcessor
Processes the given event.- Specified by:
processEvent
in interfaceEventProcessor
- Parameters:
event
- the event to process- Throws:
Exception
-
setRemainingDurationOfCurrentPhase
public void setRemainingDurationOfCurrentPhase(long remainingDuration)
Description copied from interface:TrafficLightOperatingSystem
Set the remaining duration of the current traffic light program phase of this traffic light group. Please consider only using numbers that fulfill the condition >= 0 to avoid unwanted changes. Negative numbers usage will affect the next phase so that the absolute value of the given negative number will be subtracted from the remaining duration of the next phase.- Specified by:
setRemainingDurationOfCurrentPhase
in interfaceTrafficLightOperatingSystem
- Parameters:
remainingDuration
- the new phase remaining duration in millisecond
-
switchToPhaseIndex
public void switchToPhaseIndex(int newPhaseId)
Description copied from interface:TrafficLightOperatingSystem
Switches the phase in the current traffic light program to the phase with the given id. Remaining phase duration will be reset.- Specified by:
switchToPhaseIndex
in interfaceTrafficLightOperatingSystem
- Parameters:
newPhaseId
- id of the phase it will be switched to
-
switchToCustomState
public void switchToCustomState(List<TrafficLightState> stateList)
Description copied from interface:TrafficLightOperatingSystem
Switches all traffic lights which belong to this group to the given state. The states will be held until switched to another list of states, or to another program or phase index.- Specified by:
switchToCustomState
in interfaceTrafficLightOperatingSystem
- Parameters:
stateList
- the list of states to set (one state for each traffic light in the correct order)
-
switchToProgram
public void switchToProgram(String newProgramId)
Description copied from interface:TrafficLightOperatingSystem
Sets a new traffic light program, identified by the givennewProgramId
, to this traffic light group. Important: when interacting with SUMO one should consider that after changing a program the new program will NOT begin from its first phase, but from the time at which the previous program was interrupted (and from the according phase). Consider using theTrafficLightOperatingSystem.switchToProgramAndPhase(String newProgramId, int phaseId)
method to avoid this effect. Therefore changing the program to the same program doesn't change anything.- Specified by:
switchToProgram
in interfaceTrafficLightOperatingSystem
- Parameters:
newProgramId
- Id of the new traffic light program.
-
switchToProgramAndPhase
public void switchToProgramAndPhase(String newProgramId, int phaseId)
Description copied from interface:TrafficLightOperatingSystem
Sets a new traffic light program with the given id to this traffic light group and also sets the wanted phase for the new program. Important: Internal this is made with *two* TraCI commands because it's not possible to do it in one step while interacting with SUMO.- Specified by:
switchToProgramAndPhase
in interfaceTrafficLightOperatingSystem
- Parameters:
newProgramId
- Id of the new traffic light programphaseId
- the index of the phase to switch to
-
getSignalSequence
public Collection<TrafficLightState> getSignalSequence(String trafficLightProgramId, int trafficLightId)
Description copied from interface:TrafficLightOperatingSystem
Returns a sequence of states for a certain traffic light, where each state represents a state of the traffic light during a phase within a traffic light program. If there is no program with given id, a sequence of states for the current program is returned.- Specified by:
getSignalSequence
in interfaceTrafficLightOperatingSystem
- Parameters:
trafficLightProgramId
- id of the traffic light program to look intotrafficLightId
- id of a traffic light- Returns:
- a sequence of states for a certain traffic light within a traffic light program with given id or a sequence of states for the current program.
-
getControlledLanes
public Collection<String> getControlledLanes()
Description copied from interface:TrafficLightOperatingSystem
Returns a collection of incoming lanes controlled by this traffic light group.- Specified by:
getControlledLanes
in interfaceTrafficLightOperatingSystem
- Returns:
- controlled lanes
-
getTrafficLightGroup
public TrafficLightGroup getTrafficLightGroup()
Description copied from interface:TrafficLightOperatingSystem
Getter for the traffic light group.- Specified by:
getTrafficLightGroup
in interfaceTrafficLightOperatingSystem
- Returns:
- Traffic light group
-
getAllPrograms
public Collection<TrafficLightProgram> getAllPrograms()
Description copied from interface:TrafficLightOperatingSystem
Returns all traffic light programs that are registered for a traffic light group using this operating system.- Specified by:
getAllPrograms
in interfaceTrafficLightOperatingSystem
- Returns:
- all traffic light programs that are registered for a traffic light group
-
getCurrentProgram
public TrafficLightProgram getCurrentProgram()
Description copied from interface:TrafficLightOperatingSystem
Returns the traffic light program that is currently running on a traffic light group using this operating system.- Specified by:
getCurrentProgram
in interfaceTrafficLightOperatingSystem
- Returns:
- the current traffic light program
-
getCurrentPhase
public TrafficLightProgramPhase getCurrentPhase()
Description copied from interface:TrafficLightOperatingSystem
Returns the traffic light program phase that is currently running on a traffic light group using this operating system.- Specified by:
getCurrentPhase
in interfaceTrafficLightOperatingSystem
- Returns:
- the current traffic light program phase
-
getAllTrafficLights
public List<TrafficLight> getAllTrafficLights()
Description copied from interface:TrafficLightOperatingSystem
Returns all traffic lights a traffic light group using this operating system.- Specified by:
getAllTrafficLights
in interfaceTrafficLightOperatingSystem
- Returns:
- all traffic lights within a traffic light group
-
assembleCamMessage
public CamBuilder assembleCamMessage(CamBuilder camBuilder)
Description copied from interface:CommunicationModuleOwner
Assembles aCamBuilder
(Cooperative Awareness Message) using the givenMessageRouting
and the units' status information.- Specified by:
assembleCamMessage
in interfaceCommunicationModuleOwner
- Parameters:
camBuilder
- the routing for theCam
- Returns:
- the assembled
Cam
, which can be sent
-
-