5 Commits

Author SHA1 Message Date
Oleg Kalachev
c08c8ad91c pyflix@0.9 2025-10-03 06:49:44 +03:00
Oleg Kalachev
e44f32fca7 pyflix: don't quit on any sendto error 2025-10-03 06:47:56 +03:00
Oleg Kalachev
ca03bdb260 pyflix: partially fix wireless downloading logs 2025-10-03 06:46:56 +03:00
Oleg Kalachev
b3dffe99fb pyflix: add passing event name to off method 2025-10-03 06:46:29 +03:00
Oleg Kalachev
6e6a71fa69 Remove unneeded advice from troubleshooting 2025-10-03 06:45:16 +03:00
5 changed files with 25 additions and 9 deletions

View File

@@ -35,4 +35,3 @@ Do the following:
* **Calibrate the RC** if you use it. Type `cr` command in Serial Monitor and follow the instructions.
* **Check the RC data** if you use it. Use `rc` command, `Control` should show correct values between -1 and 1, and between 0 and 1 for the throttle.
* **Check the IMU output using QGroundControl**. Connect to the drone using QGroundControl on your computer. Go to the *Analyze* tab, *MAVLINK Inspector*. Plot the data from the `SCALED_IMU` message. The gyroscope and accelerometer data should change according to the drone movement.
* **Check the gyroscope only attitude estimation**. Comment out `applyAcc();` line in `estimate.ino` and check if the attitude estimation in QGroundControl. It should be stable, but only drift very slowly.

View File

@@ -59,6 +59,13 @@ flix.on('disconnected', lambda: print('Disconnected from Flix'))
flix.on('print', lambda text: print(f'Flix says: {text}'))
```
Unsubscribe from events using `off` method:
```python
flix.off('print') # unsubscribe from print events
flix.off(callback) # unsubscribe specific callback
```
You can also wait for specific events using `wait` method. This method returns the data associated with the event:
```python

View File

@@ -87,10 +87,15 @@ class Flix:
self._event_listeners[event] = []
self._event_listeners[event].append(callback)
def off(self, callback: Callable):
for event in self._event_listeners:
if callback in self._event_listeners[event]:
self._event_listeners[event].remove(callback)
def off(self, event_or_callback: Union[str, Callable]):
if isinstance(event_or_callback, str):
event = event_or_callback.lower()
if event in self._event_listeners:
del self._event_listeners[event]
else:
for event in self._event_listeners:
if event_or_callback in self._event_listeners[event]:
self._event_listeners[event].remove(event_or_callback)
def _trigger(self, event: str, *args):
event = event.lower()
@@ -365,7 +370,9 @@ class Flix:
self.mavlink.serial_control_send(0, 0, 0, 0, len(cmd_bytes), cmd_bytes)
if not wait_response:
return ''
response = self.wait('print_full', timeout=0.1, value=lambda text: text.startswith(response_prefix))
timeout = 0.1
if cmd == 'log': timeout = 10 # log download may take more time
response = self.wait('print_full', timeout=timeout, value=lambda text: text.startswith(response_prefix))
return response[len(response_prefix):].strip()
except TimeoutError:
continue

View File

@@ -24,13 +24,16 @@ def main():
if addr in TARGETS: # packet from target
if source_addr is None:
continue
sock.sendto(data, source_addr)
try:
sock.sendto(data, source_addr)
packets += 1
except: pass
else: # packet from source
source_addr = addr
for target in TARGETS:
sock.sendto(data, target)
packets += 1
packets += 1
print(f'\rPackets: {packets}', end='')
if __name__ == '__main__':

View File

@@ -1,6 +1,6 @@
[project]
name = "pyflix"
version = "0.8"
version = "0.9"
description = "Python API for Flix drone"
authors = [{ name="Oleg Kalachev", email="okalachev@gmail.com" }]
license = "MIT"