Skip to content

Commit

Permalink
Run simulator and pfs in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
srikarg89 committed May 31, 2020
1 parent c9f4be4 commit 19e2e30
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion src/hermes/hermes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def __init__(self, config):


def run(self):
print(self.submodules[0].measure_pdms())
for submodule in self.submodules:
sub_thread = Thread(target=submodule.run)
sub_thread.daemon = True
sub_thread.start()
submodule.run()
27 changes: 15 additions & 12 deletions src/hermes/modules/eps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#https://drive.google.com/drive/u/0/folders/1RtOsvaIf1FDO5OYh6ZsVETSZuCb2_O6_ page 39
import time
from enum import Enum
from .helpers import read_file, write_file

Expand Down Expand Up @@ -84,18 +85,20 @@ def reset(self):


def run(self):
# Add some sort of control loop? (What does the EPS do when its just being left)
# Implement watchdog
commands = read_file(self.command_filename)
performed_command = False
for register in commands:
self.ingest(register, commands[register])
performed_command = True
if read_file(self.command_filename) != self.empty_commands:
write_file(self.command_filename, self.empty_commands)
self.state_dict = {-1: self.state}
if read_file(self.state_filename) != self.state_dict:
write_file(self.state_filename, self.state_dict)
while True:
time.sleep(0.1) # Temporary for testing, should remove this in final version
print(self.measure_pdms())
# Implement watchdog
commands = read_file(self.command_filename)
performed_command = False
for register in commands:
self.ingest(register, commands[register])
performed_command = True
if read_file(self.command_filename) != self.empty_commands:
write_file(self.command_filename, self.empty_commands)
self.state_dict = {-1: self.state}
if read_file(self.state_filename) != self.state_dict:
write_file(self.state_filename, self.state_dict)


def get_pin_num(self, command):
Expand Down
19 changes: 12 additions & 7 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import sys
import sys, os
# Add MCL to path so that we can import it
sys.path.append(os.path.abspath(os.path.join('../..', 'pfs')))

import json
import time
import argparse
from hermes import Hermes
from threading import Thread

from hermes import Hermes
from MainControlLoop.main_control_loop import MainControlLoop

def hermes_thread(hermes):
while True:
time.sleep(0.1)
hermes.run()

def mcl_thread(mcl):
while True:
mcl.execute()


def ingest(inp):
Expand All @@ -23,7 +26,9 @@ def main():
# args = parser.parse_args()
config = json.load(open("config.json"))
hermes = Hermes(config)
thread = Thread(target=hermes_thread, args=(hermes,))
hermes.run()
mcl = MainControlLoop()
thread = Thread(target=mcl_thread, args=(mcl,))
thread.daemon = True
thread.start()

Expand Down

0 comments on commit 19e2e30

Please sign in to comment.