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

Pre-competition rover.py refactor 2: Electric Boogaloo #9

Draft
wants to merge 43 commits into
base: HappySad
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
14445f6
feat(config.py): add `Config` type
onkoe May 22, 2024
d4f88a8
feat(communication.py): initial implementation
onkoe May 22, 2024
708ed97
feat(navigation): ok yeah i refactored location.py
onkoe May 23, 2024
94ce345
fix(communication.py): use more obvious arg names
onkoe May 23, 2024
cd0241f
feat(gps_controller.py): add start/stop methods
onkoe May 23, 2024
7dba736
fix(Navigation): access the GPS
onkoe May 23, 2024
803093d
feat(Navigation): include finish method
onkoe May 23, 2024
c453371
a wip commit. don’t keep in tree
onkoe May 23, 2024
78fe5f5
fix: Use Python 3.7 syntax
onkoe May 25, 2024
d7b9d0d
chore(temp): add explanation on the true bearing
onkoe May 25, 2024
8e8b4f9
chore(Config): formatting
onkoe May 25, 2024
dec5bbd
chore(main): add wheels deadlock TODO
onkoe May 25, 2024
83d5ef1
fix(Rover): use `gps_` over `swift_`
onkoe May 25, 2024
a6256c7
fix(Nav): take IP an a str, not int
onkoe May 25, 2024
5e1b716
fix(GpsControl): take swift ip as a str
onkoe May 25, 2024
d22e210
feat(GpsControl): use "true bearing" over "angle"
onkoe May 25, 2024
4312844
fix(comm.py): use Socket.extend list syntax
onkoe May 25, 2024
ea03e2c
feat(comm.py): no longer use -90 to 90 speeds
onkoe May 25, 2024
53b0c3d
feat(Comm): add `send_lights_off` method
onkoe May 25, 2024
9c7ccd3
chore: python version for rye
onkoe May 25, 2024
316eb31
feat(Coordinate): add `get_` to getter methods
onkoe May 25, 2024
d00dfd8
fix(Navigation): Python 3.7 errors
onkoe May 25, 2024
b9e46be
fix(Navigation): incorrect bearing methods
onkoe May 25, 2024
756d7ab
fix(gps_controller.py): formatting
onkoe May 25, 2024
cfd48e0
feat(tools/list_cameras.py): add opencv camera list tool
May 25, 2024
bb541d4
feat(Config): let users pass in a config path
May 25, 2024
c9de80b
feat(Communication): use `Config` to get IP/port
May 25, 2024
1276e29
feat(Communiction): return the sent bytearrays
May 25, 2024
67eba7a
refactor(GpsController): use a Process
May 26, 2024
4541a97
fix(GpsController): join the process back
May 26, 2024
18d66f4
feat(GpsController): use a Config input for constructor
May 26, 2024
2d60cf5
feat(args.py): Initial version
May 26, 2024
3d3ecaa
chore: Remove unused libs/Locationf9p.py
May 26, 2024
af1c53b
chore(list_cameras.py): remove unused import
May 26, 2024
3c5d8b4
feat(Coordinate): move to its own module
May 26, 2024
5c8c765
fix(Args): check if id is None first
May 26, 2024
34724a5
fix(Config): missed f-string lol
May 26, 2024
f8ace78
fix(ArucoTracker): use specific dict for dataclass typing
May 26, 2024
335bf3e
feat: Add `new_main.py`
May 26, 2024
245574f
feat(Rover): get config from `config.py`
May 26, 2024
e5320d3
feat(Rover): more realistic layout
May 26, 2024
76514a4
fix(Rover): imports (vscode on drugs?)
May 26, 2024
898bac9
fix(Navigation): config, queue, navigate
May 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.18
pypy@3.7.13
12 changes: 12 additions & 0 deletions explain
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
calc_bearing function: Calulates the `true bearing` for the rover

- true bearing is the bearing from North

bearing_to: This calculates the `relative bearing` between the rover and a coordinate

- This would be the difference between the rover's tru bearing and the coords true bearing
- relative bearing is the bearing between any two objects

gps_controller we need calc_bearing

navigation we need bearing_to
171 changes: 0 additions & 171 deletions libs/Locationf9p.py

This file was deleted.

92 changes: 92 additions & 0 deletions libs/args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from argparse import ArgumentParser, Namespace
from dataclasses import dataclass
from typing import Union, List
from loguru import logger

from libs.coordinate import Coordinate


@dataclass
class Args:
aruco_id: Union[int, None] # the ArUco tag ID to search for, if any
coord_file_path: str # a file that's in the format: `lat lon`, each on a new line
coordinate_list: List[Coordinate]
camera_id: int # the camera to use. defaults to 0

def __init__(self):
"""
Gets the command line arugments and updates internal state.
"""
arg_parser = ArgumentParser()

# get opencv camera id
arg_parser.add_argument(
"--camera_id",
"-c",
required=False,
default=0,
type=int,
help="The OpenCV capture device (camera) ID to use. Use `tools/camera_list.py` to determine usable values.",
)

# get the coordinate file path
arg_parser.add_argument(
"--coords",
"-f",
required=True,
type=str,
help="A file path pointing to a list of coordinates. The file should have one coordinate pair per line, in this format: `lat long`",
)

# get the aruco ID to use
arg_parser.add_argument(
"--aruco_id",
"-a",
required=False,
type=int,
help="The ArUco ID number to use from the DICT_4X4_50 list. Safe testing values are 0 and 1.",
)

# place all data into internal state
args: Namespace = arg_parser.parse_args()

self.aruco_id = args.aruco_id
if self.aruco_id is not None:
if self.aruco_id > 50 or self.aruco_id < 0:
logger.error(
f"You must pass an ArUco ID within the range: [0, 50]. You gave: `{self.aruco_id}`."
)
exit(1)

self.camera_id = args.camera_id if args.camera_id else 0

self.coord_file_path = args.coords
coordinate_list = []

with open(self.coord_file_path) as file:
for line in file:
try:
(lat_str, lon_str) = line.split(" ")

# attempt to parse the strings into two numbers
(lat, lon) = (
float(lat_str.replace("\ufeff", "")),
float(lon_str.replace("\ufeff", "")),
)

# create a `Coordinate` from the data
coordinate_list.append(Coordinate(lat, lon))
except ValueError as e:
logger.error(
f"Failed to parse given coordinate file. Failed with error: `{e}`"
)
exit(1)

file.close()
self.coordinate_list = coordinate_list
logger.info(f"The coordinates file was parsed successfully! Here's the list: {self.coordinate_list}")


pass

pass
Loading
Loading