Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Commit

Permalink
Added some constants that are commonly changed to flightconfig.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-McKanna committed Feb 6, 2019
1 parent e7a5108 commit 228ff0c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
5 changes: 3 additions & 2 deletions flight/AIs/test_hover.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from ..drone.drone_controller import DroneController
from .. import constants as c
from ... import flightconfig as f

HOVERTASK_DURATION = 10

controller = DroneController(c.Drones.LEONARDO_SIM)

controller.add_takeoff_task(c.DEFAULT_ALTITUDE)
controller.add_takeoff_task(f.DEFAULT_ALTITUDE)
controller.add_hover_task(
c.DEFAULT_ALTITUDE, HOVERTASK_DURATION, c.Priorities.MEDIUM)
f.DEFAULT_ALTITUDE, HOVERTASK_DURATION, c.Priorities.MEDIUM)
controller.add_land_task(c.Priorities.MEDIUM)

controller.run()
26 changes: 0 additions & 26 deletions flight/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,9 @@ class MavBitmasks(Enum):
Drones.LEONARDO: '/dev/serial/by-id/usb-3D_Robotics_PX4_FMU_v2.x_0-if00'
}

# Set to true for more detailed error messages and backtraces
DEBUG = True

# How high in meters the drone will default flight
DEFAULT_ALTITUDE = 1

# How fast (in meters/s) to move by default
DEFAULT_SPEED = 0.50

# Maximum speed (in meters/s) before being considered unsafe
SPEED_THRESHOLD = 1

# Maximum altitude (in meters) before being considered unsafe
MAXIMUM_ALLOWED_ALTITUDE = 1.5

# How often to run safety checks
SAFETY_CHECKS_DELAY = 0.5

# Thrust level during takeoff
DEFAULT_TAKEOFF_THRUST = 0.7

# Consider takeoff complete after reaching this percent of target takeoff
# altitude
PERCENT_TARGET_ALTITUDE = 0.3

# Expands or contracts time calculations (divide 1 by your average real-time
# factor in Gazebo simulator)
SIMULATION_MULTIPLIER = 1

# How often to run main control loop
DELAY_INTERVAL = 0.1

Expand Down
7 changes: 4 additions & 3 deletions flight/drone/drone_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ..tasks.task_base import TaskBase
from ..utils.priority_queue import PriorityQueue
from ..utils.timer import Timer
from ... import flightconfig as f

class DroneController(object):
"""Controls the actions of a drone.
Expand Down Expand Up @@ -89,7 +90,7 @@ def run(self):

# Only print stack trace for completely unexpected things
self._logger.critical(type(e).__name__)
if c.DEBUG is True:
if f.DEBUG is True:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback,
limit=2, file=sys.stdout)
Expand Down Expand Up @@ -200,10 +201,10 @@ def _update(self):
def _do_safety_checks(self):
"""Check for exceptional conditions."""
try:
if self._drone.airspeed > c.SPEED_THRESHOLD:
if self._drone.airspeed > f.SPEED_THRESHOLD:
raise exceptions.VelocityExceededThreshold()

if (self._drone.rangefinder.distance > c.MAXIMUM_ALLOWED_ALTITUDE):
if (self._drone.rangefinder.distance > f.MAXIMUM_ALLOWED_ALTITUDE):
raise exceptions.AltitudeExceededThreshold()

except Exception as e:
Expand Down
5 changes: 3 additions & 2 deletions flight/tasks/takeoff_task.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from task_base import TaskBase
from .. import constants as c
from ... import flightconfig as f

class TakeoffTask(TaskBase):
"""A task that takes off the drone from the ground.
Expand All @@ -25,10 +26,10 @@ def __init__(self, drone, altitude):
def perform(self):
current_altitude = self._drone.rangefinder.distance

if current_altitude >= self._target_alt * c.PERCENT_TARGET_ALTITUDE:
if current_altitude >= self._target_alt * f.PERCENT_TARGET_ALTITUDE:
return True

thrust = c.DEFAULT_TAKEOFF_THRUST
thrust = f.DEFAULT_TAKEOFF_THRUST

self._drone.set_attitude(0, 0, 0, thrust)
return False
25 changes: 25 additions & 0 deletions flightconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Set to true for more detailed error messages and backtraces
DEBUG = True

# How high in meters the drone will default flight
DEFAULT_ALTITUDE = 1

# How fast (in meters/s) to move by default
DEFAULT_SPEED = 0.50

# Maximum speed (in meters/s) before being considered unsafe
SPEED_THRESHOLD = 1

# Maximum altitude (in meters) before being considered unsafe
MAXIMUM_ALLOWED_ALTITUDE = 1.5

# Consider takeoff complete after reaching this percent of target takeoff
# altitude
PERCENT_TARGET_ALTITUDE = 0.3

# Expands or contracts time calculations (divide 1 by your average real-time
# factor in Gazebo simulator)
SIMULATION_MULTIPLIER = 1

# Thrust level during takeoff
DEFAULT_TAKEOFF_THRUST = 0.7

0 comments on commit 228ff0c

Please sign in to comment.