-
Notifications
You must be signed in to change notification settings - Fork 249
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
Daniel Suzuki's Bootcamp #97
Changes from 14 commits
6233569
6475dd9
f58d22c
7c6c0e2
59eb834
74363d7
6397d68
e8374a4
3a3ab64
f99add2
4ed6568
12c127a
2db4cbd
7921777
aa75507
a275c5d
e9e5458
06021a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,12 +36,16 @@ def __init__(self, waypoint: location.Location, acceptance_radius: float) -> Non | |
# ============ | ||
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
# ============ | ||
# set as closest landing to waypoint | ||
self.has_sent_landing_command = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably don't need this one either |
||
self.halt_at_initialization = True | ||
self.is_halt_at_waypoint = False | ||
self.closest_pad = location.Location(float("inf"), float("inf")) | ||
|
||
# Add your own | ||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ | ||
# self.shortest_distance = [float("inf"), float("inf")] | ||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
# ============ | ||
|
||
def run( | ||
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]" | ||
|
@@ -67,8 +71,52 @@ def run( | |
# ============ | ||
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓ | ||
# ============ | ||
def square(number: float) -> float: | ||
return number**2 | ||
|
||
def squared_distance_from_position( | ||
point: location.Location, current_position: location.Location | ||
) -> float: | ||
distance = square(point.location_x - current_position.location_x) + ( | ||
square(point.location_y - current_position.location_y) | ||
) | ||
return distance | ||
|
||
# Do something based on the report and the state of this class... | ||
if report.status == drone_status.DroneStatus.HALTED: | ||
|
||
if self.halt_at_initialization: | ||
|
||
command = commands.Command.create_set_relative_destination_command( | ||
self.waypoint.location_x - report.position.location_x, | ||
self.waypoint.location_y - report.position.location_y, | ||
) | ||
self.halt_at_initialization = False | ||
self.is_halt_at_waypoint = True | ||
|
||
elif self.is_halt_at_waypoint: | ||
for landing_pad in landing_pad_locations: | ||
distance_from_position = squared_distance_from_position( | ||
landing_pad, self.waypoint | ||
) | ||
current_shortest_distance = ( | ||
self.closest_pad.location_x - report.position.location_x | ||
) ** 2 + (self.closest_pad.location_y - report.position.location_y) ** 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use your square_distance_... function here too |
||
if distance_from_position < current_shortest_distance: | ||
self.closest_pad = landing_pad | ||
|
||
command = commands.Command.create_set_relative_destination_command( | ||
self.closest_pad.location_x - report.position.location_x, | ||
self.closest_pad.location_y - report.position.location_y, | ||
) | ||
self.is_halt_at_waypoint = False | ||
|
||
elif ( | ||
(report.position.location_x - self.closest_pad.location_x) ** 2 | ||
+ (report.position.location_y - self.closest_pad.location_y) ** 2 | ||
) <= ((self.acceptance_radius) ** 2): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think your brackets are wrong here, your elif ends before the <= operator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've realized that when i use black modules , the brackets that I add at the front of 'elif' and after '**2' end are removed. Is there any way to resolve this? |
||
|
||
command = commands.Command.create_land_command() | ||
|
||
# ============ | ||
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can delete this here too