Skip to content

Commit 5adda7e

Browse files
committed
fix RL weird errors
1 parent 987e39c commit 5adda7e

File tree

8 files changed

+133
-43
lines changed

8 files changed

+133
-43
lines changed

docker/runner/docker-compose.yml

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3'
2-
31
services:
42

53
roboteam_primary_ai:
@@ -225,4 +223,24 @@ services:
225223
- ./ssl-game-controller-config:/config
226224
- ./ssl-game-controller-data:/data
227225
command: -address :8081
228-
profiles: ["simulator","diff","game", "RL"]
226+
profiles: ["simulator","diff","game", "RL"]
227+
228+
simulator:
229+
image: ${SUMATRA_IMAGE_SIMULATOR:-sumatra:latest}
230+
command: "-hl --moduli sim_server --autoRef --maxSpeed --initialCommand PREPARE_KICKOFF_BLUE --waitForAis --playingTime ${SUMATRA_TARGET_STAGE_TIME:-0} --timeout ${SUMATRA_TIMEOUT:-0} ${SUMATRA_SIMULATOR_ADDITIONAL_ARGS:-}"
231+
user: "${USER_ID:-1000}:${GROUP_ID:-1000}"
232+
volumes:
233+
- "./temp/${PROJECT_NAME}/simulator/build:/Sumatra/data"
234+
- "./temp/${PROJECT_NAME}/simulator/data:/Sumatra/data"
235+
networks:
236+
- default
237+
profiles: ["RL"]
238+
239+
ai-blue:
240+
image: ${SUMATRA_IMAGE_BLUE:-sumatra:latest}
241+
command: "-hl --moduli sim_client --host simulator --aiBlue ${SUMATRA_AI_ADDITIONAL_ARGS:-}"
242+
user: "${USER_ID:-1000}:${GROUP_ID:-1000}"
243+
environment:
244+
- SUMATRA_INFLUX_DB_URL=${SUMATRA_INFLUX_DB_URL:-http://influxdb:8086}
245+
- SUMATRA_INFLUX_DB_PASSWORD=${SUMATRA_INFLUX_DB_PASSWORD:-}
246+
- SUMATRA_INFLUX_DB_USERNAME=${SUMATRA_INFLUX_DB_USERNAME:-}

docker/runner/ssl-game-controller-config/state-store.json.stream

+10-16
Large diffs are not rendered by default.

roboteam_ai/src/RL/README.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Nova AI
22

3-
RL implementation to swap out the play system
3+
RL implementation to swap out the play system. Current goal is to make the role division dynamic.
44

55
## Features
66

@@ -12,7 +12,22 @@ RL implementation to swap out the play system
1212

1313

1414
## Explanation .py scripts
15-
- getRefereeState.py gets the state of the referee
1615
- GetState.py gets a combined state and contains 2 functions, one to get the ball position and one to get robot position
1716
- sentActionCommand sends a command using proto to the legacy AI system
1817
- teleportBall.py to tp the ball to a location we can define in our environment
18+
19+
20+
## High-level RL explanation
21+
22+
# Loop
23+
Agent receives a state in the form of where all the robots are, if we are dribbling and where the ball is.
24+
25+
26+
Every loop the game needs to be reset. This means resetting:
27+
- Time
28+
- Current stage
29+
-
30+
31+
Also when a ball placement happens, we need to extract the designated position and teleport the ball there for faster simulation.
32+
33+

roboteam_ai/src/RL/getState.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# Make sure to go back to the main roboteam directory
1414
current_dir = os.path.dirname(os.path.abspath(__file__))
15-
roboteam_path = os.path.abspath(os.path.join(current_dir, "..", "..", "..", ".."))
15+
roboteam_path = os.path.abspath(os.path.join(current_dir, "..", "..", ".."))
1616

1717
# Add to sys.path
1818
sys.path.append(roboteam_path)

roboteam_ai/src/RL/resetReferee.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
import sys
3+
import os
4+
from google.protobuf.timestamp_pb2 import Timestamp
5+
from google.protobuf.duration_pb2 import Duration
6+
7+
# Make sure to go back to the main roboteam directory
8+
current_dir = os.path.dirname(os.path.abspath(__file__))
9+
roboteam_path = os.path.abspath(os.path.join(current_dir, "..", "..", ".."))
10+
11+
# Add to sys.path
12+
sys.path.append(roboteam_path)
13+
14+
# Assuming you have generated Python classes from your .proto files
15+
from roboteam_networking.proto_CI.ssl_gc_state_pb2 import State, GameState, Command
16+
from roboteam_networking.proto_CI.ssl_gc_referee_message_pb2 import Referee
17+
from roboteam_networking.proto_CI.ssl_gc_common_pb2 import Team
18+
19+
20+
def reset_game_state_blue_kickoff():
21+
# Create a new State message
22+
new_state = State()
23+
24+
# Set the GameState to KICKOFF for Blue team
25+
new_state.game_state.type = GameState.KICKOFF
26+
new_state.game_state.for_team = Team.BLUE
27+
28+
# Set the current command to KICKOFF for Blue team
29+
new_state.command.type = Command.KICKOFF
30+
new_state.command.for_team = Team.BLUE
31+
32+
# Set Blue team as the first kickoff team
33+
new_state.first_kickoff_team = Team.BLUE
34+
35+
# Reset stage and timers
36+
new_state.stage = Referee.NORMAL_FIRST_HALF
37+
new_state.stage_time_elapsed.Clear()
38+
new_state.stage_time_left.Clear()
39+
new_state.match_time_start.GetCurrentTime() # Set to current time
40+
41+
# Reset team states
42+
for team, is_blue in [("Blue", True), ("Yellow", False)]:
43+
team_info = new_state.team_state[team]
44+
team_info.name = team
45+
team_info.goals = 0
46+
team_info.yellow_cards.clear()
47+
team_info.red_cards.clear()
48+
team_info.timeouts_left = 4 # Or appropriate number
49+
team_info.timeout_time_left.CopyFrom(Duration(seconds=300)) # 5 minutes
50+
team_info.ball_placement_failures = 0
51+
team_info.on_positive_half = is_blue # Blue on positive half, Yellow on negative
52+
53+
return new_state
54+
55+
# Usage
56+
new_state_change = reset_game_state_blue_kickoff()
57+
# Use this new_state_change to update your game controller state

roboteam_ai/src/RL/sentActionCommand.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Make sure to go back to the main roboteam directory
66
current_dir = os.path.dirname(os.path.abspath(__file__))
7-
roboteam_path = os.path.abspath(os.path.join(current_dir, "..", "..", "..", ".."))
7+
roboteam_path = os.path.abspath(os.path.join(current_dir, "..", "..", ".."))
88

99
# Add to sys.path
1010
sys.path.append(roboteam_path)

roboteam_ai/src/RL/teleportBall.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# Make sure to go back to the main roboteam directory
1515
current_dir = os.path.dirname(os.path.abspath(__file__))
16-
roboteam_path = os.path.abspath(os.path.join(current_dir, "..", "..", "..", ".."))
16+
roboteam_path = os.path.abspath(os.path.join(current_dir, "..", "..", ".."))
1717

1818
# Add to sys.path
1919
sys.path.append(roboteam_path)

roboteam_networking/proto_CI/test.py

+25-19
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
import asyncio
22
import websockets
33
from google.protobuf.json_format import MessageToJson, Parse
4-
from ssl_gc_api_pb2 import Input, Output
4+
from ssl_gc_api_pb2 import Input
5+
from ssl_gc_change_pb2 import Change
6+
from ssl_gc_common_pb2 import Team
7+
from ssl_gc_state_pb2 import Command
58

6-
async def reset_match(uri='ws://localhost:8081/api/control'):
9+
async def reset_and_stop_match(uri='ws://localhost:8081/api/control'):
710
async with websockets.connect(uri) as websocket:
8-
# Create an Input message
9-
input_message = Input()
10-
input_message.reset_match = True
11-
12-
# Convert the message to JSON
13-
json_message = MessageToJson(input_message)
14-
15-
# Send the message
16-
await websocket.send(json_message)
17-
print(f"Sent reset command: {json_message}")
11+
12+
# Step 1: Reset the match
13+
reset_message = Input(reset_match=True)
14+
await websocket.send(MessageToJson(reset_message))
15+
response = await websocket.recv()
1816

19-
# Wait for a response
17+
# Step 2: Send STOP command
18+
stop_message = Input(
19+
change=Change(
20+
new_command_change=Change.NewCommand(
21+
command=Command(
22+
type=Command.Type.STOP,
23+
for_team=Team.UNKNOWN
24+
)
25+
)
26+
)
27+
)
28+
await websocket.send(MessageToJson(stop_message))
29+
print(f"Sent STOP command: {MessageToJson(stop_message)}")
2030
response = await websocket.recv()
21-
output_message = Parse(response, Output())
22-
print(f"Received response: {MessageToJson(output_message)}")
2331

24-
async def main():
25-
await reset_match()
26-
print("Reset command sent to SSL Game Controller")
32+
print("Reset and STOP commands sent to SSL Game Controller")
2733

2834
if __name__ == "__main__":
29-
asyncio.run(main())
35+
asyncio.run(reset_and_stop_match())

0 commit comments

Comments
 (0)