← Previous: System Overview | Next: Configuration →
- Overview
- Architecture
- Application Flow
- Component Management
- Control Modes
- Button Interactions
- Shutdown Management
- Error Handling
- Configuration
The main application (main.py) is the entry point for the hexapod system. It coordinates between voice control, manual control (gamepad), and the task interface to provide a unified control system for the robot.
The application supports two primary control modes:
- Voice Control Mode: Primary interaction through voice commands with button support
- Manual Control Mode: Gamepad-based control with voice control as secondary option
graph TB
subgraph "Main Application"
subgraph "Core Components"
TI[TaskInterface<br/>• Robot Control<br/>• Task Execution<br/>• Button Handling]
VC[VoiceControl<br/>• Wake Word Detection<br/>• Command Processing<br/>• Audio Processing]
MC[ManualController<br/>• Gamepad Input<br/>• Mode Management<br/>• LED Feedback]
end
subgraph "Hardware Integration"
H[Hexapod<br/>• Servo Control<br/>• Movement<br/>• Calibration]
BH[ButtonHandler<br/>• GPIO Input<br/>• Long/Short Press<br/>• State Management]
LH[LightsHandler<br/>• Visual Feedback<br/>• Status Display]
end
end
TI --> H
TI --> BH
TI --> LH
VC --> TI
MC --> TI
MC --> VC
flowchart LR
S[Startup] --> PA[Parse Arguments]
PA --> LS[Setup Logging]
LS --> CC[Create Components]
CC --> VC[Start Voice Control]
VC --> IC[Initialize Manual Controller]
IC --> ML[Main Loop]
ML --> SD[Shutdown Detection]
SD --> CL[Cleanup]
CL --> E[Exit]
- Command Line Parsing: Parse arguments for configuration
- Logging Setup: Initialize logging system with specified level
- Component Creation: Create TaskInterface and VoiceControl
- Voice Control Start: Start voice control thread
- Manual Controller: Initialize gamepad controller (optional)
- Main Loop: Enter main application loop
The main loop continuously:
- Monitors for shutdown events
- Handles button interactions
- Coordinates between control modes
- Manages component state
- Shutdown Detection: PS5 button or KeyboardInterrupt
- Component Cleanup: Stop all threads and components
- Resource Deallocation: Clean up hardware resources
- Thread Joining: Wait for all threads to complete
- Exit: Terminate application
Role: Central coordination hub
- Manages robot control and movement
- Handles task execution and queuing
- Processes button interactions
- Coordinates between voice and manual control
Key Features:
- Voice control pause/resume management
- Task execution with blocking prevention
- Button interaction processing
- System state management
Role: Voice command processing
- Wake word detection (Porcupine)
- Command recognition (Rhino)
- Audio processing and streaming
- Context management
Key Features:
- Real-time audio processing
- Natural language understanding
- Command execution through TaskInterface
- Context-aware responses
Role: Gamepad-based control
- Input processing and mapping
- Mode switching (Body/Gait/Voice)
- LED feedback for status
- Shutdown coordination
Key Features:
- DualSense controller support
- Multiple control modes
- Visual feedback through LEDs
- Seamless mode switching
Primary Interface: Voice commands Secondary Interface: Button interactions Features:
- Wake word activation
- Natural language commands
- Task execution and control
- System state management
Button Actions:
- Short Press: Toggle system on/off
- Long Press: Sound source localization
- During Task: Stop current task
Primary Interface: Gamepad Secondary Interface: Voice commands Modes:
- Body Control: Direct body movement via inverse kinematics
- Gait Control: Walking and turning via gait generator
- Voice Control: Switch back to voice mode
Gamepad Controls:
- Left Stick: Movement direction
- Right Stick: Rotation
- Options Button: Toggle between body/gait control
- Create Button: Toggle voice control mode
- PS5 Button: Emergency shutdown
Hardware: GPIO pin 26 (Raspberry Pi) Detection:
- Short Press: Toggle system state
- Long Press (3+ seconds): Sound source localization
- During Blocking Task: Stop current task
stateDiagram-v2
[*] --> Idle
Idle --> Pressed : Button Down
Pressed --> LongPress : 3+ seconds
Pressed --> ShortPress : Button Up
LongPress --> Idle : Button Up
ShortPress --> Idle : Button Up
Idle --> [*]
- Toggle: Start/stop system
- Long Press: Activate sound source localization
- Stop Task: Interrupt blocking operations
- External Control Paused: Different behavior during critical tasks
- PS5 Button: Emergency shutdown via gamepad
- KeyboardInterrupt: Ctrl+C from terminal
- Shutdown Event: Programmatic shutdown
flowchart LR
ST[Shutdown Trigger] --> SC[Shutdown Cleanup]
SC --> VS[Stop Voice Control]
VS --> MS[Stop Manual Controller]
MS --> TC[Task Interface Cleanup]
TC --> TJ[Thread Joining]
TJ --> RD[Resource Deallocation]
RD --> E[Exit]
- Thread Management: Stop and join all threads
- Hardware Cleanup: Deactivate servos and cleanup GPIO
- Resource Deallocation: Free memory and close connections
- Logging: Final status messages
- Manual Controller Failure: Fallback to voice-only mode
- Voice Control Failure: System cannot start
- Hardware Errors: Graceful degradation
- Exception Handling: Caught in main loop
- Component Recovery: Automatic restart where possible
- State Monitoring: Continuous health checks
- Force Cleanup: Ensure resources are freed
- Thread Termination: Handle hanging threads
- Hardware Safety: Ensure servos are deactivated
Required:
--access-key: Picovoice access key for voice control
Optional:
--audio-device-index: Audio input device selection--log-dir: Logging directory--log-config-file: Logging configuration file--log-level: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL, USER_INFO, ODAS_USER_INFO, GAMEPAD_MODE_INFO)--clean: Clean existing logs--print-context: Print voice control context
- Multi-level Logging: Component-specific loggers
- File Rotation: 10MB max, 5 backup files
- Console Output: Colored output for user messages
- Performance Monitoring: Detailed operation logging
- Device Selection: Automatic or manual audio device
- Processing Parameters: Sample rate, channels, buffer size
- Voice Control: Wake word and command recognition settings
- Component Settings: Individual component configuration
- Performance Tuning: Thread management and timing