1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#!/bin/bash
# SOURCE: https://github.com/ctu-mrs
### BEGIN INIT INFO
# Provides: tmux
# Required-Start: $local_fs $network dbus
# Required-Stop: $local_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start the server
### END INIT INFO
# if [ "$(id -u)" == "0" ]; then
# exec sudo -u mrs "$0" "$@"
# fi
source $HOME/.bashrc
# location of the running script
DIR_PATH=$(cd $(dirname $0); pwd)
ROS_LAUNCH_PATH="$DIR_PATH/../ros_launch"
ROS_CONFIG_PATH="$DIR_PATH/../ros_config"
echo $ROS_LAUNCH_PATH
# ROS_RVIZ_PATH="$DIR_PATH/../../ros_rviz"
# ROS_MAP_PATH="$DIR_PATH/../../maps"
# check if workspace was built
[[ -f $DIR_PATH/../devel/setup.bash ]] ||
{ echo "Build the workspace first!"; exit 1; }
# location for storing the bag files
# * do not change unless you know what you are doing
MAIN_DIR=~/"bag_files"
# the project name
# * is used to define folder name in ~/$MAIN_DIR
PROJECT_NAME=fortis
# the name of the TMUX session
# * can be used for attaching as 'tmux a -t <session name>'
SESSION_NAME="fortis_0"
NAMESPACE="loader/ugv1/"
#NAMESPACE="fortis_0"
# the IP of the server
# * using this, depending on your use case, might be preferable over
# * 'localhost', since this information is passed to outside nodes
# * (e.g. outside node accessing hosted database)
SESSION_IP=$(hostname -I | awk '{print $1}')
# following commands will be executed first in each window
# * do NOT put ; at the end
pre_input="mkdir -p $MAIN_DIR/$PROJECT_NAME; \
export SERVER=$SESSION_NAME; \
export SERVER_IP=$SESSION_IP; \
export DIR_PATH=$DIR_PATH; \
export ROS_NAMESPACE=$NAMESPACE; \
export ROS_LAUNCH_PATH=$ROS_LAUNCH_PATH; \
export ROS_CONFIG_PATH=$ROS_CONFIG_PATH; \
source $DIR_PATH/../singularity/mount/addons.sh; \
source $DIR_PATH/../devel/setup.bash"
# export ROS_RVIZ_PATH=$ROS_RVIZ_PATH; \
# export ROS_MAP_PATH=$ROS_MAP_PATH; \
# export ROS_MAP_PATH_DEFAULT=$MAIN_DIR/$PROJECT_NAME; \
# source $DIR_PATH/config/hdw.sh; \
# source $DIR_PATH/config/sftw.sh; \
# define commands
# 'name' 'command'
# * DO NOT PUT SPACES IN THE NAMES
# * "new line" after the command => the command will be called after start
# * NO "new line" after the command => the command will wait for user's <enter>
input=(
'Btop' 'btop
'
'Rviz' 'waitForRos; rosrun rviz rviz -d $ROS_CONFIG_PATH/rviz_config/bobcatupdated.rviz
'
'StaticTFs' 'waitForRos; roslaunch $ROS_LAUNCH_PATH/bobcat_tfs.launch
'
'C_Lidar' 'waitForRos; roslaunch $ROS_LAUNCH_PATH/hw_3d_lidar_v3_nodelet.launch
'
'LIO-SAM' 'waitForRos; roslaunch $ROS_LAUNCH_PATH/loc_lio_sam.launch \
rviz:=0 \
navsat_latitude:=$LIO_SAM_NAVSAT_DATUM_LATITUDE \
navsat_longitude:=$LIO_SAM_NAVSAT_DATUM_LONGITUDE \
navsat_heading:=$LIO_SAM_NAVSAT_DATUM_HEADING
'
'RosTPC' 'waitForRos; roslaunch ros_tcp_endpoint endpoint.launch
'
'GlobalMap' 'waitForRos; [ $MAP_SERVER_ENABLED -eq 1 ] &&
../shell/load_map.sh $MAP_SERVER_MAP_NAME lio_sam/mapping/map_global/map ||
roslaunch $ROS_LAUNCH_PATH/nav_pypc2map.launch
'
'MoveBaseFlex' 'waitForRos; roslaunch $ROS_LAUNCH_PATH/nav_move_base_flex.launch
'
'FlexBe' 'waitForRos; roslaunch $ROS_LAUNCH_PATH/dm_flexbe.launch flexbe_mode:=0
'
'GoTo' 'waitForRos; roslaunch $ROS_LAUNCH_PATH/dm_flexbe_as_nav.launch
'
'Load' 'waitForRos; roslaunch $ROS_LAUNCH_PATH/dm_flexbe_as_task.launch
'
'Unload' 'waitForRos; roslaunch $ROS_LAUNCH_PATH/dm_flexbe_as_unload.launch
'
'WPN' 'waitForRos; roslaunch $ROS_LAUNCH_PATH/nav_wpn.launch
'
'HQScene' 'waitForRos; roslaunch unity_hq_scene unity_hqsimulation_scene.launch
'
# 'EchoTopics' 'waitForRos; rostopic echo /loader/ugv1/imu/wit/imu
# '
'HzTopics' 'waitForRos; rostopic hz /loader/ugv1/imu/wit/imu
'
'roscore' 'checkRos || roscore && exit
'
)
# the name of the window to focus after start
init_window="HQScene"
# automatically attach to the new session?
# {true, false}, default true
attach="true"
###########################
### DO NOT MODIFY BELOW ###
###########################
# prefere the user-compiled tmux
if [ -f /usr/local/bin/tmux ]; then
export TMUX_BIN=/usr/local/bin/tmux
else
export TMUX_BIN=/usr/bin/tmux
fi
# find the session
FOUND=$( $TMUX_BIN ls | grep $SESSION_NAME )
if [ $? == "0" ]; then
echo "The session already exists"
exit
fi
# Absolute path to this script. /home/user/bin/foo.sh
SCRIPT=$(readlink -f $0)
# Absolute path this script is in. /home/user/bin
SCRIPTPATH=`dirname $SCRIPT`
if [ -z ${TMUX} ];
then
TMUX= $TMUX_BIN new-session -s "$SESSION_NAME" -d
echo "Starting new session."
else
echo "Already in tmux, leave it first."
exit
fi
# get the iterator
ITERATOR_FILE="$MAIN_DIR/$PROJECT_NAME"/iterator.txt
if [ -e "$ITERATOR_FILE" ]
then
ITERATOR=`cat "$ITERATOR_FILE"`
ITERATOR=$(($ITERATOR+1))
else
echo "iterator.txt does not exist, creating it"
mkdir -p "$MAIN_DIR/$PROJECT_NAME"
touch "$ITERATOR_FILE"
ITERATOR="1"
fi
echo "$ITERATOR" > "$ITERATOR_FILE"
# create file for logging terminals' output
LOG_DIR="$MAIN_DIR/$PROJECT_NAME/"
SUFFIX=$(date +"%Y_%m_%d_%H_%M_%S")
SUBLOG_DIR="$LOG_DIR/"$ITERATOR"_"$SUFFIX""
TMUX_DIR="$SUBLOG_DIR/tmux"
mkdir -p "$SUBLOG_DIR"
mkdir -p "$TMUX_DIR"
# link the "latest" folder to the recently created one
rm "$LOG_DIR/latest" > /dev/null 2>&1
rm "$MAIN_DIR/latest" > /dev/null 2>&1
ln -sf "$SUBLOG_DIR" "$LOG_DIR/latest"
ln -sf "$SUBLOG_DIR" "$MAIN_DIR/latest"
# create arrays of names and commands
for ((i=0; i < ${#input[*]}; i++));
do
((i%2==0)) && names[$i/2]="${input[$i]}"
((i%2==1)) && cmds[$i/2]="${input[$i]}"
done
# run tmux windows
for ((i=0; i < ${#names[*]}; i++));
do
$TMUX_BIN new-window -t $SESSION_NAME:$(($i+1)) -n "${names[$i]}"
done
sleep 3
# start loggers
for ((i=0; i < ${#names[*]}; i++));
do
$TMUX_BIN pipe-pane -t $SESSION_NAME:$(($i+1)) -o "ts | cat >> $TMUX_DIR/$(($i+1))_${names[$i]}.log"
done
# send commands
for ((i=0; i < ${#cmds[*]}; i++));
do
$TMUX_BIN send-keys -t $SESSION_NAME:$(($i+1)) "cd $SCRIPTPATH;
${pre_input};
${cmds[$i]}"
done
# identify the index of the init window
init_index=0
for ((i=0; i < ((${#names[*]})); i++));
do
if [ ${names[$i]} == "$init_window" ]; then
init_index=$(expr $i + 1)
fi
done
$TMUX_BIN select-window -t $SESSION_NAME:$init_index
if [[ "$attach" == "true" ]]; then
$TMUX_BIN -2 attach-session -t $SESSION_NAME
else
echo "The session was started"
echo "You can later attach by calling:"
echo " tmux a -t $SESSION_NAME"
fi