-
Notifications
You must be signed in to change notification settings - Fork 0
/
main3.py
86 lines (66 loc) · 2.33 KB
/
main3.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
import time, math, socket
import handlers
import comm
"""
Scénario alternatif v1 : voir image/main2.png
"""
# ======== Settings ========
# :)
LIDAR_ENABLE = True
# Side
BLUE_SIDE = False
# Only run on negative edge of jumper switch
JUMPER_SAFE = False
# Continues after the obstacle is no more
RESTART_AFTER_OBS_CLEAR = False
# Pretty self explanatory
LIDAR_DETECT_RADIUS = 450
# Only check with table bounds - margin for lidar
LIDAR_TABLE_MARGIN = 10
# Offset to the border of the table
BORDER_SETUP_OFFSET = 35
# Time to wait between commands
INST_WAIT = 0.3
# ===========================
# We start off at the bottom left or right corner of the table facing forwards
# So the X is unchanged but Y is flipped when we are on the bottom right, so Yellow team
SIDE_DIR = 1 if BLUE_SIDE else -1
START_X = SIDE_DIR * (handlers.ROBOT_WIDTH - handlers.ENCODER_OFFSET_TO_FRONT) + (
0 if BLUE_SIDE else handlers.TABLE_LENGTH)
START_Y = BORDER_SETUP_OFFSET + handlers.ROBOT_LENGTH / 2.0
START_THETA = 0 if BLUE_SIDE else math.radians(180)
# Example scenario
class CustomScenario(handlers.Scenario):
def play(self):
st = time.time()
#self.move(275-(ROBOT_LENGTH-ARM_OFFSET_TO_FRONT), 0)
self.move(215)
for i in range(3):
self.arm_deploy(not BLUE_SIDE, True)
self.arm_turn(not BLUE_SIDE, SIDE_DIR * 90)
self.add_score(5)
self.arm_deploy(not BLUE_SIDE, False, blocking=False)
if i != 2:
self.move(220)
self.move(550)
for i in range(3):
self.arm_deploy(not BLUE_SIDE, True)
self.arm_turn(not BLUE_SIDE, SIDE_DIR * 90)
self.add_score(5)
self.arm_deploy(not BLUE_SIDE, False, blocking=False)
if i != 2:
self.move(220)
self.move(250)
self.move(-250)
self.turn(SIDE_DIR * 60)
self.move(855)
self.turn(SIDE_DIR * (-60))
self.move(550)
self.asserv.stop()
self.add_score(10)
print(f"Running {'Blue' if BLUE_SIDE else 'Yellow'} side scenario.")
asserv = comm.make_asserv()
action = comm.make_action()
scenar = CustomScenario(asserv, action, START_X, START_Y, START_THETA, INST_WAIT, JUMPER_SAFE,
LIDAR_ENABLE, RESTART_AFTER_OBS_CLEAR, LIDAR_DETECT_RADIUS, LIDAR_TABLE_MARGIN)
scenar.run()