Skip to content

Commit 2f4e217

Browse files
committed
demo version
1 parent 837cdd5 commit 2f4e217

File tree

2 files changed

+8
-46
lines changed

2 files changed

+8
-46
lines changed

main.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def main():
2727
message_queue = queue.SimpleQueue()
2828

2929
referee_receiver = RefereeMessageReceiver(message_queue, debug=False)
30-
vision_receiver = VisionDataReceiver(message_queue, debug=False)
31-
decision_maker = StartUpController(game, debug=False)
30+
vision_receiver = VisionDataReceiver(message_queue)
31+
decision_maker = StartUpController(game)
3232

3333
# Start the data receiving in separate threads
3434
vision_thread = threading.Thread(target=vision_receiver.pull_game_data)
@@ -42,19 +42,10 @@ def main():
4242
vision_thread.start()
4343
referee_thread.start()
4444

45-
<<<<<<< HEAD
4645
TIME = 0.5
4746
FRAMES_IN_TIME = round(60 * TIME)
48-
=======
49-
begin = time.time()
50-
51-
TIME = 0.5
52-
FRAMES_IN_TIME = round(60 * TIME)
53-
54-
>>>>>>> 05bd7f6 (Change RefereeCommand and Stage to enum class)
5547
frames = 0
5648

57-
begin = time.time()
5849
try:
5950
logger.debug("LOCATED BALL")
6051
logger.debug(f"Predicting robot position with {TIME} seconds of motion")
@@ -66,34 +57,14 @@ def main():
6657
if message_type == MessageType.VISION:
6758
frames += 1
6859
game.add_new_state(message)
69-
<<<<<<< HEAD
7060
actual = game.records[-1] # JUST FOR TESTING - don't do this irl
71-
=======
72-
# access current state data
73-
# print(
74-
# game.current_state.yellow_robots[0].x,
75-
# game.current_state.yellow_robots[0].y,
76-
# )
77-
78-
# access game records from -x number of frames ago
79-
# print(game.records[-1].ts, game.records[-1].ball[0].x)
80-
81-
actual = game._records[-1] # JUST FOR TESTING - don't do this irl
82-
83-
>>>>>>> 05bd7f6 (Change RefereeCommand and Stage to enum class)
8461
if (
8562
len(predictions) >= FRAMES_IN_TIME
8663
and predictions[-FRAMES_IN_TIME] != None
8764
):
88-
<<<<<<< HEAD
8965
logger.debug(
9066
"Ball prediction inaccuracy delta (cm): "
9167
+ "{:.20f}".format(
92-
=======
93-
print(
94-
"Ball prediction inaccuracy delta (cm): ",
95-
"{:.20f}".format(
96-
>>>>>>> 05bd7f6 (Change RefereeCommand and Stage to enum class)
9768
100
9869
* math.sqrt(
9970
(
@@ -107,7 +78,6 @@ def main():
10778
)
10879
** 2
10980
)
110-
<<<<<<< HEAD
11181
)
11282
)
11383
for i in range(6):
@@ -152,21 +122,11 @@ def main():
152122
)
153123
)
154124
)
155-
=======
156-
),
157-
)
158-
# for i in range(6):
159-
# print(f"Blue robot {i} prediction inaccuracy delta (cm): ", '{:.20f}'.format(100 * math.sqrt((actual.blue_robots[i].x - predictions[-FRAMES_IN_TIME].blue_robots[i].x)**2 + (actual.blue_robots[i].y - predictions[-FRAMES_IN_TIME].blue_robots[i].y)**2)))
160-
# for i in range(6):
161-
# print(f"Yellow robot {i} prediction inaccuracy delta (cm): ", '{:.20f}'.format(100 * math.sqrt((actual.yellow_robots[i].x - predictions[-FRAMES_IN_TIME].yellow_robots[i].x)**2 + (actual.yellow_robots[i].y - predictions[-FRAMES_IN_TIME].yellow_robots[i].y)**2)))
162-
>>>>>>> 05bd7f6 (Change RefereeCommand and Stage to enum class)
163125

164126
predictions.append(game.predict_frame_after(TIME))
165127

166128
elif message_type == MessageType.REF:
167129
game.add_new_referee_data(message)
168-
print(game.last_command)
169-
print(game.stage_time_left)
170130

171131
decision_maker.make_decision()
172132

team_controller/src/utils/network_utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
logger = logging.getLogger(__name__)
1010

11+
1112
def setup_socket(
1213
sock: socket.socket, address: Tuple[str, int], bind_socket: bool = False
1314
) -> socket.socket:
@@ -40,7 +41,6 @@ def setup_socket(
4041
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
4142

4243
# sock.settimeout(0.005) # Set timeout to 1 frame period (60 FPS)
43-
logger.info(
4444
logging.info(
4545
"Socket setup completed with address %s and bind_socket=%s",
4646
address,
@@ -79,7 +79,9 @@ def receive_data(sock: socket.socket) -> Optional[bytes]:
7979
return None
8080

8181

82-
def send_command(address: Tuple[str, int], command: object, is_sim_robot_cmd: bool = False) -> Optional[bytes]:
82+
def send_command(
83+
address: Tuple[str, int], command: object, is_sim_robot_cmd: bool = False
84+
) -> Optional[bytes]:
8385
"""
8486
Sends a command to the specified address over a UDP socket.
8587
@@ -89,8 +91,8 @@ def send_command(address: Tuple[str, int], command: object, is_sim_robot_cmd: bo
8991
is_sim_robot_cmd (bool): If True, the function will attempt to receive a response from the server.
9092
9193
Returns:
92-
Optional[bytes]: The data received, or None if no data is received or if an error occurs.
93-
94+
Optional[bytes]: The data received, or None if no data is received or if an error occurs.
95+
9496
This function creates a temporary UDP socket, serializes the command, and sends it to the specified address.
9597
If the command being sent is a RobotControl packet there will be a response packet which will be received.
9698
Errors during serialization or socket operations are logged, with specific handling if the `SerializeToString`

0 commit comments

Comments
 (0)