-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot1.py
More file actions
60 lines (50 loc) · 2.23 KB
/
robot1.py
File metadata and controls
60 lines (50 loc) · 2.23 KB
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
import utils
from utils import Position as Position
from rcj_soccer_robot import RCJSoccerRobot, TIME_STEP
class MyRobot1(RCJSoccerRobot):
def run(self):
self.transmitter = utils.Transmitter(self)
self.ball_log = utils.Manage_log(200)
self.robot_log = utils.Manage_log(20)
self.move = utils.Move(self.robot_log, self.ball_log)
self.mode = "goalkeeper" # or captain
self.init = False
while self.robot.step(TIME_STEP) != -1:
if self.is_new_data():
teamData = self.transmitter.getData()
gps_data = self.get_gps_coordinates()
position = Position(
gps_data[0], gps_data[1], self.get_compass_heading())
if self.is_new_ball_data():
ball_data = self.get_new_ball_data()
my_ball_pos = utils.get_ballpos(
position, ball_data["direction"][1], ball_data["direction"][0], ball_data["strength"])
else:
ball_data = None
my_ball_pos = None
ball_pos = my_ball_pos
if (self.init == False):
"""
teamcolor: -1 blue
1 yellow
"""
if (position.y >= 0):
teamcolor = -1
else:
teamcolor = 1
self.init = True
if ball_pos == None:
for i in teamData.values():
if i["ballpos"] != None:
ball_pos = i["ballpos"]
self.ball_log.set_data(ball_pos)
if self.mode == "goalkeeper":
motorOut = self.move.goalkeeper(
position, self.ball_log.get_PrePos(), teamcolor)
elif self.mode == "captain":
motorOut = self.move.captain(
position, self.ball_log.get_PrePos(), teamcolor)
self.left_motor.setVelocity(motorOut[0])
self.right_motor.setVelocity(motorOut[1])
self.transmitter.sendData(
self.player_id, position, my_ball_pos)