-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch_interface.sh
More file actions
executable file
·182 lines (157 loc) · 5.55 KB
/
Copy pathlaunch_interface.sh
File metadata and controls
executable file
·182 lines (157 loc) · 5.55 KB
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
#!/bin/bash
set -o pipefail
# Define color variables
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color (Reset)
while getopts m:t:f opt; do
case $opt in
m)
# Usage: ./launch_interface.sh -m $HELLO_FLEET_PATH/maps/<map_name>.yaml
if [[ -f $OPTARG ]]; then
MAP="-m $OPTARG"
fi
;;
f)
# Usage: ./launch_interface.sh -f
FIREBASE="-f"
;;
esac
done
timestamp='stretch4_web_teleop_'$(date '+%Y%m%d%H%M')
logdir="$HOME/stretch_user/log/web_teleop/$timestamp"
logfile_ros="$logdir/start_ros2.txt"
logfile_node="$logdir/start_web_server_and_robot_browser.txt"
logzip="$logdir/stretch4_web_teleop_logs.zip"
mkdir -p $logdir
# Validate web teleop installation
function validate_installation {
local cert_dir="$HOME/ament_ws/src/stretch4_web_teleop/certificates"
local env_file="$HOME/ament_ws/src/stretch4_web_teleop/.env"
echo -e "${BLUE}Validating web teleop installation...${NC}"
# Check certificates folder exists
if [ ! -d "$cert_dir" ]; then
echo -e "${RED}ERROR:${NC} Certificates folder not found at $cert_dir"
echo " Update your ROS workspace: https://docs.hello-robot.com/0.3/installation/ros_workspace/"
return 1
fi
# Check .env file exists
if [ ! -f "$env_file" ]; then
echo -e "${RED}ERROR:${NC} .env file not found at $env_file"
echo " Update your ROS workspace: https://docs.hello-robot.com/0.3/installation/ros_workspace/"
return 1
fi
# Check certificate files exist with correct naming
local certfile_name="${HELLO_FLEET_ID}+6.pem"
local keyfile_name="${HELLO_FLEET_ID}+6-key.pem"
if [ ! -f "$cert_dir/$certfile_name" ]; then
echo -e "${RED}ERROR:${NC} Certificate file not found at $cert_dir/$certfile_name"
echo " Update your ROS workspace: https://docs.hello-robot.com/0.3/installation/ros_workspace/"
return 1
fi
if [ ! -f "$cert_dir/$keyfile_name" ]; then
echo -e "${RED}ERROR:${NC} Key file not found at $cert_dir/$keyfile_name"
echo " Update your ROS workspace: https://docs.hello-robot.com/0.3/installation/ros_workspace/"
return 1
fi
# Validate .env file contains correct paths
local env_certfile=$(grep '^certfile=' "$env_file" | cut -d'=' -f2)
local env_keyfile=$(grep '^keyfile=' "$env_file" | cut -d'=' -f2)
if [ "$env_certfile" != "$certfile_name" ]; then
echo -e "${RED}ERROR:${NC} .env certfile is set to '$env_certfile' but should be '$certfile_name'"
echo " Update your ROS workspace: https://docs.hello-robot.com/0.3/installation/ros_workspace/"
return 1
fi
if [ "$env_keyfile" != "$keyfile_name" ]; then
echo -e "${RED}ERROR:${NC} .env keyfile is set to '$env_keyfile' but should be '$keyfile_name'"
echo " Update your ROS workspace: https://docs.hello-robot.com/0.3/installation/ros_workspace/"
return 1
fi
# Check node_modules folder exists
local node_modules_dir="$HOME/ament_ws/src/stretch4_web_teleop/node_modules"
if [ ! -d "$node_modules_dir" ]; then
echo -e "${RED}ERROR:${NC} node_modules folder not found at $node_modules_dir"
echo " Run 'npm install --force' to install dependencies OR update your ROS workspace https://docs.hello-robot.com/0.3/installation/ros_workspace/"
return 1
fi
# Check npm dependencies have no errors
cd "$HOME/ament_ws/src/stretch4_web_teleop"
npm list --depth=0 >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${RED}ERROR:${NC} npm dependencies have errors. "
echo " Run 'npm install --force' to fix OR update your ROS workspace https://docs.hello-robot.com/0.3/installation/ros_workspace/"
return 1
fi
echo -e "${GREEN}✓ Installation validation passed${NC}"
return 0
}
function echo_failure_help {
zip -r $logzip $logdir/ >/dev/null
echo ""
echo "#############################################"
echo -e "${RED}FAILURE. COULD NOT LAUNCH WEB TELEOP.${NC}"
echo "Look at the troubleshooting guide for solutions to common issues: https://docs.hello-robot.com/0.3/getting_started/demos_web_teleop/#troubleshooting"
echo "or contact Hello Robot support and include $logzip"
echo "#############################################"
echo ""
exit 1
}
function print_interface_urls {
ifconfig | awk '
/^[^ \t]/ {
iface=$1
sub(/:$/, "", iface)
next
}
/inet / {
ip=""
for (i=1; i<=NF; i++) {
if ($i ~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) {
ip=$i
break
}
}
if (ip == "" || ip == "127.0.0.1") next
if (iface == "tailscale0") {
print "Tailscale: https://" ip "/operator"
} else if (iface ~ /^(wlan|wl)/) {
print "WiFi: https://" ip "/operator"
} else if (iface ~ /^(eth|en)/) {
print "Ethernet: https://" ip "/operator"
} else {
print iface ": https://" ip "/operator"
}
}'
}
echo "#############################################"
echo "LAUNCHING WEB TELEOP"
echo "#############################################"
validate_installation
if [ $? -ne 0 ]; then
echo_failure_help
fi
cd $HOME/ament_ws/src/stretch4_web_teleop
./start_ros2.sh -l $logdir $MAP |& tee $logfile_ros
if [ $? -ne 0 ]; then
echo_failure_help
fi
# echo ""
cd $HOME/ament_ws/src/stretch4_web_teleop
./start_web_server_and_robot_browser.sh -l $logdir $FIREBASE |& tee $logfile_node
if [ $? -ne 0 ]; then
echo_failure_help
fi
zip -r $logzip $logdir/ >/dev/null
echo ""
echo "#############################################"
echo -e "${GREEN}DONE! WEB TELEOP IS UP!${NC}"
echo "Visit the appropriate URL(s) below to see web teleop:"
if [ "$FIREBASE" = "-f" ]; then
echo "https://web.hello-robot.com/"
else
echo "Localhost: https://localhost/operator"
print_interface_urls
fi
echo "#############################################"
echo ""