diff --git a/config.yml b/config.yml index 82818a1..e44fbf7 100644 --- a/config.yml +++ b/config.yml @@ -1,3 +1,8 @@ +core: + mode: winclient + serverip: 192.168.1.20 + clientip: 192.168.1.21 + server: Hyper-Vs + arm: ip: 192.168.1.145 - \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index c7afb5c..5827b32 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,7 @@ requests git+https://github.com/Byeongdulee/python-urx.git psycopg2 pyyaml +Flask # Development matplotlib diff --git a/run.py b/run.py index 7fa2a76..86978fb 100755 --- a/run.py +++ b/run.py @@ -21,6 +21,9 @@ config = None keeprunning = True arm_ready = False led_ready = False +camera_ready = False +sensor_ready = False +vm_ready = False killme = None #pool = None @@ -33,9 +36,17 @@ def led_start_callback(res): global led_ready led_ready = True -def cam_start_callback(res): - global cam_ready - cam_ready = True +def camera_start_callback(res): + global camera_ready + camera_ready = True + +def sensor_start_callback(res): + global sensor_ready + sensor_ready = True + +def vm_start_callback(res): + global vm_ready + vm_ready = True def wait_for(val, name): if val is False: @@ -43,23 +54,34 @@ def wait_for(val, name): while val is False: sleep(0.1) -def setup(pool): +def setup_server(pool): + # linux server setup global config global counter + global sensor_ready + global camera_ready + global led_ready + global arm_ready + fprint("Starting Jukebox control system...") pool.apply_async(ur5_control.init, (config["arm"]["ip"],), callback=arm_start_callback) #pool.apply_async(led_control.init, callback=led_start_callback) - #pool.apply_async(cam_control.init, callback=led_start_callback) + #pool.apply_async(camera_control.init, callback=camera_start_callback) + #pool.apply_async(sensor_control.init, callback=sensor_start_callback) wait_for(led_ready, "LED controller initialization") + wait_for(sensor_ready, "Sensor Initialization") + wait_for(camera_ready, "Camera initilization") wait_for(arm_ready, "UR5 initilization") - wait_for(cam_ready, "Camera initilization") + + + return True -def mainloop(pool): +def mainloop_server(pool): global config global counter global killme @@ -68,7 +90,40 @@ def mainloop(pool): killall() counter = counter + 1 -class Logger(object): + + +def setup_client(pool, config): + # Windows client setup + + # Open loading wepage + def run_app(): + from flask import Flask, render_template + app = Flask(__name__) + + @app.route('/') + def index(): + return render_template('index.html') + + app.run(debug=True, use_reloader=False) + + p = Process(target=run_app) + p.start() + # start Linux server VM + if config["core"]["server"] == "Hyper-V": + run_cmd("Start-VM -Name Jukebox*") # any and all VMs starting with "Jukebox" + + # Wait for VM to start and be reachable over the network + #pool.apply_async(vm_control.init, callback=vm_start_callback) + + wait_for(vm_ready, "VM Startup") + p.terminate() + return True + + +def mainloop_client(pool): + sleep(0.1) + +"""class Logger(object): def __init__(self, filename="output.log"): self.log = open(filename, "a") self.terminal = sys.stdout @@ -83,10 +138,7 @@ class Logger(object): sleep(0) def flush(self): - print("",end="") - - - + print("",end="")""" def killall(): procs = active_children() @@ -140,8 +192,14 @@ if __name__ == "__main__": counter = 0 killme = manager.Value('d', 0) signal.signal(signal.SIGINT, killall_signal) - if setup(pool): - while(keeprunning): - mainloop(pool) + if config["core"]["mode"] == "winclient": + if setup_client(pool, config): + while(keeprunning): + mainloop_client(pool) + + elif config["core"]["mode"] == "linuxserver": + if setup_server(pool): + while(keeprunning): + mainloop_server(pool) diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..cc705b5 --- /dev/null +++ b/static/style.css @@ -0,0 +1,24 @@ +body { + text-align: center; + padding-top: 100px; +} + +.spinner { + border: 16px solid #f3f3f3; + border-top: 16px solid #002554; + border-radius: 50%; + width: 120px; + height: 120px; + animation: spin 2s linear infinite; + margin: auto; +} + +@keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } +} + +p { + margin-top: 20px; + font-size: 20px; +} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..f4d6573 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,13 @@ + + + + + + Loading + + + +
+

Waiting for backend server to start...

+ +