Skip to content

Commit

Permalink
Merge pull request #102 from asmithie13/Redo_PLC_#98
Browse files Browse the repository at this point in the history
Redo plc #98
  • Loading branch information
asmithie13 authored Mar 2, 2024
2 parents ac0879d + 2f9cb71 commit fa5451f
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 244 deletions.
16 changes: 10 additions & 6 deletions PLC_Files/PLC1.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
OCCUPIED C
SWITCH A5 B6
LIGHT !C11
SwitchOcc or not SwitchRightOcc
SWITCH

OCCUPIED !C
SWITCH A5 C11
LIGHT C11
SwitchOcc or SwitchRightOcc
CurrentLIGHT

SwitchOcc
LeftLIGHT

not SwitchOcc and SwitchRightOcc
RightLIGHT
41 changes: 0 additions & 41 deletions PLC_Files/PLC_Red.txt

This file was deleted.

89 changes: 19 additions & 70 deletions PLC_Files/Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,77 +8,26 @@
from Track_Resources.Block import Block

class Parser():
def __init__(self, inputPLC, outPuttedBlocks):
def __init__(self, inputPLC, CrossingTriplesIDS, outPuttedBlocks):
self.inputPLC = inputPLC
self.CrossingTriplesIDS = CrossingTriplesIDS
self.outPuttedBlocks = outPuttedBlocks
self.commandsToRun = []
self.blockOccsByID = [False] * 26 #initially no blocks are occupied

def blockState(self): #will break up inputPLC into what commands to run based off of conditions of occupancies
lines = self.inputPLC.split('\n')
index = 0
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

for char in alphabet:
occupied_blocks = [block for block in self.outPuttedBlocks if char in block.ID and block.occupied]
self.blockOccsByID[index] = True if occupied_blocks else False
index = index + 1

index = 0
indexOcc = 0
indexNotOcc = 0
indexNextOcc = 0
indexEnd = len(lines) - 1

for length in range(2,25): #start with 2 for C
if (length + 1) >= 25 or not ("OCCUPIED " + alphabet[length]) in lines: break

isOcc = False

if (length + 1) < 25 and "OCCUPIED " + alphabet[length + 1] in lines : indexNextOcc = lines.index("OCCUPIED " + alphabet[length + 1])
else: indexNextOcc = indexEnd

indexOcc = lines.index("OCCUPIED " + alphabet[length])
indexNotOcc = lines.index("OCCUPIED !" + alphabet[length])

if self.blockOccsByID[length]:
isOcc = True

if isOcc:
indexLoopStart = indexOcc + 1
indexLoopEnd = indexNotOcc - 1
else:
indexLoopStart = indexNotOcc + 1
if indexNextOcc != indexEnd : indexLoopEnd = indexNextOcc - 1
else: indexLoopEnd = indexNextOcc + 1

for pos in range(indexLoopStart, indexLoopEnd):
self.commandsToRun.append(lines[pos])


def parsePLC(self):
self.blockState()

for line in self.commandsToRun:
if line == '' : break
tokens = line.strip().split()
command = tokens[0]
parameters = tokens[1:]
block_id = parameters[0][1:] if parameters[0][0] == '!' else parameters[0]
match = [block for block in self.outPuttedBlocks if block.ID == block_id]

if command == "LIGHT" or command == "CROSSING":
if parameters[0][0] != '!':
match[0].state = True
else:
match[0].state = False

#CHANGE TO BE LIKE ABOVE JUST WITH DEFAULT STATES

elif command == "SWITCH":
if int(parameters[1][1:]) - 1 == int(parameters[0][1:]): match[0].state = True
else : match[0].state = False

self.commandsToRun = []


lines = self.inputPLC.split('\n')
switchLogic, curLightLogic, leftLightLogic, rightLightLogic = lines[0], lines[3], lines[6], lines[9]

CrossingTripleBlocks = [
[block for row in self.CrossingTriplesIDS for element in row
for block in self.outPuttedBlocks if str(element) == str(block.ID[1:])][i:i + 3]
for i in range(0, len(self.CrossingTriplesIDS) * 3, 3)
]

for data in CrossingTripleBlocks:
SwitchOcc = data[0].occupied
SwitchRightOcc = data[2].occupied

data[0].switchState = eval(switchLogic)
data[0].lightState = eval(curLightLogic)
data[1].lightState = eval(leftLightLogic)
data[2].lightState = eval(rightLightLogic)
Binary file modified PLC_Files/__pycache__/Parser.cpython-311.pyc
Binary file not shown.
19 changes: 12 additions & 7 deletions Track_Resources/Block.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Define the Block class
class Block:
def __init__(self, light, crossing, switch, state,occupied,id,speedLimit,authority):
self.LIGHT = light
self.CROSSING = crossing
self.SWITCH = switch
self.state = state
self.occupied = occupied
def __init__(self, lineColor, blockSection, blockNum, hasLight, hasCrossing, hasSwitch, lightState, crossingState, switchState,id,speedLimit):
self.lineColor = lineColor
self.blockSection = blockSection
self.blockNum = blockNum
self.LIGHT = hasLight
self.CROSSING = hasCrossing
self.SWITCH = hasSwitch
self.lightState = lightState
self.crossingState = crossingState
self.switchState = switchState
self.occupied = False
self.ID = id
self.speedLimit = speedLimit
self.authority = authority
self.authority = None

Binary file modified Track_Resources/__pycache__/Block.cpython-311.pyc
Binary file not shown.
132 changes: 66 additions & 66 deletions Wayside SW/Red_Line.csv
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
Line,Section,Block Number,Block Length (m),Block Grade (%),Speed Limit (Km/Hr),Infrastructure,Station Side,ELEVATION (M),CUMALTIVE ELEVATION (M)
Red,A,1,50,0.5,40,Light,,0.25,0.25
Red,A,2,50,1,40,,,0.50,0.75
Red,A,3,50,1.5,40,,,0.75,1.50
Red,B,4,50,2,40,Light,,1.00,2.50
Red,A,1,50,0.5,40,,,0.25,0.25
Red,A,2,50,1,40,,,0.5,0.75
Red,A,3,50,1.5,40,,,0.75,1.5
Red,B,4,50,2,40,,,1,2.5
Red,B,5,50,1.5,40,,,0.75,3.25
Red,B,6,50,1,40,,,0.50,3.75
Red,B,6,50,1,40,,,0.5,3.75
Red,C,7,75,0.5,40,STATION: SHADYSIDE,Left/Right,0.38,4.13
Red,C,8,75,0,40,Light,,0.00,4.13
Red,C,9,75,0,40,SWITCH TO/FROM YARD (75-yard),,0.00,4.13
Red,D,10,75,0,40,Light,,0.00,4.13
Red,C,8,75,0,40,,,0,4.13
Red,C,9,75,0,40,,,0,4.13
Red,D,10,75,0,40,,,0,4.13
Red,D,11,75,-0.5,40,RAILWAY CROSSING,,-0.38,3.75
Red,D,12,75,-1,40,,,-0.75,3.00
Red,E,13,70,-2,40,Light,,-1.40,1.60
Red,D,12,75,-1,40,,,-0.75,3
Red,E,13,70,-2,40,,,-1.4,1.6
Red,E,14,60,-1.25,40,,,-0.75,0.85
Red,E,15,60,-1,40,SWITCH (15-16; 1-16),,-0.60,0.25
Red,F,16,50,-0.5,40,STATION: HERRON AVE,Left/Right,-0.25,0.00
Red,F,17,200,-0.5,55,Light,,-1.00,-1.00
Red,E,15,60,-1,40,SWITCH (15-16; 15-1),,-0.6,0.25
Red,F,16,50,-0.5,40,STATION: HERRON AVE,Left/Right,-0.25,0
Red,F,17,200,-0.5,55,,,-1,-1
Red,F,18,400,-0.06025,70,,,-0.24,-1.24
Red,F,19,400,0,70,,,0.00,-1.24
Red,F,20,200,0,70,,,0.00,-1.24
Red,G,21,100,0,55,STATION; SWISSVILLE,Left/Right,0.00,-1.24
Red,G,22,100,0,55,Light,,0.00,-1.24
Red,G,23,100,0,55,,,0.00,-1.24
Red,H,24,50,0,70,Light,,0.00,-1.24
Red,H,25,50,0,70,STATION; PENN STATION; UNDERGROUND,Left/Right,0.00,-1.24
Red,H,26,50,0,70,UNDERGROUND,,0.00,-1.24
Red,H,27,50,0,70,SWITCH (27-28; 27-76); UNDERGROUND,,0.00,-1.24
Red,H,28,50,0,70,UNDERGROUND,,0.00,-1.24
Red,H,29,60,0,70,UNDERGROUND,,0.00,-1.24
Red,H,30,60,0,70,UNDERGROUND,,0.00,-1.24
Red,H,31,50,0,70,UNDERGROUND,,0.00,-1.24
Red,H,32,50,0,70,SWITCH (32-33; 33-72); UNDERGROUND,,0.00,-1.24
Red,H,33,50,0,70,UNDERGROUND,,0.00,-1.24
Red,H,34,50,0,70,UNDERGROUND,,0.00,-1.24
Red,H,35,50,0,70,STATION; STEEL PLAZA; UNDERGROUND,Left/Right,0.00,-1.24
Red,H,36,50,0,70,UNDERGROUND,,0.00,-1.24
Red,H,37,50,0,70,UNDERGROUND,,0.00,-1.24
Red,H,38,50,0,70,SWITCH (38-39; 38-71); UNDERGROUND,,0.00,-1.24
Red,H,39,50,0,70,UNDERGROUND,,0.00,-1.24
Red,H,40,60,0,70,UNDERGROUND,,0.00,-1.24
Red,H,41,60,0,70,UNDERGROUND,,0.00,-1.24
Red,H,42,50,0,70,UNDERGROUND,,0.00,-1.24
Red,H,43,50,0,70,SWITCH (43-44; 44-67); UNDERGROUND,,0.00,-1.24
Red,H,44,50,0,70,UNDERGROUND,,0.00,-1.24
Red,H,45,50,0,70,STATION; FIRST AVE; UNDERGROUND,Left/Right,0.00,-1.24
Red,I,46,75,0,70,Light,,0.00,-1.24
Red,I,47,75,0,70,RAILWAY CROSSING,,0.00,-1.24
Red,I,48,75,0,70,STATION; STATION SQUARE,Left/Right,0.00,-1.24
Red,J,49,50,0,60,Light,,0.00,-1.24
Red,J,50,50,0,60,,,0.00,-1.24
Red,J,51,50,0,55,,,0.00,-1.24
Red,J,52,43.2,0,55,SWITCH (52-53; 52-66),,0.00,-1.24
Red,J,53,50,0,55,,,0.00,-1.24
Red,J,54,50,0,55,,,0.00,-1.24
Red,K,55,75,0.5,55,Light,,0.38,-0.87
Red,F,19,400,0,70,,,0,-1.24
Red,F,20,200,0,70,,,0,-1.24
Red,G,21,100,0,55,STATION; SWISSVILLE,Left/Right,0,-1.24
Red,G,22,100,0,55,,,0,-1.24
Red,G,23,100,0,55,,,0,-1.24
Red,H,24,50,0,70,,,0,-1.24
Red,H,25,50,0,70,STATION; PENN STATION; UNDERGROUND,Left/Right,0,-1.24
Red,H,26,50,0,70,UNDERGROUND,,0,-1.24
Red,H,27,50,0,70,SWITCH (27-28; 27-76); UNDERGROUND,,0,-1.24
Red,H,28,50,0,70,UNDERGROUND,,0,-1.24
Red,H,29,60,0,70,UNDERGROUND,,0,-1.24
Red,H,30,60,0,70,UNDERGROUND,,0,-1.24
Red,H,31,50,0,70,UNDERGROUND,,0,-1.24
Red,H,32,50,0,70,SWITCH (32-33; 32-72); UNDERGROUND,,0,-1.24
Red,H,33,50,0,70,UNDERGROUND,,0,-1.24
Red,H,34,50,0,70,UNDERGROUND,,0,-1.24
Red,H,35,50,0,70,STATION; STEEL PLAZA; UNDERGROUND,Left/Right,0,-1.24
Red,H,36,50,0,70,UNDERGROUND,,0,-1.24
Red,H,37,50,0,70,UNDERGROUND,,0,-1.24
Red,H,38,50,0,70,SWITCH (38-39; 38-71); UNDERGROUND,,0,-1.24
Red,H,39,50,0,70,UNDERGROUND,,0,-1.24
Red,H,40,60,0,70,UNDERGROUND,,0,-1.24
Red,H,41,60,0,70,UNDERGROUND,,0,-1.24
Red,H,42,50,0,70,UNDERGROUND,,0,-1.24
Red,H,43,50,0,70,SWITCH (43-44; 43-67); UNDERGROUND,,0,-1.24
Red,H,44,50,0,70,UNDERGROUND,,0,-1.24
Red,H,45,50,0,70,STATION; FIRST AVE; UNDERGROUND,Left/Right,0,-1.24
Red,I,46,75,0,70,,,0,-1.24
Red,I,47,75,0,70,RAILWAY CROSSING,,0,-1.24
Red,I,48,75,0,70,STATION; STATION SQUARE,Left/Right,0,-1.24
Red,J,49,50,0,60,,,0,-1.24
Red,J,50,50,0,60,,,0,-1.24
Red,J,51,50,0,55,,,0,-1.24
Red,J,52,43.2,0,55,SWITCH (52-53; 52-66),,0,-1.24
Red,J,53,50,0,55,,,0,-1.24
Red,J,54,50,0,55,,,0,-1.24
Red,K,55,75,0.5,55,,,0.38,-0.87
Red,K,56,75,0.5,55,,,0.38,-0.49
Red,K,57,75,0.5,55,,,0.38,-0.12
Red,L,58,75,1,55,Light,,0.75,0.63
Red,L,58,75,1,55,,,0.75,0.63
Red,L,59,75,0.5,55,,,0.38,1.01
Red,L,60,75,0,55,STATION; SOUTH HILLS JUNCTION,Left/Right,0.00,1.01
Red,M,61,75,-0.5,55,Light,,-0.38,0.63
Red,L,60,75,0,55,STATION; SOUTH HILLS JUNCTION,Left/Right,0,1.01
Red,M,61,75,-0.5,55,,,-0.38,0.63
Red,M,62,75,-1,55,,,-0.75,-0.12
Red,M,63,75,-1,55,,,-0.75,-0.87
Red,N,64,75,-0.5,55,Light,,-0.38,-1.24
Red,N,65,75,0,55,,,0.00,-1.24
Red,N,66,75,0,55,,,0.00,-1.24
Red,O,67,50,0,55,Light,,0.00,-1.24
Red,P,68,50,0,55,Light,,0.00,-1.24
Red,P,69,50,0,55,UNDERGROUND,,0.00,-1.24
Red,P,70,50,0,55,UNDERGROUND,,0.00,-1.24
Red,Q,71,50,0,55,Light,,0.00,-1.24
Red,R,72,50,0,55,Light,,0.00,-1.24
Red,S,73,50,0,55,Light,,0.00,-1.24
Red,S,74,50,0,55,UNDERGROUND,,0.00,-1.24
Red,S,75,50,0,55,UNDERGROUND,,0.00,-1.24
Red,T,76,50,0,55,Light,,0.00,-1.24
Red,N,64,75,-0.5,55,,,-0.38,-1.24
Red,N,65,75,0,55,,,0,-1.24
Red,N,66,75,0,55,,,0,-1.24
Red,O,67,50,0,55,,,0,-1.24
Red,P,68,50,0,55,,,0,-1.24
Red,P,69,50,0,55,UNDERGROUND,,0,-1.24
Red,P,70,50,0,55,UNDERGROUND,,0,-1.24
Red,Q,71,50,0,55,,,0,-1.24
Red,R,72,50,0,55,,,0,-1.24
Red,S,73,50,0,55,,,0,-1.24
Red,S,74,50,0,55,UNDERGROUND,,0,-1.24
Red,S,75,50,0,55,UNDERGROUND,,0,-1.24
Red,T,76,50,0,55,,,0,-1.24
Loading

0 comments on commit fa5451f

Please sign in to comment.