Skip to content

Commit 80bc4cf

Browse files
committed
feat(motor_test): More work on the motor tests sub-application
1 parent fd4fdef commit 80bc4cf

3 files changed

Lines changed: 471 additions & 127 deletions

File tree

ardupilot_methodic_configurator/backend_flightcontroller.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,43 @@ def set_param(self, param_name: str, param_value: float) -> None:
490490
return
491491
self.master.param_set_send(param_name, param_value)
492492

493+
def fetch_param(self, param_name: str, timeout: int = 5) -> Optional[float]:
494+
"""
495+
Fetch a parameter from the flight controller using MAVLink PARAM_REQUEST_READ message.
496+
497+
Args:
498+
param_name (str): The name of the parameter to fetch.
499+
timeout (int): Timeout in seconds to wait for the response. Default is 5.
500+
501+
Returns:
502+
float: The value of the parameter, or None if not found or timeout occurred.
503+
504+
"""
505+
if self.master is None: # FIXME for testing only pylint: disable=fixme
506+
return None
507+
508+
# Send PARAM_REQUEST_READ message
509+
self.master.mav.param_request_read_send(
510+
self.master.target_system,
511+
self.master.target_component,
512+
param_name.encode("utf-8"),
513+
-1, # param_index: -1 means use param_id instead
514+
)
515+
516+
# Wait for PARAM_VALUE response
517+
start_time = time_time()
518+
while time_time() - start_time < timeout:
519+
msg = self.master.recv_match(type="PARAM_VALUE", blocking=False)
520+
if msg is not None:
521+
# Check if this is the parameter we requested
522+
received_param_name = msg.param_id.rstrip("\x00")
523+
if received_param_name == param_name:
524+
logging_debug(_("Received parameter: %s = %s"), param_name, msg.param_value)
525+
return float(msg.param_value)
526+
time_sleep(0.01) # Small sleep to prevent busy waiting
527+
528+
raise TimeoutError(_("Timeout waiting for parameter %s") % param_name)
529+
493530
def reset_and_reconnect(
494531
self,
495532
reset_progress_callback: Union[None, Callable[[int, int], None]] = None,

0 commit comments

Comments
 (0)