Skip to content

Commit

Permalink
Lets try again
Browse files Browse the repository at this point in the history
  • Loading branch information
demonking-mw committed Sep 12, 2024
1 parent 0355958 commit 03a9f53
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
14 changes: 7 additions & 7 deletions modules/bootcamp/decision_simple_waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============

def clearance(self, report: drone_report.DroneReport) -> bool:
"""Function checks whether the drone has reached waypoint without using square root operation"""
distance_x = self.waypoint.location_x - report.position.location_x
Expand Down Expand Up @@ -76,24 +77,23 @@ def run(
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
# ============



if report.status == drone_status.DroneStatus.HALTED:
#In this case, the drone need to head to the waypoint
# In this case, the drone need to head to the waypoint
if not self.clearance(report):
print(f"Departed for waypoint mission from halted position : {report.position}")
command = commands.Command.create_set_relative_destination_command(self.waypoint.location_x-report.position.location_x, self.waypoint.location_y-report.position.location_y)
command = commands.Command.create_set_relative_destination_command(
self.waypoint.location_x - report.position.location_x,
self.waypoint.location_y - report.position.location_y,
)
elif not self.has_sent_landing_command:
#In this case, the drone need to land
# In this case, the drone need to land
print("send landing command")
command = commands.Command.create_land_command()
self.has_sent_landing_command = True
elif report.status == drone_status.DroneStatus.MOVING and self.clearance(report):
command = commands.Command.create_halt_command()
print("HALT COMMAND SENT")



# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============
Expand Down
34 changes: 21 additions & 13 deletions modules/bootcamp/decision_waypoint_landing_pads.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non
# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============

def clearance(self, position: location.Location) -> bool:
"""Function checks whether the drone has reached waypoint without using square root operation"""
distance_x = self.waypoint.location_x - position.location_x
Expand All @@ -54,8 +55,11 @@ def clearance(self, position: location.Location) -> bool:
clear = distance_squared < self.acceptance_radius**2
return clear

def findpad(self,
current_location: "location.Location", landing_pad_locations: "list[location.Location]") -> location.Location:
def findpad(
self,
current_location: "location.Location",
landing_pad_locations: "list[location.Location]",
) -> location.Location:
"""
Find the closest landing pad and return its location
"""
Expand All @@ -70,7 +74,6 @@ def findpad(self,
smallest_distance_squared = distance_squared
return landing_pad_locations[closest_index]


def run(
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]"
) -> commands.Command:
Expand All @@ -96,34 +99,39 @@ def run(
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
# ============


if report.status == drone_status.DroneStatus.HALTED:
#If the drone is halted, then get it to the proper stage of action
# If the drone is halted, then get it to the proper stage of action
if not self.clearance(report.position) and not self.landing_procedure:
#In this case, the drone need to head to the waypoint
# In this case, the drone need to head to the waypoint
print(f"Departed for waypoint mission from halted position : {report.position}")
command = commands.Command.create_set_relative_destination_command(self.waypoint.location_x-report.position.location_x, self.waypoint.location_y-report.position.location_y)
command = commands.Command.create_set_relative_destination_command(
self.waypoint.location_x - report.position.location_x,
self.waypoint.location_y - report.position.location_y,
)
elif self.clearance(report.position):
#The drone need to head to the landing pad
# The drone need to head to the landing pad
closest_landing_pad = self.findpad(report.position, landing_pad_locations)
self.pad_location_x = closest_landing_pad.location_x
self.pad_location_y = closest_landing_pad.location_y
command = commands.Command.create_set_relative_destination_command(self.pad_location_x-report.position.location_x, self.pad_location_y-report.position.location_y)
command = commands.Command.create_set_relative_destination_command(
self.pad_location_x - report.position.location_x,
self.pad_location_y - report.position.location_y,
)
print("moving toward nearest landing pad")
#Indicate that the drone is heading to landing pad
# Indicate that the drone is heading to landing pad
self.landing_procedure = True
elif not self.has_sent_landing_command:
#In this case, the drone need to land
# In this case, the drone need to land
print("send landing command")
command = commands.Command.create_land_command()
self.has_sent_landing_command = True
elif report.status == drone_status.DroneStatus.MOVING:
if self.clearance(report.position) and not self.landing_procedure:
#stop the drone if it reaches the waypoint
# stop the drone if it reaches the waypoint
command = commands.Command.create_halt_command()
print("HALT COMMAND SENT: reached waypoint")
elif self.clearance(location.Location(self.pad_location_x, self.pad_location_y)):
#stop the drone if it reaches the waypoint
# stop the drone if it reaches the waypoint
command = commands.Command.create_halt_command()
print("HALT COMMAND SENT: reached landing pad")

Expand Down
4 changes: 3 additions & 1 deletion modules/bootcamp/detect_landing_pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def run(self, image: np.ndarray) -> "tuple[list[bounding_box.BoundingBox], np.nd
# * conf
# * device
# * verbose
predictions = self.__model.predict(source=image, conf=0.75, device=self.__DEVICE, verbose=False)
predictions = self.__model.predict(
source=image, conf=0.75, device=self.__DEVICE, verbose=False
)
# Get the Result object
prediction = predictions[0]
# Plot the annotated image from the Result object
Expand Down

0 comments on commit 03a9f53

Please sign in to comment.