An intelligent robotic lamp that combines computer vision, voice AI, and ROS2 control for natural human-robot interaction.
- 🖐️ Hand Tracking (Primary): Follows index fingertip with MediaPipe
- 👁️ Face Tracking (Fallback): Switches to face tracking when no hand detected
- 🔄 Seamless Switching: Intelligent priority system for smooth transitions
- 🗣️ Speech-to-Text: Deepgram real-time transcription
- 🧠 Emotion Analysis: Cerebras LLM for natural language understanding
- 🎭 Emotion Control: Dynamic lamp expressions (happy, sad, angry, confused, etc.)
- 🤖 AI Mode: Automatic tracking and movement
- 🖐️ Manual Mode: Voice-activated manual teaching mode
- 🎤 Voice Commands: "AI mode" / "manual mode" for seamless switching
- ROS2 Control: Professional robot control system
- ESP32 Communication: Eye position and emotion display
- Waveshare Servo Control: Multi-axis positioning via persistent symlinks
- Camera Support: USB cameras with auto-focus optimization
- Serial Protocol: Arduino/ESP32 compound commands
git clone <your-repo-url>
cd Robo-Lamp_AI
./install.shThe installation script automatically:
- ✅ Creates fresh virtual environment with all dependencies
- ✅ Detects and configures ESP32 and Servo Board hardware
- ✅ Sets up persistent device symlinks
- ✅ Configures user permissions
- ✅ Creates test and launcher scripts
- ✅ Generates comprehensive documentation
Edit hybrid_hand_face_controlled_lamp.py:
DEEPGRAM_API_KEY = "your_deepgram_key_here"
CEREBRAS_API_KEY = "your_cerebras_key_here"# Interactive mode (shows output, good for development)
./run_lamp.sh
# Background service mode (logs to file, good for production)
./start_lamp_service.sh &- Ubuntu 20.04+ / Linux
- Python 3.8+
- ROS2 Humble (optional but recommended)
- USB Camera
- ESP32 with CP2102 USB-to-UART Bridge (optional)
- Waveshare Servo Driver Board with CH340 (optional)
# Install ROS2 Humble
sudo apt update
sudo apt install ros-humble-desktop
source /opt/ros/humble/setup.bash
# Install additional ROS2 packages
sudo apt install ros-humble-cv-bridge ros-humble-std-srvsThe installation script automatically sets up reliable communication with all serial devices:
- 🔗 Persistent Symlink: Always available at
/dev/esp32-lamp - Function: Emotion display and eye position control
- Hardware: CP2102 USB-to-UART Bridge (VID:
10c4, PID:ea60)
- 🔗 Persistent Symlink: Always available at
/dev/waveshare-servo - Function: Multi-axis servo control for lamp positioning
- Hardware: QinHeng CH340 USB Serial Controller (VID:
1a86, PID:55d3)
- 🚫 No More USB Port Issues: Works regardless of which USB ports you use
- ⚡ Automatic Detection: Finds devices based on hardware identifiers
- 🔐 Permission Setup: Adds user to
dialoutgroup for serial access - 🧪 Built-in Testing: Includes communication test scripts for all devices
- 🔄 Reliable Reconnection: Handles unplugging/reconnecting automatically
# Test all devices
python3 test_all_devices.py
# Test individual devices
python3 esp32_test.py # ESP32 only
python3 servo_test.py # Servo board only- "Manual mode" / "Switch to manual" → Enable manual teaching
- "AI mode" / "Automatic mode" → Resume automatic tracking
- "I'm happy" → Happy expression
- "This is confusing" → Confused expression
- "Stop tracking" → Angry expression
- Natural speech is analyzed for emotional content
- Show your index finger → Lamp follows hand immediately
- Hide hand → Automatically switches to face tracking
- Show face → Lamp follows face movements
- Say "manual mode"
- Physically move the lamp (hardware unlocks when force applied)
- Say "AI mode" to resume automatic tracking
CAMERA_INDEX = 2 # USB camera index
CAMERA_WIDTH = 640 # Resolution width
CAMERA_HEIGHT = 480 # Resolution height
TARGET_FPS = 30 # Frame rateDEEPGRAM_API_KEY = "your_key" # Speech-to-text
CEREBRAS_API_KEY = "your_key" # LLM emotion analysis- Published:
/servo_node/delta_twist_cmds(lamp movement) - Published:
/camera/image_raw(camera feed) - Subscribed:
/joint_states(current lamp position) - Service:
/lamp/set_manual_mode(mode switching)
Format: #idle#position#curiosity#emotion#
Example: #off#DEFAULT#off#happy#
Robo-Lamp_AI/
├── hybrid_hand_face_controlled_lamp.py # Main application
├── hand_tracking_controlled_lamp.py # Original hand tracking
├── voice_camera_controlled_lamp.py # Original face tracking
├── requirements.txt # Python dependencies
├── install.sh # Comprehensive installation script
├── run_lamp.sh # Interactive launcher (auto-generated)
├── start_lamp_service.sh # Background service launcher
├── test_all_devices.py # Combined hardware test
├── esp32_test.py # ESP32 communication test
├── servo_test.py # Servo board communication test
├── config.example.py # Configuration template
├── setup.py # Python package setup
├── venv/ # Virtual environment (created by install.sh)
├── image-analysis/ # Gemini AI image analysis tool
│ ├── src/
│ │ ├── index.js # CLI interface
│ │ └── imageAnalyzer.js # Core analysis functionality
│ ├── images/ # Input images
│ ├── output/ # Processed images
│ └── package.json # Node.js dependencies
└── README.md # This file
# Activate environment
source venv/bin/activate
source /opt/ros/humble/setup.bash
# Run with custom Arduino port
python3 hybrid_hand_face_controlled_lamp.py /dev/ttyUSB1
# Run with debug output
ROS_LOG_LEVEL=DEBUG python3 hybrid_hand_face_controlled_lamp.py# Hand detection has priority
if hand_detected:
mode = "hand"
target = hand_center
elif face_detected:
mode = "face"
target = face_center
else:
mode = "search"# Mode switching checked before emotion analysis
async def process_voice_command(transcript):
if await check_mode_commands(transcript):
return # Mode command processed
# Continue with emotion analysis
emotion = await analyze_emotion_with_cerebras(transcript)# Respects manual mode setting
def publish_velocity_command(self, x, y, z):
if not self.should_move_lamp():
return # Blocked in manual mode
# Publish ROS2 TwistStamped message# Check available cameras
ls /dev/video*
# Test camera access
python3 -c "import cv2; cap = cv2.VideoCapture(2); print('Camera OK' if cap.isOpened() else 'Camera Failed')"# Check all persistent symlinks
ls -la /dev/esp32-lamp /dev/waveshare-servo
# Test all devices
python3 test_all_devices.py
# Check if devices are detected
lsusb | grep -E "10c4:ea60|1a86:55d3" # ESP32 and Servo Board
# Reload udev rules (after connecting devices)
sudo udevadm control --reload-rules
sudo udevadm trigger
# Check user permissions
groups # Should include 'dialout'# Reload udev rules
sudo udevadm control --reload-rules
sudo udevadm trigger
# Monitor udev events
sudo udevadm monitor# Check group membership
groups
# Add to dialout group if needed
sudo usermod -a -G dialout $(whoami)
newgrp dialout # Apply immediately# Test with different baud rates
python3 -c "
import serial
with serial.Serial('/dev/esp32-lamp', 9600) as s:
print('9600 baud OK')
with serial.Serial('/dev/esp32-lamp', 115200) as s:
print('115200 baud OK')
"# Reinstall MediaPipe
pip uninstall mediapipe
pip install mediapipe==0.10.21# Check ROS2 nodes
ros2 node list
# Check topics
ros2 topic list
# Test service
ros2 service call /lamp/set_manual_mode std_srvs/srv/SetBool "data: true"# Check audio devices
python3 -c "import pyaudio; p = pyaudio.PyAudio(); print(f'Audio devices: {p.get_device_count()}')"
# Test microphone
arecord -l# Recreate virtual environment
rm -rf venv
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtFor CSI ribbon camera on Raspberry Pi running Ubuntu 22.04:
Edit /boot/firmware/config.txt:
# Enable camera
start_x=1
gpu_mem=128
# Camera module overlay (adjust for your camera)
dtoverlay=ov5647 # For Pi Camera v1
# dtoverlay=imx219 # For Pi Camera v2
# dtoverlay=imx708 # For Pi Camera v3# Install libcamera and tools
sudo apt update
sudo apt install libcamera-apps libcamera-tools
# Install Python libraries
pip install picamera2 opencv-python# Test camera detection
libcamera-hello --list-cameras
# Capture test image
libcamera-still -o test.jpgThe repository includes a Gemini AI-powered image analysis tool:
cd image-analysis
npm install
cp .env.example .env
# Add your GOOGLE_API_KEY to .env# General image analysis
npm start images/photo.jpg
# Focus on specific objects
npm start images/photo.jpg "notebook"
npm start images/photo.jpg "phone"- General Image Description: Comprehensive descriptions
- Object Detection: Automatic detection with bounding boxes
- Focused Analysis: Crop and analyze specific objects
- Text Recognition: OCR and text analysis
./install.sh- Comprehensive installation (Python + Hardware + Testing)python3 verify_setup.py- Verify installation completeness
./run_lamp.sh- Interactive mode (development, shows output)./start_lamp_service.sh- Background service (production, logs to file)
python3 test_all_devices.py- Test all hardwarepython3 esp32_test.py- Test ESP32 onlypython3 servo_test.py- Test servo board only
# Check service logs
tail -f /home/$(whoami)/lamp_service.log
# Monitor hardware detection
sudo udevadm monitor
# Check system status
systemctl status # If running as systemd service- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- MediaPipe for hand and face tracking
- ROS2 for robot control framework
- Deepgram for speech-to-text
- Cerebras for LLM emotion analysis
- OpenCV for computer vision
- Google Gemini AI for image analysis
For issues and questions:
- 🐛 Bug Reports: Open an issue on GitHub
- 💬 Discussions: Use GitHub Discussions
- 📧 Direct Contact: [Your Contact Info]
Built with ❤️ for natural human-robot interaction