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
|
2013-12-30 20:54:42 -04:00
|
|
|
# To enable PWM on FMUv1 on ttyS1 add a /fs/microsd/APM/AUXPWM.en 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
|
2013-08-03 05:51:59 -03:00
|
|
|
echo "APM/nostart found - skipping APM startup"
|
|
|
|
sh /etc/init.d/rc.error
|
|
|
|
fi
|
2013-01-25 05:36:33 -04:00
|
|
|
|
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"
|
2013-08-03 05:51:59 -03:00
|
|
|
if mount -t binfs /dev/null /bin
|
|
|
|
then
|
|
|
|
echo "binfs mounted OK"
|
|
|
|
else
|
|
|
|
sh /etc/init.d/rc.error
|
|
|
|
fi
|
2013-02-17 22:55:58 -04:00
|
|
|
fi
|
2013-01-20 17:21:44 -04:00
|
|
|
|
|
|
|
set sketch NONE
|
2014-01-13 21:41:07 -04:00
|
|
|
if rm /fs/microsd/APM/boot.log
|
|
|
|
then
|
|
|
|
echo "removed old boot.log"
|
|
|
|
fi
|
2014-01-13 00:04:42 -04:00
|
|
|
set logfile /fs/microsd/APM/BOOT.LOG
|
2013-01-20 17:21:44 -04:00
|
|
|
|
2013-08-03 05:51:59 -03:00
|
|
|
if [ ! -f /bin/ArduPilot ]
|
2013-01-20 17:21:44 -04:00
|
|
|
then
|
2013-08-03 05:51:59 -03:00
|
|
|
echo "/bin/ardupilot not found"
|
|
|
|
sh /etc/init.d/rc.error
|
2013-01-20 17:21:44 -04:00
|
|
|
fi
|
|
|
|
|
2013-08-05 22:27:34 -03:00
|
|
|
if mkdir /fs/microsd/APM > /dev/null
|
2013-01-20 17:21:44 -04:00
|
|
|
then
|
2013-08-03 05:51:59 -03:00
|
|
|
echo "Created APM directory"
|
|
|
|
fi
|
2013-03-21 00:59:58 -03:00
|
|
|
|
2013-10-30 01:33:42 -03:00
|
|
|
if [ -f /bin/lsm303d ]
|
2013-08-03 05:51:59 -03:00
|
|
|
then
|
|
|
|
echo "Detected FMUv2 board"
|
|
|
|
set BOARD FMUv2
|
2013-10-30 01:33:42 -03:00
|
|
|
else
|
|
|
|
echo "Detected FMUv1 board"
|
|
|
|
set BOARD FMUv1
|
2013-08-03 05:51:59 -03:00
|
|
|
fi
|
2013-07-25 22:12:37 -03:00
|
|
|
|
2013-11-22 06:54:37 -04:00
|
|
|
if [ $BOARD == FMUv1 ]
|
2013-08-03 05:51:59 -03:00
|
|
|
then
|
2013-11-22 06:54:37 -04:00
|
|
|
set deviceC /dev/ttyS2
|
2013-12-30 20:54:42 -04:00
|
|
|
if [ -f /fs/microsd/APM/AUXPWM.en ]
|
2013-08-03 05:51:59 -03:00
|
|
|
then
|
2013-11-22 06:54:37 -04:00
|
|
|
set deviceD /dev/null
|
2013-12-30 20:54:42 -04:00
|
|
|
else
|
|
|
|
set deviceD /dev/ttyS1
|
2013-08-03 05:51:59 -03:00
|
|
|
fi
|
2013-11-22 06:54:37 -04:00
|
|
|
else
|
|
|
|
set deviceC /dev/ttyS1
|
|
|
|
set deviceD /dev/ttyS2
|
2013-08-03 05:51:59 -03:00
|
|
|
fi
|
|
|
|
|
2013-10-30 01:33:42 -03:00
|
|
|
if uorb start
|
|
|
|
then
|
|
|
|
echo "uorb started OK"
|
|
|
|
else
|
|
|
|
sh /etc/init.d/rc.error
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# try the px4io start twice. Some FMUv2 board don't
|
|
|
|
# come up the first time
|
|
|
|
set HAVE_PX4IO false
|
|
|
|
if px4io start
|
|
|
|
then
|
|
|
|
set HAVE_PX4IO true
|
|
|
|
else
|
2013-12-12 21:44:47 -04:00
|
|
|
# it may be in bootloader mode
|
|
|
|
echo Loading /etc/px4io/px4io.bin
|
|
|
|
tone_alarm MBABGP
|
|
|
|
if px4io update /etc/px4io/px4io.bin
|
|
|
|
then
|
|
|
|
echo "upgraded PX4IO firmware OK"
|
|
|
|
tone_alarm MSPAA
|
|
|
|
else
|
|
|
|
echo "Failed to upgrade PX4IO firmware"
|
|
|
|
tone_alarm MNGGG
|
|
|
|
fi
|
|
|
|
sleep 1
|
2013-10-30 01:33:42 -03:00
|
|
|
if px4io start
|
|
|
|
then
|
|
|
|
set HAVE_PX4IO true
|
|
|
|
# play happy tune again
|
|
|
|
tone_alarm start
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $HAVE_PX4IO == true ]
|
|
|
|
then
|
|
|
|
echo "PX4IO board OK"
|
|
|
|
echo "PX4IO board OK" >> $logfile
|
2013-12-12 21:44:47 -04:00
|
|
|
if px4io checkcrc /etc/px4io/px4io.bin
|
|
|
|
then
|
|
|
|
echo "PX4IO CRC OK"
|
|
|
|
echo "PX4IO CRC OK" >> $logfile
|
|
|
|
else
|
|
|
|
echo "PX4IO CRC failure"
|
|
|
|
echo "PX4IO CRC failure" >> $logfile
|
|
|
|
tone_alarm MBABGP
|
|
|
|
if px4io forceupdate 14662 /etc/px4io/px4io.bin
|
|
|
|
then
|
|
|
|
sleep 1
|
|
|
|
if px4io start
|
|
|
|
then
|
|
|
|
echo "PX4IO restart OK"
|
|
|
|
echo "PX4IO restart OK" >> $logfile
|
|
|
|
tone_alarm MSPAA
|
|
|
|
else
|
|
|
|
echo "PX4IO restart failed"
|
|
|
|
echo "PX4IO restart failed" >> $logfile
|
|
|
|
tone_alarm MNGGG
|
|
|
|
sh /etc/init.d/rc.error
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "PX4IO update failed"
|
|
|
|
echo "PX4IO update failed" >> $logfile
|
|
|
|
tone_alarm MNGGG
|
|
|
|
fi
|
|
|
|
fi
|
2013-10-30 01:33:42 -03:00
|
|
|
else
|
|
|
|
echo "No PX4IO board found"
|
|
|
|
echo "No PX4IO board found" >> $logfile
|
|
|
|
|
|
|
|
if [ $BOARD == FMUv2 ]
|
|
|
|
then
|
|
|
|
sh /etc/init.d/rc.error
|
|
|
|
fi
|
|
|
|
|
|
|
|
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
|
|
|
|
mkblctrl -mkmode x
|
|
|
|
fi
|
2013-11-22 06:54:37 -04:00
|
|
|
fi
|
2013-10-30 01:33:42 -03:00
|
|
|
|
2013-11-22 06:54:37 -04:00
|
|
|
if [ $BOARD == FMUv1 -a $deviceD == /dev/ttyS1 ]
|
|
|
|
then
|
|
|
|
echo "Setting FMU mode_serial"
|
|
|
|
fmu mode_serial
|
|
|
|
else
|
|
|
|
echo "Setting FMU mode_pwm"
|
|
|
|
fmu mode_pwm
|
2013-10-30 01:33:42 -03:00
|
|
|
fi
|
|
|
|
|
2013-08-05 22:39:00 -03:00
|
|
|
|
2013-08-03 05:51:59 -03:00
|
|
|
echo "Starting APM sensors"
|
|
|
|
echo "Starting APM sensors" > $logfile
|
|
|
|
if ms5611 start
|
|
|
|
then
|
|
|
|
echo "ms5611 started OK"
|
|
|
|
else
|
|
|
|
sh /etc/init.d/rc.error
|
|
|
|
fi
|
|
|
|
|
|
|
|
if adc start
|
|
|
|
then
|
|
|
|
echo "adc started OK"
|
|
|
|
else
|
|
|
|
sh /etc/init.d/rc.error
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $BOARD == FMUv1 ]
|
|
|
|
then
|
|
|
|
echo "Starting FMUv1 sensors"
|
|
|
|
if hmc5883 start
|
|
|
|
then
|
|
|
|
echo "hmc5883 started OK"
|
|
|
|
else
|
|
|
|
sh /etc/init.d/rc.error
|
|
|
|
fi
|
2013-10-30 01:33:42 -03:00
|
|
|
if mpu6000 start
|
|
|
|
then
|
|
|
|
echo "mpu6000 started OK"
|
|
|
|
else
|
|
|
|
sh /etc/init.d/rc.error
|
|
|
|
fi
|
2013-12-08 05:45:32 -04:00
|
|
|
if l3gd20 start
|
|
|
|
then
|
|
|
|
echo "l3gd20 started OK"
|
|
|
|
else
|
|
|
|
echo "No l3gd20"
|
|
|
|
echo "No l3gd20" >> $logfile
|
|
|
|
fi
|
2013-08-03 05:51:59 -03:00
|
|
|
else
|
|
|
|
echo "Starting FMUv2 sensors"
|
|
|
|
if hmc5883 start
|
|
|
|
then
|
|
|
|
echo "Using external magnetometer"
|
|
|
|
fi
|
2013-12-08 05:45:32 -04:00
|
|
|
if mpu6000 start
|
2013-10-30 01:33:42 -03:00
|
|
|
then
|
2013-12-08 05:45:32 -04:00
|
|
|
echo "Found MPU6000"
|
|
|
|
echo "Found MPU6000" >> $logfile
|
|
|
|
else
|
|
|
|
echo "No MPU6000"
|
|
|
|
echo "No MPU6000" >> $logfile
|
|
|
|
fi
|
|
|
|
if l3gd20 start
|
2013-08-03 05:51:59 -03:00
|
|
|
then
|
2013-12-08 05:45:32 -04:00
|
|
|
echo "l3gd20 started OK"
|
|
|
|
else
|
|
|
|
sh /etc/init.d/rc.error
|
|
|
|
fi
|
|
|
|
if lsm303d start
|
|
|
|
then
|
|
|
|
echo "lsm303d started OK"
|
|
|
|
else
|
|
|
|
sh /etc/init.d/rc.error
|
2013-08-03 05:51:59 -03:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# optional ETS airspeed sensor
|
|
|
|
if ets_airspeed start
|
|
|
|
then
|
|
|
|
echo "Found ETS airspeed sensor" >> $logfile
|
|
|
|
fi
|
|
|
|
|
2013-08-21 08:06:54 -03:00
|
|
|
if meas_airspeed start
|
|
|
|
then
|
|
|
|
echo "Found MEAS airspeed sensor" >> $logfile
|
|
|
|
fi
|
|
|
|
|
2013-08-03 05:51:59 -03:00
|
|
|
echo "Trying PX4IO board"
|
|
|
|
echo "Trying PX4IO board" >> $logfile
|
|
|
|
|
2013-09-11 01:15:35 -03:00
|
|
|
# rgbled
|
|
|
|
if rgbled start
|
|
|
|
then
|
|
|
|
echo "rgbled started OK"
|
|
|
|
else
|
|
|
|
echo "Failed to start rgbled driver" >> $logfile
|
|
|
|
fi
|
|
|
|
|
2014-01-13 21:41:07 -04:00
|
|
|
if [ $BOARD == FMUv2 ]
|
|
|
|
then
|
|
|
|
if mtd start
|
|
|
|
then
|
|
|
|
echo "started mtd driver OK"
|
|
|
|
else
|
|
|
|
echo "failed to start mtd driver"
|
|
|
|
sh /etc/init.d/rc.error
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-08-03 05:51:59 -03:00
|
|
|
echo Starting ArduPilot
|
2013-11-22 06:54:37 -04:00
|
|
|
echo Starting ArduPilot $deviceA $deviceC $deviceD >> $logfile
|
|
|
|
if ArduPilot -d $deviceA -d2 $deviceC -d3 $deviceD start
|
2013-08-03 05:51:59 -03:00
|
|
|
then
|
|
|
|
echo ArduPilot started OK
|
2013-01-20 17:21:44 -04:00
|
|
|
else
|
2013-08-03 05:51:59 -03:00
|
|
|
sh /etc/init.d/rc.error
|
|
|
|
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-08-05 23:11:18 -03:00
|
|
|
|