Making an ESP32-based quadcopter from scratch
Python arduinoautopilotcontrol-theorydroneesp32flight-controlflight-controllermavlinkquadcopterquadcopter-firmwareuav
Updates in pyflix Rename mav_to to system_id to match firmware naming. Readme updates.
Oleg Kalachev32f417efae87
diff --git a/tools/pyflix/README.md b/tools/pyflix/README.mdindex ac06773..46c607d 100644--- a/tools/pyflix/README.md+++ b/tools/pyflix/README.md@@ -71,7 +71,7 @@ The `value` argument specifies a condition for filtering events. It can be eithe```pythonflix.wait('armed', value=True) # wait until armedflix.wait('armed', value=False) # wait until disarmed-flix.wait('motors', value=lambda motors: all(m == 0 for m in motors)) # wait until all motors stop+flix.wait('motors', value=lambda motors: not any(motors)) # wait until all motors stopflix.wait('attitude_euler', value=lambda att: att[0] > 0) # wait until roll angle is positive```@@ -106,7 +106,7 @@ Full list of events:Get and set firmware parameters using `get_param` and `set_param` methods:```python-print(flix.get_param('PITCH_P')) # get parameter value+pitch_p = flix.get_param('PITCH_P') # get parameter valueflix.set_param('PITCH_P', 5) # set parameter value```diff --git a/tools/pyflix/flix.py b/tools/pyflix/flix.pyindex 303090b..2d55590 100644--- a/tools/pyflix/flix.py+++ b/tools/pyflix/flix.py@@ -34,18 +34,18 @@ class Flix:acc: List[float]gyro: List[float]- mav_id: int+ system_id: intmessages: Dict[str, Dict[str, Any]] # MAVLink messages storagevalues: Dict[Union[str, int], Union[float, List[float]]] = {} # named values_connection_timeout = 3_print_buffer: str = ''- def __init__(self, mav_id: int=1, wait_connection: bool=True):- if not (0 <= mav_id < 256):- raise ValueError('mav_id must be in range [0, 255]')+ def __init__(self, system_id: int=1, wait_connection: bool=True):+ if not (0 <= system_id < 256):+ raise ValueError('system_id must be in range [0, 255]')self._setup_mavlink()- self.mav_id = mav_id+ self.system_id = system_idself._init_state()try:# Direct connection@@ -57,7 +57,7 @@ class Flix:# Port busy - using proxylogger.debug('Listening on port 14560 (proxy)')self.connection: mavutil.mavfile = mavutil.mavlink_connection('udpin:0.0.0.0:14555', source_system=254) # type: ignore- self.connection.target_system = mav_id+ self.connection.target_system = system_idself.mavlink: mavlink.MAVLink = self.connection.mavself._event_listeners: Dict[str, List[Callable[..., Any]]] = {}self.messages = {}@@ -253,7 +253,7 @@ class Flix:for attempt in range(3):try:logger.debug(f'Get param {name} (attempt #{attempt + 1})')- self.mavlink.param_request_read_send(self.mav_id, 0, name.encode('ascii'), -1)+ self.mavlink.param_request_read_send(self.system_id, 0, name.encode('ascii'), -1)msg: mavlink.MAVLink_param_value_message = \self.wait('mavlink.PARAM_VALUE', value=lambda msg: msg.param_id == name, timeout=0.1)return msg.param_value@@ -267,7 +267,7 @@ class Flix:for attempt in range(3):try:logger.debug(f'Set param {name} to {value} (attempt #{attempt + 1})')- self.mavlink.param_set_send(self.mav_id, 0, name.encode('ascii'), value, mavlink.MAV_PARAM_TYPE_REAL32)+ self.mavlink.param_set_send(self.system_id, 0, name.encode('ascii'), value, mavlink.MAV_PARAM_TYPE_REAL32)self.wait('mavlink.PARAM_VALUE', value=lambda msg: msg.param_id == name, timeout=0.1)returnexcept TimeoutError:@@ -297,7 +297,7 @@ class Flix:raise ValueError('roll, pitch, yaw must be in range [-1, 1]')if not 0 <= throttle <= 1:raise ValueError('throttle must be in range [0, 1]')- self.mavlink.manual_control_send(self.mav_id, roll * 1000, pitch * 1000, yaw * 1000, throttle * 1000, 0) # type: ignore+ self.mavlink.manual_control_send(self.system_id, roll * 1000, pitch * 1000, yaw * 1000, throttle * 1000, 0) # type: ignoredef set_mode(self, mode: Literal['MANUAL', 'ACRO', 'STAB', 'USER']):raise NotImplementedError('Setting mode is not implemented yet')