Skip to content

Commit c058838

Browse files
committed
Add micros lifecycle manager package used to launch microros docker container that controls ear movement
1 parent f715f5f commit c058838

File tree

13 files changed

+829
-0
lines changed

13 files changed

+829
-0
lines changed
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
# Coffee Ears ESP32 Package
2+
3+
ROS2 package for controlling Coffee Buddy robot ears via ESP32 and micro-ROS agent. This package manages the Docker container lifecycle for micro-ROS communication with the ESP32 ear motion controller.
4+
5+
## Overview
6+
7+
This package replaces the manual Docker command with a proper ROS2 integration that provides:
8+
9+
- **Automated micro-ROS agent management** via Docker containers
10+
- **Health monitoring and auto-restart** capabilities
11+
- **Configurable parameters** for device paths and settings
12+
- **ROS2 launch file integration** with the Coffee Buddy system
13+
- **Status monitoring** and diagnostics
14+
15+
## Current vs New Approach
16+
17+
**Before (Manual):**
18+
```bash
19+
sudo docker run -it --rm -v /dev:/dev --privileged --net=host microros/micro-ros-agent:jazzy serial --dev /dev/ttyUSB1 -v6
20+
```
21+
22+
**After (ROS2 Integrated):**
23+
```bash
24+
ros2 launch coffee_ears_esp32 ears_system.launch.py
25+
```
26+
27+
## Installation
28+
29+
### Build the Package
30+
31+
```bash
32+
cd coffee_ws
33+
colcon build --packages-select coffee_ears_esp32
34+
source install/setup.bash
35+
```
36+
37+
## Usage
38+
39+
### Launch Options
40+
41+
#### 1. Complete Ear System (Recommended)
42+
```bash
43+
# Start complete system with defaults
44+
ros2 launch coffee_ears_esp32 ears_system.launch.py
45+
46+
# With custom device
47+
ros2 launch coffee_ears_esp32 ears_system.launch.py device_path:=/dev/ttyUSB0
48+
49+
# With custom settings
50+
ros2 launch coffee_ears_esp32 ears_system.launch.py device_path:=/dev/ttyUSB0 verbosity:=4
51+
```
52+
53+
#### 2. Micro-ROS Agent Only
54+
```bash
55+
# Start just the micro-ROS agent manager
56+
ros2 launch coffee_ears_esp32 microros_agent.launch.py
57+
58+
# With custom parameters
59+
ros2 launch coffee_ears_esp32 microros_agent.launch.py \
60+
device_path:=/dev/ttyUSB0 \
61+
verbosity:=4 \
62+
auto_start:=false
63+
```
64+
65+
#### 3. Manual Script (Alternative)
66+
```bash
67+
# Use the bash script directly
68+
./src/coffee_ears_esp32/scripts/start_microros_agent.sh
69+
70+
# With options
71+
./src/coffee_ears_esp32/scripts/start_microros_agent.sh --device /dev/ttyUSB0 --verbosity 4
72+
```
73+
74+
### Launch Parameters
75+
76+
| Parameter | Default | Description |
77+
|-----------|---------|-------------|
78+
| `device_path` | `/dev/ttyUSB1` | Serial device path for ESP32 |
79+
| `verbosity` | `6` | micro-ROS agent verbosity (0-6) |
80+
| `auto_start` | `true` | Start agent automatically |
81+
| `restart_on_failure` | `true` | Auto-restart on failures |
82+
| `health_check_interval` | `5.0` | Health check frequency (seconds) |
83+
84+
## ROS2 Interface
85+
86+
### Topics
87+
88+
#### Published by micro-ROS Manager:
89+
- `/microros_agent/status` (std_msgs/Bool) - Agent running status
90+
- `/microros_agent/diagnostics` (std_msgs/String) - Diagnostic messages
91+
92+
#### Subscribed by micro-ROS Manager:
93+
- `/microros_agent/control` (std_msgs/Bool) - Start/stop agent commands
94+
95+
#### ESP32 Interface (from Arduino code):
96+
- `/ear_motion_command` (std_msgs/Int32) - Send motion commands to ESP32
97+
98+
### Commands
99+
100+
#### Control Ear Motions
101+
```bash
102+
# Send predefined motion commands (1-12)
103+
ros2 topic pub /ear_motion_command std_msgs/Int32 "data: 1" # Ear twitch
104+
ros2 topic pub /ear_motion_command std_msgs/Int32 "data: 4" # Alert ears
105+
ros2 topic pub /ear_motion_command std_msgs/Int32 "data: 8" # Happy ears
106+
```
107+
108+
#### Monitor System Status
109+
```bash
110+
# Check if micro-ROS agent is running
111+
ros2 topic echo /microros_agent/status
112+
113+
# Monitor diagnostics
114+
ros2 topic echo /microros_agent/diagnostics
115+
116+
# Check if ESP32 node is connected
117+
ros2 node list | grep ear_motion_node
118+
```
119+
120+
#### Control Agent
121+
```bash
122+
# Start the agent
123+
ros2 topic pub /microros_agent/control std_msgs/Bool "data: true"
124+
125+
# Stop the agent
126+
ros2 topic pub /microros_agent/control std_msgs/Bool "data: false"
127+
```
128+
129+
## ESP32 Motion Library
130+
131+
The ESP32 implements 12 predefined ear motions:
132+
133+
1. **Ear twitch** - Quick ear movement
134+
2. **Ear wiggle** - Alternating ear movement
135+
3. **Ear sweep** - Full range motion
136+
4. **Alert ears** - Focused attention position
137+
5. **Relaxed ears** - Calm position
138+
6. **Curious tilt** - Questioning position
139+
7. **Startled ears** - Quick surprised motion
140+
8. **Happy ears** - Joyful wiggling
141+
9. **Annoyed flick** - Quick dismissive motion
142+
10. **Scanning ears** - Listening position
143+
11. **Sleepy ears** - Tired position
144+
12. **Greeting ears** - Welcoming motion
145+
146+
## Integration with Coffee Buddy System
147+
148+
### Expression System Integration
149+
```python
150+
# Include in system-wide launch files
151+
IncludeLaunchDescription(
152+
PythonLaunchDescriptionSource([
153+
FindPackageShare('coffee_ears_esp32'),
154+
'/launch/ears_system.launch.py'
155+
]),
156+
launch_arguments={'device_path': '/dev/ttyUSB1'}.items()
157+
)
158+
```
159+
160+
### Emotion Mapping
161+
The ear motions can be mapped to Coffee Buddy emotions:
162+
- **Alert** → Wake word detection, focused attention
163+
- **Happy** → Positive interactions, successful operations
164+
- **Startled** → Unexpected events, errors
165+
- **Sleepy** → Idle state, low power mode
166+
- **Curious** → Processing user input, thinking
167+
168+
## Troubleshooting
169+
170+
### Common Issues
171+
172+
#### Device Not Found
173+
```bash
174+
# Check available devices
175+
ls -la /dev/tty* | grep -E "(USB|ACM)"
176+
177+
# Try different device path
178+
ros2 launch coffee_ears_esp32 ears_system.launch.py device_path:=/dev/ttyUSB0
179+
```
180+
181+
#### Permission Denied
182+
```bash
183+
# Add user to dialout group (logout/login required)
184+
sudo usermod -a -G dialout $USER
185+
186+
# Or temporary fix
187+
sudo chmod 666 /dev/ttyUSB1
188+
```
189+
190+
#### Docker Issues
191+
```bash
192+
# Check if Docker is running
193+
sudo systemctl status docker
194+
195+
# Add user to docker group (logout/login required)
196+
sudo usermod -a -G docker $USER
197+
198+
# Pull the image manually
199+
sudo docker pull microros/micro-ros-agent:jazzy
200+
```
201+
202+
#### ESP32 Connection Issues
203+
```bash
204+
# Monitor serial connection
205+
sudo dmesg | tail -f
206+
207+
# Check micro-ROS agent logs
208+
ros2 topic echo /microros_agent/diagnostics
209+
210+
# Restart the ESP32
211+
ros2 topic pub /microros_agent/control std_msgs/Bool "data: false"
212+
ros2 topic pub /microros_agent/control std_msgs/Bool "data: true"
213+
```
214+
215+
### Monitoring
216+
217+
#### System Health
218+
```bash
219+
# Check all ear-related nodes
220+
ros2 node list | grep -E "(ear|microros)"
221+
222+
# Monitor connection status
223+
ros2 topic hz /microros_agent/status
224+
225+
# View all ear topics
226+
ros2 topic list | grep -E "(ear|microros)"
227+
```
228+
229+
## Development
230+
231+
### Package Structure
232+
```
233+
coffee_ears_esp32/
234+
├── coffee_ears_esp32/
235+
│ ├── __init__.py
236+
│ └── microros_manager.py # Main manager node
237+
├── launch/
238+
│ ├── microros_agent.launch.py # Agent only
239+
│ └── ears_system.launch.py # Complete system
240+
├── scripts/
241+
│ └── start_microros_agent.sh # Manual script
242+
├── package.xml
243+
├── setup.py
244+
└── README.md
245+
```
246+
247+
### Adding New Features
248+
249+
To extend the package:
250+
1. Modify `microros_manager.py` for new container management features
251+
2. Add new launch files for different configurations
252+
3. Update parameters in launch files for new settings
253+
254+
## License
255+
256+
Apache-2.0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
Coffee Ears ESP32 Package
3+
4+
ROS2 package for controlling Coffee Buddy robot ears via ESP32 and micro-ROS agent.
5+
This package manages the Docker container lifecycle for micro-ROS communication
6+
with the ESP32 ear motion controller.
7+
"""
8+
9+
__version__ = "0.0.0"
10+
__author__ = "kpatch"
11+
__email__ = "[email protected]"

0 commit comments

Comments
 (0)