-
Notifications
You must be signed in to change notification settings - Fork 15
/
run_docker.sh
executable file
·162 lines (134 loc) · 3.13 KB
/
run_docker.sh
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
#!/usr/bin/env bash
# Get this script's path
pushd `dirname $0` > /dev/null
SCRIPTPATH=`pwd`
popd > /dev/null
set -e
source $SCRIPTPATH/support/fun.cfg
USAGE="Usage: \n run_docker [OPTIONS...]
\n\n
Help Options:
\n
-h,--help \tShow help options
\n\n
Application Options:
\n
-r,--robot \tRobot model [spot|go1], example: -r spot
\n
-d,--device \tInput device type [ps3|xbox|twist|keyboard], example: -d ps3
\n
-w,--world \tWorld name [empty|ruins|pyramid|ramps|stairs|office], example: -w ruins
\n
-g,--gui \tLaunch rviz
\n
-n,--net \tLaunch docker with shared network, useful to visualize the ROS topics on the host machine
\n
-l,--local \tRun a local ROS workspace inside the container [workspace], example: -l ros_ws"
# Default
ROBOT_NAME=
ROBOT_MODEL=spot
DEVICE=keyboard
WORLD_NAME=empty
GUI=false
RUN_LOCAL_WS=false
DOCKER_NET=bridge
ROS_WS=
CONTAINER_NAME="wolf-app"
IMAGE_TAG="focal"
wolf_banner
if [[ ( $1 == "--help") || $1 == "-h" ]]
then
echo -e $USAGE
exit 0
fi
while [ -n "$1" ]; do # while loop starts
case "$1" in
-r|--robot)
ROBOT_MODEL="$2"
shift
;;
-d|--device)
DEVICE="$2"
shift
;;
-w|--world)
WORLD_NAME="$2"
shift
;;
-g|--gui)
GUI=true
;;
-n|--net)
DOCKER_NET=host
;;
-l|--local)
ROS_WS="$2"
RUN_LOCAL_WS=true
shift
;;
*) print_warn "Option $1 not recognized!"
echo -e $USAGE
exit 0;;
esac
shift
done
# Checks
if [[ ( $ROBOT_MODEL == "spot") || ( $ROBOT_MODEL == "go1")]]
then
print_info "Selected robot: $ROBOT_MODEL"
else
print_warn "Wrong robot model option!"
echo -e $USAGE
exit 0
fi
if [[ ( $DEVICE == "ps3") || ( $DEVICE == "xbox") || ( $DEVICE == "twist") || ( $DEVICE == "keyboard") ]]
then
print_info "Selected input device: $DEVICE"
else
print_warn "Wrong input device option!"
echo -e $USAGE
exit 0
fi
if [[ ( $WORLD_NAME == "empty") || ( $WORLD_NAME == "ruins") || ( $WORLD_NAME == "pyramid") || ( $WORLD_NAME == "ramps") || ( $WORLD_NAME == "stairs") || ( $WORLD_NAME == "office") ]]
then
print_info "Selected world: $WORLD_NAME"
else
print_warn "Wrong world option!"
echo -e $USAGE
exit 0
fi
if [[ ( $IMAGE_TAG == "focal") || ( $IMAGE_TAG == "jammy") ]]
then
ROS=noetic
else
print_warn "Wrong image option!"
echo -e $USAGE
exit 0
fi
# Define the image name
IMAGE_NAME=serger87/$CONTAINER_NAME:$IMAGE_TAG
# Hacky
xhost +local:docker
if [ `sudo systemctl is-active docker` = "inactive" ]; then
echo "Docker inactive. Starting docker..."
sudo systemctl start docker
fi
# Cleanup the docker container before launching it
docker rm -f $CONTAINER_NAME > /dev/null 2>&1 || true
# Run the container with shared X11
# Opt1 run the code within the docker container by sourcing the local ROS workspace (useful for development)
# Opt2 run the code within the docker container by sourcing the ROS workspace INSIDE docker (useful as a demo)
if $RUN_LOCAL_WS;
then
if [ -f "$HOME/$ROS_WS/devel/setup.bash" ];
then
print_info "Selected ros workspace: $ROS_WS"
run_local_ros_workspace $ROS_WS $ROS
else
print_warn "The file $HOME/$ROS_WS/devel/setup.bash does not exist!"
echo -e $USAGE
exit 0
fi
else
run_docker_ros_workspace $ROS
fi