Skip to content

Commit

Permalink
configurator: rewrite in python and add config for px4_v1_14_0_beta_d…
Browse files Browse the repository at this point in the history
…ronecan_vtol
  • Loading branch information
PonomarevDA committed Mar 17, 2024
1 parent ebb078e commit 7568130
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
6 changes: 6 additions & 0 deletions configs/vehicles/px4_v1_14_0_beta_dronecan_vtol.yaml
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
52 changes: 52 additions & 0 deletions scripts/configurator.py
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()
6 changes: 4 additions & 2 deletions scripts/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Commands (with aliases):
}

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
REPOSITORY_DIR="$(dirname "$SCRIPT_DIR")"

# Kill the container if sniffer is disconnected
slcan_checker() {
Expand Down Expand Up @@ -163,10 +164,11 @@ dronecan_vtol_v1_14_0() {
kill_all_related_containers
setup_dronecan_hitl_config
slcan_checker&
vehicle="px4_v1_14_0_beta_dronecan_vtol"
if [[ $OPTIONS == "--force" ]]; then
./configure.sh px4_v1_14_0_beta_dronecan_vtol
${REPOSITORY_DIR}/scripts/configurator.py ${REPOSITORY_DIR}/configs/vehicles/${vehicle}.yaml
fi
docker container run --rm $DOCKER_FLAGS $IMAGE_NAME ./scripts/run_sim.sh px4_v1_14_0_beta_dronecan_vtol
docker container run --rm $DOCKER_FLAGS $IMAGE_NAME ./scripts/run_sim.sh ${vehicle}
}

dronecan_quadrotor() {
Expand Down

0 comments on commit 7568130

Please sign in to comment.