Skip to content

Commit

Permalink
reduced rate, fixed ball placement
Browse files Browse the repository at this point in the history
  • Loading branch information
aelhabashy committed Nov 7, 2024
1 parent b68af28 commit d178436
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
27 changes: 23 additions & 4 deletions roboteam_ai/src/RL/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,28 @@ def __init__(self):

def check_ball_placement(self):
"""
Function to teleport the ball to the designated position for ball placement if necessary
Function to teleport the ball to the designated position for ball placement if necessary.
"""
# Get the current referee state
referee_state, referee_info = get_referee_state() # Assuming get_referee_state() is in scope

# Extract the command from the referee state
self.ref_command = referee_info['command']
print("ref command", self.ref_command)


# If ref gives command BALL_PLACEMENT_US OR BALL_PLACEMENT_THEM
if (self.ref_command == "BALL_PLACEMENT_US") or ("BALL_PLACEMENT_THEM"):
teleport_ball(self.x, self.y) # Teleport the ball to the designated location

if (self.ref_command == 16 or self.ref_command == 17):
referee_state, referee_data = get_referee_state()

if referee_data["designated_position"]is not None:
self.x, self.y = referee_data["designated_position"]["x"]/1000, referee_data["designated_position"]["y"]/1000

# Teleport the ball to the designated location
teleport_ball(self.x, self.y)
else:
print("No designated position provided in referee state.")


def get_referee_state(self):
"""
Expand Down Expand Up @@ -171,8 +186,12 @@ def step(self, action):
observation_space,_ = self.get_observation()

done = self.is_terminated() # If task is completed (a goal was scored)
if(done):
reset()
truncated = self.is_truncated() # Determine if the episode was truncated, too much time or a yellow card

time.sleep(0.25) # DELAY FOR STEPS (ADJUST LATER)

return observation_space, reward, done, truncated, {}


Expand Down
14 changes: 12 additions & 2 deletions roboteam_ai/src/RL/src/getState.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,22 @@ def get_referee_state():
"ball_placement_failures": blue_team_info.ball_placement_failures
}

# Return both the raw referee_state object and a dictionary of extracted details
if referee_state.HasField('designated_position'):
designated_position = {
"x": referee_state.designated_position.x,
"y": referee_state.designated_position.y
}
else:
designated_position = None

# Return both the raw referee_state object and a dictionary of extracted details
return referee_state, {
"yellow_team": yellow_team_data,
"blue_team": blue_team_data,
"stage": referee_state.stage,
"command": referee_state.command
"command": referee_state.command,
"designated_position": designated_position
}

except DecodeError:
Expand Down Expand Up @@ -204,4 +214,4 @@ def get_referee_state():
print(f"Score: {blue_team['score']}, Red Cards: {blue_team['red_cards']}, Yellow Cards: {blue_team['yellow_cards']}")
print(f"Fouls: {blue_team['fouls']}, Ball Placement Failures: {blue_team['ball_placement_failures']}")

get_ball_state()
print(get_referee_state())
4 changes: 2 additions & 2 deletions roboteam_ai/src/RL/src/teleportBall.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

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

# Add to sys.path
sys.path.append(roboteam_path)
Expand Down Expand Up @@ -50,5 +50,5 @@ def teleport_ball(x, y, z=0.0):

if __name__ == "__main__":

teleport_ball(400, 4000)
teleport_ball(5.000, 4.300, 0.0)
print("Script execution completed")

0 comments on commit d178436

Please sign in to comment.