|
| 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" |
0 commit comments