From 868574508ad28b13f5298c41cd0eb328ea5fc8f8 Mon Sep 17 00:00:00 2001 From: Bob Long Date: Tue, 25 Jun 2024 09:34:05 +1000 Subject: [PATCH] Tools: add SITL defaults processor Also added default files for Volanti SW-241 --- .../Carbonix_scripts/process_sitl_defaults.py | 52 ++++++++++++ Tools/Carbonix_scripts/sitl_build.sh | 15 ++++ .../sitl_params/cbxvolanti_hl.parm | 83 +++++++++++++++++++ .../sitl_params/cbxvolanti_rf.parm | 46 ++++++++++ 4 files changed, 196 insertions(+) create mode 100644 Tools/Carbonix_scripts/process_sitl_defaults.py create mode 100755 Tools/Carbonix_scripts/sitl_build.sh create mode 100644 libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/sitl_params/cbxvolanti_hl.parm create mode 100644 libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/sitl_params/cbxvolanti_rf.parm diff --git a/Tools/Carbonix_scripts/process_sitl_defaults.py b/Tools/Carbonix_scripts/process_sitl_defaults.py new file mode 100644 index 0000000000..a63497e9ae --- /dev/null +++ b/Tools/Carbonix_scripts/process_sitl_defaults.py @@ -0,0 +1,52 @@ +''' +Build SITL default parameter files for use with SITL launcher +''' + +import os +import re +import fnmatch +import argparse + + +def main(): + parser = argparse.ArgumentParser(description='Build SITL default parameter files') + parser.add_argument('input_file', help='Input file to process') + parser.add_argument('output_file', help='Output file to write to') + args = parser.parse_args() + + defaults = process_defaults(args.input_file) + with open(args.output_file, "w") as f: + f.write("\n".join(defaults)) + + +def process_defaults(file, depth=0): + if depth > 10: + raise Exception("Too many levels of @include") + + param_list = [] + with open(file, "r") as f: + lines = f.read().splitlines() + for line in lines: + if line.startswith("@include"): + rel_path = line.split(maxsplit=1)[1] + path = os.path.join(os.path.dirname(file), rel_path) + param_list.extend( + process_defaults(path, depth + 1) + ) + continue + + if line.startswith("@delete"): + pattern = line.split(maxsplit=1)[1] + for i in range(len(param_list)): + param_name = re.split(r"[\s,]+", param_list[i])[0] + if fnmatch.fnmatch(param_name, pattern): + param_list[i] = "#deleted " + param_list[i] + line = "#" + line + + param_list.append(line) + + return param_list + + +if __name__ == "__main__": + main() diff --git a/Tools/Carbonix_scripts/sitl_build.sh b/Tools/Carbonix_scripts/sitl_build.sh new file mode 100755 index 0000000000..af53c645bb --- /dev/null +++ b/Tools/Carbonix_scripts/sitl_build.sh @@ -0,0 +1,15 @@ +# Exit if any command fails +set -e + +# Loop through all .parm files in libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/sitl_params/ +for file in libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/sitl_params/*.parm +do + mkdir -p build/sitl + outfile=build/sitl/$(basename $file) + echo "Processing $(basename $file)" + # Run parse_sitl_params.py script passing full path to .parm file and output folder + python Tools/Carbonix_scripts/process_sitl_defaults.py $file $outfile +done + +./waf configure --board sitl --define=CARBOPILOT=1 --debug +./waf plane diff --git a/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/sitl_params/cbxvolanti_hl.parm b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/sitl_params/cbxvolanti_hl.parm new file mode 100644 index 0000000000..76068fee8a --- /dev/null +++ b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/sitl_params/cbxvolanti_hl.parm @@ -0,0 +1,83 @@ +# Carbonix Volanti Headless Parameters +@include ../../CubeOrange-Volanti/defaults.parm +ARSPD_OFFSET,2013 +ARSPD_TYPE,2 +ARSPD2_OFFSET,2013 +ARSPD2_PIN,2 +ARSPD2_TYPE,2 +@delete BATT*_PIN +BATT2_AMP_PERVLT,12.75 +BATT2_MONITOR,4 +BATT2_VOLT_MULT,40.4 +BATT3_AMP_PERVLT,12.75 +BATT3_MONITOR,4 +BATT3_VOLT_MULT,40.4 +GPS_TYPE,1 +GPS_TYPE2,1 +@delete INS_* +INS_ACC2OFFS_X,0.001 +INS_ACC2OFFS_Y,0.001 +INS_ACC2OFFS_Z,0.001 +INS_ACC2SCAL_X,1.001 +INS_ACC2SCAL_Y,1.001 +INS_ACC2SCAL_Z,1.001 +INS_ACCOFFS_X,0.001 +INS_ACCOFFS_Y,0.001 +INS_ACCOFFS_Z,0.001 +INS_ACCSCAL_X,1.001 +INS_ACCSCAL_Y,1.001 +INS_ACCSCAL_Z,1.001 +INS_GYR_CAL,0 # taken from quadplane autotest parameters, just in case +NAVL1_PERIOD,14 +@delete PTCH_RATE_* +PTCH_RATE_FF,1.407055 +PTCH_RATE_I,0.2125 +PTCH_RATE_IMAX,0.888889 +PTCH_RATE_P,0.309954 +@delete PTCH2SRV_* +@delete Q_A_* +Q_A_ACCEL_P_MAX,30000 +Q_A_ACCEL_R_MAX,30000 +Q_A_ACCEL_Y_MAX,4500 +Q_A_RAT_PIT_D,0.002 +Q_A_RAT_PIT_P,0.15 +Q_A_RAT_RLL_D,0.002 +Q_A_RAT_RLL_P,0.15 +Q_A_RATE_P_MAX,60 +Q_A_RATE_R_MAX,60 +Q_A_RATE_Y_MAX,12 +Q_A_SLEW_YAW,1500 +@delete Q_M_* +@delete Q_P_* +@delete RLL_RATE_* +RLL_RATE_FF,0.552741 +RLL_RATE_I,0.2125 +RLL_RATE_IMAX,0.888889 +RLL_RATE_P,0.141009 +RNGFND1_PIN,0 +RNGFND1_SCALING,40 +RNGFND1_TYPE,1 +@delete SERVO* +SERVO3_MAX,2000 +SERVO3_MIN,1000 +SERVO3_TRIM,1000 +SIM_ARSPD_RATIO,1.6 +SIM_ARSPD2_RATIO,1.6 +SIM_BATT_CAP_AH,29.33 +SIM_GPS_POS_X,-0.12 +SIM_GPS_POS_Y,-0.17 +SIM_GPS_POS_Z,-0.06 +SIM_GPS2_DISABLE,0 +SIM_GPS2_POS_X,-0.12 +SIM_GPS2_POS_Y,0.17 +SIM_GPS2_POS_Z,-0.06 +SIM_IMU_POS_X,-0.21 +SIM_IMU_POS_Z,-0.03 +SIM_MAG1_DEVID,70403 +SIM_MAG2_DEVID,72963 +SIM_PLD_LAT,43.17443 +SIM_PLD_LON,-71.78664 +SIM_SONAR_POS_X,-0.12 +SIM_SONAR_POS_Z,0.05 +SIM_SONAR_SCALE,40 +@delete YAW2SRV_* diff --git a/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/sitl_params/cbxvolanti_rf.parm b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/sitl_params/cbxvolanti_rf.parm new file mode 100644 index 0000000000..a0168963b4 --- /dev/null +++ b/libraries/AP_HAL_ChibiOS/hwdef/CarbonixCommon/sitl_params/cbxvolanti_rf.parm @@ -0,0 +1,46 @@ +# Carbonix Volanti RealFlight Parameters +@include ../../CubeOrange-Volanti/defaults.parm +# SITL-specific parameters +AHRS_EKF_TYPE,3 +ARSPD_OFFSET,2013 +ARSPD_TYPE,2 +ARSPD2_OFFSET,2013 +ARSPD2_PIN,2 +ARSPD2_TYPE,2 +BATT_OPTIONS,0 # Disable reporting sag corrected voltage, because it already is (due to RF bug) +BATT2_AMP_PERVLT,8.5 +BATT2_CURR_PIN,12 +BATT2_MONITOR,4 +BATT2_VOLT_MULT,10.1 +BATT2_VOLT_PIN,13 +BATT3_AMP_PERVLT,8.5 +BATT3_CURR_PIN,12 +BATT3_MONITOR,4 +BATT3_VOLT_MULT,10.1 +BATT3_VOLT_PIN,13 +BATT4_MONITOR,0 +GPS_TYPE,1 +GPS_TYPE2,1 +@delete INS_* +RNGFND1_PIN,0 +RNGFND1_SCALING,40 +RNGFND1_TYPE,1 +SERVO7_FUNCTION,21 # RealFlight model uses old servo numbering +SIM_ARSPD_RATIO,1.6 +SIM_ARSPD2_RATIO,1.6 +SIM_GPS_POS_X,-0.12 +SIM_GPS_POS_Y,-0.17 +SIM_GPS_POS_Z,-0.06 +SIM_GPS2_DISABLE,0 +SIM_GPS2_POS_X,-0.12 +SIM_GPS2_POS_Y,0.17 +SIM_GPS2_POS_Z,-0.06 +SIM_IMU_POS_X,-0.21 +SIM_IMU_POS_Z,-0.03 +SIM_MAG1_DEVID,70403 +SIM_MAG2_DEVID,72963 +SIM_PLD_LAT,43.17443 +SIM_PLD_LON,-71.78664 +SIM_SONAR_POS_X,-0.12 +SIM_SONAR_POS_Z,0.05 +SIM_SONAR_SCALE,40