Commit 8394b4dc authored by enfo's avatar enfo

Added local base support and improved feedback

parent 3b48785d
#!/bin/bash
# Input files:
BASE=base
UAV=uav
UAV_FILE=$1
BASE_FILE=$2
FINAL_OUTPUT_FILE=$3
if [ -z "$UAV_FILE" ]; then
UAV_FILE="uav.ubx"
fi
if [ -z "$BASE_FILE" ]; then
BASE_FILE="base.ubx"
fi
if [ -z "$FINAL_OUTPUT_FILE" ]; then
FINAL_OUTPUT_FILE="uav.pos"
fi
if [ ! -f $UAV_FILE ]; then
echo -e "\e[31m\e[39mError:UAV-file does not exist."
echo
echo "Usage:"
echo " $0 uav_rawfile [base_rawfile [output_file]]"
echo
echo "Default values: uav.ubx base.ubx ubv.pos"
exit -1
fi
ONLINE_MODE=true
FINAL_OUTPUT_DIR=.
FINAL_OUTPUT_FILE=$FINAL_OUTPUT_DIR/uav.pos
INTERM_DIR="rtk_interm"
INTERM_DIR="rtk_intermediates"
BASE_FILE=${BASE}.ubx
UAV_FILE=${UAV}.ubx
UAV_NAME=rover
BASE_NAME=base
FINAL_OUTPUT_OPTIONS="-c -s | -d 5"
FINAL_MODE=2 #RTK
......@@ -19,9 +38,11 @@ FINAL_MODE=2 #RTK
EUREF_URL='ftp://igs.bkg.bund.de/EUREF/obs'
DEFAULT_FORMAT='ubx'
# Intermediate files
UAV_INTERM="$INTERM_DIR/${UAV}"
BASE_INTERM="$INTERM_DIR/${BASE}"
UAV_INTERM="$INTERM_DIR/${UAV_NAME}"
BASE_INTERM="$INTERM_DIR/${BASE_NAME}"
# Programs:
SCRIPT_DIR=`dirname $0`
......@@ -34,11 +55,18 @@ CLOSEST_BS=${SCRIPT_DIR}/scripts/get_closest_basestation.py
EUREF_URL_GENERATOR=${SCRIPT_DIR}/scripts/get_euref_urls.py
INPUT_FILE_EXT=".obs .nav .eph .sp3 .sbs"
# Define colors:
YELLOW="\e[33m"
RED="\e[31m"
DEFAULT="\e[39m"
USE_COLORS=true
if $USE_COLORS; then
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
DEFAULT="\e[39m"
UNDERLINED="\e[4m"
DEFAULT_ATTR="\e[0m"
fi
# Fail if any part of a pipe fails
set -o pipefail
......@@ -54,8 +82,24 @@ fi
mkdir -p $INTERM_DIR
function get_extension() {
filename=$(basename "$fullfile");
echo ${filename##*.}
}
UAV_FILE_EXTENSION=".${UAV_FILE##*.}"
if [ "$UAV_FILE_EXTENSION" == ".senti" ]; then
UAV_CONV_EXTRA_SETTINGS="-r ubx"
elif [ "$UAV_FILE_EXTENSION" == ".dat" ]; then
echo -e "${YELLOW}Warning:${DEFAULT} Could not auto-detect UAV input format. Defaulting to ${DEFAULT_FORMAT}.";
UAV_CONV_EXTRA_SETTINGS="-r ${DEFAULT_FORMAT}"
fi
echo
# Convert observations to RINEX
${CONVBIN} ${UAV_FILE} -ts 2000/01/01 00:00:00 -d "$INTERM_DIR"
echo -e "${GREEN}Converting observations to RINEX${DEFAULT}"
${CONVBIN} -ts 1990/01/01 00:00:00 -d "$INTERM_DIR" -o "$UAV_NAME.obs" -n "$UAV_NAME.nav" -g "$UAV_NAME.gnav" -h "$UAV_NAME.hnav" -q "$UAV_NAME.qnav" -l "$UAV_NAME.lnav" -s "$UAV_NAME.sbs" ${UAV_CONV_EXTRA_SETTINGS} ${UAV_FILE}
if [ ! $? -eq 0 ]; then
echo
echo -e "${RED}Error:${DEFAULT} Could not convert ${UAV_FILE}.";
......@@ -63,7 +107,15 @@ if [ ! $? -eq 0 ]; then
fi
if $HAS_BASE; then
${CONVBIN} ${BASE_FILE} -ts 2000/01/01 00:00:00 -d "$INTERM_DIR"
BASE_FILE_EXTENSION=".${BASE_FILE%%*.}"
if [ "$BASE_FILE_EXTENSION" == ".senti" ]; then
BASE_CONV_EXTRA_SETTINGS="-r ubx"
elif [ "$BASE_FILE_EXTENSION" == ".dat" ]; then
echo -e "${YELLOW}Warning:${DEFAULT} Could not auto-detect base's input format. Defaulting to ${DEFAULT_FORMAT}.";
BASE_CONV_EXTRA_SETTINGS="-r ${DEFAULT_FORMAT}"
fi
${CONVBIN} -ts 1990/01/01 00:00:00 -d "$INTERM_DIR" -o "$BASE_NAME.obs" -n "$BASE_NAME.nav" -g "$BASE_NAME.gnav" -h "$BASE_NAME.hnav" -q "$BASE_NAME.qnav" -l "$BASE_NAME.lnav" -s "$BASE_NAME.sbs" ${BASE_CONV_EXTRA_SETTINGS} ${BASE_FILE}
if [ ! $? -eq 0 ]; then
echo
echo -e "${YELLOW}Warning:${DEFAULT} Could not convert ${UAV_FILE}.";
......@@ -72,7 +124,7 @@ if $HAS_BASE; then
fi
fi
# Get generate RNX file names
# Get generated RNX file names
UAV_RNX_FILES=""
BASE_RNX_FILES=""
for ext in $INPUT_FILE_EXT; do
......@@ -93,6 +145,8 @@ else
INPUT_FILES="$UAV_RNX_FILES"
fi
echo
echo -e "${GREEN}Getting single position solution${DEFAULT}"
# Get single position from observations
${RNX2RTKP} -p 0 -s "|" -o $INTERM_DIR/single.pos $INPUT_FILES
if [ ! $? -eq 0 ]; then
......@@ -105,12 +159,12 @@ fi
AVG_SINGLE_LLH=$(${RTKLIB2AVG} $INTERM_DIR/single.pos 5 6 | tail -n1)
if [ ! $? -eq 0 ]; then
echo
echo "${RED}Error:${DEFAULT} Could not find single position.";
echo -e "${RED}Error:${DEFAULT} Could not find single position.";
exit -1;
fi
echo
echo "Average single pos lat long: " ${AVG_SINGLE_LLH}
echo -e "Average ${UNDERLINED}single${DEFAULT_ATTR} lat long height position:" ${AVG_SINGLE_LLH}
echo
if $ONLINE_MODE; then
......@@ -121,16 +175,15 @@ if $ONLINE_MODE; then
echo -e "${RED}Error:${DEFAULT} Could not find basestation ID.";
exit -1;
fi
echo "Closest base station: " ${BS}
BSID=$(echo $BS | rev | cut -f 1 -d ' ' | rev )
echo "ID:" $BSID
echo -e "Closest base station: ${GREEN}" ${BS} "${DEFAULT}"
echo
BSID=$(echo $BS | rev | cut -f 1 -d ' ' | rev )
# Find the start and end-file of the uav
awk_string='{ printf "%04d-%02d-%02dT%02d:%02d:%02.6f",$1,$2,$3,$4,$5,$6; }'
FIRST_OBS=$(head -n 100 $INTERM_DIR/${UAV}.obs | grep "FIRST OBS" |
FIRST_OBS=$(head -n 100 $INTERM_DIR/${UAV_NAME}.obs | grep "FIRST OBS" |
awk "${awk_string}")
LAST_OBS=$(head -n 100 $INTERM_DIR/${UAV}.obs | grep "LAST OBS" |
LAST_OBS=$(head -n 100 $INTERM_DIR/${UAV_NAME}.obs | grep "LAST OBS" |
awk "${awk_string}")
echo "First observation: " ${FIRST_OBS}
......@@ -151,8 +204,12 @@ if $ONLINE_MODE; then
# Download and unzip basestation file
cache_dir=basestations
mkdir -p $cache_dir
if [ ! -e "$cache_dir/$BS_FILENAME" ]; then
if [ -e "$cache_dir/$BS_FILENAME" ]; then
echo -e "${GREEN}Using cached base station data:${DEFAULT} $BS_FILENAME"
else
if [ ! -e "$cache_dir/$BS_BASENAME.crx" ]; then
echo -e "${GREEN}Downloaded public base station data.${DEFAULT}"
if [ ! -e "$cache_dir/$BS_ZIPPEDNAME" ]; then
wget $BS_URL -P $cache_dir
if [ ! $? -eq 0 ]; then
......@@ -181,9 +238,11 @@ fi
MODE=2 # Kinematic
if [ $HAS_BASE == false ]; then
if ! $ONLINE_MODE; then
echo "${RED}Error:${DEFAULT} can not get RTK solution without a base."
echo -e "${RED}Error:${DEFAULT} can not get RTK solution without a base."
exit -1;
fi
echo -e "${GREEN}Calculating UAV position solution${DEFAULT} ${YELLOW}without local base${DEFAULT}"
INPUT_FILES=${UAV_RNX_FILES}
BASE_STATION_FILES="$cache_dir/$BS_FILENAME"
${RNX2RTKP} -o "$FINAL_OUTPUT_FILE" -p ${MODE} $FINAL_OUTPUT_OPTIONS $INPUT_FILES $BASE_STATION_FILES
......@@ -192,12 +251,12 @@ if [ $HAS_BASE == false ]; then
exit -1;
fi
echo
echo "Done."
echo -e "Sucessfully created ${GREEN}rtk solution${DEFAULT} file ${YELLOW}without local base${DEFAULT}: $FINAL_OUTPUT_FILE"
exit 0
fi
if $ONLINE_MODE; then
echo "Getting local base RTK solution"
if $ONLINE_MODE ; then
echo -e "Getting the RTK solution for the ${GREEN}local base${DEFAULT}"
BASE_STATION_FILES="$cache_dir/$BS_FILENAME"
${RNX2RTKP} -o "$INTERM_DIR/base.pos" -p 2 -c -s "|" ${BASE_RNX_FILES} $BASE_STATION_FILES
if [ ! $? -eq 0 ]; then
......@@ -206,25 +265,30 @@ if $ONLINE_MODE; then
exit -1;
fi
BASE_STATION_POSITION=$(${RTKLIB2AVG} $INTERM_DIR/base.pos 1 6 | tail -n1)
BASE_STATION_POSITION=$(${RTKLIB2AVG} $INTERM_DIR/base.pos 1 | tail -n1)
if [ ! $? -eq 0 ]; then
echo
echo "${YELLOW}Warning:${DEFAULT} Could not find Q=1 base position, switching to Q=2.";
echo -e "${YELLOW}Warning:${DEFAULT} Could not find Q=1 base position, switching to Q=2.";
BASE_STATION_POSITION=$(${RTKLIB2AVG} $INTERM_DIR/base.pos 2 5 | tail -n1)
if [ ! $? -eq 0 ]; then
echo
echo "${RED}Error:${DEFAULT} Could not find accurate base station position.";
echo -e "${RED}Error:${DEFAULT} Could not find accurate base station position.";
exit -1;
fi
fi
echo
echo -e "Average ${UNDERLINED}RTK${DEFAULT_ATTR} base station lat long height position:" ${BASE_STATION_POSITION}
else
echo "Using base llh: average of single position"
echo "Using average of single position solution as base position:"
BASE_STATION_POSITION=$AVG_SINGLE_LLH
fi
echo -e "${GREEN}Calculating UAV position solution:${DEFAULT}"
${RNX2RTKP} -o "$FINAL_OUTPUT_FILE" -p ${FINAL_MODE} -l $BASE_STATION_POSITION $FINAL_OUTPUT_OPTIONS $UAV_RNX_FILES $BASE_RNX_FILES $BASE_STATION_FILES
echo
if [ $? -eq 0 ]; then
echo "Sucessfully created rtk solution file: $FINAL_OUTPUT_FILE"
echo -e "Sucessfully created ${GREEN}rtk solution file${DEFAULT} with ${GREEN}local base${DEFAULT}: $FINAL_OUTPUT_FILE"
else
echo "${RED}Error:${DEFAULT} could not generate rtk position"
echo -e "${RED}Error:${DEFAULT} could not generate rtk position"
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment