在px4启动文件RCS中,可以看到对autostart文件的读取
#
# Set parameters and env variables for selected AUTOSTART.
#
if ! param compare SYS_AUTOSTART 0
then
. ${R}etc/init.d/rc.autostart
fi
在固件编译前,我们找不到这个文件,完成固件编译后,会出现在
/home/user/PX4-Autopilot/build/px4_fmu-v5_default/etc/init.d/rc.autostart文件中,打开该文件,能看到(内容过长只截取一段):
if param compare SYS_AUTOSTART 13002
then
set AIRFRAME 13002_firefly6
fi
if param compare SYS_AUTOSTART 13010
then
set AIRFRAME 13010_claire
fi
if param compare SYS_AUTOSTART 13012
then
set AIRFRAME 13012_convergence
fi
if param compare SYS_AUTOSTART 13030
then
set AIRFRAME 13030_generic_vtol_quad_tiltrotor
fi
if [ ${AIRFRAME} != none ]
then
. /etc/init.d/airframes/${AIRFRAME}//当选择不同机架,则会自动读取对应机架的文件
else
echo "ERROR [init] No file matches SYS_AUTOSTART value found in : /etc/init.d/airframes"
param set SYS_AUTOSTART 0
tone_alarm ${TUNE_ERR}
fi
unset AIRFRAME
这里就有两种方式可以选择不同机架,1、在参数表修改SYS_AUTOSTART参数,该参数直接对应不同的机架文件;2、在机架表里自行寻找
我们可以打开4001 X型四轴,进行探究
. ${R}etc/init.d/rc.mc_defaults
set MIXER quad_x
set PWM_OUT 1234
. ${R}etc/init.d/rc.mc_defaults我们对该文件进行追踪
set VEHICLE_TYPE mc
param set-default IMU_GYRO_RATEMAX 800
param set-default NAV_ACC_RAD 2
param set-default RTL_RETURN_ALT 30
param set-default RTL_DESCEND_ALT 10
param set-default PWM_MAIN_MAX 1950
param set-default PWM_MAIN_MIN 1075
param set-default PWM_MAIN_RATE 400
param set-default GPS_UBX_DYNMODEL 6
set MIXER_AUX pass
set PWM_AUX_OUT 1234
也是对参数进行设置,其中set VEHICLE_TYPE mc这行代码很重要,在别的机架文件中也会用到,该参数代表了后续需要运行什么机架的应用程序。
返回到RCS文件中,我们能看到下面代码
#
# If autoconfig parameter was set, reset it and save parameters.
#
if [ $AUTOCNF = yes ]
then
param set SYS_AUTOCONFIG 0
fi
当SYS_AUTOCONFIG设置过一遍以后,就不再运行。再往下能看到对不同飞行器启动文件的加载。
#
# Configure vehicle type specific parameters.
# Note: rc.vehicle_setup is the entry point for rc.interface,
# rc.fw_apps, rc.mc_apps, rc.rover_apps, and rc.vtol_apps.
#
. ${R}etc/init.d/rc.vehicle_setup
然后在rc.vehicle_setup文件中,我们能看到
#!/bin/sh
#
# Vehicle configuration setup script.
#
# NOTE: Script variables are declared/initialized/unset in the rcS script.
#
#
# Fixed wing setup.
#
if [ $VEHICLE_TYPE = fw ]
then
if [ $MIXER = none ]
then
# Set default mixer for fixed wing if not defined.
set MIXER AERT
fi
if [ $MAV_TYPE = none ]
then
# Set a default MAV_TYPE = 1 if not defined.
set MAV_TYPE 1
fi
# Set the mav type parameter.
param set MAV_TYPE ${MAV_TYPE}
# Load mixer and configure outputs.
. ${R}etc/init.d/rc.interface
# Start standard fixedwing apps.
. ${R}etc/init.d/rc.fw_apps
fi
#
# Multicopter setup.
#
if [ $VEHICLE_TYPE = mc ]
then
if [ $MIXER = none ]
then
echo "MC mixer undefined"
fi
if [ $MAV_TYPE = none ]
then
# Set a default MAV_TYPE = 2 if not defined.
set MAV_TYPE 2
# Use mixer to detect vehicle type
if [ $MIXER = coax ]
then
set MAV_TYPE 3
fi
if [ $MIXER = hexa_x -o $MIXER = hexa_+ ]
then
set MAV_TYPE 13
fi
if [ $MIXER = hexa_cox ]
then
set MAV_TYPE 13
fi
if [ $MIXER = octo_x -o $MIXER = octo_+ ]
then
set MAV_TYPE 14
fi
if [ $MIXER = octo_cox -o $MIXER = octo_cox_w ]
then
set MAV_TYPE 14
fi
if [ $MIXER = tri_y_yaw- -o $MIXER = tri_y_yaw+ ]
then
set MAV_TYPE 15
fi
fi
# Set the mav type parameter.
param set MAV_TYPE ${MAV_TYPE}
# Load mixer and configure outputs.
. ${R}etc/init.d/rc.interface
# Start standard multicopter apps.
. ${R}etc/init.d/rc.mc_apps
fi
针对不同的飞行器,都会有对应的MAV_TYPE,一些常规的构型都会和MIXER进行对应。要不就需要写在机架中,类似13001,在其文件中我们能看到如下参数
param set-default VT_TYPE 0
set MAV_TYPE 19
set MIXER vtol_tailsitter_duo
set PWM_OUT 123456
在确定好MAV_TYPE参数后,将会进入rc.interface对混控文件进行更新
#!/bin/sh
#
# Script to configure control interfaces.
#
#
# NOTE: environment variable references:
# If the dollar sign ('$') is followed by a left bracket ('{') then the
# variable name is terminated with the right bracket character ('}').
# Otherwise, the variable name goes to the end of the argument.
#
set OUTPUT_CMD pwm_out
set MIXER_AUX_FILE none
set MIXER_EXTRA_FILE none
set OUTPUT_DEV none
set OUTPUT_AUX_DEV /dev/pwm_output1
set OUTPUT_EXTRA_DEV /dev/pwm_output0
#
# If mount (gimbal) control is enabled and output mode is AUX, set the aux
# mixer to mount (override the airframe-specific MIXER_AUX setting).
#
if param greater -s MNT_MODE_IN -1
then
if param compare -s MNT_MODE_OUT 0
then
set MIXER_AUX mount
fi
fi
#
# Set the default output mode if none was set.
#
if [ $OUTPUT_MODE = none ]
then
if [ $USE_IO = yes ]
then
# Enable IO output only if IO is present.
if [ $IO_PRESENT = yes ]
then
set OUTPUT_MODE io
if param greater -s DSHOT_CONFIG 0
then
set OUTPUT_CMD dshot
fi
fi
else
if param greater -s DSHOT_CONFIG 0
then
set OUTPUT_MODE dshot
set OUTPUT_CMD dshot
else
set OUTPUT_MODE pwm_out
fi
fi
fi
#
# If OUTPUT_MODE = none then something is wrong with setup and we shouldn't try to enable output.
#
if [ $OUTPUT_MODE != none ]
then
if [ $OUTPUT_MODE = hil -o $OUTPUT_MODE = sim ]
then
if ! pwm_out_sim start -m $OUTPUT_MODE
then
tune_control play error
fi
fi
if [ $OUTPUT_MODE = uavcan_esc ]
then
if param compare UAVCAN_ENABLE 0
then
param set UAVCAN_ENABLE 3
fi
fi
if [ $OUTPUT_MODE = io ]
then
. ${R}etc/init.d/rc.io
fi
if [ $OUTPUT_MODE = $OUTPUT_CMD -o $OUTPUT_MODE = io ]
then
if ! $OUTPUT_CMD start
then
echo "$OUTPUT_CMD start failed"
tune_control play error
fi
fi
#
# Start IO for RC input if needed.
#
if [ $IO_PRESENT = yes ]
then
if [ $OUTPUT_MODE != io ]
then
. ${R}etc/init.d/rc.io
fi
fi
fi
if [ $MIXER != none -a $MIXER != skip ]
then
#
# Load main mixer.
#
if [ $MIXER_AUX = none -a $USE_IO = yes ]
then
set MIXER_AUX ${MIXER}
fi
if [ "$MIXER_FILE" = none ]
then
if [ -f ${SDCARD_MIXERS_PATH}/${MIXER}.main.mix ]
then
# Use the mixer file from the SD-card if it exists.
set MIXER_FILE ${SDCARD_MIXERS_PATH}/${MIXER}.main.mix
else
# Try out the old convention, for backward compatibility.
if [ -f ${SDCARD_MIXERS_PATH}/${MIXER}.mix ]
then
set MIXER_FILE ${SDCARD_MIXERS_PATH}/${MIXER}.mix
else
set MIXER_FILE /etc/mixers/${MIXER}.main.mix
fi
fi
fi
set OUTPUT_DEV /dev/pwm_output0
if [ $OUTPUT_MODE = uavcan_esc ]
then
set OUTPUT_DEV /dev/uavcan/esc
fi
if mixer load ${OUTPUT_DEV} ${MIXER_FILE}
then
echo "INFO [init] Mixer: ${MIXER_FILE} on ${OUTPUT_DEV}"
else
echo "ERROR [init] Failed loading mixer: ${MIXER_FILE}"
tune_control play -t 18 # tune 18 = PROG_PX4IO_ERR
fi
else
if [ $MIXER != skip ]
then
echo "ERROR [init] Mixer undefined"
tune_control play -t 18 # tune 18 = PROG_PX4IO_ERR
fi
fi
if [ $MIXER_AUX != none ]
then
#
# Load aux mixer.
#
if [ -f ${SDCARD_MIXERS_PATH}/${MIXER_AUX}.aux.mix ]
then
set MIXER_AUX_FILE ${SDCARD_MIXERS_PATH}/${MIXER_AUX}.aux.mix
else
if [ -f /etc/mixers/${MIXER_AUX}.aux.mix ]
then
set MIXER_AUX_FILE /etc/mixers/${MIXER_AUX}.aux.mix
fi
fi
if [ $MIXER_AUX_FILE != none ]
then
# Append aux mixer to main device.
if param greater SYS_HITL 0
then
if mixer append ${OUTPUT_DEV} ${MIXER_AUX_FILE}
then
echo "INFO [init] Mixer: ${MIXER_AUX_FILE} appended to ${OUTPUT_DEV}"
else
echo "ERROR [init] Failed appending mixer: ${MIXER_AUX_FILE}"
fi
fi
if [ -e $OUTPUT_AUX_DEV -a $OUTPUT_MODE != hil ]
then
if mixer load ${OUTPUT_AUX_DEV} ${MIXER_AUX_FILE}
then
echo "INFO [init] Mixer: ${MIXER_AUX_FILE} on ${OUTPUT_AUX_DEV}"
else
echo "ERROR [init] Failed loading mixer: ${MIXER_AUX_FILE}"
fi
else
echo "INFO [init] setting PWM_AUX_OUT none"
set PWM_AUX_OUT none
fi
# for DShot do not configure pwm values
if [ $OUTPUT_CMD != dshot ]
then
# Set min / max for aux out and rates.
if [ $PWM_AUX_OUT != none ]
then
# Set PWM_AUX output frequency.
if [ $PWM_AUX_RATE != none ]
then
pwm rate -c ${PWM_AUX_OUT} -r ${PWM_AUX_RATE} -d ${OUTPUT_AUX_DEV}
fi
fi
fi
fi
fi
param set PWM_AUX_OUT ${PWM_AUX_OUT}
if [ $OUTPUT_MODE = pwm_out -o $OUTPUT_MODE = io ]
then
if [ $PWM_OUT != none ]
then
# Set PWM output frequency.
if [ $PWM_MAIN_RATE != none ]
then
pwm rate -c ${PWM_OUT} -r ${PWM_MAIN_RATE}
fi
fi
fi
param set PWM_MAIN_OUT ${PWM_OUT}
if [ $EXTRA_MIXER_MODE != none ]
then
if [ -f ${SDCARD_MIXERS_PATH}/${MIXER_EXTRA}.aux.mix ]
then
# Use the mixer file from the SD-card if it exists.
set MIXER_EXTRA_FILE ${SDCARD_MIXERS_PATH}/${MIXER_EXTRA}.aux.mix
else
# Try out the old convention, for backward compatibility.
if [ -f ${SDCARD_MIXERS_PATH}/${MIXER_EXTRA}.mix ]
then
set MIXER_EXTRA_FILE ${SDCARD_MIXERS_PATH}/${MIXER_EXTRA}.mix
else
set MIXER_EXTRA_FILE /etc/mixers/${MIXER_EXTRA}.aux.mix
fi
fi
if mixer load ${OUTPUT_EXTRA_DEV} ${MIXER_EXTRA_FILE}
then
echo "INFO [init] Mixer: ${MIXER_EXTRA_FILE} on ${OUTPUT_EXTRA_DEV}"
else
echo "ERROR [init] Failed loading mixer: ${MIXER_EXTRA_FILE}"
tune_control play -t 20
fi
if [ $PWM_EXTRA_OUT != none ]
then
# Set PWM output frequency.
if [ $PWM_EXTRA_RATE != none ]
then
pwm rate -c ${PWM_EXTRA_OUT} -r ${PWM_EXTRA_RATE}
fi
fi
fi
unset OUTPUT_CMD
unset MIXER_AUX_FILE
unset MIXER_EXTRA_FILE
unset OUTPUT_DEV
unset OUTPUT_AUX_DEV
unset OUTPUT_EXTRA_DEV
在该文件中,将会对mixer文件进行读取,并进行更新,然后进行app应用的启动