Skip to content

Commit

Permalink
Changed ParrotAnafi to make commands async friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
mihirbala committed Jan 31, 2024
1 parent 1baf10a commit bdf1559
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
34 changes: 24 additions & 10 deletions onboard/python/implementation/drones/ParrotAnafiDrone.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ def __init__(self, **kwargs):
self.drone = Drone(self.ip)
self.active = False

''' Awaiting methods '''

async def hovering(self, timeout=None):
# Let the task start before checking for hover state.
await asyncio.sleep(3)
start = None
if timeout is not None:
start = time.time()
while True:
if self.drone(FlyingStateChanged(state="hovering", _policy="check")).success():
break
elif start is not None and time.time() - start < timeout:
break
else:
await asyncio.sleep(1)

''' Connection methods '''

async def connect(self):
Expand Down Expand Up @@ -61,7 +77,8 @@ async def stopStreaming(self):
''' Take off / Landing methods '''

async def takeOff(self):
self.drone(TakeOff()).wait().success()
self.drone(TakeOff())
await self.hovering()

async def land(self):
self.drone(Landing()).wait().success()
Expand All @@ -71,28 +88,26 @@ async def setHome(self, lat, lng, alt):

async def rth(self):
self.hover()
self.drone(return_to_home()).wait().success()
self.drone(return_to_home())

''' Movement methods '''

async def PCMD(self, roll, pitch, yaw, gaz):
self.drone(
PCMD(1, roll, pitch, yaw, gaz, timestampAndSeqNum=0)
>> FlyingStateChanged(state="hovering", _timeout=5)
)

async def moveTo(self, lat, lng, alt):
self.drone(
moveTo(lat, lng, alt, move_mode.orientation_mode.to_target, 0.0)
>> moveToChanged(status='DONE')
>> FlyingStateChanged(state="hovering", _timeout=5)
).wait().success()
)
await self.hovering()

async def moveBy(self, x, y, z, t):
self.drone(
moveBy(x, y, z, t)
>> FlyingStateChanged(state="hovering", _timeout=5)
).wait().success()
)
await self.hovering()

async def rotateTo(self, theta):
# TODO: Rotate to exact heading
Expand All @@ -109,9 +124,8 @@ async def setGimbalPose(self, yaw_theta, pitch_theta, roll_theta):
pitch_frame_of_reference="absolute",
pitch=pitch_theta,
roll_frame_of_reference="none",
roll=roll_theta,
roll=roll_theta,)
)
>> attitude(pitch_absolute=pitch_theta, _policy="wait", _float_tol=(1e-3, 1e-1))).wait().success()

async def hover(self):
await self.PCMD(0, 0, 0, 0)
Expand Down
2 changes: 1 addition & 1 deletion onboard/python/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, args):
self.source = 'command'
self.mission = None
self.missionTask = None
self.manual = True #default to manual control
self.manual = True # Default to manual control
self.heartbeats = 0

async def initializeConnection(self):
Expand Down

0 comments on commit bdf1559

Please sign in to comment.