-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
53 lines (39 loc) · 1.14 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import paho.mqtt.client as mqtt
import threading
from robot_sim import Robot
import time
import signal
import simulator
from pso import CLPSO
global_simulator_thread = None
DIMENSION = 2
global_keypress = 0
MAX_WIDTH = 640
MAX_HEIGHT = 640
robot_list = []
stop_flag = threading.Event()
def main():
global global_simulator_thread
for n in range(1,100):
robot_list.append(Robot(n,0,DIMENSION,[MAX_WIDTH/2-100,MAX_HEIGHT/2+100]))
print("connecting")
global_simulator_thread = threading.Thread(target=simulator.simulator,args=(robot_list,))
global_simulator_thread.start()
counter = 0
while True:
time.sleep(0.01)
sol = CLPSO(robot_list,DIMENSION,10e-3)
counter=counter+1
if(sol != -1):
print(f"Reached Maxima Minima! {robot_list[sol].position}; Total iterations: {counter}")
break
def handler(signum, frame):
global global_simulator_thread
print("shutting down...")
stop_flag.set()
global_simulator_thread.join()
print("shutting down successful")
exit(1)
if __name__ == "__main__":
signal.signal(signal.SIGINT, handler)
main()