-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
configurator: rewrite in python and add config for px4_v1_14_0_beta_d…
…ronecan_vtol
- Loading branch information
1 parent
ebb078e
commit b516c0f
Showing
4 changed files
with
62 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
firmware: https://github.com/ZilantRobotics/PX4-Autopilot/releases/download/v1.14.0-0.4.1-beta1/px4_fmu-v5_default.px4 | ||
params: | ||
- configs/px4/v1.14/quadcopter/airframe.yaml | ||
- configs/px4/v1.14/quadcopter/dronecan.yaml | ||
- configs/px4/dronecan.yaml | ||
- configs/px4/common.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Autopilot configurator: | ||
1. Download a firmware and upload to a target if it is specified in yaml file | ||
2. Configure autopilot parameters if it is specified in yaml file | ||
""" | ||
import os | ||
import subprocess | ||
import wget | ||
from argparse import ArgumentParser | ||
import yaml | ||
|
||
SCRIPTS_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
REPO_DIR = os.path.dirname(SCRIPTS_DIR) | ||
BINARY_OUTPUT_PATH = f"{REPO_DIR}/firmware.bin" | ||
|
||
def configure(yaml_path : str) -> None: | ||
with open(yaml_path, 'r') as file: | ||
config = yaml.safe_load(file) | ||
|
||
flags = [] | ||
|
||
firmware = config.get('firmware') | ||
if firmware is not None: | ||
if os.path.exists(BINARY_OUTPUT_PATH): | ||
os.remove(BINARY_OUTPUT_PATH) | ||
wget.download(firmware, out=BINARY_OUTPUT_PATH) | ||
flags += ['--firmware', BINARY_OUTPUT_PATH] | ||
|
||
params = config.get('params') | ||
if params is not None and len(params) > 0: | ||
flags += ['-f', '--config'] | ||
for param in params: | ||
flags.append(f"{REPO_DIR}/{param}") | ||
|
||
if len(flags) > 0: | ||
subprocess.run(["autopilot-configurator", "-v", *flags]) | ||
if os.path.exists(BINARY_OUTPUT_PATH): | ||
os.remove(BINARY_OUTPUT_PATH) | ||
|
||
def configure_cli(): | ||
""" | ||
ArgumentParser wrapper under configure() function. | ||
This function can be used in pyproject.toml | ||
""" | ||
parser = ArgumentParser(description=__doc__) | ||
parser.add_argument('path', help='Path to config .yaml file') | ||
args = parser.parse_args() | ||
configure(args.path) | ||
|
||
if __name__ == "__main__": | ||
configure_cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters