Skip to content

Commit

Permalink
[ardrone] Auto startup and configure paparazzi
Browse files Browse the repository at this point in the history
Added the possibility to auto startup paparazzi sdk or raw version. Automaticly configures the drone with the airframe file.
  • Loading branch information
fvantienen authored and flixr committed Sep 11, 2013
1 parent 604b5e1 commit c488f35
Show file tree
Hide file tree
Showing 6 changed files with 336 additions and 15 deletions.
35 changes: 23 additions & 12 deletions conf/Makefile.omap
Expand Up @@ -78,34 +78,45 @@ elf: $(OBJDIR)/$(TARGET).elf
# Program the device and start it.
load upload program: $(OBJDIR)/$(TARGET).elf

# If it is not the SDK version, then kill program.elf
ifneq ($(BOARD_TYPE), sdk)
-echo "killall -9 program.elf" | telnet $(HOST)
endif

# Kill the application
-echo "killall -9 $(TARGET).elf" | telnet $(HOST)

# Upload the modules and start the application
# Make the target dir and edit the config
-{ \
echo "mkdir -p $(TARGET_DIR)"; \
echo "mkdir -p $(TARGET_DIR)"; \
echo "if grep -q \"start_paparazzi *= \" /data/config.ini; then sed -i 's/\(start_paparazzi *= *\).*/\\\1$(ARDRONE2_START_PAPARAZZI)/g' /data/config.ini; else echo \"start_paparazzi = $(ARDRONE2_START_PAPARAZZI)\" >> /data/config.ini; fi"; \
echo "if grep -q \"wifi_mode *= \" /data/config.ini; then sed -i 's/\(wifi_mode *= *\).*/\\\1$(ARDRONE2_WIFI_MODE)/g' /data/config.ini; else echo \"wifi_mode = $(ARDRONE2_WIFI_MODE)\" >> /data/config.ini; fi"; \
echo "if grep -q \"ssid_single_player *= \" /data/config.ini; then sed -i 's/\(ssid_single_player *= *\).*/\\\1$(ARDRONE2_SSID)/g' /data/config.ini; else echo \"ssid_single_player = $(ARDRONE2_SSID)\" >> /data/config.ini; fi"; \
echo "if grep -q \"static_ip_address_base *= \" /data/config.ini; then sed -i 's/\(static_ip_address_base *= *\).*/\\\1$(ARDRONE2_IP_ADDRESS_BASE)/g' /data/config.ini; else echo \"static_ip_address_base = $(ARDRONE2_IP_ADDRESS_BASE)\" >> /data/config.ini; fi"; \
echo "if grep -q \"static_ip_address_probe *= \" /data/config.ini; then sed -i 's/\(static_ip_address_probe *= *\).*/\\\1$(ARDRONE2_IP_ADDRESS_PROBE)/g' /data/config.ini; else echo \"static_ip_address_probe = $(ARDRONE2_IP_ADDRESS_PROBE)\" >> /data/config.ini; fi"; \
} | telnet $(HOST)

# Upload the drivers and new application
{ \
echo "binary"; \
echo "put $(PAPARAZZI_SRC)/sw/ext/ardrone2_drivers/cdc-acm.ko /$(SUB_DIR)/cdc-acm.ko"; \
echo "put $(PAPARAZZI_SRC)/sw/ext/ardrone2_drivers/check_update.sh check_update.sh"; \
echo "put $(PAPARAZZI_SRC)/sw/ext/ardrone2_drivers/wifi_setup.sh wifi_setup.sh"; \
echo "put $(OBJDIR)/$(TARGET).elf /$(SUB_DIR)/$(TARGET).elf"; \
echo "quit"; \
} | ftp -n $(HOST)

# Upload the modules and start the application
-{ \
echo "cd $(TARGET_DIR)"; \
echo "insmod cdc-acm.ko"; \
echo "chmod 777 $(TARGET).elf"; \
echo "./$(TARGET).elf > /dev/null 2>&1 &"; \
-{ \
echo "mv /data/video/check_update.sh /bin/"; \
echo "mv /data/video/wifi_setup.sh /bin/"; \
echo "chmod 777 /bin/check_update.sh" \
echo "chmod 777 /bin/wifi_setup.sh" \
echo "insmod $(TARGET_DIR)/cdc-acm.ko"; \
echo "chmod 777 $(TARGET_DIR)/$(TARGET).elf"; \
echo "$(TARGET_DIR)/$(TARGET).elf > /dev/null 2>&1 &"; \
} | telnet $(HOST)

ifeq ($(ARDRONE2_REBOOT),1)
-{ \
echo "reboot"; \
} | telnet $(HOST)
endif


# Link: create ELF output file from object files.
Expand Down
8 changes: 7 additions & 1 deletion conf/boards/ardrone2_raw.makefile
Expand Up @@ -15,11 +15,17 @@ $(TARGET).ARCHDIR = $(ARCH)

# -----------------------------------------------------------------------
USER=foobar
HOST=192.168.1.1
HOST?=192.168.1.1
SUB_DIR=raw
FTP_DIR=/data/video
TARGET_DIR=$(FTP_DIR)/$(SUB_DIR)
# -----------------------------------------------------------------------
ARDRONE2_START_PAPARAZZI ?= 0
ARDRONE2_WIFI_MODE ?= 0
ARDRONE2_SSID ?= ardrone2_paparazzi
ARDRONE2_IP_ADDRESS_BASE ?= 192.168.1.
ARDRONE2_IP_ADDRESS_PROBE ?= 1
# -----------------------------------------------------------------------

# The GPS sensor is connected trough USB so we have to define the device
GPS_PORT ?= UART1
Expand Down
6 changes: 6 additions & 0 deletions conf/boards/ardrone2_sdk.makefile
Expand Up @@ -20,6 +20,12 @@ SUB_DIR=sdk
FTP_DIR=/data/video
TARGET_DIR=$(FTP_DIR)/$(SUB_DIR)
# -----------------------------------------------------------------------
ARDRONE2_START_PAPARAZZI ?= 0
ARDRONE2_WIFI_MODE ?= 0
ARDRONE2_SSID ?= ardrone2_paparazzi
ARDRONE2_IP_ADDRESS_BASE ?= 192.168.1.
ARDRONE2_IP_ADDRESS_PROBE ?= 1
# -----------------------------------------------------------------------

# The GPS sensor is connected trough USB so we have to define the device
GPS_PORT ?= UART1
Expand Down
5 changes: 3 additions & 2 deletions sw/airborne/boards/ardrone/electrical_raw.c
Expand Up @@ -68,10 +68,11 @@ static struct {
int fd;

void electrical_init(void) {
// First we try to kill the program.elf if it is running (done here because initializes first)
system("killall -9 program.elf");

// Initialize 12c device for power
fd = open( "/dev/i2c-1", O_RDWR );


if ( ioctl( fd, I2C_SLAVE_FORCE, 0x4a) < 0 ) {
fprintf( stderr, "Failed to set slave address: %m\n" );
}
Expand Down
96 changes: 96 additions & 0 deletions sw/ext/ardrone2_drivers/check_update.sh
@@ -0,0 +1,96 @@
#!/bin/sh

UPDATE_DIR=/update
UPDATE_PATH=$UPDATE_DIR/ardrone2_update.plf
VERSION_PATH=$UPDATE_DIR/version.txt
ERR_PATH=$UPDATE_DIR/err.log

echo "Check if need to start paparazzi ..."
START_PAPARAZZI=`grep start_paparazzi /data/config.ini | awk -F "=" '{ gsub(/ */,"",$2); print $2}'`
case $START_PAPARAZZI in
1)
START_PAPARAZZI=raw
;;
2)
START_PAPARAZZI=sdk
;;
*)
START_PAPARAZZI=no
;;
esac
echo "START_PAPARAZZI=$START_PAPARAZZI"

echo "Copy version.txt file in ftp directory"
cp /firmware/version.txt $VERSION_PATH

PELF_ARGS=$(cat /tmp/.program.elf.arguments | tr '\n' ' ')

echo "Check if update is necessary ..."
if [ -e $UPDATE_PATH ] ; then
VERSION=`cat $VERSION_PATH`

if [ -e $ERR_PATH ] ; then
CHECK_ERR=`cat $ERR_PATH`
if [ "$CHECK_ERR" = "NEED_TO_FLASH" ] ; then
CHECK_PLF=`/bin/checkplf $UPDATE_PATH $VERSION`
if [ "$CHECK_PLF" = "NEED_TO_FLASH" ] ; then
echo "ERR=FLASH_KO" > $ERR_PATH
else
/bin/checkplf $UPDATE_PATH $VERSION > $ERR_PATH
fi
else
/bin/checkplf $UPDATE_PATH $VERSION > $ERR_PATH
fi
else
/bin/checkplf $UPDATE_PATH $VERSION > $ERR_PATH
fi

CHECK_ERR=`cat $ERR_PATH`
if [ "$CHECK_ERR" = "NEED_TO_FLASH" ] ; then
echo "File $UPDATE_PATH exists... Start updating..."
pinst_trigger
echo "Rebooting..."
reboot
else
if [ "$CHECK_ERR" = "VERSION_OK" ] ; then
echo "Version OK"
elif [ "$CHECK_ERR" = "ERR=FLASH_KO" ] ; then
echo "Error during Updating... Removing..."
else
echo "File $UPDATE_PATH not valid... Removing..."
fi
# Cleaning update directory
rm -Rf $UPDATE_DIR/*
cp /firmware/version.txt $VERSION_PATH
echo "Start Drone software..."
inetd

# Check what to start
if [ "$START_PAPARAZZI" = "raw" ] ; then
(/data/video/raw/ap.elf; gpio 181 -d ho 1) &
elif [ "$START_PAPARAZZI" = "sdk" ] ; then
(/data/video/sdk/ap.elf; gpio 181 -d ho 1) &
else
(/bin/program.elf ${PELF_ARGS}; gpio 181 -d ho 1) &
fi
fi
else
echo "File $UPDATE_PATH doesn't exists... Start Drone software..."
# Cleaning update directory
rm -Rf $UPDATE_DIR/*
cp /firmware/version.txt $VERSION_PATH

inetd
# Check what to start
if [ "$START_PAPARAZZI" = "raw" ] ; then
(/bin/program.elf ${PELF_ARGS}; gpio 181 -d ho 1) &
sleep 10
(/data/video/raw/ap.elf; gpio 181 -d ho 1) &
elif [ "$START_PAPARAZZI" = "sdk" ] ; then
(/bin/program.elf ${PELF_ARGS}; gpio 181 -d ho 1) &
sleep 10
(/data/video/sdk/ap.elf; gpio 181 -d ho 1) &
else
(/bin/program.elf ${PELF_ARGS}; gpio 181 -d ho 1) &
fi
fi

0 comments on commit c488f35

Please sign in to comment.