Add local loading page
This commit is contained in:
		| @@ -1,3 +1,8 @@ | |||||||
|  | core: | ||||||
|  |   mode: winclient | ||||||
|  |   serverip: 192.168.1.20 | ||||||
|  |   clientip: 192.168.1.21 | ||||||
|  |   server: Hyper-Vs | ||||||
|  |  | ||||||
| arm: | arm: | ||||||
|   ip: 192.168.1.145 |   ip: 192.168.1.145 | ||||||
|    |  | ||||||
| @@ -7,6 +7,7 @@ requests | |||||||
| git+https://github.com/Byeongdulee/python-urx.git | git+https://github.com/Byeongdulee/python-urx.git | ||||||
| psycopg2 | psycopg2 | ||||||
| pyyaml | pyyaml | ||||||
|  | Flask | ||||||
|  |  | ||||||
| # Development | # Development | ||||||
| matplotlib | matplotlib | ||||||
|   | |||||||
							
								
								
									
										88
									
								
								run.py
									
									
									
									
									
								
							
							
						
						
									
										88
									
								
								run.py
									
									
									
									
									
								
							| @@ -21,6 +21,9 @@ config = None | |||||||
| keeprunning = True | keeprunning = True | ||||||
| arm_ready = False | arm_ready = False | ||||||
| led_ready = False | led_ready = False | ||||||
|  | camera_ready = False | ||||||
|  | sensor_ready = False | ||||||
|  | vm_ready = False | ||||||
| killme = None | killme = None | ||||||
| #pool = None | #pool = None | ||||||
|  |  | ||||||
| @@ -33,9 +36,17 @@ def led_start_callback(res): | |||||||
|     global led_ready |     global led_ready | ||||||
|     led_ready = True |     led_ready = True | ||||||
|  |  | ||||||
| def cam_start_callback(res): | def camera_start_callback(res): | ||||||
|     global cam_ready |     global camera_ready | ||||||
|     cam_ready = True |     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): | def wait_for(val, name): | ||||||
|     if val is False: |     if val is False: | ||||||
| @@ -43,23 +54,34 @@ def wait_for(val, name): | |||||||
|         while val is False: |         while val is False: | ||||||
|             sleep(0.1) |             sleep(0.1) | ||||||
|  |  | ||||||
| def setup(pool): | def setup_server(pool): | ||||||
|  |     # linux server setup | ||||||
|     global config |     global config | ||||||
|     global counter |     global counter | ||||||
|  |     global sensor_ready | ||||||
|  |     global camera_ready | ||||||
|  |     global led_ready | ||||||
|  |     global arm_ready | ||||||
|  |  | ||||||
|     fprint("Starting Jukebox control system...") |     fprint("Starting Jukebox control system...") | ||||||
|     pool.apply_async(ur5_control.init, (config["arm"]["ip"],), callback=arm_start_callback) |     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(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(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(arm_ready, "UR5 initilization") | ||||||
|     wait_for(cam_ready, "Camera initilization") |      | ||||||
|  |      | ||||||
|  |      | ||||||
|          |          | ||||||
|     return True |     return True | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def mainloop(pool): | def mainloop_server(pool): | ||||||
|     global config |     global config | ||||||
|     global counter |     global counter | ||||||
|     global killme |     global killme | ||||||
| @@ -68,7 +90,40 @@ def mainloop(pool): | |||||||
|         killall() |         killall() | ||||||
|     counter = counter + 1 |     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"): |     def __init__(self, filename="output.log"): | ||||||
|         self.log = open(filename, "a") |         self.log = open(filename, "a") | ||||||
|         self.terminal = sys.stdout |         self.terminal = sys.stdout | ||||||
| @@ -83,10 +138,7 @@ class Logger(object): | |||||||
|             sleep(0) |             sleep(0) | ||||||
|          |          | ||||||
|     def flush(self): |     def flush(self): | ||||||
|         print("",end="") |         print("",end="")""" | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def killall(): | def killall(): | ||||||
|     procs = active_children() |     procs = active_children() | ||||||
| @@ -140,8 +192,14 @@ if __name__ == "__main__": | |||||||
|         counter = 0 |         counter = 0 | ||||||
|         killme = manager.Value('d', 0) |         killme = manager.Value('d', 0) | ||||||
|         signal.signal(signal.SIGINT, killall_signal) |         signal.signal(signal.SIGINT, killall_signal) | ||||||
|         if setup(pool): |         if config["core"]["mode"] == "winclient": | ||||||
|             while(keeprunning): |             if setup_client(pool, config): | ||||||
|                 mainloop(pool) |                 while(keeprunning): | ||||||
|  |                     mainloop_client(pool) | ||||||
|  |  | ||||||
|  |         elif config["core"]["mode"] == "linuxserver": | ||||||
|  |             if setup_server(pool): | ||||||
|  |                 while(keeprunning): | ||||||
|  |                     mainloop_server(pool) | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										24
									
								
								static/style.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								static/style.css
									
									
									
									
									
										Normal file
									
								
							| @@ -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; | ||||||
|  | } | ||||||
							
								
								
									
										13
									
								
								templates/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								templates/index.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | <!DOCTYPE html> | ||||||
|  | <html lang="en"> | ||||||
|  | <head> | ||||||
|  |     <meta charset="UTF-8"> | ||||||
|  |     <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||||
|  |     <title>Loading</title> | ||||||
|  |     <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> | ||||||
|  | </head> | ||||||
|  | <body> | ||||||
|  |     <div class="spinner"></div> | ||||||
|  |     <p>Waiting for backend server to start...</p> | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
		Reference in New Issue
	
	Block a user