Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ jobs:
with:
token: ${{secrets.ACCESS_TOKEN}}

- name: install dependencies
run: pip3 install dataclasses
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

px4params/scrparser.py. When I wrote that I was targeting Python 3.7 compatibility since that's the oldest "supported" Python but I then realized we use 3.6 in some places. This is backwards compatibility for 3.6, dataclasses are built into 3.7+

Daniel and I decided to add it directly here because the bionic docker containers aren't behaving (unrelated to my changes) and I couldn't build a new one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO worth adding a comment in the file or commit message, so we can remove it later on.


- name: make clang-tidy-quiet
run: make clang-tidy-quiet
3 changes: 3 additions & 0 deletions .github/workflows/mavros_mission_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ jobs:
ccache -s
ccache -z

- name: install dependencies
run: pip3 install dataclasses

- name: check environment
run: |
export
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/mavros_offboard_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
ccache -s
ccache -z

- name: install dependencies
run: pip3 install dataclasses

- name: check environment
run: |
export
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ shellcheck_all:
validate_module_configs:
@find "$(SRC_DIR)"/src/modules "$(SRC_DIR)"/src/drivers "$(SRC_DIR)"/src/lib -name *.yaml -type f \
-not -path "$(SRC_DIR)/src/lib/mixer_module/*" -not -path "$(SRC_DIR)/src/lib/crypto/libtommath/*" -print0 | \
xargs -0 "$(SRC_DIR)"/Tools/validate_yaml.py --schema-file "$(SRC_DIR)"/validation/module_schema.yaml
xargs -0 "$(SRC_DIR)"/Tools/validate.py --schema-file "$(SRC_DIR)"/validation/module_schema.yaml

# Cleanup
# --------------------------------------------------------------------
Expand Down
497 changes: 497 additions & 0 deletions Tools/migrate_c_params.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Tools/module_config/generate_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def parse_yaml_parameters_config(yaml_config, ethernet_supported):
for tag in ['decimal', 'increment', 'category', 'volatile',
'min', 'max', 'unit', 'reboot_required']:
if tag in param:
if type(param[tag]) is bool and not param[tag]:
continue
tags += '\n * @{:} {:}'.format(tag, param[tag])

for i in range(num_instances):
Expand Down
2 changes: 1 addition & 1 deletion Tools/serial/generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def parse_yaml_serial_config(yaml_config):
else:
default_port_str = port_config['default']

if default_port_str != "":
if default_port_str != "" and default_port_str != 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is this a number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Daniel had used that as a "null" default for the sagetech transponder driver. However I see that just two days back he fixed that. I no longer need this, I'll remove it.

if default_port_str not in serial_ports:
raise Exception("Default Port {:} not found for {:}".format(default_port_str, serial_command['label']))

Expand Down
88 changes: 88 additions & 0 deletions Tools/validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#! /usr/bin/env python3
""" Script to validate YAML file(s) against a YAML schema file """

import argparse
import logging
import pprint
import sys
import os

try:
import yaml
except ImportError as e:
print("Failed to import yaml: " + str(e))
print("")
print("You may need to install it using:")
print(" pip3 install --user pyyaml")
print("")
sys.exit(1)

try:
import cerberus
except ImportError as e:
print("Failed to import cerberus: " + str(e))
print("")
print("You may need to install it using:")
print(" pip3 install --user cerberus")
print("")
sys.exit(1)


def load_data_file(file_name: str):
with open(file_name) as stream:
try:
return yaml.safe_load(stream)
except:
raise Exception("Unable to parse schema file: syntax error or unsupported file format")


def main():
parser = argparse.ArgumentParser(description='Validate YAML or JSON file(s) against a schema')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is json being handled?


parser.add_argument('data_file', nargs='+', help='data file(s)')
parser.add_argument('--schema-file', type=str, action='store',
help='schema file', required=True)
parser.add_argument('--skip-if-no-schema', dest='skip_if_no_schema',
action='store_true',
help='Skip test if schema file does not exist')
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
help='Verbose Output')

args = parser.parse_args()

data_files = args.data_file
schema_file = args.schema_file

if args.verbose:
logging.basicConfig(level=logging.INFO)
else:
logging.basicConfig(level=logging.ERROR)

if args.skip_if_no_schema and not os.path.isfile(schema_file):
logging.info(f"Schema file {schema_file} not found, skipping")
sys.exit(0)

# load the schema
schema = load_data_file(schema_file)
validator = cerberus.Validator(schema, allow_unknown=False)

# validate the specified data files
for data_file in data_files:
logging.info(f"Validating {data_file}")

document = load_data_file(data_file)

# ignore top-level entries prefixed with __ for yaml module definitions
for key in list(document.keys()):
if key.startswith('__'):
del document[key]

if not validator.validate(document):
logging.error(f"Found validation errors with {data_file}:")
logging.error(pprint.pformat(validator.errors))

raise Exception("Validation of {:} failed".format(data_file))


if __name__ == "__main__":
main()
4 changes: 3 additions & 1 deletion Tools/validate_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@

try:
validate(instance=json_data, schema=schema)
except:
except Exception as ex:
print(ex.path.pop(), ex.instance)
print("JSON validation for {:} failed (schema: {:})".format(json_file, schema_file))
raise


68 changes: 0 additions & 68 deletions Tools/validate_yaml.py

This file was deleted.

24 changes: 24 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
argparse
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't see that. I'll fix.

argcomplete
coverage
cerberus
empy
jinja2
kconfiglib
matplotlib==3.0.*
numpy
nunavut>=1.1.0
packaging
pkgconfig
pyros-genmsg
pyulog
pyyaml
requests
serial
six
toml
psutil
wheel
jsonschema
dataclasses
pynacl
2 changes: 2 additions & 0 deletions src/drivers/actuators/modalai_esc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ px4_add_module(
qc_esc_packet_types.h
qc_esc_packet.c
qc_esc_packet.h
MODULE_CONFIG
module.yaml
DEPENDS
px4_work_queue
)
113 changes: 113 additions & 0 deletions src/drivers/actuators/modalai_esc/module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
module_name: modalai_esc
parameters:
- definitions:
UART_ESC_BAUD:
default: 250000
description:
long: Default rate is 250Kbps, which is used in off-the-shelf MoadalAI ESC products.
short: UART ESC baud rate
type: int32
unit: bit/s
volatile: false
UART_ESC_CONFIG:
default: 0
description:
long: Selects what type of UART ESC, if any, is being used.
short: UART ESC configuration
max: 1
min: 0
reboot_required: true
type: enum
values:
0: '- Disabled'
1: '- VOXL ESC'
volatile: false
UART_ESC_MODE:
default: 0
description:
long: Selects what type of mode is enabled, if any
short: UART ESC Mode
max: 2
min: 0
reboot_required: true
type: enum
values:
0: '- None'
1: '- Turtle Mode enabled via AUX1'
2: '- Turtle Mode enabled via AUX2'
volatile: false
UART_ESC_MOTOR1:
default: 3
description:
short: UART ESC Motor 1 Mapping. 1-4 (negative for reversal)
max: 4
min: -4
type: int32
volatile: false
UART_ESC_MOTOR2:
default: 2
description:
short: UART ESC Motor 2 Mapping. 1-4 (negative for reversal)
max: 4
min: -4
type: int32
volatile: false
UART_ESC_MOTOR3:
default: 4
description:
short: UART ESC Motor 3 Mapping. 1-4 (negative for reversal)
max: 4
min: -4
type: int32
volatile: false
UART_ESC_MOTOR4:
default: 1
description:
short: UART ESC Motor 4 Mapping. 1-4 (negative for reversal)
max: 4
min: -4
type: int32
volatile: false
UART_ESC_RPM_MAX:
default: 15000
description:
long: Maximum RPM for ESC
short: UART ESC RPM Max
type: int32
unit: RPM
volatile: false
UART_ESC_RPM_MIN:
default: 5500
description:
long: Minimum RPM for ESC
short: UART ESC RPM Min
type: int32
unit: RPM
volatile: false
group: UART ESC
- definitions:
UART_ESC_DEAD1:
decimal: 10
default: 0.3
description:
long: Must be greater than Deadzone 2. Absolute value of stick position needed to activate a motor.
short: UART ESC Mode Deadzone 1
increment: 0.01
max: 0.99
min: 0.01
type: float
volatile: false
group: UART ESC Mode Deadzone 1
- definitions:
UART_ESC_DEAD2:
decimal: 10
default: 0.02
description:
long: Must be less than Deadzone 1. Absolute value of stick position considered no longer on the X or Y axis, thus targetting a specific motor (single).
short: UART ESC Mode Deadzone 2
increment: 0.01
max: 0.99
min: 0.01
type: float
volatile: false
group: UART ESC Mode Deadzone 2
Loading