A hexapod robot project for ESP32 hardware with Webots simulation support. Uses a shared C++ codebase for locomotion logic with platform-specific servo implementations.
jareds-hexapod/
├── lib/
│ ├── HexapodCore/ # Platform-independent locomotion library
│ └── ESP32Servos/ # ESP32 servo implementation
├── src/ # ESP32 firmware
├── webots/ # Webots simulation
│ ├── worlds/ # World files
│ ├── controllers/ # Controller code
│ └── protos/ # Custom robot models
├── platformio.ini # PlatformIO configuration
└── README.md
- ESP32 development board
- 18× servo motors (SG90 or similar)
- 5-6V power supply for servos
- Connection wires
The servos are mapped as follows (see src/main.cpp):
| Leg | Position | Joints (Coxa/Femur/Tibia) |
|---|---|---|
| 0 | Front-Right | 13, 12, 14 |
| 1 | Middle-Right | 27, 26, 25 |
| 2 | Rear-Right | 33, 32, 35 |
| 3 | Rear-Left | 34, 39, 36 |
| 4 | Middle-Left | 4, 16, 17 |
| 5 | Front-Left | 5, 18, 19 |
- PlatformIO (VS Code extension or CLI)
- USB drivers for ESP32
- Webots R2023b or later
- C++ compiler (MinGW on Windows, GCC on Linux, Clang on macOS)
-
Build the project:
cd c:\jaredcode\jareds-hexapod pio run -
Upload to ESP32:
pio run --target upload -
Monitor serial output:
pio device monitor
-
Open Webots
-
Load the world file:
- File → Open World
- Navigate to:
c:\jaredcode\jareds-hexapod\webots\worlds\hexapod.wbt
-
Build the controller (first time only):
- The controller should auto-compile when you load the world
- Alternatively, in the controller directory:
cd webots/controllers/hexapod_controller make
-
Run the simulation:
- Click the Play button in Webots
- The hexapod should initialize and move to standing position
Platform-independent hexapod control logic:
Hexapod.h/cpp: Main hexapod control classServoInterface.h: Abstract servo interfaceKinematics.h/cpp: Leg kinematics (future)Gait.h/cpp: Gait patterns (future)
ESP32 (lib/ESP32Servos):
- Uses ESP32Servo library
- Implements
ServoInterfacefor physical servos
Webots (webots/controllers/hexapod_controller):
- Uses Webots Motor and PositionSensor devices
- Implements
ServoInterfacefor simulated servos - Shares same
Hexapodclass as ESP32
- ✅ 18-servo hexapod control (6 legs × 3 joints)
- ✅ Hardware abstraction layer
- ✅ ESP32 firmware with servo control
- ✅ Webots simulation environment
- ✅ Basic poses (stand, rest)
- Inverse kinematics for leg positioning
- Tripod gait for walking
- Wave gait for slow walking
- Turning and rotation
- Remote control (Bluetooth/WiFi)
- IMU integration for balance
- Autonomous navigation
- Design gaits in Webots: Quickly iterate on locomotion algorithms
- Test in simulation: Verify behavior without hardware
- Deploy to ESP32: Same code runs on real hardware
- Fine-tune: Adjust parameters for physical characteristics
- Ensure PlatformIO is installed correctly
- Check that ESP32 board is selected in
platformio.ini - Verify USB connection and drivers
- Check that
WEBOTS_HOMEenvironment variable is set - Verify Makefile paths match your installation
- Rebuild controller:
cd webots/controllers/hexapod_controller && make clean && make
- Check power supply (servos need 5-6V, ESP32 GPIO is 3.3V)
- Verify pin connections match
SERVO_PINSarray - Test individual servos with simple sketch
MIT License - see LICENSE file for details.
Contributions welcome! Please open an issue or pull request.