Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OldUser101 Testing #50

Merged
merged 11 commits into from
Dec 7, 2024
2 changes: 1 addition & 1 deletion robot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
MARKER,
BASE_MARKER,
ARENA_MARKER,
POTATO_MARKER,
TARGET_MARKER,
MARKER_TYPE,
TEAM
)
Expand Down
4 changes: 2 additions & 2 deletions robot/apriltags3.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import numpy as np
import scipy.spatial.transform as transform

from robot.game_config import MARKER
from robot.game_config import MARKER, MARKER_TYPE


######################################################################
Expand Down Expand Up @@ -435,7 +435,7 @@ def detect(self, img, estimate_tag_pose=False, camera_params=None):
if camera_params is None:
raise ValueError(
"camera_params must be provided to detect if estimate_tag_pose is set to True")
tag_size = MARKER(tag.id).size
tag_size = MARKER.get_size(tag.id)

camera_fx, camera_fy, camera_cx, camera_cy = [
c for c in camera_params]
Expand Down
4 changes: 2 additions & 2 deletions robot/game_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
MARKER,
MARKER_TYPE,
ARENA_MARKER,
POTATO_MARKER,
TARGET_MARKER,
BASE_MARKER,
)
from .startup_poems import POEM_ON_STARTUP
Expand All @@ -19,7 +19,7 @@
__all__ = (
"TEAM",
"MARKER",
"POTATO_MARKER",
"TARGET_MARKER",
"MARKER_TYPE",
"BASE_MARKER",
"ARENA_MARKER",
Expand Down
57 changes: 37 additions & 20 deletions robot/game_config/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import typing

from .teams import TEAM
#from teams import TEAM

"""
Hiiii!
Expand All @@ -13,20 +14,23 @@
Byee!
- Holly (2023-2024)


Don't know what to say. - Nathan Gill (2024 - 2025)
No semi-colons please - Scott Wilson (2024 - 2025)
[Put your future messages here]
"""

class MARKER_TYPE(enum.Enum): # Keep something like this to determine if a marker is a wall or not.
POTATO = enum.auto()
TARGET = enum.auto()
ARENA = enum.auto()


class BASE_MARKER: # Base marker class that POTATO_MARKER and ARENA_MARKER derive from.
team_marker_colors: dict = { # Colour definitions for each team defined in TEAMS
TEAM.RUSSET: (255, 64, 0), # RED
TEAM.SWEET: (255, 255, 32), # YELLOW
TEAM.MARIS_PIPER: (50,255,0), # GREEN
TEAM.PURPLE: (255, 32, 255), # PURPLE
TEAM.RUBY: (0, 0, 255), # RED
TEAM.JADE: (0, 255, 0), # GREEN
TEAM.TOPAZ: (0, 255, 255), # YELLOW
TEAM.DIAMOND: (255, 0, 0), # BLUE
}

def __init__(
Expand All @@ -47,10 +51,10 @@ def __repr__(self) -> str:
@property
def bounding_box_color(self) -> tuple:
if self.type == MARKER_TYPE.ARENA: # If it is a wall
return tuple(reversed((125, 249, 225))) # Turquoise
elif self.owning_team==TEAM.ARENA: # If it is a Hot Potato (game object owned by ARENA)
return tuple(reversed((225, 249, 125))) # Turquoise
elif self.owning_team==TEAM.ARENA: # If it is a Sheep (game object owned by ARENA)
return tuple(reversed((255,255,255))) # White
else: # If it is a Jacket Potato (game object owned by a team.)
else: # If it is a Jewel (game object owned by a team.)
return tuple(reversed(self.team_marker_colors[self.owning_team])) # Picks the team colour from above

class ARENA_MARKER(BASE_MARKER): # Not much going on here. This represents a wall.
Expand All @@ -61,17 +65,24 @@ def __repr__(self) -> str:
return f"<Marker(ARENA)/>"


class POTATO_MARKER(BASE_MARKER): # This is a game object rather than a wall. Add properties you want to keep track of
class TARGET_MARKER(BASE_MARKER): # This is a game object rather than a wall. Add properties you want to keep track of
def __init__(
self, id: int, owner: TEAM
) -> None:
super().__init__(id, MARKER_TYPE.POTATO)
super().__init__(id, MARKER_TYPE.TARGET)
self.owning_team = owner

def __repr__(self) -> str:
return f"<Marker(POTATO) owning_team={self.owning_team} />"
return f"<Marker(TARGET) owning_team={self.owning_team} />"

class MARKER(BASE_MARKER): # This is literally just how the code gets the different marker types.
@staticmethod
def get_size(id: int):
tg = MARKER.by_id(id)
if tg.owning_team == TEAM["ARENA"]:
return 0.2
return 0.08

@staticmethod
def by_id(id: int, team: typing.Union[TEAM, None] = None) -> BASE_MARKER: # team is currently unused, but it is referenced throughout the code. It is the team of the robot I believe (check this)
"""
Expand All @@ -97,14 +108,20 @@ def by_id(id: int, team: typing.Union[TEAM, None] = None) -> BASE_MARKER: # team
there). In practice these markers start at 100.
"""

ARENA_WALL_LOWER_ID = 40
if id >= ARENA_WALL_LOWER_ID:
if id > 99:
return ARENA_MARKER(id)

wrappingId = id % 20 # Make sure that the ID range wraps after 20 values.
if wrappingId<4: # If it is a Jacket Potato (has a team)
owning_team = TEAM[f"T{wrappingId}"] # Set to the corresponding TEAM enum.
else: # If it is a Hot Potato (Has no team)
owning_team = TEAM["ARENA"]

return POTATO_MARKER(id, owning_team)
if id < 24:
owning_team = TEAM["ARENA"]
elif id == 30 or id == 31 or id == 53:
owning_team = TEAM["T3"]
elif id == 28 or id == 29 or id == 52:
owning_team = TEAM["T2"]
elif id == 26 or id == 27 or id == 51:
owning_team = TEAM["T1"]
elif id == 24 or id == 25 or id == 50:
owning_team = TEAM["T0"]
else:
raise Exception("AHHHHHH!")

return TARGET_MARKER(id, owning_team)
23 changes: 13 additions & 10 deletions robot/game_config/startup_poems.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from random import randint

class POEM_ON_STARTUP:
## These jokes are terrible, (ChatGPT 4o Generated)
jokes = [
"Why did the potato cross the road? \
He saw a fork up ahead.",
"What do you say to a baked potato that's angry? \
Anything you like, just butter it up.",
"Funny Potato Joke",
"Farm Facts: There are around 5000 different varieties of potato",
"Farm Facts: Potatoes were first domesticated in Peru around 4500 years ago around Lake Titicaca",
"Farm Facts: The word potato originates from the Taino \"batata\", meaning sweet potato.",
"Farm Facts: China is the leading producer of potatoes, with 94.3 million tonnes produced in 2021",
"Farm Facts: The maximum theoretical voltage "
"Why don't dragons tell secrets? \
Because they always breathe fire!",
"Why did the ruby go to school? \
To become a little more polished!",
"Why do sheep make terrible detectives? \
Because they always follow the herd!",
"What's a dragon's favourite type of exercise? \
Flame-ups!",
"What did the diamond say to the ruby at the party? \
You're looking radiant tonight!",
"Why was the sheep so quiet? \
Because it was feeling a little wool-gathered!",
]

@staticmethod
Expand Down
20 changes: 11 additions & 9 deletions robot/game_config/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
that the school will be competing as.
"""
class TEAM(enum.Enum):
RUSSET = "Solanum Tuberosum 'Ranger Russet'" # This matches T0, for example.
SWEET = "Ipomoea batatas"
MARIS_PIPER = "Solanum Tuberosum 'Maris Piper'"
PURPLE = "Solanum Tuberosum 'Vitolette'"
ARENA = "HOTTTTT!"

## These easter eggs are locations that the corresponding gems were found (ChatGPT 4o Generated)
RUBY = "Mogok Valley, Myanmar (Burma)" # This matches T0, for example.
JADE = "Hetian (Hotan), Xinjiang, China"
TOPAZ = "St. John's Island (Zabargad Island), Egypt"
DIAMOND = "Golconda, India"
ARENA = "Nothing!"
# There is no T value for ARENA, so there is no way that the assignment of team to a marker can accidentally assign ARENA if the logic goes wrong.

T0 = "Solanum Tuberosum 'Ranger Russet'"
T1 = "Ipomoea batatas"
T2 = "Solanum Tuberosum 'Maris Piper'"
T3 = "Solanum Tuberosum 'Vitolette'"
T0 = "Mogok Valley, Myanmar (Burma)"
T1 = "Hetian (Hotan), Xinjiang, China"
T2 = "St. John's Island (Zabargad Island), Egypt"
T3 = "Golconda, India"

6 changes: 3 additions & 3 deletions robot/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,14 @@ def _draw_bounding_box(self, frame, detections):
"""
polygon_is_closed = True
for detection in detections:
marker_info = MARKER(detection.id, self.zone)
marker_info = MARKER.by_id(detection.id, self.zone)
marker_info_colour = marker_info.bounding_box_color
marker_code = detection.id

# The reverse is because OpenCV expects BGR but we use RGB
colour = reversed(marker_info_colour
colour = tuple(reversed(marker_info_colour
if marker_info_colour is not None
else DEFAULT_BOUNDING_BOX_COLOUR)
else DEFAULT_BOUNDING_BOX_COLOUR))

# need to have this EXACT integer_corners syntax due to opencv bug
# https://stackoverflow.com/questions/17241830/
Expand Down
2 changes: 1 addition & 1 deletion robot/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self,
start_enable_5v = True,
):

self.zone = game_config.TEAM.RUSSET
self.zone = game_config.TEAM.RUBY
self.mode = "competition"
self._max_motor_voltage = max_motor_voltage

Expand Down
Loading