Skip to content

Commit 18b2893

Browse files
committed
created flight interface module
1 parent 99024a9 commit 18b2893

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
from . import conversions # to be implemented
3+
from .. import drone_odometry_local
4+
5+
from ..common.mavlink.modules import drone_odometry
6+
from ..common.mavlink.modules import flight_controller
7+
8+
class FlightInterface:
9+
10+
__create_key = object()
11+
12+
def create(
13+
cls,
14+
address: str,
15+
timeout_home: float
16+
) -> "tuple[bool, FlightInterface | None]":
17+
result, controller = flight_controller.FlightController.create(address)
18+
if not result:
19+
return False, None
20+
21+
result, home_location = controller.get_home_location(timeout_home)
22+
if not result:
23+
return False, None
24+
25+
return True, FlightInterface(cls.__create_key, controller, home_location)
26+
27+
def __init__(
28+
self,
29+
create_key: object,
30+
controller: flight_controller.FlightController,
31+
home_location: drone_odometry.DroneLocation,
32+
) -> None:
33+
assert create_key is FlightInterface.__create_key, "Use create() method"
34+
35+
self.controller = controller
36+
self.home_location = home_location
37+
38+
def run(self) -> "tuple[bool, drone_odometry_local.DroneOdometryLocal | None]":
39+
40+
result, drone_odometry = self.controller.get_odometry()
41+
if not result:
42+
return False, None
43+
44+
drone_position = drone_odometry.position
45+
46+
result, drone_position_local = conversions.global_to_local(drone_position, self.home_location)
47+
if not result:
48+
return False, None
49+
50+
drone_orientation = drone_odometry.orientation
51+
52+
return drone_odometry_local.DroneOdometryLocal.create(drone_position_local, drone_orientation)
53+

0 commit comments

Comments
 (0)