Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,19 @@ The sensor diagnostics demo is the fastest way to try ros2_medkit:

```bash
cd demos/sensor_diagnostics
docker compose up
# Open http://localhost:3000 for the Web UI
# Run ./run-demo.sh for an interactive walkthrough
./run-demo.sh
# Docker services start in daemon mode
# Web UI available at http://localhost:3000

# Explore the API
./check-demo.sh
```

**Options:**
```bash
./run-demo.sh --attached # Run in foreground with logs
./check-demo.sh # Interactive API demonstration
./stop-demo.sh # Stop the demo
```

**Features:**
Expand All @@ -69,6 +79,9 @@ cd demos/turtlebot3_integration
./run-demo.sh
# Gazebo will open, Web UI at http://localhost:3000
# Try: ./send-nav-goal.sh 2.0 0.5

# To stop
./stop-demo.sh
```

**Features:**
Expand Down
50 changes: 35 additions & 15 deletions demos/sensor_diagnostics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,32 @@ This demo showcases ros2_medkit's data monitoring, configuration management, and
### Using Docker (Recommended)

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

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

# Or run the demo script
./run-demo.sh
# Explore the API with interactive demonstration
./check-demo.sh

# To stop the demo
./stop-demo.sh
```

**Options:**
```bash
./run-demo.sh --attached # Run in foreground with logs
./run-demo.sh --update # Pull latest images before running
./run-demo.sh --no-cache # Build without cache
```

**Advanced usage:**
```bash
# Manual Docker control (if needed)
docker compose up # Start services manually
docker compose down # Stop services
```

### Building from Source
Expand Down Expand Up @@ -126,40 +144,40 @@ Sensor Topics → anomaly_detector monitors

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

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

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

### View Configurations

```bash
# List all LiDAR configurations
curl http://localhost:8080/api/v1/apps/lidar_sim/configurations | jq
curl http://localhost:8080/api/v1/apps/lidar-sim/configurations | jq

# Get specific parameter
curl http://localhost:8080/api/v1/apps/lidar_sim/configurations/noise_stddev | jq
curl http://localhost:8080/api/v1/apps/lidar-sim/configurations/noise_stddev | jq
```

### Inject Faults

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

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

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

| Script | Description |
|--------|-------------|
| `run-demo.sh` | Interactive demo walkthrough |
| `run-demo.sh` | Start Docker services (daemon mode) |
| `stop-demo.sh` | Stop Docker services |
| `check-demo.sh` | Interactive API demonstration and exploration |
| `inject-noise.sh` | Inject high noise fault |
| `inject-failure.sh` | Cause sensor timeout |
| `inject-nan.sh` | Inject NaN values |
Expand Down
108 changes: 108 additions & 0 deletions demos/sensor_diagnostics/check-demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash
# Sensor Diagnostics Demo - Interactive API Demonstration
# Explores ros2_medkit capabilities with simulated sensors

GATEWAY_URL="${GATEWAY_URL:-http://localhost:8080}"
API_BASE="${GATEWAY_URL}/api/v1"

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

echo_step() {
echo -e "\n${BLUE}=== $1 ===${NC}\n"
}

echo_success() {
echo -e "${GREEN}✓ $1${NC}"
}

echo_error() {
echo -e "${RED}✗ $1${NC}"
}

echo "╔════════════════════════════════════════════════════════════╗"
echo "║ Sensor Diagnostics Demo - API Explorer ║"
echo "║ (ros2_medkit + Simulated Sensors) ║"
echo "╚════════════════════════════════════════════════════════════╝"

# Check for jq dependency
if ! command -v jq >/dev/null 2>&1; then
echo_error "'jq' is required but not installed."
echo " Please install jq (e.g., 'sudo apt-get install jq') and retry."
exit 1
fi

# Check gateway health
echo ""
echo "Checking gateway health..."
if ! curl -sf "${API_BASE}/health" > /dev/null 2>&1; then
echo_error "Gateway not available at ${GATEWAY_URL}"
echo " Start with: ./run-demo.sh"
exit 1
fi
echo_success "Gateway is healthy!"

echo_step "1. Checking Gateway Health"
curl -s "${API_BASE}/health" | jq '.'

echo_step "2. Listing All Areas (Namespaces)"
curl -s "${API_BASE}/areas" | jq '.items[] | {id: .id, name: .name, description: .description}'

echo_step "3. Listing All Components"
curl -s "${API_BASE}/components" | jq '.items[] | {id: .id, name: .name, area: .area}'

echo_step "4. Listing All Apps (ROS 2 Nodes)"
curl -s "${API_BASE}/apps" | jq '.items[] | {id: .id, name: .name, namespace: .namespace}'

echo_step "5. Reading LiDAR Data"
echo "Getting latest scan from LiDAR simulator..."
curl -s "${API_BASE}/apps/lidar-sim/data/scan" | jq '{
angle_min: .angle_min,
angle_max: .angle_max,
range_min: .range_min,
range_max: .range_max,
sample_ranges: .ranges[:5]
}'

echo_step "6. Reading IMU Data"
echo "Getting latest IMU reading..."
curl -s "${API_BASE}/apps/imu-sim/data/imu" | jq '{
linear_acceleration: .linear_acceleration,
angular_velocity: .angular_velocity
}'

echo_step "7. Reading GPS Fix"
echo "Getting current GPS position..."
curl -s "${API_BASE}/apps/gps-sim/data/fix" | jq '{
latitude: .latitude,
longitude: .longitude,
altitude: .altitude,
status: .status
}'

echo_step "8. Listing LiDAR Configurations"
echo "These parameters can be modified at runtime to inject faults..."
curl -s "${API_BASE}/apps/lidar-sim/configurations" | jq '.items[] | {name: .name, value: .value, type: .type}'

echo_step "9. Checking Current Faults"
curl -s "${API_BASE}/faults" | jq '.'

echo ""
echo_success "API demonstration complete!"
echo ""
echo "🔧 Try injecting faults with these scripts:"
echo " ./inject-noise.sh # Increase sensor noise"
echo " ./inject-failure.sh # Cause sensor timeouts"
echo " ./inject-nan.sh # Inject NaN values"
echo " ./inject-drift.sh # Inject sensor drift"
echo " ./restore-normal.sh # Restore normal operation"
echo ""
echo "🌐 Web UI: http://localhost:3000"
echo "🌐 REST API: http://localhost:8080/api/v1/"
echo ""
echo "📖 More examples:"
echo " curl ${API_BASE}/apps/imu-sim/configurations | jq # IMU parameters"
echo " curl ${API_BASE}/apps/gps-sim/data/fix | jq # GPS data"
10 changes: 5 additions & 5 deletions demos/sensor_diagnostics/inject-drift.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/bin/bash
# Inject sensor drift fault - demonstrates LEGACY fault reporting path
# LiDAR drift → DiagnosticArray → /diagnostics → diagnostic_bridge → FaultManager
# LiDAR drift → DiagnosticArray → /diagnostics → diagnostic-bridge → FaultManager

GATEWAY_URL="${GATEWAY_URL:-http://localhost:8080}"
API_BASE="${GATEWAY_URL}/api/v1"

echo "Injecting DRIFT fault (Legacy path: LiDAR → diagnostic_bridge)..."
echo "Injecting DRIFT fault (Legacy path: LiDAR → diagnostic-bridge)..."
echo ""

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

Expand All @@ -21,5 +21,5 @@ echo ""
echo "Fault codes expected (auto-generated from diagnostic name):"
echo " - LIDAR_SIM (DRIFTING status, WARN severity)"
echo ""
echo "Watch the drift accumulate with: curl ${GATEWAY_URL}/api/v1/apps/lidar_sim/data/scan | jq '.ranges[:5]'"
echo "Watch the drift accumulate with: curl ${GATEWAY_URL}/api/v1/apps/lidar-sim/data/scan | jq '.ranges[:5]'"
echo "Check faults with: curl ${GATEWAY_URL}/api/v1/faults | jq"
8 changes: 4 additions & 4 deletions demos/sensor_diagnostics/inject-failure.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/bin/bash
# Inject sensor failure (timeout) fault - demonstrates MODERN fault reporting path
# IMU sensor → anomaly_detector → FaultManager (via ReportFault service)
# IMU sensor → anomaly-detector → FaultManager (via ReportFault service)

GATEWAY_URL="${GATEWAY_URL:-http://localhost:8080}"
API_BASE="${GATEWAY_URL}/api/v1"

echo "Injecting SENSOR FAILURE fault (Modern path: IMU → anomaly_detector)..."
echo "Injecting SENSOR FAILURE fault (Modern path: IMU → anomaly-detector)..."

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

echo ""
echo "✓ IMU failure injected!"
echo " Fault reporting path: imu_simanomaly_detector → /fault_manager/report_fault"
echo " Fault reporting path: imu-simanomaly-detector → /fault_manager/report_fault"
echo " The anomaly detector should report SENSOR_TIMEOUT fault directly to FaultManager."
echo " Check faults with: curl ${API_BASE}/faults | jq"
18 changes: 9 additions & 9 deletions demos/sensor_diagnostics/inject-nan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ echo ""

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

# MODERN PATH: IMU/GPS → anomaly_detector → FaultManager (direct service call)
# MODERN PATH: IMU/GPS → anomaly-detector → FaultManager (direct service call)
echo "[MODERN PATH] Enabling IMU inject_nan..."
echo " Fault path: imu_simanomaly_detector → /fault_manager/report_fault"
curl -s -X PUT "${API_BASE}/apps/imu_sim/configurations/inject_nan" \
echo " Fault path: imu-simanomaly-detector → /fault_manager/report_fault"
curl -s -X PUT "${API_BASE}/apps/imu-sim/configurations/inject_nan" \
-H "Content-Type: application/json" \
-d '{"value": true}'
echo ""

echo "[MODERN PATH] Enabling GPS inject_nan..."
echo " Fault path: gps_simanomaly_detector → /fault_manager/report_fault"
curl -s -X PUT "${API_BASE}/apps/gps_sim/configurations/inject_nan" \
echo " Fault path: gps-simanomaly-detector → /fault_manager/report_fault"
curl -s -X PUT "${API_BASE}/apps/gps-sim/configurations/inject_nan" \
-H "Content-Type: application/json" \
-d '{"value": true}'

echo ""
echo "✓ NaN injection enabled on multiple sensors!"
echo ""
echo "Fault codes expected:"
echo " - LIDAR_SIM (from diagnostic_bridge, auto-generated from diagnostic name)"
echo " - SENSOR_NAN (from anomaly_detector)"
echo " - LIDAR_SIM (from diagnostic-bridge, auto-generated from diagnostic name)"
echo " - SENSOR_NAN (from anomaly-detector)"
echo ""
echo "Check faults with: curl ${API_BASE}/faults | jq"
12 changes: 6 additions & 6 deletions demos/sensor_diagnostics/inject-noise.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#!/bin/bash
# Inject high noise fault - demonstrates LEGACY fault reporting path
# LiDAR/Camera → DiagnosticArray → /diagnostics → diagnostic_bridge → FaultManager
# LiDAR/Camera → DiagnosticArray → /diagnostics → diagnostic-bridge → FaultManager

GATEWAY_URL="${GATEWAY_URL:-http://localhost:8080}"
API_BASE="${GATEWAY_URL}/api/v1"

echo "Injecting HIGH NOISE fault (Legacy path: LiDAR/Camera → diagnostic_bridge)..."
echo "Injecting HIGH NOISE fault (Legacy path: LiDAR/Camera → diagnostic-bridge)..."
echo ""

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

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

Expand Down
Loading