This project demonstrates how to acquire data from a BNO055 Inertial Measurement Unit (IMU) using an ESP32 microcontroller, running FreeRTOS and micro-ROS. The firmware reads accelerometer, gyroscope, and quaternion data from the BNO055 sensor, publishes it as a sensor_msgs/Imu message over a ROS 2 network, and allows visualization on a ROS 2 host (e.g., using RViz or rqt). The project is built with ESP-IDF and integrates micro-ROS for seamless ROS 2 compatibility.
- Reads BNO055 IMU data (acceleration in m/s², angular velocity in rad/s, and orientation quaternions).
- Publishes IMU data to the
/imu_datatopic using micro-ROS. - Uses FreeRTOS for task management and mutex-based data synchronization.
- Configurable for UDP communication with a micro-ROS agent.
- Includes error handling and logging for robust operation.
- Microcontroller: ESP32-based board (e.g., ESP32-DevKitC).
- IMU Sensor: BNO055 connected via I2C (SDA: GPIO 21, SCL: GPIO 22).
- Host PC: Ubuntu 22.04+ with ROS 2 Humble installed.
- Connection: USB for flashing and optional serial debugging; Wi-Fi for micro-ROS communication.
- ESP-IDF: Version 4.4 or 5.0 (recommended).
- micro-ROS: ESP-IDF component for ROS 2 integration (included as a submodule).
- ROS 2: Humble distribution on the host PC.
- Docker: For micro-ROS agent setup (optional).
- Tools:
idf.py,git, andcmake.
Clone this repository and initialize submodules:
git clone <your-repo-url> BNO055_microROS
cd BNO055_microROS
git submodule update --init --recursiveInstall ESP-IDF (v4.4 recommended):
mkdir -p ~/esp
cd ~/esp
git clone -b v4.4 --recursive https://github.com/espressif/esp-idf.git
cd esp-idf
./install.sh
. ./export.shThe components/micro_ros_espidf_component directory is a Git submodule. Ensure it’s properly initialized (see above). If you encounter Git warnings, refer to the Troubleshooting section.
Navigate to the project directory and build:
cd ~/esp/BNO055_microROS
idf.py buildConnect your ESP32 via USB and flash:
idf.py -p /dev/ttyUSB0 flashInstall ROS 2 Humble and the micro-ROS agent on your host PC:
sudo apt update
sudo apt install ros-humble-desktop ros-humble-micro-ros-agentUpdate main/main.c with your Wi-Fi credentials and micro-ROS agent IP/port:
#define CONFIG_MICRO_ROS_AGENT_IP "your-agent-ip"
#define CONFIG_MICRO_ROS_AGENT_PORT "8888"Alternatively, use serial communication by modifying the micro-ROS transport settings.
Start the agent on the host PC:
source /opt/ros/humble/setup.bash
ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888For serial communication:
ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyUSB0-
Monitor Serial Output (optional): View logs from the ESP32:
idf.py -p /dev/ttyUSB0 monitor
Logs include BNO055 initialization status and IMU data.
-
Verify Published Topics: On the ROS 2 host, check for the
/imu_datatopic:source /opt/ros/humble/setup.bash ros2 topic listExpected output includes
/imu_data(type:sensor_msgs/Imu). -
Visualize IMU Data:
- RViz:
Add an
rviz2
Imudisplay, set the topic to/imu_data, and configure visualization (e.g., orientation arrows). - rqt:
Use
rqt
rqt_plotto plot fields like/imu_data/linear_acceleration/x.
- RViz:
- main/main.c: Main application code.
- Initializes I2C and BNO055 sensor.
- Runs two FreeRTOS tasks:
bno055_task: Reads IMU data at 10 Hz and stores it in a mutex-protected structure.micro_ros_task: Publishes IMU data to/imu_datausing micro-ROS.
- Uses a mutex for thread-safe data access.
- components/micro_ros_espidf_component: micro-ROS ESP-IDF component (submodule).
- Git Submodule Warning: If you see a warning about
components/micro_ros_espidf_componentbeing an embedded repository:git rm --cached components/micro_ros_espidf_component git submodule add https://github.com/micro-ROS/micro_ros_espidf_component.git components/micro_ros_espidf_component
- I2C Errors: Verify BNO055 wiring (SDA: GPIO 21, SCL: GPIO 22) and I2C address (0x28 or 0x29).
- micro-ROS Connection Issues: Ensure the agent’s IP/port matches
CONFIG_MICRO_ROS_AGENT_IPandCONFIG_MICRO_ROS_AGENT_PORT. - BNO055 Initialization Failure: Check power supply (3.3V) and I2C pull-up resistors.
- The BNO055 is configured in NDOF mode for fused orientation data.
- IMU data is scaled to SI units (m/s² for acceleration, rad/s for angular velocity, normalized quaternions).
- Covariance values in
sensor_msgs/Imuare placeholders; adjust based on sensor specifications. - For serial communication, modify the micro-ROS transport in
main.cand agent settings.
This project is licensed under the MIT License. See the LICENSE file for details.