-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategy.py
150 lines (136 loc) · 6.3 KB
/
strategy.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from numpy import pi,array_equal,array,tan
from simClasses import Ball,Robot,Target,Obstacle
import action
from time import sleep
class StrategyTesting:
def __init__(self):
self.ball=Ball()
self.redRob=Robot()
self.greenRob=Robot()
self.pinkRob=Robot()
self.arrayFunctions = [self.pinkRob, self.redRob, self.greenRob] # [Goalkeeper, Defender, Attacker]
def simConnect(self,clientID):
self.clientID=clientID
self.ball.simConnect(self.clientID,'ball')
self.redRob.simConnect(self.clientID,'soccerRob_pos','soccerRob_teamMarker','soccerRob_IDMarker','leftMotor','rightMotor')
self.greenRob.simConnect(self.clientID,'soccerRob_pos#0','soccerRob_teamMarker#0','soccerRob_IDMarker#0','leftMotor#0','rightMotor#0')
self.pinkRob.simConnect(self.clientID,'soccerRob_pos#1','soccerRob_teamMarker#1','soccerRob_IDMarker#1','leftMotor#1','rightMotor#1')
if self.redRob.simCheckConnection():
print('RedRob ready to play!')
else:
print('RedRob not found...')
if self.greenRob.simCheckConnection():
print('GreenRob ready to play!')
else:
print('GreenRob not found...')
if self.pinkRob.simCheckConnection():
print('pinkRob ready to play!')
else:
print('pinkRob not found...')
if self.ball.simCheckConnection():
print('Ball ready to play!\n')
else:
print('Ball not found...\n')
self.redRob.simGetPose('infLeft_cornor')
self.greenRob.simGetPose('infLeft_cornor')
self.pinkRob.simGetPose('infLeft_cornor')
self.ball.simGetPose('infLeft_cornor')
i=0
while self.redRob.xPos == 0 or self.greenRob.xPos == 0 or self.pinkRob.xPos == 0 or self.ball.xPos == 0 :
self.redRob.simGetPose('infLeft_cornor')
self.greenRob.simGetPose('infLeft_cornor')
self.pinkRob.simGetPose('infLeft_cornor')
self.ball.simGetPose('infLeft_cornor')
i+=1
print(i,'tentativas até pegar as posições\n')
def play(self):
self.arrayFunctions[0].simGetPose('infLeft_cornor')
self.arrayFunctions[1].simGetPose('infLeft_cornor')
self.arrayFunctions[2].simGetPose('infLeft_cornor')
self.ball.simGetPose('infLeft_cornor')
action.screenOutBall(self.arrayFunctions[0],self.ball,10,False,90,30)
arraySideCrossing, flagCrossing = action.verifyCrossing(self.arrayFunctions[2], self.ball, True, self.arrayFunctions[1], self.arrayFunctions[0])
if(not flagCrossing):#If the robot not crossed
action.directGoal(self.arrayFunctions[2], self.ball, True, self.arrayFunctions[1], self.arrayFunctions[0])
action.protectGoal(self.arrayFunctions[1],self.ball,50)
else:
action.ballCrossing(self.arrayFunctions[2], self.ball, arraySideCrossing, True, self.arrayFunctions[1], self.arrayFunctions[0])
self.arrayFunctions = action.positionChange(self.arrayFunctions, self.ball, arraySideCrossing)
class DrawRedDragons:
def __init__(self):
self.ball=Ball()
self.redRob=Robot()
self.greenRob=Robot()
self.pinkRob=Robot()
def simConnect(self,clientID):
self.clientID=clientID
self.ball.simConnect(self.clientID,'ball')
self.redRob.simConnect(self.clientID,'soccerRob_pos','soccerRob_teamMarker','soccerRob_IDMarker','leftMotor','rightMotor')
self.greenRob.simConnect(self.clientID,'soccerRob_pos#0','soccerRob_teamMarker#0','soccerRob_IDMarker#0','leftMotor#0','rightMotor#0')
self.pinkRob.simConnect(self.clientID,'soccerRob_pos#1','soccerRob_teamMarker#1','soccerRob_IDMarker#1','leftMotor#1','rightMotor#1')
if self.redRob.simCheckConnection():
print('RedRob ready to play!')
else:
print('RedRob not found...')
if self.greenRob.simCheckConnection():
print('GreenRob ready to play!')
else:
print('GreenRob not found...')
if self.pinkRob.simCheckConnection():
print('pinkRob ready to play!')
else:
print('pinkRob not found...')
if self.ball.simCheckConnection():
print('Ball ready to play!\n')
else:
print('Ball not found...\n')
self.redRob.simGetPose('infLeft_cornor')
self.greenRob.simGetPose('infLeft_cornor')
self.pinkRob.simGetPose('infLeft_cornor')
self.ball.simGetPose('infLeft_cornor')
i=0
while self.redRob.xPos == 0 or self.greenRob.xPos == 0 or self.pinkRob.xPos == 0 or self.ball.xPos == 0 :
self.redRob.simGetPose('infLeft_cornor')
self.greenRob.simGetPose('infLeft_cornor')
self.pinkRob.simGetPose('infLeft_cornor')
self.ball.simGetPose('infLeft_cornor')
i+=1
print(i,'tentativas até pegar as posições\n')
def play(self):
path=array([[30,30,pi/2],
[30,100,pi/2],
[55,80,-pi/2],
[30,60,pi],
[60,30,0],
[82,30,0],
[93,45,pi/2],
[82,56,pi],
[71,45,-pi/2],
[82,30,0],
[123,31,0],
[140,47,pi/2],
[123,64,pi],
[106,47,-pi/2],
[123,31,0],
[140,47,pi/2],
[140,100,pi/2],
[140,30,-pi/2]])
i=0
while i<=len(path):
self.redRob.simGetPose('infLeft_cornor')
self.greenRob.simGetPose('infLeft_cornor')
self.pinkRob.simGetPose('infLeft_cornor')
action.holdPosition(self.redRob,float(path[i,0])-10,float(path[i,1]),float(path[i,2]))
action.holdPosition(self.pinkRob,130,20,pi/2)
action.holdPosition(self.greenRob,20,110,-pi/2)
if self.redRob.arrive():
i+=1
if i==len(path):
action.stop(self.redRob)
action.stop(self.pinkRob)
action.stop(self.greenRob)
exit()
if self.pinkRob.arrive():
action.sweepBall(self.pinkRob)
if self.greenRob.arrive():
action.sweepBall(self.greenRob)