Skip to content

Commit

Permalink
Merge pull request #90 from asmithie13/add_authority/speed_blocks_#87
Browse files Browse the repository at this point in the history
Add authority/speed blocks #87
  • Loading branch information
asmithie13 authored Feb 24, 2024
2 parents 7b20402 + 68c211a commit 3db179c
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 33 deletions.
9 changes: 6 additions & 3 deletions PLC_Files/PLC1.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
LIGHT B6
OCCUPIED C
SWITCH A5 B6
LIGHT !C11
CROSSING !A3
SWITCH A5 C11

OCCUPIED !C
SWITCH A5 C11
LIGHT C11
14 changes: 7 additions & 7 deletions PLC_Files/PLC_Definitions.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
LIGHT ID #Block is Green
LIGHT !ID #Block is Red

CROSSING ID #Block is Up
CROSSING !ID #Block is Down

SWITCH ID1 ID2 #Block SWITCH points to ID2 now
OCCUPIED A #Perform actions if any block of A is OCCUPIED
SWITCH A5 B6 #SWITCH position of A5 to B6
LIGHT !C11 #Light of C11 is red
#CROSSING goes here, if blank, we just skip
OCCUPIED !A #Perform if every block of A is not OCCUPIED
SWITCH A5 C11
LIGHT C11 #Light of C11 is green
42 changes: 37 additions & 5 deletions PLC_Files/Parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,58 @@ class Parser():
def __init__(self, inputPLC, outPuttedBlocks):
self.inputPLC = inputPLC
self.outPuttedBlocks = outPuttedBlocks
self.commandsToRun = []
self.blockOccsByID = [False] * 26 #initially no blocks are occupied

def parsePLC(self):
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

for char in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
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

for length in range(2,25): #start with 2 for C

if self.blockOccsByID[length]:
index = index
else:
index = index + 4

if index > 8 : break

for len in range(index + 1, index + 4):
self.commandsToRun.append(lines[len])

for line in lines:
index = index + 8

if index > 8 : break


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 = [block for block in self.outPuttedBlocks if block.ID == parameters[0]]
match[0].state = True
else:
match = [block for block in self.outPuttedBlocks if block.ID == parameters[0][1:]]
match[0].state = False

elif command == "SWITCH":
match = [block for block in self.outPuttedBlocks if block.ID == parameters[0]]
if int(parameters[1][1:]) - 1 == int(parameters[0][1:]): match[0].state = True
else : match[0].state = False

self.commandsToRun = []


Binary file modified PLC_Files/__pycache__/Parser.cpython-311.pyc
Binary file not shown.
4 changes: 3 additions & 1 deletion Track_Resources/Block.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Define the Block class
class Block:
def __init__(self, light, crossing, switch, state,occupied,id):
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
self.ID = id
self.speedLimit = speedLimit
self.authority = authority

Binary file modified Track_Resources/__pycache__/Block.cpython-311.pyc
Binary file not shown.
39 changes: 22 additions & 17 deletions Wayside SW/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self):
uic.loadUi("Wayside SW/Wayside_UI_Rough.ui",self)

# Global constants for LIGHT, CROSSING, and SWITCH
LIGHT_CONST = [True, False, False, False,False]
LIGHT_CONST = [True, False, False, True,False]
CROSSING_CONST = [False, True, False, True,False]
SWITCH_CONST = [False, False, True, True,False]
NORMAL_CONST = [False, False, False, False, False]
Expand All @@ -41,21 +41,21 @@ def __init__(self):
self.B5_Switch_Positions = ["B6","C11"]

#Defining important blocks
A1 = Block(*NORMAL_CONST,"A1")
A2 = Block(*NORMAL_CONST,"A2")
A3 = Block(*CROSSING_CONST,"A3")
A4 = Block(*NORMAL_CONST,"A4")
A5 = Block(*SWITCH_CONST,"A5")
B6 = Block(*LIGHT_CONST,"B6")
B7 = Block(*NORMAL_CONST,"B7")
B8 = Block(*NORMAL_CONST,"B8")
B9 = Block(*NORMAL_CONST,"B9")
B10 = Block(*NORMAL_CONST,"B10")
C11 = Block(*LIGHT_CONST,"C11")
C12 = Block(*NORMAL_CONST,"C12")
C13 = Block(*NORMAL_CONST,"C13")
C14 = Block(*NORMAL_CONST,"C14")
C15 = Block(*NORMAL_CONST,"C15")
A1 = Block(*NORMAL_CONST,"A1",50,None)
A2 = Block(*NORMAL_CONST,"A2",50,None)
A3 = Block(*CROSSING_CONST,"A3",50,None)
A4 = Block(*NORMAL_CONST,"A4",50,None)
A5 = Block(*SWITCH_CONST,"A5",50,None)
B6 = Block(*LIGHT_CONST,"B6",50,None)
B7 = Block(*NORMAL_CONST,"B7",50,None)
B8 = Block(*NORMAL_CONST,"B8",50,None)
B9 = Block(*NORMAL_CONST,"B9",50,None)
B10 = Block(*NORMAL_CONST,"B10",50,None)
C11 = Block(*LIGHT_CONST,"C11",50,None)
C12 = Block(*NORMAL_CONST,"C12",50,None)
C13 = Block(*NORMAL_CONST,"C13",50,None)
C14 = Block(*NORMAL_CONST,"C14",50,None)
C15 = Block(*NORMAL_CONST,"C15",50,None)

#Defines an array of these blocks

Expand All @@ -64,7 +64,7 @@ def __init__(self):
self.SwitchBlocks = ["B5","B6","C11"]

#Create Parser Object
self.FileParser = Parser(None,self.BlockArray) #Currently empty onject
self.FileParser = Parser(None,self.AllBlocks) #Currently empty onject

# Buttons
self.fileButton.clicked.connect(self.on_file_button_clicked)
Expand Down Expand Up @@ -266,12 +266,17 @@ def switchButtonPushed(self):

def updateBlocks(self,new_data):
sentBlocks = new_data

for block in self.AllBlocks: block.occupied = False

for block_id in sentBlocks:
for block in self.AllBlocks:
if block_id == block.ID:
block.occupied = True

self.BlockOcc.setText(" ".join(sentBlocks))
if self.label_7.text() == "AUTOMATIC" : self.FileParser.parsePLC()
self.blockActions()
self.sendSpecialBlocks.emit(self.BlockArray)


Expand Down

0 comments on commit 3db179c

Please sign in to comment.