Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor configuration script #53

Merged
merged 10 commits into from
Mar 17, 2024
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ To get the list of all supported modes, just type:
To run PX4 Cyphal quadcopter, type:

```bash
./scripts/docker.sh cq # cq = cyphal_quadrotor
./scripts/docker.sh cq # cq = px4_v1_14_0_cyphal_quadcopter
```

To run PX4 Dronecan VTOL, type:
Expand Down Expand Up @@ -123,17 +123,17 @@ Well, here is the output of the command:

```bash
Primary supported modes (with aliases):
cyphal_quadrotor,cq | Cyphal PX4 v1.14-beta Quadrotor x (4001)
cyphal_standard_vtol,csv | Cyphal PX4 v1.14-beta Standard VTOL (13000)
dronecan_quadrotor,dq | DroneCAN PX4 v1.14-beta Quadrotor (4001)
dronecan_vtol_v1_14_0,dv | DroneCAN PX4 v1.14-beta Standard VTOL (13000)
dronecan_vtol_v1_12_1,dvo | DroneCAN PX4 v1.12 vtol 13070
px4_v1_14_0_cyphal_quadcopter,cq | Cyphal PX4 v1.14-beta Quadrotor x (4001)
px4_v1_14_0_cyphal_quadplane_vtol,csv | Cyphal PX4 v1.14-beta Standard VTOL (13000)
px4_v1_14_0_dronecan_quadrotor,dq | DroneCAN PX4 v1.14-beta Quadrotor (4001)
px4_v1_14_0_dronecan_quadplane_vtol,dv | DroneCAN PX4 v1.14-beta Standard VTOL (13000)
px4_v1_12_1_dronecan_vtol,dvo | DroneCAN PX4 v1.12 vtol 13070

Other modes:
sitl_inno_vtol | MAVLink PX4 v1.12 vtol 13070
sitl_flight_goggles | MAVLink PX4 v1.12 Quadrotor (4001)
cyphal_and_dronecan | 2 CAN AP v4.4.0 Copter
cyphal_octorotor,co | Cyphal PX4 v1.14-beta Octorotor Coaxial (12001)
sitl_inno_vtol | MAVLink PX4 v1.12 vtol 13070
sitl_flight_goggles | MAVLink PX4 v1.12 Quadrotor (4001)
cyphal_and_dronecan | 2 CAN AP v4.4.0 Copter
px4_v1_14_0_cyphal_octorotor,co | Cyphal PX4 v1.14-beta Octorotor Coaxial (12001)

```

Expand Down
2 changes: 1 addition & 1 deletion configs/px4/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CBRK_SUPPLY_CHK: 894281
COM_ARM_CHK_ESCS: 0
CBRK_IO_SAFETY: 22027
SYS_BOARD_SENS: 0
COM_RC_IN_MODE: 1
COM_RC_IN_MODE: 4 # Stick input disabled (it used to be 1 and the vehicle was Not ready).
FD_ACT_EN: 0 # Enable Actuator Failure check

WV_EN: 0 # Weather vane. By default Enabled.
Expand Down
5 changes: 5 additions & 0 deletions configs/vehicles/px4_v1_12_1_dronecan_vtol.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
firmware: https://github.com/ZilantRobotics/PX4-Autopilot/releases/download/v1.12.1_hitl/px4_fmu-v5_default.px4
params:
- configs/px4/v1.13/vtol_13070/airframe.yaml
- configs/px4/dronecan.yaml
- configs/px4/common.yaml
7 changes: 7 additions & 0 deletions configs/vehicles/px4_v1_14_0_cyphal_octoplane_vtol.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
firmware: https://github.com/ZilantRobotics/PX4-Autopilot/releases/download/v1.14.0-0.4.1-beta1/px4_fmu-v5_cyphal.px4
params:
- configs/px4/v1.14/vtol_octoplane_coaxial/airframe.yaml
- configs/px4/v1.14/vtol_octoplane_coaxial/cyphal.yaml
- configs/px4/v1.14/vtol_octoplane_coaxial/geometry.yaml
- configs/px4/cyphal.yaml
- configs/px4/common.yaml
5 changes: 5 additions & 0 deletions configs/vehicles/px4_v1_14_0_cyphal_octorotor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
firmware: https://github.com/ZilantRobotics/PX4-Autopilot/releases/download/v1.14.0-0.4.1-beta1/px4_fmu-v5_cyphal.px4
params:
- configs/px4/v1.14/octorotor/airframe.yaml
- configs/px4/cyphal.yaml
- configs/px4/common.yaml
6 changes: 6 additions & 0 deletions configs/vehicles/px4_v1_14_0_cyphal_quadcopter.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_cyphal.px4
params:
- configs/px4/v1.14/quadcopter/airframe.yaml
- configs/px4/v1.14/quadcopter/cyphal.yaml
- configs/px4/cyphal.yaml
- configs/px4/common.yaml
6 changes: 6 additions & 0 deletions configs/vehicles/px4_v1_14_0_cyphal_quadplane_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_cyphal.px4
params:
- configs/px4/v1.14/standard_vtol/airframe.yaml
- configs/px4/v1.14/standard_vtol/cyphal.yaml
- configs/px4/cyphal.yaml
- configs/px4/common.yaml
6 changes: 6 additions & 0 deletions configs/vehicles/px4_v1_14_0_dronecan_quadplane_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/standard_vtol/airframe.yaml
- configs/px4/v1.14/standard_vtol/dronecan.yaml
- configs/px4/dronecan.yaml
- configs/px4/common.yaml
6 changes: 6 additions & 0 deletions configs/vehicles/px4_v1_14_0_dronecan_quadrotor.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
2 changes: 1 addition & 1 deletion missions/ci/square.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SCRIPTS_DIR=$REPOSITORY_DIR/scripts
$SCRIPTS_DIR/docker.sh kill
sleep 1

$SCRIPTS_DIR/configure.sh cyphal_quadrotor
${REPOSITORY_DIR}/scripts/configurator.py ${REPOSITORY_DIR}/configs/vehicles/px4_v1_14_0_cyphal_quadcopter.yaml
$SCRIPTS_DIR/docker.sh cq &
sleep 15 # px4 needs time after booting up to initialize everything
$SCRIPTS_DIR/test_scenario.sh --mission $CURRENT_DIR/square.plan
Expand Down
2 changes: 1 addition & 1 deletion missions/ci/sviyazhsk_vtol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SCRIPTS_DIR=$REPOSITORY_DIR/scripts
$SCRIPTS_DIR/docker.sh kill
sleep 1

$SCRIPTS_DIR/configure.sh px4_v1_14_0_beta_cyphal_vtol
$SCRIPTS_DIR/configure.sh px4_v1_14_0_cyphal_quadplane_vtol
$SCRIPTS_DIR/docker.sh csv &
sleep 15 # px4 needs time after booting up to initialize everything
$SCRIPTS_DIR/test_scenario.sh --mission $CURRENT_DIR/sviyazhsk_vtol.plan
Expand Down
2 changes: 1 addition & 1 deletion missions/ci/takeoff_and_land.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SCRIPTS_DIR=$REPOSITORY_DIR/scripts
$SCRIPTS_DIR/docker.sh kill
sleep 1

$SCRIPTS_DIR/configure.sh cyphal_quadrotor
${REPOSITORY_DIR}/scripts/configurator.py ${REPOSITORY_DIR}/configs/vehicles/px4_v1_14_0_cyphal_quadcopter.yaml
$SCRIPTS_DIR/docker.sh cq &
sleep 15 # px4 needs time after booting up to initialize everything
$SCRIPTS_DIR/test_scenario.sh --mission $CURRENT_DIR/takeoff_and_land.plan
Expand Down
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()
127 changes: 0 additions & 127 deletions scripts/configure.sh

This file was deleted.

Loading
Loading