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
|
|
|
|
# To disable use of a PX4IO board add a file /fs/microsd/APM/fmu_only
|
|
|
|
|
|
|
|
set deviceA /dev/ttyACM0
|
|
|
|
set deviceC /dev/ttyS1
|
|
|
|
|
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
|
|
|
|
|
|
|
|
if [ -f /bin/ArduPlane ]
|
|
|
|
then
|
|
|
|
set sketch ArduPlane
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f /bin/ArduCopter ]
|
|
|
|
then
|
|
|
|
set sketch ArduCopter
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f /bin/APMrover2 ]
|
|
|
|
then
|
|
|
|
set sketch APMrover2
|
|
|
|
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-02-17 22:55:58 -04:00
|
|
|
if [ -f /fs/microsd/px4io.bin ]
|
|
|
|
then
|
|
|
|
echo "Checking for new px4io firmware"
|
|
|
|
if cmp /fs/microsd/px4io.bin /fs/microsd/px4io.bin.loaded
|
|
|
|
then
|
|
|
|
echo "No new px4io firmware"
|
|
|
|
else
|
|
|
|
echo "Loading /fs/microsd/px4io.bin"
|
2013-02-20 03:15:23 -04:00
|
|
|
if px4io update /fs/microsd/px4io.bin > /fs/microsd/APM/px4io_update.log
|
|
|
|
then
|
|
|
|
cp /fs/microsd/px4io.bin /fs/microsd/px4io.bin.loaded
|
|
|
|
echo "Loaded /fs/microsd/px4io.bin OK" >> /fs/microsd/APM/px4io_update.log
|
|
|
|
else
|
|
|
|
echo "Failed loading /fs/microsd/px4io.bin" >> /fs/microsd/APM/px4io_update.log
|
|
|
|
echo "Failed to upgrade PX4IO firmware - check PX4IO is in bootloader mode"
|
|
|
|
fi
|
2013-02-17 22:55:58 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-01-20 17:21:44 -04:00
|
|
|
echo "Starting APM sensors"
|
2013-02-17 22:55:58 -04:00
|
|
|
uorb start
|
2013-01-20 17:21:44 -04:00
|
|
|
mpu6000 start
|
|
|
|
ms5611 start
|
|
|
|
hmc5883 start
|
2013-01-20 22:55:58 -04:00
|
|
|
adc start
|
|
|
|
|
2013-02-17 22:55:58 -04:00
|
|
|
if [ -f /fs/microsd/APM/fmu_only ]
|
2013-01-20 17:21:44 -04:00
|
|
|
then
|
2013-02-17 22:55:58 -04:00
|
|
|
echo "Setting up PX4FMU direct mode"
|
2013-01-20 17:21:44 -04:00
|
|
|
fmu start mode_pwm
|
2013-02-17 22:55:58 -04:00
|
|
|
if [ $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
|
2013-02-17 22:55:58 -04:00
|
|
|
else
|
|
|
|
echo "Setting up PX4IO board"
|
|
|
|
px4io start
|
|
|
|
echo "Loading FMU_pass mixer"
|
|
|
|
mixer load /dev/pwm_output /etc/mixers/FMU_pass.mix
|
|
|
|
echo "Setting FMU mode_serial"
|
|
|
|
fmu mode_serial
|
2013-01-20 17:21:44 -04:00
|
|
|
fi
|
2013-02-17 22:55:58 -04:00
|
|
|
|
2013-01-20 17:21:44 -04:00
|
|
|
echo Starting $sketch
|
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-01-25 05:36:33 -04:00
|
|
|
fi
|
2013-02-17 22:55:58 -04:00
|
|
|
|
|
|
|
echo "rc.APM finished"
|