2013-01-20 17:21:44 -04:00
|
|
|
#!nsh
|
|
|
|
|
|
|
|
# APM startup script for NuttX on PX4
|
|
|
|
|
2013-02-17 22:55:58 -04:00
|
|
|
# To disable APM startup add a /fs/microsd/APM/nostart file
|
2013-07-11 00:18:54 -03:00
|
|
|
# To enable mkblctrl startup add a /fs/microsd/APM/mkblctrl file
|
|
|
|
# To enable mavlink on ttys0 add a /fs/microsd/APM/mavlink-ttys0 file
|
2013-02-17 22:55:58 -04:00
|
|
|
|
|
|
|
set deviceA /dev/ttyACM0
|
2013-07-11 00:18:54 -03:00
|
|
|
|
2013-03-17 22:25:45 -03:00
|
|
|
# check for an old file called APM, caused by
|
|
|
|
# a bug in an earlier firmware release
|
|
|
|
if [ -f /fs/microsd/APM ]
|
|
|
|
then
|
|
|
|
echo "APM file found - renaming"
|
|
|
|
mv /fs/microsd/APM /fs/microsd/APM.old
|
|
|
|
fi
|
|
|
|
|
2013-01-25 05:36:33 -04:00
|
|
|
if [ -f /fs/microsd/APM/nostart ]
|
|
|
|
then
|
|
|
|
echo "APM/nostart found - skipping"
|
|
|
|
else
|
|
|
|
|
2013-01-20 17:21:44 -04:00
|
|
|
# mount binfs so we can find the built-in apps
|
2013-02-17 22:55:58 -04:00
|
|
|
if [ -f /bin/reboot ]
|
|
|
|
then
|
|
|
|
echo "binfs already mounted"
|
|
|
|
else
|
|
|
|
echo "Mounting binfs"
|
|
|
|
mount -t binfs /dev/null /bin
|
|
|
|
fi
|
2013-01-20 17:21:44 -04:00
|
|
|
|
|
|
|
set sketch NONE
|
2013-03-21 01:05:08 -03:00
|
|
|
set logfile /fs/microsd/APM/boot.log
|
2013-01-20 17:21:44 -04:00
|
|
|
|
2013-05-04 01:31:22 -03:00
|
|
|
if [ -f /bin/ArduPilot ]
|
2013-01-20 17:21:44 -04:00
|
|
|
then
|
2013-05-04 01:31:22 -03:00
|
|
|
set sketch ArduPilot
|
2013-01-20 17:21:44 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $sketch != NONE ]
|
|
|
|
then
|
2013-03-16 05:46:51 -03:00
|
|
|
if mkdir /fs/microsd/APM
|
|
|
|
then
|
|
|
|
echo "Created APM directory"
|
|
|
|
fi
|
2013-03-21 00:59:58 -03:00
|
|
|
|
2013-07-25 22:12:37 -03:00
|
|
|
uorb start
|
|
|
|
if mpu6000 start
|
|
|
|
then
|
|
|
|
echo "Detected FMUv1 board"
|
|
|
|
set BOARD FMUv1
|
|
|
|
else
|
|
|
|
l3gd20 start
|
|
|
|
echo "Detected FMUv2 board"
|
|
|
|
set BOARD FMUv2
|
|
|
|
fi
|
|
|
|
|
2013-07-31 09:24:22 -03:00
|
|
|
if [ -f /fs/microsd/APM/mavlink-ttys0 ]
|
|
|
|
then
|
|
|
|
set deviceC /dev/ttyS0
|
|
|
|
else
|
|
|
|
if [ $BOARD == FMUv1 ]
|
|
|
|
then
|
|
|
|
set deviceC /dev/ttyS2
|
|
|
|
else
|
|
|
|
set deviceC /dev/ttyS1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-07-31 05:58:04 -03:00
|
|
|
echo checking for /etc/px4io/px4io.bin
|
|
|
|
if [ -f /etc/px4io/px4io.bin ]
|
2013-02-17 22:55:58 -04:00
|
|
|
then
|
|
|
|
echo "Checking for new px4io firmware"
|
2013-07-31 05:58:04 -03:00
|
|
|
if cmp /etc/px4io/px4io.bin /fs/microsd/px4io.loaded
|
2013-02-17 22:55:58 -04:00
|
|
|
then
|
|
|
|
echo "No new px4io firmware"
|
|
|
|
else
|
2013-07-31 05:58:04 -03:00
|
|
|
echo Loading /etc/px4io/px4io.bin
|
2013-05-31 23:41:28 -03:00
|
|
|
tone_alarm MBABGP
|
2013-07-31 05:58:04 -03:00
|
|
|
if px4io update /etc/px4io/px4io.bin > /fs/microsd/APM/px4io_update.log
|
2013-02-20 03:15:23 -04:00
|
|
|
then
|
2013-07-31 05:58:04 -03:00
|
|
|
cp /etc/px4io/px4io.bin /fs/microsd/px4io.loaded
|
|
|
|
echo Loaded /etc/px4io/px4io.bin OK >> /fs/microsd/APM/px4io_update.log
|
2013-05-31 23:41:28 -03:00
|
|
|
tone_alarm MSPAA
|
2013-02-20 03:15:23 -04:00
|
|
|
else
|
2013-07-31 05:58:04 -03:00
|
|
|
echo Failed loading /etc/px4io/px4io.bin >> /fs/microsd/APM/px4io_update.log
|
2013-07-25 22:12:37 -03:00
|
|
|
echo "check Safety Button" >> /fs/microsd/APM/px4io_update.log
|
2013-07-31 05:58:04 -03:00
|
|
|
echo "Failed to upgrade PX4IO firmware"
|
2013-05-31 23:41:28 -03:00
|
|
|
tone_alarm MNGGG
|
2013-02-20 03:15:23 -04:00
|
|
|
fi
|
2013-02-17 22:55:58 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-01-20 17:21:44 -04:00
|
|
|
echo "Starting APM sensors"
|
2013-03-21 01:05:08 -03:00
|
|
|
echo "Starting APM sensors" > $logfile
|
2013-07-25 22:12:37 -03:00
|
|
|
if [ $BOARD == FMUv1 ]
|
|
|
|
then
|
|
|
|
ms5611 start
|
|
|
|
hmc5883 start
|
|
|
|
adc start
|
|
|
|
else
|
|
|
|
ms5611 start
|
|
|
|
if hmc5883 start
|
|
|
|
then
|
|
|
|
echo "Using external magnetometer"
|
|
|
|
fi
|
|
|
|
lsm303d start
|
|
|
|
adc start
|
|
|
|
fi
|
2013-06-02 21:17:27 -03:00
|
|
|
if ets_airspeed start
|
|
|
|
then
|
|
|
|
echo "Found ETS airspeed sensor" >> $logfile
|
|
|
|
fi
|
2013-01-20 22:55:58 -04:00
|
|
|
|
2013-03-21 00:59:58 -03:00
|
|
|
echo "Trying PX4IO board"
|
2013-03-21 01:05:08 -03:00
|
|
|
echo "Trying PX4IO board" >> $logfile
|
2013-03-21 00:59:58 -03:00
|
|
|
if px4io start
|
2013-01-20 17:21:44 -04:00
|
|
|
then
|
2013-03-21 00:59:58 -03:00
|
|
|
echo "PX4IO board OK"
|
2013-03-21 01:05:08 -03:00
|
|
|
echo "PX4IO board OK" >> $logfile
|
2013-04-25 07:00:20 -03:00
|
|
|
echo "Setting FMU mode_pwm"
|
|
|
|
fmu mode_pwm
|
2013-07-30 09:58:02 -03:00
|
|
|
#echo "Loading FMU_pass mixer"
|
|
|
|
#mixer load /dev/pwm_output /etc/mixers/FMU_pass.mix
|
2013-07-31 09:24:22 -03:00
|
|
|
if [ $BOARD == FMUv1 ] && [ $deviceC == /dev/ttyS1 ]
|
2013-04-25 07:00:20 -03:00
|
|
|
then
|
|
|
|
# ttyS1 is used for PWM output for 4 extra channels
|
|
|
|
set deviceC /dev/ttyS2
|
|
|
|
fi
|
2013-03-21 00:59:58 -03:00
|
|
|
else
|
|
|
|
echo "No PX4IO board found"
|
2013-03-21 01:05:08 -03:00
|
|
|
echo "No PX4IO board found" >> $logfile
|
2013-07-11 00:18:54 -03:00
|
|
|
|
|
|
|
if [ -f /fs/microsd/APM/mkblctrl ]
|
|
|
|
then
|
|
|
|
echo "APM/mkblctrl found - switch to MK I2C ESCs"
|
|
|
|
echo "APM/mkblctrl found - switch to MK I2C ESCs" >> $logfile
|
|
|
|
echo "Setting up mkblctrl driver"
|
|
|
|
echo "Setting up mkblctrl driver" >> $logfile
|
|
|
|
sleep 1
|
|
|
|
mkblctrl -mkmode x
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
|
2013-02-17 22:55:58 -04:00
|
|
|
echo "Setting up PX4FMU direct mode"
|
2013-03-18 17:57:13 -03:00
|
|
|
fmu mode_pwm
|
2013-07-31 09:24:22 -03:00
|
|
|
if [ $BOARD == FMUv1 ] && [ $deviceC == /dev/ttyS1 ]
|
2013-01-20 17:21:44 -04:00
|
|
|
then
|
|
|
|
# ttyS1 is used for PWM output when there
|
|
|
|
# is no IO board
|
2013-02-17 22:55:58 -04:00
|
|
|
set deviceC /dev/ttyS2
|
2013-01-20 17:21:44 -04:00
|
|
|
fi
|
|
|
|
fi
|
2013-02-17 22:55:58 -04:00
|
|
|
|
2013-01-20 17:21:44 -04:00
|
|
|
echo Starting $sketch
|
2013-06-26 21:49:03 -03:00
|
|
|
echo Starting $sketch $deviceA $deviceC >> $logfile
|
2013-02-17 22:55:58 -04:00
|
|
|
$sketch -d $deviceA -d2 $deviceC start
|
2013-01-20 17:21:44 -04:00
|
|
|
|
|
|
|
# if starting on the console, tell nsh to exit
|
|
|
|
# this prevents it from chewing bytes
|
2013-02-17 22:55:58 -04:00
|
|
|
if [ $deviceC == /dev/ttyS0 ]
|
2013-01-20 17:21:44 -04:00
|
|
|
then
|
2013-02-17 22:55:58 -04:00
|
|
|
echo "Exiting from nsh shell"
|
2013-01-20 17:21:44 -04:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "No APM sketch found"
|
|
|
|
fi
|
2013-02-17 22:55:58 -04:00
|
|
|
|
|
|
|
echo "rc.APM finished"
|
2013-03-21 01:05:08 -03:00
|
|
|
echo "rc.APM finished" >> $logfile
|
2013-05-12 22:25:40 -03:00
|
|
|
fi
|