This file contains instructions for AI agents working with this codebase.
Project Name: ESP32 Hebbian Learning Robot
High-Level Goal: To create a robotic arm that learns to control its own movements in real-time, directly on the ESP32-S3, without relying on a pre-trained model.
Core Learning Algorithm: The system uses a biologically-inspired approach called Predictive Coding with a Hebbian Learning Rule.
For more detailed information, please refer to the Technical Report.
- MCU: ESP32-S3-DevKitC-1 v1.1
- Servos: 6x FeeTech Serial Bus Servos (daisy-chained)
- Servo Interface: Waveshare Bus Servo Adapter (A) (UART to Half-Duplex Serial)
- Sensor: SparkFun BMA400 Accelerometer (I2C)
- Visuals: Onboard Addressable RGB LED (GPIO 38)
- Framework: ESP-IDF v5.4
- Language: C
- Key Libraries/Components:
espressif/esp-dsp: For hardware-accelerated dot product calculations in the neural network.espressif/led_strip: For controlling the RGB LED.nvs_flash: For saving/loading the neural network weights.console,linenoise,esp_vfs_console: For the serial command interface.
main/: Contains the main application source code.components/: Contains ESP-IDF components.tests/: Contains unit tests.training/: Contains MCP servers and other training-related files.examples/: Contains client example code.
This project requires the ESP-IDF toolchain. If the idf.py command is not available, you must install it first. The following steps will set up the environment in a new session:
-
Install System Dependencies: This project requires
libusbfor theopenocdtool. You can install it with:sudo apt-get update && sudo apt-get install -y libusb-1.0-0 -
Download ESP-IDF: The ESP-IDF repository is not included in the sandbox. Clone it into your home directory:
mkdir -p ~/esp cd ~/esp git clone -b v5.5 --recursive https://github.com/espressif/esp-idf.git
-
Install ESP-IDF Tools: Run the installation script to download and set up the toolchains:
cd ~/esp/esp-idf ./install.sh all
-
Activate the Environment: Before building or testing, you must activate the ESP-IDF environment in your shell session by sourcing the
export.shscript:source ~/esp/esp-idf/export.sh
After this, the
idf.pycommand will be available in yourPATH. -
Install Python Dependencies: The training and testing scripts require several Python libraries. Install them using the provided
requirements.txtfile. It is recommended to do this after activating the ESP-IDF environment to ensure they are installed into the correct Python virtual environment.pip install -r requirements.txt
This project includes a set of Python-based unit tests that can be run without any hardware. These tests use mock objects to simulate the ESP32 device.
To run the tests:
-
Activate the ESP-IDF Environment: Make sure you have activated the environment as described in the "Environment Setup" section.
-
Navigate to the tests directory:
cd tests -
Run the unit test script:
python unit_test_script.py --mode unit
A successful run will show "Overall Result: PASSED".
This project uses the ESP-IDF build system. To build and flash the project, run the following commands:
idf.py build
idf.py -p (PORT) flashReplace (PORT) with the serial port of your ESP32 device.
- Bus Manager: All communication with the servos is handled by the bus manager task in
main.c. When adding new commands that interact with the servos, use the bus manager to send requests and receive responses. - MCP Server: The MCP server in
mcp_server.cis used for remote control. To add new tools, add them to thehandle_list_toolsfunction and implement the corresponding logic inhandle_call_tool. - Error Handling: The Feetech protocol implementation in
feetech_protocol.cincludes error handling and retries. When adding new communication functions, be sure to follow the existing error handling patterns. - Dependencies: The project has several dependencies, which are managed by the ESP-IDF build system. If you add new dependencies, be sure to update the
CMakeLists.txtfile accordingly.