Skip to content

Commit

Permalink
Revised bootcamp code
Browse files Browse the repository at this point in the history
  • Loading branch information
Khalil-Hawari authored Feb 4, 2025
1 parent ab89d0b commit c345cca
Show file tree
Hide file tree
Showing 3 changed files with 327 additions and 343 deletions.
168 changes: 84 additions & 84 deletions modules/bootcamp/decision_example.py
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
"""
BOOTCAMPERS DO NOT MODIFY THIS FILE.
Example decision with figure 8.
"""

from .. import commands
from .. import drone_report
from .. import drone_status
from .. import location
from ..private.decision import base_decision


# Disable for bootcamp use
# No enable
# pylint: disable=duplicate-code,unused-argument


class DecisionExample(base_decision.BaseDecision):
"""
Example of sending commands to the drone.
"""

def __init__(self, waypoint: location.Location, acceptance_radius: float) -> None:
"""
Initialize all persistent variables here with self.
"""
self.waypoint = waypoint
print(f"Waypoint: {waypoint}")

self.acceptance_radius = acceptance_radius

self.command_index = 0
self.commands = [
commands.Command.create_set_relative_destination_command(50.0, 37.5),
commands.Command.create_set_relative_destination_command(0.0, -75.0),
commands.Command.create_set_relative_destination_command(-50.0, 37.5),
commands.Command.create_set_relative_destination_command(-50.0, -37.5),
commands.Command.create_set_relative_destination_command(0.0, 75.0),
commands.Command.create_set_relative_destination_command(50.0, -37.5),
commands.Command.create_set_relative_destination_command(-50.0, 0.0),
commands.Command.create_set_relative_destination_command(50.0, 0.0),
]

self.has_sent_landing_command = False

self.counter = 0

def run(
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]"
) -> commands.Command:
"""
Makes the drone fly in a figure 8, then land.
This method will be called in an infinite loop, something like this:
```py
while True:
report, landing_pad_locations = get_input()
command = Decision.run(report, landing_pad_locations)
put_output(command)
```
"""
# Default command
command = commands.Command.create_null_command()

if report.status == drone_status.DroneStatus.HALTED and self.command_index < len(
self.commands
):
# Print some information for debugging
print(self.counter)
print(self.command_index)
print(f"Halted at: {report.position}")

command = self.commands[self.command_index]
self.command_index += 1
elif report.status == drone_status.DroneStatus.HALTED and not self.has_sent_landing_command:
command = commands.Command.create_land_command()

self.has_sent_landing_command = True

self.counter += 1

return command
"""
BOOTCAMPERS DO NOT MODIFY THIS FILE.
Example decision with figure 8.
"""

from .. import commands
from .. import drone_report
from .. import drone_status
from .. import location
from ..private.decision import base_decision


# Disable for bootcamp use
# No enable
# pylint: disable=duplicate-code,unused-argument


class DecisionExample(base_decision.BaseDecision):
"""
Example of sending commands to the drone.
"""

def __init__(self, waypoint: location.Location, acceptance_radius: float) -> None:
"""
Initialize all persistent variables here with self.
"""
self.waypoint = waypoint
print(f"Waypoint: {waypoint}")

self.acceptance_radius = acceptance_radius

self.command_index = 0
self.commands = [
commands.Command.create_set_relative_destination_command(50.0, 37.5),
commands.Command.create_set_relative_destination_command(0.0, -75.0),
commands.Command.create_set_relative_destination_command(-50.0, 37.5),
commands.Command.create_set_relative_destination_command(-50.0, -37.5),
commands.Command.create_set_relative_destination_command(0.0, 75.0),
commands.Command.create_set_relative_destination_command(50.0, -37.5),
commands.Command.create_set_relative_destination_command(-50.0, 0.0),
commands.Command.create_set_relative_destination_command(50.0, 0.0),
]

self.has_sent_landing_command = False

self.counter = 0

def run(
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]"
) -> commands.Command:
"""
Makes the drone fly in a figure 8, then land.
This method will be called in an infinite loop, something like this:
```py
while True:
report, landing_pad_locations = get_input()
command = Decision.run(report, landing_pad_locations)
put_output(command)
```
"""
# Default command
command = commands.Command.create_null_command()

if report.status == drone_status.DroneStatus.HALTED and self.command_index < len(
self.commands
):
# Print some information for debugging
print(self.counter)
print(self.command_index)
print(f"Halted at: {report.position}")

command = self.commands[self.command_index]
self.command_index += 1
elif report.status == drone_status.DroneStatus.HALTED and not self.has_sent_landing_command:
command = commands.Command.create_land_command()

self.has_sent_landing_command = True

self.counter += 1

return command
176 changes: 86 additions & 90 deletions modules/bootcamp/decision_simple_waypoint.py
Original file line number Diff line number Diff line change
@@ -1,90 +1,86 @@
"""
BOOTCAMPERS TO COMPLETE.
Travel to designated waypoint.
"""

from .. import commands
from .. import drone_report

# Disable for bootcamp use
# pylint: disable-next=unused-import
from .. import drone_status
from .. import location
from ..private.decision import base_decision


# Disable for bootcamp use
# No enable
# pylint: disable=duplicate-code,unused-argument


class DecisionSimpleWaypoint(base_decision.BaseDecision):
"""
Travel to the designed waypoint.
"""

def __init__(self, waypoint: location.Location, acceptance_radius: float) -> None:
"""
Initialize all persistent variables here with self.
"""
self.waypoint = waypoint
print(f"Waypoint: {waypoint}")

self.acceptance_radius = acceptance_radius

# ============
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
# ============

# Write here

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============

def run(
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]"
) -> commands.Command:
"""
Make the drone fly to the waypoint.
You are allowed to create as many helper methods as you want,
as long as you do not change the __init__() and run() signatures.
This method will be called in an infinite loop, something like this:
```py
while True:
report, landing_pad_locations = get_input()
command = Decision.run(report, landing_pad_locations)
put_output(command)
```
"""
# Default command
command = commands.Command.create_null_command()

# ============
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
# ============

# Do something based on the report and the state of this class...

if report.status == drone_status.DroneStatus.HALTED:
delta_x = report.position.location_x - self.waypoint.location_x
delta_y = report.position.location_y - self.waypoint.location_y
on_waypoint = delta_x**2 + delta_y**2 < self.acceptance_radius**2

if on_waypoint:
command = commands.Command.create_land_command()

else:
command = commands.Command.create_set_relative_destination_command(
self.waypoint.location_x, self.waypoint.location_y
)

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============

return command
"""
BOOTCAMPERS TO COMPLETE.
Travel to designated waypoint.
"""

from .. import commands
from .. import drone_report

# Disable for bootcamp use
# pylint: disable-next=unused-import
from .. import drone_status
from .. import location
from ..private.decision import base_decision


# Disable for bootcamp use
# No enable
# pylint: disable=duplicate-code,unused-argument


class DecisionSimpleWaypoint(base_decision.BaseDecision):
"""
Travel to the designed waypoint.
"""

def __init__(self, waypoint: location.Location, acceptance_radius: float) -> None:
"""
Initialize all persistent variables here with self.
"""
self.waypoint = waypoint
print(f"Waypoint: {waypoint}")

self.acceptance_radius = acceptance_radius

# ============
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
# ============

# Write here

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============

def run(
self, report: drone_report.DroneReport, landing_pad_locations: "list[location.Location]"
) -> commands.Command:
"""
Make the drone fly to the waypoint.
You are allowed to create as many helper methods as you want,
as long as you do not change the __init__() and run() signatures.
This method will be called in an infinite loop, something like this:
```py
while True:
report, landing_pad_locations = get_input()
command = Decision.run(report, landing_pad_locations)
put_output(command)
```
"""
# Default command
command = commands.Command.create_null_command()

# ============
# ↓ BOOTCAMPERS MODIFY BELOW THIS COMMENT ↓
# ============

if report.status == drone_status.DroneStatus.HALTED:
delta_x = self.waypoint.location_x - report.position.location_x
delta_y = self.waypoint.location_y - report.position.location_y
on_waypoint = delta_x**2 + delta_y**2 < self.acceptance_radius**2

if on_waypoint:
command = commands.Command.create_land_command()

else:
command = commands.Command.create_set_relative_destination_command(delta_x, delta_y)

# ============
# ↑ BOOTCAMPERS MODIFY ABOVE THIS COMMENT ↑
# ============

return command
Loading

0 comments on commit c345cca

Please sign in to comment.