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

initial workflow #98

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Automated Code Formatting with Black

on:
pull_request:
types: [opened]
push:
branches:
- main

jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
token: ${{ secrets.BLACK_FORMATTER_TOKEN }}

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11'

- name: Install Black
run: pip install black

- name: Format code with Black
run: black .

- name: Commit and push changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git commit -am "Format code with Black" || exit 0 # The exit 0 is used to prevent the workflow from failing if no changes are made
git push origin HEAD:${GITHUB_REF#refs/heads/}
25 changes: 20 additions & 5 deletions src/algorithm/navigation_algorithm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import heapq
import random

# import matplotlib.pyplot as plt


Expand All @@ -16,7 +17,9 @@ class AStarGrid:
:param end_y: (int) Y-coordinate of the goal position.
"""

def __init__(self, rows: int, cols: int, start_x: int, start_y: int, end_x: int, end_y: int):
def __init__(
self, rows: int, cols: int, start_x: int, start_y: int, end_x: int, end_y: int
):
self.rows = rows
self.cols = cols
self.spacing = 1.0
Expand Down Expand Up @@ -111,7 +114,16 @@ def get_neighbors(self, node: tuple) -> list:
"""
neighbors = []
row, col = node
directions = [(-1, 0), (1, 0), (0, -1), (0, 1), (-1, -1), (-1, 1), (1, -1), (1, 1)]
directions = [
(-1, 0),
(1, 0),
(0, -1),
(0, 1),
(-1, -1),
(-1, 1),
(1, -1),
(1, 1),
]

for dr, dc in directions:
new_row, new_col = row + dr, col + dc
Expand Down Expand Up @@ -160,7 +172,10 @@ def create_grid_visualization(grid, spacing=1.0):
elif grid.grid[i, j] == 1:
colors.append([1, 1, 0])

edge_colors = [[0.5, 0.5, 0.5] for _ in range((grid.rows - 1) * grid.cols + (grid.cols - 1) * grid.rows)]
edge_colors = [
[0.5, 0.5, 0.5]
for _ in range((grid.rows - 1) * grid.cols + (grid.cols - 1) * grid.rows)
]
edge_points = []

for i in range(grid.rows):
Expand Down Expand Up @@ -191,7 +206,7 @@ def move(path):
(-1, -1): (0.4, 0.5), # Up-Right
(-1, 1): (0.2, 0.4), # Up-Left
(1, -1): (-0.2, -0.4), # Down-Left
(1, 1): (-0.4, -0.2) # Down-Right
(1, 1): (-0.4, -0.2), # Down-Right
}
current_node = path[0]
next_node = path[1]
Expand All @@ -201,6 +216,7 @@ def move(path):

return move_power


# grid_size = 1000
# grid = AStarGrid(grid_size, grid_size, start_x=0, start_y=0, end_x=grid_size - 2, end_y=grid_size - 2)
# grid.generate_random_grid(grid_size, grid_size)
Expand Down Expand Up @@ -242,4 +258,3 @@ def move(path):
#
# visualizer.run()
# visualizer.destroy_window()

38 changes: 25 additions & 13 deletions src/communication/stm_com.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ def send_command(self):
self.left_speed = 79
self.right_speed = 79
self.byte_light_maini = (
(1 if self.led_r else 0) |
(1 if self.led_g else 0) << 1 |
(1 if self.led_y else 0) << 2 |
(1 if self.gripper_open else 0) << 3
(1 if self.led_r else 0)
| (1 if self.led_g else 0) << 1
| (1 if self.led_y else 0) << 2
| (1 if self.gripper_open else 0) << 3
)
command = struct.pack(
"BBBB", 38, self.right_speed, self.left_speed, self.byte_light_maini
)
command = struct.pack('BBBB', 38, self.right_speed, self.left_speed, self.byte_light_maini)
checksum = sum(command) & 0xFF
command += struct.pack('B', checksum)
command += struct.pack("B", checksum)
# command = f"&{chr(self.right_speed)}{chr(self.left_speed)}{chr(self.byte_light_maini)}"
# checksum = sum(command.encode()) & 0xFF
# command += chr(checksum)
Expand All @@ -71,26 +73,36 @@ def read_response(self):
if self.ser.in_waiting > 0:
start = self.ser.read(1)
print(f"l1 start {start}")
if start == b'&':
if start == b"&":

read = self.ser.read(2)
calculated_checksum = (ord('&') + read[0]) & 0xFF
calculated_checksum = (ord("&") + read[0]) & 0xFF
print(f"l2 start {read}")
if read[0] == ord('Y') and read[1] == calculated_checksum:
if read[0] == ord("Y") and read[1] == calculated_checksum:
print(f"l3 start {read}")
return False
return True

def scale_value(self, x, src_range, dst_range):
scaled = dst_range[0] + ((x - src_range[0]) * (dst_range[1] - dst_range[0]) / (src_range[1] - src_range[0]))
scaled = dst_range[0] + (
(x - src_range[0])
* (dst_range[1] - dst_range[0])
/ (src_range[1] - src_range[0])
)
return int(scaled)

def close(self):
self.ser.close()


def scale_value(x, src_range, dst_range):
scaled = dst_range[0] + ((x - src_range[0]) * (dst_range[1] - dst_range[0]) / (src_range[1] - src_range[0]))
scaled = dst_range[0] + (
(x - src_range[0])
* (dst_range[1] - dst_range[0])
/ (src_range[1] - src_range[0])
)
return int(scaled)
x = scale_value(0.5, (-1,1), (64, 93))
print(x)


x = scale_value(0.5, (-1, 1), (64, 93))
print(x)
16 changes: 13 additions & 3 deletions src/go_autonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class GoAutonomy:
"""class for autonomous navigation of the rover. use it in the logic of mission control."""

def __init__(self, stm_com, stelite_com):
self.config = load_config("utils/config_oak.json")
self.camera_oak = CameraOAK(self.config, visualize=False)
Expand All @@ -19,8 +20,18 @@ def __init__(self, stm_com, stelite_com):
self.stm_com = stm_com
self.stelite_com = stelite_com
self.track_maker = TrackMaker()
self.end_goal = (self.point_cloud_mapper.res - 3, self.point_cloud_mapper.res - 2)
self.a_star_grid = AStarGrid(self.point_cloud_mapper.res, self.point_cloud_mapper.res, start_x=0, start_y=0, end_x=self.end_goal[0], end_y=self.end_goal[1])
self.end_goal = (
self.point_cloud_mapper.res - 3,
self.point_cloud_mapper.res - 2,
)
self.a_star_grid = AStarGrid(
self.point_cloud_mapper.res,
self.point_cloud_mapper.res,
start_x=0,
start_y=0,
end_x=self.end_goal[0],
end_y=self.end_goal[1],
)
self.start_loop = True
self.rover_in_target = False

Expand Down Expand Up @@ -50,4 +61,3 @@ def run(self):
start_autonomy = self.stm_com.update(moves[0], moves[1])
if self.a_star_grid.goal == rover_sector:
self.rover_in_target = True

6 changes: 4 additions & 2 deletions src/gps/gps2sector.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def update_sector(self) -> tuple[int, int]:
self.latitude, self.longitude = self.read_json_position()

dist_x, dist_y = self.convert_cords_to_distance_diff()
sector_diff_x, sector_diff_y = self.convert_distance_to_sector_diff(dist_x, dist_y)
sector_diff_x, sector_diff_y = self.convert_distance_to_sector_diff(
dist_x, dist_y
)
x_sector = self.INITIAL_X_SECTOR + sector_diff_x
y_sector = self.INITIAL_Y_SECTOR + sector_diff_y

Expand All @@ -44,7 +46,7 @@ def update_pose_from_gps(self, pose: np.ndarray(4) = np.eye(4)) -> np.ndarray(4)
def read_json_position(self) -> tuple[int, int]:
with open(self.cords_position_json_path, "r") as cords_json:
data = json.load(cords_json)
return data['latitude'], data['longitude']
return data["latitude"], data["longitude"]

def convert_cords_to_distance_diff(self) -> tuple[int, int]:
"""
Expand Down
8 changes: 5 additions & 3 deletions src/gps/reading_gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
parsedLine = pynmea2.parse(newline)
if newline.find("$GPRMC") > -1:
print(f"outputDict: {outputDict}")
outputDict['latitude'] = parsedLine.latitude
outputDict['longitude'] = parsedLine.longitude
with open("/home/jetson/repos/TrailblazerML/src/utils/position.json", 'w') as OutputFile:
outputDict["latitude"] = parsedLine.latitude
outputDict["longitude"] = parsedLine.longitude
with open(
"/home/jetson/repos/TrailblazerML/src/utils/position.json", "w"
) as OutputFile:
json.dump(outputDict, OutputFile)
except UnicodeDecodeError:
print("Invalid byte encountered. Skipping.")
Expand Down
9 changes: 7 additions & 2 deletions src/logic_mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class LogicMission:
def __init__(self):

self.stm_com = STMCom(port="/dev/ttyACM0")
self.satellite_communicator = SatelliteCommunicator(port="/dev/ttyTHS1", baudrate=115200)
self.satellite_communicator = SatelliteCommunicator(
port="/dev/ttyTHS1", baudrate=115200
)
self.mision_is_on = True
self.autonomy_is_on = False

Expand Down Expand Up @@ -73,7 +75,10 @@ def handle_stage_1(self):
self.stm_com.girpper_open = False
self.stm_com.send_command()

if self.satellite_communicator.latitude != None and self.satellite_communicator.longitude != None:
if (
self.satellite_communicator.latitude != None
and self.satellite_communicator.longitude != None
):
time.sleep(0.5)
self.stm_com.led_r = False
self.stm_com.led_g = False
Expand Down
14 changes: 7 additions & 7 deletions src/logic_mission/satelite_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import struct
from satellite_communicator import SatelliteCommunicator
from satellite_communicator import SatelliteCommunicator

# Assuming SatelliteCommunicator class code is already defined and imported as you provided earlier.

Expand All @@ -8,25 +8,25 @@
communicator = SatelliteCommunicator(port="/dev/ttyUSB1", baudrate=115200)

# Send Arm/Disarm command (Assuming 0x01 means Arm)
communicator.send_message(communicator.MSG_ID_ARM_DISARM, b'\x01')
communicator.send_message(communicator.MSG_ID_ARM_DISARM, b"\x01")

# Send Navigate GPS command with example coordinates (Latitude, Longitude)
latitude = 34.052235 # Example latitude
longitude = -118.243683 # Example longitude
gps_data = struct.pack('>ff', latitude, longitude)
gps_data = struct.pack(">ff", latitude, longitude)
communicator.send_message(communicator.MSG_ID_NAVIGATE_GPS, gps_data)

# Notify task completion
communicator.task_completed()

# Set a new stage (Example stage 1)
communicator.send_message(communicator.MSG_ID_SET_STAGE, b'\x01')
communicator.send_message(communicator.MSG_ID_SET_STAGE, b"\x01")

# Locate Aruco Tags command
communicator.send_message(communicator.MSG_ID_LOCATE_ARUCO_TAGS, b'')
communicator.send_message(communicator.MSG_ID_LOCATE_ARUCO_TAGS, b"")

# Send a detection command (assuming no additional body data is needed)
communicator.send_message(communicator.MSG_ID_DETECTION, b'')
communicator.send_message(communicator.MSG_ID_DETECTION, b"")

# Set parameters command (assuming no additional body data is needed)
communicator.send_message(communicator.MSG_ID_SET_PARAMETERS, b'')
communicator.send_message(communicator.MSG_ID_SET_PARAMETERS, b"")
Loading