-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_inspection.sh
More file actions
executable file
·132 lines (116 loc) · 6.72 KB
/
Copy pathstart_inspection.sh
File metadata and controls
executable file
·132 lines (116 loc) · 6.72 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
#!/usr/bin/env bash
# ═══════════════════════════════════════════════════════════════════════════
# EV Drone Inspection — ONE-CLICK launcher
#
# Brings up the whole stack in the right order and opens the Control Center:
# 1. PX4 SITL + Gazebo (warehouse world) — run_sim.sh
# 2. ROS2 bridge (camera feed + live editing) — ros2 run camera_bridge bridge_all
# 3. Control Center dashboard — run_control_center.py (opens browser)
#
# Close this terminal window (or press Ctrl+C) to shut EVERYTHING down cleanly.
# ═══════════════════════════════════════════════════════════════════════════
PROJECT="/home/dikshant/Desktop/drone_inspector"
PX4_DIR="$HOME/Desktop/PX4-Autopilot"
PYTHON_BIN="/home/dikshant/miniconda3/bin/python"
ROS_SETUP="/opt/ros/humble/setup.bash"
WS_SETUP="$PROJECT/ros2_ws/install/setup.bash"
PORT=8765
LOG_DIR="/tmp/drone_inspection_logs"
PX4_LOG="$LOG_DIR/px4_sitl_console.log"
BRIDGE_LOG="$LOG_DIR/bridge.log"
DASH_LOG="$LOG_DIR/dashboard.log"
# ── Re-launch self inside a visible terminal (when started from the icon) ───
if [ -z "${INSIDE_TERM:-}" ]; then
exec gnome-terminal --title="EV Drone Inspection" -- \
bash -c "INSIDE_TERM=1 '$0'; echo; echo 'Press Enter to close…'; read"
fi
mkdir -p "$LOG_DIR"
c_blue='\033[1;36m'; c_grn='\033[1;32m'; c_yel='\033[1;33m'; c_red='\033[1;31m'; c_off='\033[0m'
step(){ echo -e "\n${c_blue}▶ $*${c_off}"; }
ok(){ echo -e "${c_grn} ✓ $*${c_off}"; }
warn(){ echo -e "${c_yel} ! $*${c_off}"; }
# ── Cleanup: tear the whole stack down on exit ─────────────────────────────
cleanup() {
echo -e "\n${c_red}■ Shutting down EV Drone Inspection…${c_off}"
pkill -f run_control_center 2>/dev/null
pkill -f "camera_bridge bridge_all" 2>/dev/null
pkill -f "ros2 run camera_bridge" 2>/dev/null
pkill -9 -f gzclient 2>/dev/null
pkill -9 -f gzserver 2>/dev/null
pkill -9 -f "px4 " 2>/dev/null
pkill -9 -f mavsdk_server 2>/dev/null
pkill -f run_sim.sh 2>/dev/null
fuser -k ${PORT}/tcp 2>/dev/null
notify-send "EV Drone Inspection" "Stack stopped." 2>/dev/null
echo -e "${c_grn} ✓ All processes stopped.${c_off}"
}
trap cleanup EXIT INT TERM
clear
echo -e "${c_blue}╔══════════════════════════════════════════════╗${c_off}"
echo -e "${c_blue}║ EV DRONE INSPECTION — Control Center ║${c_off}"
echo -e "${c_blue}╚══════════════════════════════════════════════╝${c_off}"
echo " Logs: $LOG_DIR"
# ── 0. Clean stale state ───────────────────────────────────────────────────
step "Cleaning up any previous run…"
pkill -9 -f gzserver 2>/dev/null; pkill -9 -f gzclient 2>/dev/null
pkill -9 -f "px4 " 2>/dev/null; pkill -9 -f mavsdk_server 2>/dev/null
pkill -f run_control_center 2>/dev/null; pkill -f "ros2 run camera_bridge" 2>/dev/null
fuser -k ${PORT}/tcp 2>/dev/null
rm -rf /tmp/gazebo-$USER-rtshaderlibcache 2>/dev/null # corrupt shader cache → hang fix
rm -f /tmp/scene_cmd.json /tmp/scene_state.json 2>/dev/null
sleep 2
ok "Clean."
# ── 1. PX4 SITL + Gazebo ───────────────────────────────────────────────────
step "Starting PX4 SITL + Gazebo (warehouse)… (first launch can take ~60s)"
( "$PROJECT/run_sim.sh" > "$PX4_LOG" 2>&1 ) &
echo " console → $PX4_LOG"
echo -n " waiting for the drone to be ready"
ready=0
for i in $(seq 1 150); do
if grep -qE "Ready for takeoff|INFO *\[commander\] Ready" "$PX4_LOG" 2>/dev/null; then
ready=1; break
fi
if ! pgrep -f "px4|gzserver" >/dev/null 2>&1 && [ "$i" -gt 15 ]; then
echo; warn "PX4 process exited early — check $PX4_LOG"; break
fi
echo -n "."; sleep 1
done
echo
[ "$ready" = 1 ] && ok "PX4 ready for takeoff." || warn "Proceeding without explicit 'ready' (continuing anyway)."
# ── 2. ROS2 bridge (camera + live world editing) ───────────────────────────
step "Starting ROS2 bridge (camera feed + live world editing)…"
( bash -c "source '$ROS_SETUP' && source '$WS_SETUP' && exec ros2 run camera_bridge bridge_all" \
> "$BRIDGE_LOG" 2>&1 ) &
echo " console → $BRIDGE_LOG"
sleep 4
if grep -qi "services ready\|listening on" "$BRIDGE_LOG" 2>/dev/null; then
ok "Bridge online (camera + spawn/delete services)."
else
warn "Bridge still initialising (it waits for Gazebo services) — check $BRIDGE_LOG"
fi
# ── 3. Control Center dashboard ────────────────────────────────────────────
step "Starting Control Center dashboard…"
( cd "$PROJECT" && exec "$PYTHON_BIN" run_control_center.py > "$DASH_LOG" 2>&1 ) &
echo " console → $DASH_LOG"
echo -n " waiting for dashboard"
for i in $(seq 1 30); do
if curl -s "http://localhost:${PORT}/api/state" >/dev/null 2>&1; then break; fi
echo -n "."; sleep 1
done
echo
ok "Dashboard up at http://localhost:${PORT}"
# Open browser (run_control_center also tries; this guarantees it)
xdg-open "http://localhost:${PORT}" >/dev/null 2>&1 &
notify-send "EV Drone Inspection" "Everything is ready — Control Center opening in your browser." 2>/dev/null
echo -e "\n${c_grn}════════════════════════════════════════════════${c_off}"
echo -e "${c_grn} READY. Drive everything from the browser:${c_off}"
echo -e " • ${c_blue}Warehouse Editor${c_off} — build/move/delete objects"
echo -e " • ${c_blue}Mission Planner${c_off} — edit waypoints, Run, or Click-to-Go"
echo -e " • ${c_blue}Top bar${c_off} — Connect / Take Off / RTL / Land"
echo -e "${c_grn}════════════════════════════════════════════════${c_off}"
echo -e "\n ${c_yel}Keep this window open. Close it (or Ctrl+C) to stop everything.${c_off}\n"
# ── Keep alive; if the dashboard dies, exit (→ cleanup) ────────────────────
while pgrep -f run_control_center >/dev/null 2>&1; do
sleep 3
done
warn "Dashboard stopped."