Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lilly branch #193

Merged
merged 28 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e707feb
assigned wayside to blocks
20lillianjones Mar 30, 2024
77d0f0e
Merge branch 'main' of https://github.com/asmithie13/ECE-1140 into li…
20lillianjones Mar 30, 2024
c41c3aa
cache
20lillianjones Mar 30, 2024
478384f
Merge branch 'main' of https://github.com/asmithie13/ECE-1140 into li…
20lillianjones Mar 30, 2024
d1dd7b7
Merge branch 'main' of https://github.com/asmithie13/ECE-1140 into li…
20lillianjones Mar 30, 2024
46d6e0b
cache
20lillianjones Mar 30, 2024
6361099
edited main sim
20lillianjones Mar 30, 2024
e3618f5
Merge branch 'main' of https://github.com/asmithie13/ECE-1140 into li…
20lillianjones Mar 30, 2024
f556a0b
Merge branch 'main' of https://github.com/asmithie13/ECE-1140 into li…
20lillianjones Mar 30, 2024
26b4b2a
cache
20lillianjones Mar 30, 2024
907d0f1
added signals from ctc to wayside hw back to mainsim
20lillianjones Mar 30, 2024
4ab33d4
fixed parser to include missing lights
20lillianjones Mar 31, 2024
2756ce0
added block-wise authority changes according to lights
20lillianjones Mar 31, 2024
01cb404
changes to parser
20lillianjones Mar 31, 2024
8e36259
began hardware implementation of module
20lillianjones Apr 1, 2024
0779d01
temporarily commented out serial comm
20lillianjones Apr 1, 2024
a51f372
created function to update boolean authority within wayside hw class
20lillianjones Apr 1, 2024
1fed1fb
cache
20lillianjones Apr 1, 2024
c68d082
finish hardware plc processing and added vitality
20lillianjones Apr 1, 2024
cccfc76
Merge branch 'main' of https://github.com/asmithie13/ECE-1140 into li…
20lillianjones Apr 1, 2024
3ce121c
cache
20lillianjones Apr 1, 2024
ece25e0
changed read track file to account for overlap
20lillianjones Apr 1, 2024
bc17f73
uncommented serial comms
20lillianjones Apr 1, 2024
ef352c9
edit block attribute label
20lillianjones Apr 3, 2024
3b3ea93
updated track controller
20lillianjones Apr 3, 2024
5e8e1aa
Merge branch 'main' of https://github.com/asmithie13/ECE-1140 into li…
20lillianjones Apr 3, 2024
c9d3988
cache
20lillianjones Apr 3, 2024
79176a1
commented-out hardware portion of code temporarily
20lillianjones Apr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified CTC/__pycache__/CTC_Maintenance.cpython-39.pyc
Binary file not shown.
Binary file modified CTC/__pycache__/CTC_Testbench.cpython-39.pyc
Binary file not shown.
Binary file modified CTC/__pycache__/CTC_UI.cpython-39.pyc
Binary file not shown.
Binary file modified CTC/__pycache__/OccupiedBlocks.cpython-39.pyc
Binary file not shown.
Binary file modified CTC/__pycache__/Schedule.cpython-39.pyc
Binary file not shown.
Binary file modified CTC/__pycache__/TempData.cpython-39.pyc
Binary file not shown.
Binary file modified CTC/__pycache__/Throughput.cpython-39.pyc
Binary file not shown.
4 changes: 0 additions & 4 deletions MainSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def pauseSim():
MainWindow.WaysideSWwindow.sendSpecialBlocks.connect(MainWindow.WaysideSW_tb.updateBlockStates)
MainWindow.WaysideSWwindow.changeModeSend.connect(MainWindow.WaysideSW_tb.receiveMode)
MainWindow.WaysideSWwindow.sendAllBlocks.connect(MainWindow.WaysideSW_tb.receiveBlocks)
MainWindow.WaysideSWwindow.sendTrainSpeedAuth.connect(MainWindow.WaysideSW_tb.displaySpeedAuth)
MainWindow.WaysideSW_tb.OccBlocksChanged.connect(MainWindow.WaysideSWwindow.updateBlocks)
MainWindow.WaysideSW_tb.tbChangeMode.connect(MainWindow.WaysideSWwindow.changeMode)
MainWindow.WaysideSW_tb.ctcIDSpeedAuthority.connect(MainWindow.WaysideSWwindow.receiveSpeedAuth)
Expand Down Expand Up @@ -123,12 +122,9 @@ def pauseSim():
MainWindow.TrackModelWindow.send_com_speed_tb.connect(MainWindow.TrackModel_tb.update_commanded_speed)
MainWindow.TrackModelWindow.send_authority_tb.connect(MainWindow.TrackModel_tb.update_authority)


#Track Model to CTC
MainWindow.TrackModelWindow.SendTicketsales.connect(MainWindow.CTCwindow.recieveTicketSales)



"""Clock Initialization"""
#Initializing Qtimer for clock
global timer
Expand Down
Binary file modified PLC_Files/__pycache__/Parser.cpython-39.pyc
Binary file not shown.
Binary file modified PLC_Files/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified Track_Model/__pycache__/TrackModel.cpython-39.pyc
Binary file not shown.
Binary file modified Track_Resources/__pycache__/Block.cpython-39.pyc
Binary file not shown.
Binary file modified Track_Resources/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified Train_Controller_SW/__pycache__/Authority.cpython-39.pyc
Binary file not shown.
Binary file modified Train_Controller_SW/__pycache__/Failure.cpython-39.pyc
Binary file not shown.
Binary file modified Train_Controller_SW/__pycache__/NonVital.cpython-39.pyc
Binary file not shown.
Binary file modified Train_Controller_SW/__pycache__/Power.cpython-39.pyc
Binary file not shown.
Binary file modified Train_Controller_SW/__pycache__/Speed.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file modified Train_Controller_SW/__pycache__/TrainController.cpython-39.pyc
Binary file not shown.
Binary file modified Train_Controller_SW/__pycache__/mainControl.cpython-39.pyc
Binary file not shown.
Binary file modified Train_Model/__pycache__/app_trainmodel_tb.cpython-39.pyc
Binary file not shown.
Binary file modified Train_Model/__pycache__/app_trainmodel_ui.cpython-39.pyc
Binary file not shown.
Binary file modified Train_Model/__pycache__/clock_test.cpython-39.pyc
Binary file not shown.
126 changes: 115 additions & 11 deletions Wayside_HW/TrackController_HW.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5 import uic
import time
import serial
import sys
import os
import re

#Using Block Class as a seperate file
#Using Block Class as a seperate file:
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(project_root)

#Enable serial communication:
#serialObject = serial.Serial('COM8', 9600)

from Wayside_HW.TrackController_HW_TB import *
from Wayside_HW.readTrackFile import *
from Wayside_HW.newParse import *
Expand All @@ -27,12 +32,20 @@ def __init__(self):
super(TrackController_HW, self).__init__()
uic.loadUi("Wayside_HW/TrackController_HW.ui", self)

#Constant lists for blocks affected based on light color:
self.LIGHT_A1 = ['A1', 'A2']
self.LIGHT_C12 = ['C12', 'D13']
self.LIGHT_G29 = ['F26', 'F27', 'F28', 'G29']
self.LIGHT_Z150 = ['Y148', 'Y149', 'Z150']

#Disable manual mode operations, as program begins in automatic operation:
self.groupBoxManual.setEnabled(False)

#Initialize an empty list to hold all blocks:
self.allTripleIDs = []
self.allTripleIDs = [] #This is unused
self.allBlocks = readTrackFile("Wayside_HW/greenLine.csv", self.allTripleIDs)
for block in self.allBlocks:
block.Wayside = "WI"

#Initialize a flag integer to determine which mode the system is currently in:
self.modeFlag = 0 #0 = Automatic, 1 = Manual, 2 = Maintenance
Expand Down Expand Up @@ -121,16 +134,53 @@ def automaticMode(self):
occupiedBlockSections.append(block.blockSection)
occupiedBlockSections.sort()

#Pare PLC file and adjust blocks accordingly:
self.allBlocks = newParse(occupiedBlockSections, self.allBlocks)

#TO-DO HERE:
#-Adjust block-wise authority based on lights and collisions
#-Move parser to RPi
#-Ensure vitality (Run calculation two/three times and compare)
#Send string with flag at end to send block occupancies serially:
occupiedBlockString = ""
for section in occupiedBlockSections:
occupiedBlockString += section
occupiedBlockString += '1'

self.sendUpdatedBlocks.emit(self.allBlocks)
occupiedBlockBytes = occupiedBlockString.encode()
#serialObject.write(occupiedBlockBytes)

'''BEGIN SERIAL COMMUNICATION'''
#Receiving serial response from the Raspberry Pi:
'''copyBlocks = self.allBlocks
attributeList = []
while True:
if serialObject.in_waiting > 0:
myAttribute = serialObject.read(serialObject.in_waiting).decode('utf-8')
if myAttribute == 'A':
break
else:
attributeList.append(myAttribute)

for block in self.allBlocks:
if block.ID == 'A1':
block.lightState = int(attributeList[0])
elif block.ID == 'C12':
block.lightState = int(attributeList[1])
elif block.ID == 'D13':
block.switchState = int(attributeList[2])
elif block.ID == 'E19':
block.crossingState = int(attributeList[3])
elif block.ID == 'F28':
block.switchState = int(attributeList[4])
elif block.ID == 'G29':
block.lightState = int(attributeList[5])
elif block.ID == 'T108':
block.crossingState = int(attributeList[6])
elif block.ID == 'Z150':
block.lightState = int(attributeList[7])'''

#Parse PLC file and adjust blocks accordingly:
self.allBlocks = newParse(occupiedBlockSections, self.allBlocks)
#if copyBlocks != self.allBlocks:
#print("ERROR: HARDWARE CONTROL INCORRECT")

#Ajust block-wise authority based on active red lights:
self.updateBooleanAuth()
self.sendUpdatedBlocks.emit(self.allBlocks) #Change argument to copyBlocks for presentation

def selectBlock(self):
self.frameLight.setEnabled(False)
Expand Down Expand Up @@ -210,6 +260,9 @@ def setLightRed(self):
if block.ID == self.comboBoxSection.currentText() + self.comboBoxBlock.currentText():
block.lightState = False
break

#Ajust block-wise authority based on active red lights:
self.updateBooleanAuth()
self.sendUpdatedBlocks.emit(self.allBlocks)

self.pushButtonGreen.setEnabled(True)
Expand All @@ -224,6 +277,9 @@ def setLightGreen(self):
if block.ID == self.comboBoxSection.currentText() + self.comboBoxBlock.currentText():
block.lightState = True
break

#Ajust block-wise authority based on active red lights:
self.updateBooleanAuth()
self.sendUpdatedBlocks.emit(self.allBlocks)

self.pushButtonRed.setEnabled(True)
Expand Down Expand Up @@ -290,4 +346,52 @@ def setCrossingDown(self):
self.pushButtonDown.setFont(QFont("Times New Roman", 12))

def handleSpeedAuthority(self, receivedSpeedAuthority):
self.sendSpeedAuthority.emit(receivedSpeedAuthority) #Pass-on distance-wise authority straight to train controller without changing
self.sendSpeedAuthority.emit(receivedSpeedAuthority) #Pass-on distance-wise authority straight to train controller without changing

def updateBooleanAuth(self):
#Ajust block-wise authority based on active red lights:
for block in self.allBlocks:
if block.ID == 'A1':
tempA1 = block.lightState
elif block.ID == 'C12':
tempC12 = block.lightState
elif block.ID == 'G29':
tempG29 = block.lightState
elif block.ID == 'Z150':
tempZ150 = block.lightState

if tempA1 == False:
for block in self.allBlocks:
if block.ID in self.LIGHT_A1:
block.authority = False
else:
for block in self.allBlocks:
if block.ID in self.LIGHT_A1:
block.authority = True

if tempC12 == False:
for block in self.allBlocks:
if block.ID in self.LIGHT_C12:
block.authority = False
else:
for block in self.allBlocks:
if block.ID in self.LIGHT_C12:
block.authority = True

if tempG29 == False:
for block in self.allBlocks:
if block.ID in self.LIGHT_G29:
block.authority = False
else:
for block in self.allBlocks:
if block.ID in self.LIGHT_G29:
block.authority = True

if tempZ150 == False:
for block in self.allBlocks:
if block.ID in self.LIGHT_Z150:
block.authority = False
else:
for block in self.allBlocks:
if block.ID in self.LIGHT_Z150:
block.authority = True
3 changes: 2 additions & 1 deletion Wayside_HW/TrackController_HW_TB.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def displayBlockStates(self):
if tempBlock.switchState == False:
self.lineEditSwitch.setText("RIGHT")
else:
self.lineEditSwitch.setText("LIGHT")
self.lineEditSwitch.setText("LEFT")

if tempBlock.CROSSING == False:
self.lineEditCrossing.setText("-")
Expand All @@ -124,4 +124,5 @@ def displayBlockStates(self):
else:
self.lineEditCrossing.setText("UP")

self.lineEditBooleanAuth.setText(str(tempBlock.authority))

34 changes: 32 additions & 2 deletions Wayside_HW/TrackController_HW_TB.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>700</width>
<height>455</height>
<height>595</height>
</rect>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -487,6 +487,36 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<widget class="QLabel" name="labelBooleanAuth">
<property name="font">
<font>
<family>Times New Roman</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Boolean Authority:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditBooleanAuth">
<property name="font">
<font>
<family>Times New Roman</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
Expand Down Expand Up @@ -559,7 +589,7 @@
</font>
</property>
<property name="text">
<string>Per-Speed Authority:</string>
<string>Per-Train Speed:</string>
</property>
</widget>
</item>
Expand Down
Binary file modified Wayside_HW/__pycache__/TrackController_HW.cpython-39.pyc
Binary file not shown.
Binary file modified Wayside_HW/__pycache__/TrackController_HW_TB.cpython-39.pyc
Binary file not shown.
Binary file modified Wayside_HW/__pycache__/newParse.cpython-39.pyc
Binary file not shown.
Binary file modified Wayside_HW/__pycache__/readTrackFile.cpython-39.pyc
Binary file not shown.
13 changes: 5 additions & 8 deletions Wayside_HW/newParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ def newParse(occupiedBlockSections, allBlocks):
fileObject = open("Wayside_HW/testOtherPLC.txt", "r")
PLCfile = fileObject.read()
allLines = PLCfile.split('\n')

for line in allLines:
tempLine = line.split(" ")
if tempLine[0] == 'IF':
if tempLine[0] == 'IF' and tempLine[1] != 'ANY':
logicFlag = 0
for section in tempLine:
if section in occupiedBlockSections:
logicFlag = 1
break
elif tempLine[0] == 'IF' and tempLine[1] == 'ANY':
logicFlag = 1

elif tempLine[0] == 'SWITCH' or tempLine[0] == 'LIGHT' or tempLine[0] == 'CROSSING':
if logicFlag == 1:
Expand All @@ -38,9 +40,4 @@ def newParse(occupiedBlockSections, allBlocks):
elif tempLine[0] == "ELSE":
logicFlag = not logicFlag

return allBlocks





return allBlocks
5 changes: 5 additions & 0 deletions Wayside_HW/readTrackFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#Function that reads all blocks from a *.csv file and assigns block attributes:
def readTrackFile(fileName,crossingTriples):
SECTIONS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
totalBlocks = []
lightBlocks = {}
with open(fileName, "r") as fileObject:
Expand All @@ -26,6 +27,10 @@ def readTrackFile(fileName,crossingTriples):
if(i == 0):
continue
else:
tempID = line[1] + line[2]
if(line[1] not in SECTIONS and tempID != 'S103' and tempID != 'S104' and tempID != 'I36' and tempID != 'I37'):
continue

if(line[6] == "RAILWAY CROSSING"):
hasCrossingTemp = True
crossingState = True
Expand Down
12 changes: 8 additions & 4 deletions Wayside_HW/testOtherPLC.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
IF ANY
LIGHT C12 1
LIGHT G29 1

IF D E F
SWITCH D13 1 1
LIGHT A1 0 2
SWITCH D13 1
LIGHT A1 0
ELSE
SWITCH D13 0 3
LIGHT A1 1 4
SWITCH D13 0
LIGHT A1 1

IF A B C D E F
SWITCH F28 1
Expand Down
Binary file modified Wayside_SW/__pycache__/WaysideSWandTB.cpython-39.pyc
Binary file not shown.
Binary file modified __pycache__/Main_UI.cpython-39.pyc
Binary file not shown.