Skip to content

Commit

Permalink
Added the flag to auto correct the junction dead lock signal state.
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYuancheng committed Nov 17, 2023
1 parent 879bd23 commit 8b569fd
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/metroEmuUI/configFiles/metroConfig_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ UDP_PORT:3001
UI_TITLE:2D Railway[Metro] System Real-world Emulator

# Init the UI update interval:
UI_INTERVAL:0.8
UI_INTERVAL:2

# Init Control paramters
# Trains collision avoidence flag.
COLL_AVOID:True

# Trains Junction auto correct flag.(Check junction state and auto correct wrong PLC signal)
JUNC_AVOID:True

# Set train dock time: ==0 train will stay in station in a random Interval, > 0 num of time
# circle train will stay in
DOCK_TIME:5
Expand Down
5 changes: 3 additions & 2 deletions src/metroEmuUI/dataMgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ def setSignals(self, reqJsonStr):
try:
reqDict = json.loads(reqJsonStr)
if gv.iMapMgr:
for key, val in reqDict.items():
gv.iMapMgr.setSingals(key, val)
if not gv.gJuncAvoid:
for key, val in reqDict.items():
gv.iMapMgr.setSingals(key, val)
respStr = json.dumps({'result': 'success'})
except Exception as err:
gv.gDebugPrint("setSignals() Error: %s" %str(err), logType=gv.LOG_EXCEPT)
Expand Down
3 changes: 2 additions & 1 deletion src/metroEmuUI/metroEmuGobal.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def gDebugPrint(msg, prt=True, logType=None):
gTrainDefSpeed = 5 # Train default speed 5 or 10 pixels per refersh frame.
gSensorCount = 0 # number of sensors.
gMinTrainDist = 80 # min distance between each trains by refresh rate
gCollAvoid = CONFIG_DICT['COLL_AVOID'] # Auto avoid collision.
gCollAvoid = CONFIG_DICT['COLL_AVOID'] # Auto avoid collision.
gJuncAvoid = CONFIG_DICT['JUNC_AVOID'] # Auto correct juction state.
gDockTime = int(CONFIG_DICT['DOCK_TIME'])

gPlcTimeout = int(CONFIG_DICT['PLC_TIMEOUT'])
Expand Down
4 changes: 2 additions & 2 deletions src/metroEmuUI/railwayMgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,14 @@ def periodic(self , now):
if not result: train.checkSignal(self.signals[key])
# stop the train if it got collision at any junction.
if collsionTrainsDict and i in collsionTrainsDict[key]:
train.setEmgStop(True)
if not gv.gJuncAvoid: train.setEmgStop(True)
train.updateTrainPos()
# update all the track's sensors state afte all the trains have moved.
self.sensors[key].updateActive(val)
# updaste all the signal, if test mode (not connect to PLC) call the
# buildin signal control logic, else the data manager will read the signal
# infromation from PLC then do the auto update.
if gv.gTestMD: self.updateSignalState(key)
if gv.gTestMD or gv.gJuncAvoid : self.updateSignalState(key)

# update the station train's docking state
for key, val in self.stations.items():
Expand Down
3 changes: 1 addition & 2 deletions src/metroEmuUI/railwayPanelMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def _drawEnvItems(self, dc):
dc.DrawText('Last update Time: '+str(timeStr), 80, 860)
dc.DrawText('Connection State: '+str(connState), 80, 875)


#-----------------------------------------------------------------------------
def _drawJunction(self, dc):
""" Draw the junction
Expand All @@ -116,7 +115,7 @@ def _drawJunction(self, dc):
for item in gv.iMapMgr.getJunction():
pos = item.getPos()
if item.getCollition():
if self.toggle:
if self.toggle and not gv.gJuncAvoid:
dc.DrawBitmap(self.bitMaps['alert'], pos[0]-15, pos[1]-15)
else:
dc.SetPen(wx.Pen('RED', width=1, style=wx.PENSTYLE_SOLID))
Expand Down

0 comments on commit 8b569fd

Please sign in to comment.