/
main.py
76 lines (63 loc) · 2.12 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# coding: UTF-8
from multiprocessing import Process, Value
from ctypes import Structure, c_int, c_bool
import os
from motorContl import MotorController
from imageProcessing import ImageProcessing
from imu import Imu
# from socketServer import Server
from sound import Sound
from debug import ERROR, WARN, INFO, DEBUG, TRACE
"""
main module
"""
# 共有メモリの構造体
class Point(Structure):
_fields_ = [('ballAngle', c_int), ('ballDis', c_int),
('stationAngle', c_int), ('stationDis', c_int),
('bodyAngle', c_int), ('preparingRestart', c_bool),
('soundPhase', c_int),
('wallX', c_int), ('wallSize', c_int)]
def info(title):
INFO(title)
INFO('module name:', __name__)
INFO('parent process:', os.getppid())
INFO('process id:', os.getpid())
if __name__ == '__main__':
info('main line')
# 共有メモリの準備
shmem = Value(Point, 0)
shmem.preparingRestart = False
shmem.relyStation = False
shmem.soundPhase = 0
# モータ制御インスタンスの生成
motorController = MotorController()
# 画像処理インスタンスの生成
imageProcessing = ImageProcessing()
# 慣性計測インスタンスの生成
imu = Imu()
# スタート時に一度ジャイロセンサの補正をしておく
imu.calibrate()
# websocketサーバの生成
# server = Server(9001)
sound = Sound()
p_motorContl = Process(target=motorController.target, args=(shmem,))
p_imageProcessing = Process(target=imageProcessing.target, args=(shmem,))
p_imu = Process(target=imu.target, args=(shmem,))
# p_server = Process(target=server.target, args=())
p_sound = Process(target=sound.target, args=(shmem,))
p_motorContl.start()
DEBUG('p_motorContl started')
p_imageProcessing.start()
DEBUG('p_imageProcessing started')
p_imu.start()
DEBUG('p_imu started')
# p_server.start()
# DEBUG('p_server started')
p_sound.start()
DEBUG('p_sound started')
p_motorContl.join()
p_imageProcessing.join()
p_imu.join()
# p_server.join()
p_sound.join()