Skip to content

Dokumentation Implementierung

Zeeljko edited this page Jul 13, 2017 · 29 revisions

1.Einleitung

Im Rahmen des Projektes Verkehrssimulation beschreibt diese Dokumentation diverse Funktionen, Parameter und Schnittstellen der bereits gezeigten Klassen in der Dokumentation Softwaredesign. An dieser Stelle sei erwähnt, dass die folgenden Beschreibungen auf Englisch sind, da für die Source-Code Kommentare ebenfalls diese Sprache bevorzugt wurde.

2. Komponente Ampelsteuerung

2.1 Klasse TrafficAgent

2.1.1 public Task GetTrafficAgentTask()

Description:

  • Creates the traffic agent task from Task Factory

Parameters:

  • none

Return value:

  • Standard-System.Threading.Tasks.TaskFactory for the current task

2.1.2 public void StartTrafficAgent()

Description:

  • Starts the traffic agent task

Parameters:

  • none

Return value:

  • void

2.1.3 public void StopTrafficAgent()

Description:

  • Stops the traffic agent task

Parameters:

  • none

Return value:

  • void

2.1.4 private void TickLogic(CancellationToken cancelToken)

Description:
Query the initial data of the simulation interface.Starts a Stopwatch for the clock, so that there is the given amount of ticks within a second.Also calls the update method of all traffic light objects and send the updated objects to the simulation.

Parameters:

  • cancelToken: Token which tells the working loop that the program should stop

Return value:

  • void

2.1.5 private TrafficLight.LightStatus convertLightStatus(ServiceReference1.TrafficLightStatus status)

Description:
Converts the status of the traffic lights from the interface type into the internal type

Parameters:

  • status: light status to be converted (from interface type to internal type)

Return value:

  • TrafficLight.LightStatus

2.1.6 private ServiceReference1.TrafficLightStatus convertLightStatus(TrafficLight.LightStatus status)

Description:
Convert the status of the traffic lights from the internal type into the interface type

Parameters:

  • status: light status to be converted (from internal type to interface type)

Return value:

  • TrafficLight.LightStatus

2.1.7 private TrafficLightGroup.Position convertLightPosition(ServiceReference1.TrafficLightPosition oldPosition)

Description:
Convert the position of the traffic lights from the interface type into the internal type

Parameters:

  • oldPosition: light position to be converted (from interface type to internal type)

Return value:

  • TrafficLightGroup.Position

2.1.8 public void SetUpdatedTrafficLightData()

Description:
Convert the internal traffic lights into traffic lights of the interface type and PUSH the traffic lights via the interface to the simulation.

Parameters:

  • none

Return value:

  • void

2.1.9 public void GetTrafficLightData()

Description:
Pulls the traffic lights from the simulation interface and convert them into internal traffic lights

Parameters:

  • none

Return value:

  • void

2.2 TrafficLight

2.2.1 private void changeState()

Description:
Changes the state from the actual state to the next state

Parameters:

  • none

Return value:

  • void

2.2.2 public void update(ref bool stateChanged)

Description:
Check if current tick count is big enough to change the state and change the state if necessary. Also updates the stateChanged reference

Parameters:

  • stateChanged: Reference to the value which tells if a traffic light has changed his state

Return value:

  • void

2.3 TrafficLightGroup

2.3.1 public void setOffset()

Description:
Sets the Offset of a traffic light group, depending on the amount of traffic lights in the group

Parameters:

  • none

Return value:

  • void

2.3.2 public void SetDuration()

Description:
Sets the Duration of all traffic lights in the group

Parameters:

  • none

Return value:

  • void

2.3.3 public void UpdateTrafficLights(ref bool stateChanged)

Description:
Calls the update method of all traffic lights in the group

Parameters:

  • stateChanged: Reference to the value which tells if at least one traffic light has changed his state

Return value:

  • void

3. Komponente Simulation

3.1 Utilities: Klasse Utils

3.1.1 public static double GetDistanceSqr(double x, double y, double x1, double y1)

Description:
Get the distance squared between two points

Parameters:

  • x: first x point
  • y: first y point
  • x1: second x point
  • y1: second y point

Return value:

  • double: distance

3.1.2 public static double GetDistance(double x, double y, double x1, double y1)

Description:
Get the distance between two points

Parameters:

  • x: first x point
  • y: first y point
  • x1: second x point
  • y1: second y point

Return value:

  • double: distance

3.2 Utilities: Klasse Config

3.2.1 public class ConfigVehicle

Description: Class for loading the vehicle - configuration into an setting object defined in App.config

Parameters:

  • none

3.2.2 public class SimulationConfig

Description: Class for loading the general configuration into an setting object defined in App.config

Parameters:

  • none

3.2.3 class CrossingConfig

Description:
Class for loading the traffic control configuration into an setting object defined in App.config

Parameters:

  • none

3.3 Utilities: Klasse StopWatchWithOffset

3.3.1 public class StopWatchWithOffset

Description:
Helperclass for using a stopwatch with a defined offset

3.3.2 public void Start()

Description:
Method for starting the stopwatch

Parameters:

  • none

Return value:

  • void

3.3.3 public void Stop()

Description:
Method for stopping the stopwatch

Parameters:

  • none

Return value:

  • void

3.3.4 public TimeSpan ElapsedTimeSpan

Description:
Field which contains the elapsed timespan.

Parameters:

  • value: setter

Return value:

  • Timespan: getter

3.4 Base: Klasse Blocks

3.4.1 public abstract class Block : IComparable

Description:
Basic Element for the simulation and the GUI

3.4.2 public enum BlockType

Description:
Enum for the two needed blocktypes: staticBlocks can't move or change their behavior, dynamic blocks do that

Parameters:

  • StaticBlock: block that cannot move
  • DynamicBlock: block that can move

Return value:

  • int

3.4.3 public abstract class BlockObject : DynamicBlock

Description:
Basic Class for most of the dynamic blocks, it adds the TmxObject to the dynamic block. This enables the transmission
and usage for the GUI.

3.5 Base: Klasse DynamicBlock

3.5.1 public abstract class DynamicBlock : Block

Description:
Basic class for most of the dynamic blocks, it defines the minimal Fields which every dynamic block needs

3.6 Base: Klasse RoadSign

3.6.1 public class RoadSign : BlockObject

Description:
Basic Class for all roadsigns.

3.6.2 public class TrafficLight : RoadSign

Description:
Implementation of the RoadSign class for the traffic light objects of the simulation and GUI.

3.6.3 public enum LightStatus

Description:
Enum for the different light states. enum numbers equals the GID of the GUI-block

Parameters:

  • Red: 12
  • Yellow: 13
  • Green: 14
  • YellowRed: 15
  • Off: 16

Return value:

  • int

3.6.4 private void changeState()

Description:
Method to change the traffic lights state while the traffic control is not available and simulation is in emergency traffic-control-mode.

Parameters:

  • none

Return value:

  • void

3.7 Base: Klasse StreetBlock

3.7.1 public class CrossingBlock : CrossingElement

Description:
Like Crossing Element and adds Coordinates and set Type to staticBlock

3.7.2 public enum StreetDirection

Description:
Enum for the directions in which a street block leads

Parameters:

  • RightToLeft: 3
  • LeftToRight: 4
  • TopToBottom: 5
  • BottomToTop: 6
  • Crossing: 7

Return value:

  • int

3.7.3 public enum CrossingDirection

Description:
Enum for the possible directions in which a crossing element leads

Parameters:

  • Left: left diretion
  • Right: right diretion
  • Straight: straight diretion
  • None: no diretion

Return value:

  • int

3.8 Base: Klasse Vehicle

3.8.1 public enum VehicleList

Description:
Enum for the possible vehicle types, values equals the GID of the values

Parameters:

  • Car1: 1004
  • Car2: 1001
  • Truck1: 1000
  • Truck2: 1002
  • Motorcycle: 1003

Return value:

  • int

3.8.2 public override void update()

Description:
Method to run the update/atc method.

Parameters:

  • none

Return value:

  • void

3.9 Simulator

3.9.1 private class Coordiantes

Description:
helper class for the simulation logic to handle X and Y coordinates and rotation in one class

3.9.2 private class Coordiantes

Description:
Init Method for the Simulator, in here, there are the initial instantiations of some fields and first creation
of the map

3.9.3 private static void VehicleReceiver_ReceiveEventHandler(object sender, VehicleEventArgs e)

Description:
Event handler for the external vehicle receiving.

Parameters:

  • sender: Object Sender
  • e: VehicleEventArgs

Return value:

  • void

3.9.4 public void initSpawningList()

Description:
Method to initialize the list of spawning points by checking the streetblocks which leads into the map and are on the border of the map.

Parameters:

  • none

Return value:

  • void

3.9.5 private void initStreetMap()

Description:
Method to initialize the street map. Filters out all non street Block and creates a map off streetblocks and crossing blocks. Also add crossing direction to the crossing fields.

Parameters:

  • none

Return value:

  • void

3.9.6 private void TickLogic()

Description:
Method contains the main loop of the simulation in which the simulation logic includig the call of the block updates run.

Parameters:

  • none

Return value:

  • void

3.9.7 private void spawnVehicle(List spawningList)

Description:
Method to choose a vehicle out of the vehicles to spawn and remove the spawned vehicle from the spawning list.

Parameters:

  • spawningList: List of integer which contains the GID of the vehicles to spawn

Return value:

  • void

3.9.8 private void setVehicle(int tempGID)

Description:
Method to create a new vehicle at a random spawning point and add the vehicle to the dynamicObject List.

Parameters:

  • tempGID: GID of the vehicle to spawn

Return value:

  • void

3.9.9 public List<List> getMapInfo(double vehicleX, double vehicleY, double rotation, Dictionary<VehicleMovementAgent.side, int> directionDistances, ref int actPosInMapListX, ref int actPosInMapListY, ref int actoffsetX, ref int actoffsetY)

Description:
Method to create the map in the sight of the vehicle in the vehicle-given view-range

Parameters:

  • vehicleX: actual X coordinates of the vehicle
  • vehicleY: actual Y coordinates of the vehicle
  • rotation: actual rotation of the vehicle
  • directionDistances: Dictionary which contains the distances for the viewing range
  • actPosInMapListX: Reference to the actual x position in the generated map
  • actPosInMapListY: Reference to the actual y position in the generated map
  • actoffsetX: Reference to the difference between the x coordinates and the x block Position*32
  • actoffsetY: Reference to the difference between the y coordinates and the y block Position*3

Return value:

  • List: List

3.9.10 private StreetBlock addStreetBlock(int GID, int posX, int posY)

Description:
Method to add a street or crossing block of the given GID (param 1) to the given position (param 2 and 3)

Parameters:

  • GID: GID of the block to set
  • posX: x position to set the block
  • posY: y position to set the bloc

Return value:

  • StreetBlock

3.9.11 public SortedDictionary<double, List> allDynamicObjectsInRange(double vehicleX, double vehicleY, double rotation, Dictionary<VehicleMovementAgent.side, int> directionDistances)

Description:
Method to get the dynamic blocks

Parameters:

  • vehicleX: actual X coordinates of the vehicle
  • vehicleY: actual Y coordinates of the vehicle
  • rotation: actual rotation of the vehicle
  • directionDistances: Dictionary which contains the distances for the viewing range

Return value:

  • SortedDictionary: double, List<DynamicBlock

4.Komponente GUI

4.1 Helper- Klasse Utils

4.1.1 public static double GetDistanceSqr(Point point1, Point point2)

Description:
Get the distance squared between two points

Parameters:

  • point1: point one
  • point2: point two

Return value:

  • double: distance

4.1.2 public static double GetDistance(Point point1, Point point2)

Description:
Get the distance between two points

Parameters:

  • point1: point one
  • point2: point two

Return value:

  • double: distance

4.2 Klasse Game1

4.2.1 protected override void Initialize()

Description:
Allows the game to perform any initialization it needs to before starting to run. This is where it can query for any required services and load any non-graphic related content. Calling base.Initialize will enumerate through any components and initialize them as well.

Parameters:

  • none

Return value:

  • void

4.2.2 protected override void LoadContent()

Description:
LoadContent will be called once per game and is the place to load all of your content.

Parameters:

  • none

Return value:

  • void

4.2.3 protected override void UnloadContent()

Description:
UnloadContent will be called once per game and is the place to unload game-specific content.

Parameters:

  • none

Return value:

  • void

4.2.4 protected override void Update(GameTime gameTime)

Description:
Allows the game to run logic such as updating the world, checking for collisions, gathering input, and playing audio.

Parameters:

  • gameTime: Provides a snapshot of timing values

Return value:

  • void

4.2.5 protected override void Draw(GameTime gameTime)

Description:
This is called when the game should draw itself.

Parameters:

  • gameTime: Provides a snapshot of timing values

Return value:

  • void

5.Komponente Fahrzeug

5.1 VehicleAgents: Klasse VehicleMovementAgent

5.1.1 internal virtual void act(Vehicle vehicle)

Description:
Method contains the loading of the streetmap and the dynamicObject List

Parameters:

  • vehicle: actual vehicle to which the vehicle agent belongs

Return value:

  • void

5.1.2 public virtual void moveVehicle(Vehicle vehicle, List<List> vehiclesStreetMap, List dynamicList, int actPosInMapListX, int actPosInMapListY, int actOffsetX, int actOffsetY)

Description:
Method contains the loading of the streetmap and the dynamicObject List

Parameters:

  • vehicle: actual vehicle to which the vehicle agent belongs
  • vehiclesStreetMap: map part around the vehicle in the view of the vehicle
  • dynamicList: List of all dynamic objects
  • actPosInMapListX: x block position of the vehicle
  • actPosInMapListY: y block position of the vehicle
  • dynamicList: value which contains the difference between x-value of vehicle and x-value of the actual block
  • dynamicList: value which contains the difference between y-value of vehicle and y-value of the actual block

Return value:

  • void

5.1.3 private double calcDistanceForSameDir(Vehicle vehicle, DynamicBlock block)

Description:
Method to calculate the distance between the actual vehicle and a given dynamic block

Parameters:

  • vehicle: actual vehicle to which the vehicle agent belongs
  • block: the dynamic object for which d´the distance should be calculated

Return value:

  • double

5.1.4 private bool isBlockInReactionSpan(double distance, Vehicle vehicle)

Description:
Method to calculate if a given vehicle can react within the given distance

Parameters:

  • distance: distance between an object and the given vehicle
  • vehicle: actual vehicle to which the vehicle agent belongs

Return value:

  • bool

5.1.5 private bool isBlockInReactionSpan(double distance, Vehicle ownVehicle, Vehicle otherVehicle)

Description:
Method to calculate if a given vehicle can react on another vehicle with the given distance

Parameters:

  • distance: distance between an object and the given vehicle
  • ownVehicle: actual vehicle to which the vehicle agent belongs
  • otherVehicle: the other vehicle

Return value:

  • bool

5.1.6 private bool isDynamicBlockAhead(Vehicle vehicle, DynamicBlock dynamicBlock)

Description: Method to check if a dynamic block is in front of the vehicle

Parameters:

  • vehicle: actual vehicle to which the vehicle agent belongs
  • dynamicBlock: dynamic block which should be checked

Return value:

  • bool

5.1.7 private void calcnewPosition(Vehicle vehicle)

Description:
Method to calculate the new position of the vehicle within the map. Belongs to actual velocity

Parameters:

  • vehicle: actual vehicle to which the vehicle agent belongs

Return value:

  • void

5.1.8 private void calcNewVelocity()

Description:
Method to calculate the new velocity of the vehicle within the map. Belongs to actual acceleration or deceleration

Parameters:

  • none

Return value:

  • void

5.1.9 private void calcNewAccerleration(bool accelerate, bool decelerate, Double fieldsToBreak)

Description:
Method to calculate the new acceleration of the vehicle within the map. The new acceleration depends on if the vehicle should be accelerate or decelerate.

Parameters:

  • accelerate: flag to signal if vehicle should accelerate
  • decelerate: flag to signal if vehicle should decelerate
  • fieldsToBreak: distance in blocks in which the vehicle should stand. Not used at the moment

Return value:

  • void

5.1.10 protected virtual void initFieldDirection()

Description:
Method to initialize the distances around the vehicle in which the driver should see street blocks.

Parameters:

  • none

Return value:

  • void

5.1.11 public virtual List loadDynamicBlockList(Vehicle vehicle)

Description:
Method to load the list of dynamic objects.

Parameters:

  • none

Return value:

  • List: DynamicBlock

5.1.12 public virtual List<List> loadStreetMap(double X, double Y, double rotation, ref int actPosX, ref int actPosY, ref int actOffSetX, ref int actOffsetY)

Description:
Method to load the street map.

Parameters:

  • none

Return value:

  • List: StreetBlock

Clone this wiki locally