1. 程式人生 > >Linux shell 自動化配置icp-slam ini檔案 rawlog檔案 log檔案位置

Linux shell 自動化配置icp-slam ini檔案 rawlog檔案 log檔案位置

1.功能:shell 自動化配置icp-slam ini檔案 rawlog檔案 log檔案位置
2.執行方式
1)將dealIni.sh 檔案置於icp-slam資料夾下
2)將icp-slam.sh置於icp-slam資料夾下
3)在icp-slam工作目錄執行命令

 ./icp-slam.sh icp_slam_demo_classic.ini all123.rawlog filelocation
 //引數說明 
 icp_slam_demo_classic.ini 可替換為自己的ini檔案
 all123.rawlog可替換為自己的rawlog檔案
 filelocation 為輸出的log檔案所在的資料夾名稱,可以自行設定
 

3.原始碼
1)dealIni.sh

#該指令碼必須用 source 命令 而且結果獲取為${var}獲取,不是return 如:source readIni.sh 否則變數無法外傳
# dealIni.sh iniFile section option
# read
# param : iniFile section option    return value --- a str    use: ${iniValue}
# param : iniFile section           return options (element: option = value) --- a str[]   use: arr_length=${#iniOptions[*]}}  element=${iniOptions[0]}
# param : iniFile                   returm sections (element: section ) --- a str[]   use: arr_length=${#iniSections[*]}}  element=${iniSections[0]}
# write
#param : -w iniFile section option value  add new element:section option    result:if not --->creat ,have--->update,exist--->do nothing
#option ,value can not be null
 
#params
iniFile=$1
section=$2
option=$3
#sun
mode="iniR"
echo 
[email protected]
| grep "\-w" >/dev/null&&mode="iniW" if [ "$#" = "5" ]&&[ "$mode" = "iniW" ];then iniFile=$2 section=$3 option=$4 value=$5 #echo $iniFile $section $option $value fi #resullt iniValue='default' iniOptions=() iniSections=() function checkFile() { #if [ "${iniFile}" = "" ] || [ 1 ];then if [ "${iniFile}" = "" ] || [ ! -f ${iniFile} ]; then echo "[error]:file --${iniFile}-- not exist!" fi } function readInIfile() { if [ "${section}" = "" ];then #通過如下兩條命令可以解析成一個數組 allSections=$(awk -F '[][]' '/\[.*]/{print $2}' ${iniFile}) iniSections=(${allSections// /}) echo "[info]:iniSections size:-${#iniSections[@]}- eles:-${iniSections[@]}- " elif [ "${section}" != "" ] && [ "${option}" = "" ];then #判斷section是否存在 allSections=$(awk -F '[][]' '/\[.*]/{print $2}' ${iniFile}) echo $allSections|grep ${section} if [ "$?" = "1" ];then echo "[error]:section --${section}-- not exist!" return 0 fi #正式獲取options #a=(獲取匹配到的section之後部分|去除第一行|去除空行|去除每一行行首行尾空格|將行內空格變為@
[email protected]
(後面分割時為陣列時,空格會導致誤拆)) a=$(awk "/\[${section}\]/{a=1}a==1" ${iniFile}|sed -e'1d' -e '/^$/d' -e 's/[ \t]*$//g' -e 's/^[ \t]*//g' -e 's/[ ]/@[email protected]/g' -e '/\[/,$d' ) b=(${a}) for i in ${b[@]};do #剔除非法字元,轉換@[email protected]為空格並新增到陣列尾 if [ -n "${i}" ]||[ "${i}" i!= "@[email protected]" ];then iniOptions[${#iniOptions[@]}]=${i//@[email protected]/ } fi done echo "[info]:iniOptions size:-${#iniOptions[@]}- eles:-${iniOptions[@]}-" elif [ "${section}" != "" ] && [ "${option}" != "" ];then # iniValue=`awk -F '=' '/\['${section}'\]/{a=1}a==1&&$1~/'${option}'/{print $2;exit}' $iniFile|sed -e 's/^[ \t]*//g' -e 's/[ \t]*$//g'` iniValue=`awk -F '=' "/\[${section}\]/{a=1}a==1" ${iniFile}|sed -e '1d' -e '/^$/d' -e '/^\[.*\]/,$d' -e "/^${option}.*=.*/!d" -e "s/^${option}.*= *//"` echo "[info]:iniValue value:-${iniValue}-" fi } function writeInifile() { #檢查檔案 checkFile allSections=$(awk -F '[][]' '/\[.*]/{print $2}' ${iniFile}) iniSections=(${allSections// /}) #判斷是否要新建section sectionFlag="0" for temp in ${iniSections[@]};do if [ "${temp}" = "${section}" ];then sectionFlag="1" break fi done if [ "$sectionFlag" = "0" ];then echo "[${section}]" >>${iniFile} fi #加入或更新value awk "/\[${section}\]/{a=1}a==1" ${iniFile}|sed -e '1d' -e '/^$/d' -e 's/[ \t]*$//g' -e 's/^[ \t]*//g' -e '/\[/,$d'|grep "${option}.\?=">/dev/null if [ "$?" = "0" ];then sectionNum=$(sed -n -e "/\[${section}\]/=" ${iniFile}) sed -i "${sectionNum},/^\[.*\]/s/\(${option}.\?=\).*/\1 ${value}/g" ${iniFile} echo "[success] update [$iniFile][$section][$option][$value]" else #新增 #echo sed -i "/^\[${section}\]/a\\${option}=${value}" ${iniFile} sed -i '/'"${option}"'/d' ${iniFile} #sed -i '/logOutput_dir=LOG_ICP-SLAM/d' ${iniFile} sed -i "/^\[${section}\]/a\\${option} = ${value}" ${iniFile} echo "[success] add [$iniFile][$section][$option][$value]" fi } #main if [ "${mode}" = "iniR" ];then checkFile readInIfile elif [ "${mode}" = "iniW" ];then writeInifile fi
  1. icp-slam.sh
#!/bin/bash
#set -x

#./icp-slam.sh icp_slam_demo_classic.ini all123.rawlog  logFileLocation
iniFile=$1
rawlog=$2
logFileLocation=$3
section="MappingApplication"
option="logOutput_dir"
#echo "iniFile: ${iniFile} rawlog: ${rawlog} logFileLocation:${logFileLocation} section: ${section} option:${option}"
source dealIni.sh -w ${iniFile} ${section} ${option} ${logFileLocation} 
#echo "logFileLocation:${logFileLocation} section: ${section} option:${option}"

icp-slam ${iniFile} ${rawlog}

3)icp_slam_demo_classic.ini

#------------------------------------------------------------
# Config file for the "ICP-SLAM" application
# See: http://www.mrpt.org/list-of-mrpt-apps/application-icp-slam/
#------------------------------------------------------------



#=======================================================
# Section: [ICP]
#  Parameters of ICP inside the ICP-based SLAM class
#=======================================================
[ICP]
maxIterations    = 80    // The maximum number of iterations to execute if convergence is not achieved before
minAbsStep_trans = 1e-6  // If the correction in all translation coordinates (X,Y,Z) is below this threshold (in meters), iterations are terminated:
minAbsStep_rot   = 1e-6  // If the correction in all rotation coordinates (yaw,pitch,roll) is below this threshold (in radians), iterations are terminated:

thresholdDist    = 0.3   // Initial maximum distance for matching a pair of points
thresholdAng_DEG = 5     // An angular factor (in degrees) to increase the matching distance for distant points.

ALFA             = 0.8   // After convergence, the thresholds are multiplied by this constant and ICP keep running (provides finer matching)

smallestThresholdDist=0.05 // This is the smallest the distance threshold can become after stopping ICP and accepting the result.
onlyClosestCorrespondences=true // 1: Use the closest points only, 0: Use all the correspondences within the threshold (more robust sometimes, but slower)
onlyUniqueRobust = true // Force unique correspondences in both directions when pairing two point clouds

# 0: icpClassic
# 1: icpLevenbergMarquardt
ICP_algorithm = icpClassic

# decimation to apply to the point cloud being registered against the map
# Reduce to "1" to obtain the best accuracy
corresponding_points_decimation = 5


#=======================================================
# Section: [MappingApplication]
# Use: Here comes global parameters for the app.
#=======================================================
[MappingApplication]
logOutput_dir = 2345678

# The source file (RAW-LOG) with action/observation pairs
rawlog_file=../../datasets/2006-01ENE-21-SENA_Telecom Faculty_one_loop_only.rawlog
rawlog_offset=0
# The directory where the log files will be saved (left in blank if no log is required)
LOG_FREQUENCY=50			// The frequency of log files generation:
SAVE_3D_SCENE=1
SAVE_POSE_LOG=0
CAMERA_3DSCENE_FOLLOWS_ROBOT=1
SHOW_PROGRESS_3D_REAL_TIME=1

SHOW_PROGRESS_3D_REAL_TIME_DELAY_MS=5
SHOW_LASER_SCANS_3D = true

localizationLinDistance	= 0.2	// The distance threshold for correcting odometry with ICP (meters)
localizationAngDistance	= 5	// The distance threshold for correcting odometry with ICP (degrees)

insertionLinDistance	= 1.2	// The distance threshold for inserting observations in the map (meters)
insertionAngDistance	= 45.0	// The distance threshold for inserting observations in the map (degrees)

minICPgoodnessToAccept	= 0.40	// Minimum ICP quality to accept correction [0,1].

# Neeeded for LM method, which only supports point-map to point-map matching.
matchAgainstTheGrid = 0

# ========================================================
#            MULTIMETRIC MAP CONFIGURATION
# See docs for (Google for) mrpt::maps::CMultiMetricMap
# ========================================================
# Creation of maps:
occupancyGrid_count=0
gasGrid_count=0
landmarksMap_count=0
beaconMap_count=0
pointsMap_count=1

# Selection of map for likelihood: (fuseAll=-1,occGrid=0, points=1,landmarks=2,gasGrid=3)
likelihoodMapSelection=-1


# ====================================================
#   MULTIMETRIC MAP: PointsMap #00
# ====================================================
# Creation Options for PointsMap 00:
[MappingApplication_pointsMap_00_insertOpts]
minDistBetweenLaserPoints   = 0.05
fuseWithExisting            = false
isPlanarMap                 = 1