-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSettings.py
89 lines (75 loc) · 2.66 KB
/
Settings.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
77
78
79
80
81
82
83
84
85
86
87
88
89
# ****************************************************************************** #
# Author: Ondrej Slama
# -------------------
# Zdrojovy kod vytvoreny v ramci projektu robotickeho vzdusneho hokeje - diplomova prace
# na VUT FSI ustavu automatizace a informatiky v Brne.
# Source code created as a part of robotic air hockey table project - Diploma thesis
# at BUT FME institute of automation and computer sience.
# ****************************************************************************** #
import numpy as np
try:
import cPickle as pickle
except ModuleNotFoundError:
import pickle
class Settings():
def __init__(self, pathToSettings = ""):
self.path = pathToSettings
self.camera = {}
self.motors = {}
self.game = {}
self.resetDefaultSettings()
self.loadSettings()
# print(self.camera["fieldCorners"])
def resetDefaultSettings(self):
self.resetCameraSettings()
self.resetMotorsSettings()
self.resetGameSettings()
def resetCameraSettings(self):
self.camera["fps"] = 80
self.camera["resolution"] = (320, 192)
self.camera["fieldCorners"] = np.float32([[0, 0], [1, 0], [1, 1], [0, 1]])
self.camera["colorToDetect"] = np.uint8([0, 255, 120])
self.camera["intervals"] = [30, 140, 140]
self.camera["lowerLimits"] = np.uint8([165, 255-140, 0])
self.camera["upperLimits"] = np.uint8([15, 255, 120+140])
self.camera["whiteBalance"] = [1.5, 1.5]
self.camera["filterConstants"] = [8, 2.2, 1.2]
self.camera["limitPuckRadius"] = 4
def resetMotorsSettings(self):
self.motors["communicationFrequency"] = 200
self.motors["velocity"] = 2800
self.motors["acceleration"] = 25000
self.motors["deceleration"] = 100000
self.motors["pGain"] = 19
def resetGameSettings(self):
self.game["maxTime"] = 180
self.game["maxScore"] = 5
self.game["applyMaxScore"] = True
self.game["applyMaxTime"] = False
self.game["difficulty"] = 3
self.game["strategy"] = 3
self.game["robotSpeed"] = 3
self.game["frequency"] = 270
def saveSettings(self):
with open(self.path, 'wb') as settingsFile:
pickle.dump(self, settingsFile)
# print(self.game["difficulty"])
# print(self.camera["fieldCorners"])
def loadSettings(self):
try:
with open(self.path, 'rb') as settingsFile:
settings = pickle.load(settingsFile)
self.camera = settings.camera
self.motors = settings.motors
self.game = settings.game
print("Settings loaded")
print(self.game["difficulty"])
# print(self.camera["fieldCorners"])
except:
self.saveSettings()
def copy(self):
newInstance = Settings(self.path)
newInstance.camera = self.camera.copy()
newInstance.motors = self.motors.copy()
newInstance.game = self.game.copy()
return newInstance