Skip to content

Commit becfc27

Browse files
committed
fix(sensor-demo): correct app IDs and improve script consistency
- Fix incorrect app IDs: use dashes instead of underscores - lidar_sim -> lidar-sim - imu_sim -> imu-sim - gps_sim -> gps-sim - camera_sim -> camera-sim - anomaly_detector -> anomaly-detector - diagnostic_bridge -> diagnostic-bridge - Split run-demo.sh into separate concerns - run-demo.sh: only starts Docker services - check-demo.sh: new interactive API demonstration script - stop-demo.sh: new script to stop services - Update all scripts to use correct Gateway API entity IDs - check-demo.sh: fixed all API endpoint calls - inject-*.sh: updated fault injection scripts - restore-normal.sh: fixed configuration and fault clearing - Update documentation - README.md: updated Quick Start and API examples - demos/sensor_diagnostics/README.md: corrected all API examples Fixes API calls that were failing with 'entity not found' errors. Makes demo scripts consistent with turtlebot3_integration behavior.
1 parent e231a5f commit becfc27

File tree

10 files changed

+387
-159
lines changed

10 files changed

+387
-159
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,19 @@ The sensor diagnostics demo is the fastest way to try ros2_medkit:
4848

4949
```bash
5050
cd demos/sensor_diagnostics
51-
docker compose up
52-
# Open http://localhost:3000 for the Web UI
53-
# Run ./run-demo.sh for an interactive walkthrough
51+
./run-demo.sh
52+
# Docker services start in daemon mode
53+
# Web UI available at http://localhost:3000
54+
55+
# Explore the API
56+
./check-demo.sh
57+
```
58+
59+
**Options:**
60+
```bash
61+
./run-demo.sh --attached # Run in foreground with logs
62+
./check-demo.sh # Interactive API demonstration
63+
./stop-demo.sh # Stop the demo
5464
```
5565

5666
**Features:**
@@ -69,6 +79,9 @@ cd demos/turtlebot3_integration
6979
./run-demo.sh
7080
# Gazebo will open, Web UI at http://localhost:3000
7181
# Try: ./send-nav-goal.sh 2.0 0.5
82+
83+
# To stop
84+
./stop-demo.sh
7285
```
7386

7487
**Features:**

demos/sensor_diagnostics/README.md

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,32 @@ This demo showcases ros2_medkit's data monitoring, configuration management, and
1717
### Using Docker (Recommended)
1818

1919
```bash
20-
# Start the demo
21-
docker compose up
20+
# Start the demo (builds and starts Docker services)
21+
./run-demo.sh
2222

23-
# In another terminal, open the Web UI
24-
# Navigate to http://localhost:3000
23+
# The script will:
24+
# 1. Build and start Docker containers in daemon mode
25+
# 2. Display access URLs and available commands
2526

26-
# Or run the demo script
27-
./run-demo.sh
27+
# Explore the API with interactive demonstration
28+
./check-demo.sh
29+
30+
# To stop the demo
31+
./stop-demo.sh
32+
```
33+
34+
**Options:**
35+
```bash
36+
./run-demo.sh --attached # Run in foreground with logs
37+
./run-demo.sh --update # Pull latest images before running
38+
./run-demo.sh --no-cache # Build without cache
39+
```
40+
41+
**Advanced usage:**
42+
```bash
43+
# Manual Docker control (if needed)
44+
docker compose up # Start services manually
45+
docker compose down # Stop services
2846
```
2947

3048
### Building from Source
@@ -126,40 +144,40 @@ Sensor Topics → anomaly_detector monitors
126144

127145
```bash
128146
# Get LiDAR scan
129-
curl http://localhost:8080/api/v1/apps/lidar_sim/data/scan | jq '.ranges[:5]'
147+
curl http://localhost:8080/api/v1/apps/lidar-sim/data/scan | jq '.ranges[:5]'
130148

131149
# Get IMU data
132-
curl http://localhost:8080/api/v1/apps/imu_sim/data/imu | jq '.linear_acceleration'
150+
curl http://localhost:8080/api/v1/apps/imu-sim/data/imu | jq '.linear_acceleration'
133151

134152
# Get GPS fix
135-
curl http://localhost:8080/api/v1/apps/gps_sim/data/fix | jq '{lat: .latitude, lon: .longitude}'
153+
curl http://localhost:8080/api/v1/apps/gps-sim/data/fix | jq '{lat: .latitude, lon: .longitude}'
136154
```
137155

138156
### View Configurations
139157

140158
```bash
141159
# List all LiDAR configurations
142-
curl http://localhost:8080/api/v1/apps/lidar_sim/configurations | jq
160+
curl http://localhost:8080/api/v1/apps/lidar-sim/configurations | jq
143161

144162
# Get specific parameter
145-
curl http://localhost:8080/api/v1/apps/lidar_sim/configurations/noise_stddev | jq
163+
curl http://localhost:8080/api/v1/apps/lidar-sim/configurations/noise_stddev | jq
146164
```
147165

148166
### Inject Faults
149167

150168
```bash
151169
# Increase sensor noise
152-
curl -X PUT http://localhost:8080/api/v1/apps/lidar_sim/configurations/noise_stddev \
170+
curl -X PUT http://localhost:8080/api/v1/apps/lidar-sim/configurations/noise_stddev \
153171
-H "Content-Type: application/json" \
154172
-d '{"value": 0.5}'
155173

156174
# Cause sensor timeout
157-
curl -X PUT http://localhost:8080/api/v1/apps/lidar_sim/configurations/failure_probability \
175+
curl -X PUT http://localhost:8080/api/v1/apps/lidar-sim/configurations/failure_probability \
158176
-H "Content-Type: application/json" \
159177
-d '{"value": 1.0}'
160178

161179
# Inject NaN values
162-
curl -X PUT http://localhost:8080/api/v1/apps/lidar_sim/configurations/inject_nan \
180+
curl -X PUT http://localhost:8080/api/v1/apps/lidar-sim/configurations/inject_nan \
163181
-H "Content-Type: application/json" \
164182
-d '{"value": true}'
165183
```
@@ -185,7 +203,9 @@ curl http://localhost:8080/api/v1/faults | jq
185203

186204
| Script | Description |
187205
|--------|-------------|
188-
| `run-demo.sh` | Interactive demo walkthrough |
206+
| `run-demo.sh` | Start Docker services (daemon mode) |
207+
| `stop-demo.sh` | Stop Docker services |
208+
| `check-demo.sh` | Interactive API demonstration and exploration |
189209
| `inject-noise.sh` | Inject high noise fault |
190210
| `inject-failure.sh` | Cause sensor timeout |
191211
| `inject-nan.sh` | Inject NaN values |
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/bin/bash
2+
# Sensor Diagnostics Demo - Interactive API Demonstration
3+
# Explores ros2_medkit capabilities with simulated sensors
4+
5+
GATEWAY_URL="${GATEWAY_URL:-http://localhost:8080}"
6+
API_BASE="${GATEWAY_URL}/api/v1"
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
BLUE='\033[0;34m'
12+
NC='\033[0m' # No Color
13+
14+
echo_step() {
15+
echo -e "\n${BLUE}=== $1 ===${NC}\n"
16+
}
17+
18+
echo_success() {
19+
echo -e "${GREEN}$1${NC}"
20+
}
21+
22+
echo_error() {
23+
echo -e "${RED}$1${NC}"
24+
}
25+
26+
echo "╔════════════════════════════════════════════════════════════╗"
27+
echo "║ Sensor Diagnostics Demo - API Explorer ║"
28+
echo "║ (ros2_medkit + Simulated Sensors) ║"
29+
echo "╚════════════════════════════════════════════════════════════╝"
30+
31+
# Check for jq dependency
32+
if ! command -v jq >/dev/null 2>&1; then
33+
echo_error "'jq' is required but not installed."
34+
echo " Please install jq (e.g., 'sudo apt-get install jq') and retry."
35+
exit 1
36+
fi
37+
38+
# Check gateway health
39+
echo ""
40+
echo "Checking gateway health..."
41+
if ! curl -sf "${API_BASE}/health" > /dev/null 2>&1; then
42+
echo_error "Gateway not available at ${GATEWAY_URL}"
43+
echo " Start with: ./run-demo.sh"
44+
exit 1
45+
fi
46+
echo_success "Gateway is healthy!"
47+
48+
echo_step "1. Checking Gateway Health"
49+
curl -s "${API_BASE}/health" | jq '.'
50+
51+
echo_step "2. Listing All Areas (Namespaces)"
52+
curl -s "${API_BASE}/areas" | jq '.items[] | {id: .id, name: .name, description: .description}'
53+
54+
echo_step "3. Listing All Components"
55+
curl -s "${API_BASE}/components" | jq '.items[] | {id: .id, name: .name, area: .area}'
56+
57+
echo_step "4. Listing All Apps (ROS 2 Nodes)"
58+
curl -s "${API_BASE}/apps" | jq '.items[] | {id: .id, name: .name, namespace: .namespace}'
59+
60+
echo_step "5. Reading LiDAR Data"
61+
echo "Getting latest scan from LiDAR simulator..."
62+
curl -s "${API_BASE}/apps/lidar-sim/data/scan" | jq '{
63+
angle_min: .angle_min,
64+
angle_max: .angle_max,
65+
range_min: .range_min,
66+
range_max: .range_max,
67+
sample_ranges: .ranges[:5]
68+
}'
69+
70+
echo_step "6. Reading IMU Data"
71+
echo "Getting latest IMU reading..."
72+
curl -s "${API_BASE}/apps/imu-sim/data/imu" | jq '{
73+
linear_acceleration: .linear_acceleration,
74+
angular_velocity: .angular_velocity
75+
}'
76+
77+
echo_step "7. Reading GPS Fix"
78+
echo "Getting current GPS position..."
79+
curl -s "${API_BASE}/apps/gps-sim/data/fix" | jq '{
80+
latitude: .latitude,
81+
longitude: .longitude,
82+
altitude: .altitude,
83+
status: .status
84+
}'
85+
86+
echo_step "8. Listing LiDAR Configurations"
87+
echo "These parameters can be modified at runtime to inject faults..."
88+
curl -s "${API_BASE}/apps/lidar-sim/configurations" | jq '.items[] | {name: .name, value: .value, type: .type}'
89+
90+
echo_step "9. Checking Current Faults"
91+
curl -s "${API_BASE}/faults" | jq '.'
92+
93+
echo ""
94+
echo_success "API demonstration complete!"
95+
echo ""
96+
echo "🔧 Try injecting faults with these scripts:"
97+
echo " ./inject-noise.sh # Increase sensor noise"
98+
echo " ./inject-failure.sh # Cause sensor timeouts"
99+
echo " ./inject-nan.sh # Inject NaN values"
100+
echo " ./inject-drift.sh # Inject sensor drift"
101+
echo " ./restore-normal.sh # Restore normal operation"
102+
echo ""
103+
echo "🌐 Web UI: http://localhost:3000"
104+
echo "🌐 REST API: http://localhost:8080/api/v1/"
105+
echo ""
106+
echo "📖 More examples:"
107+
echo " curl ${API_BASE}/apps/imu-sim/configurations | jq # IMU parameters"
108+
echo " curl ${API_BASE}/apps/gps-sim/data/fix | jq # GPS data"

demos/sensor_diagnostics/inject-drift.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ echo ""
1010

1111
# LiDAR drift: uses legacy diagnostics path
1212
echo "[LEGACY PATH] Setting LiDAR drift_rate to 0.1 m/s..."
13-
echo " Fault path: lidar_sim → /diagnostics topic → diagnostic_bridge → FaultManager"
14-
curl -s -X PUT "${API_BASE}/apps/lidar_sim/configurations/drift_rate" \
13+
echo " Fault path: lidar-sim → /diagnostics topic → diagnostic-bridge → FaultManager"
14+
curl -s -X PUT "${API_BASE}/apps/lidar-sim/configurations/drift_rate" \
1515
-H "Content-Type: application/json" \
1616
-d '{"value": 0.1}'
1717

@@ -21,5 +21,5 @@ echo ""
2121
echo "Fault codes expected (auto-generated from diagnostic name):"
2222
echo " - LIDAR_SIM (DRIFTING status, WARN severity)"
2323
echo ""
24-
echo "Watch the drift accumulate with: curl ${GATEWAY_URL}/api/v1/apps/lidar_sim/data/scan | jq '.ranges[:5]'"
24+
echo "Watch the drift accumulate with: curl ${GATEWAY_URL}/api/v1/apps/lidar-sim/data/scan | jq '.ranges[:5]'"
2525
echo "Check faults with: curl ${GATEWAY_URL}/api/v1/faults | jq"

demos/sensor_diagnostics/inject-failure.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ echo "Injecting SENSOR FAILURE fault (Modern path: IMU → anomaly_detector)..."
99

1010
# Set high failure probability - IMU will stop publishing
1111
echo "Setting IMU failure_probability to 1.0 (complete failure)..."
12-
curl -s -X PUT "${API_BASE}/apps/imu_sim/configurations/failure_probability" \
12+
curl -s -X PUT "${API_BASE}/apps/imu-sim/configurations/failure_probability" \
1313
-H "Content-Type: application/json" \
1414
-d '{"value": 1.0}'
1515

1616
echo ""
1717
echo "✓ IMU failure injected!"
18-
echo " Fault reporting path: imu_simanomaly_detector → /fault_manager/report_fault"
18+
echo " Fault reporting path: imu-simanomaly-detector → /fault_manager/report_fault"
1919
echo " The anomaly detector should report SENSOR_TIMEOUT fault directly to FaultManager."
2020
echo " Check faults with: curl ${API_BASE}/faults | jq"

demos/sensor_diagnostics/inject-nan.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ echo ""
99

1010
# LEGACY PATH: LiDAR publishes DiagnosticArray → diagnostic_bridge → FaultManager
1111
echo "[LEGACY PATH] Enabling LiDAR inject_nan..."
12-
echo " Fault path: lidar_sim → /diagnostics topic → diagnostic_bridge → FaultManager"
13-
curl -s -X PUT "${API_BASE}/apps/lidar_sim/configurations/inject_nan" \
12+
echo " Fault path: lidar-sim → /diagnostics topic → diagnostic-bridge → FaultManager"
13+
curl -s -X PUT "${API_BASE}/apps/lidar-sim/configurations/inject_nan" \
1414
-H "Content-Type: application/json" \
1515
-d '{"value": true}'
1616
echo ""
1717

1818
# MODERN PATH: IMU/GPS → anomaly_detector → FaultManager (direct service call)
1919
echo "[MODERN PATH] Enabling IMU inject_nan..."
20-
echo " Fault path: imu_sim → anomaly_detector → /fault_manager/report_fault"
21-
curl -s -X PUT "${API_BASE}/apps/imu_sim/configurations/inject_nan" \
20+
echo " Fault path: imu-sim → anomaly_detector → /fault_manager/report_fault"
21+
curl -s -X PUT "${API_BASE}/apps/imu-sim/configurations/inject_nan" \
2222
-H "Content-Type: application/json" \
2323
-d '{"value": true}'
2424
echo ""
2525

2626
echo "[MODERN PATH] Enabling GPS inject_nan..."
27-
echo " Fault path: gps_sim → anomaly_detector → /fault_manager/report_fault"
28-
curl -s -X PUT "${API_BASE}/apps/gps_sim/configurations/inject_nan" \
27+
echo " Fault path: gps-sim → anomaly_detector → /fault_manager/report_fault"
28+
curl -s -X PUT "${API_BASE}/apps/gps-sim/configurations/inject_nan" \
2929
-H "Content-Type: application/json" \
3030
-d '{"value": true}'
3131

3232
echo ""
3333
echo "✓ NaN injection enabled on multiple sensors!"
3434
echo ""
3535
echo "Fault codes expected:"
36-
echo " - LIDAR_SIM (from diagnostic_bridge, auto-generated from diagnostic name)"
37-
echo " - SENSOR_NAN (from anomaly_detector)"
36+
echo " - LIDAR_SIM (from diagnostic-bridge, auto-generated from diagnostic name)"
37+
echo " - SENSOR_NAN (from anomaly-detector)"
3838
echo ""
3939
echo "Check faults with: curl ${API_BASE}/faults | jq"

demos/sensor_diagnostics/inject-noise.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ echo ""
1010

1111
# LiDAR: increase noise stddev (uses legacy diagnostics path)
1212
echo "[LEGACY PATH] Setting LiDAR noise_stddev to 0.5 (very noisy)..."
13-
echo " Fault path: lidar_sim → /diagnostics topic → diagnostic_bridge → FaultManager"
14-
curl -s -X PUT "${API_BASE}/apps/lidar_sim/configurations/noise_stddev" \
13+
echo " Fault path: lidar-sim → /diagnostics topic → diagnostic-bridge → FaultManager"
14+
curl -s -X PUT "${API_BASE}/apps/lidar-sim/configurations/noise_stddev" \
1515
-H "Content-Type: application/json" \
1616
-d '{"value": 0.5}'
1717
echo ""
1818

1919
# Camera: add noise (uses legacy diagnostics path)
2020
echo "[LEGACY PATH] Setting Camera noise_level to 0.3..."
21-
echo " Fault path: camera_sim → /diagnostics topic → diagnostic_bridge → FaultManager"
22-
curl -s -X PUT "${API_BASE}/apps/camera_sim/configurations/noise_level" \
21+
echo " Fault path: camera-sim → /diagnostics topic → diagnostic-bridge → FaultManager"
22+
curl -s -X PUT "${API_BASE}/apps/camera-sim/configurations/noise_level" \
2323
-H "Content-Type: application/json" \
2424
-d '{"value": 0.3}'
2525

0 commit comments

Comments
 (0)