Skip to content

uditfand2712/imu_sensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BNO055 IMU Data Acquisition with micro-ROS on ESP32

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.

Features

  • Reads BNO055 IMU data (acceleration in m/s², angular velocity in rad/s, and orientation quaternions).
  • Publishes IMU data to the /imu_data topic 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.

Hardware Requirements

  • 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.

Software Requirements

  • 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, and cmake.

Setup Instructions

1. Clone the Repository

Clone this repository and initialize submodules:

git clone <your-repo-url> BNO055_microROS
cd BNO055_microROS
git submodule update --init --recursive

2. Install ESP-IDF

Install 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.sh

3. Configure micro-ROS Component

The 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.

4. Build the Firmware

Navigate to the project directory and build:

cd ~/esp/BNO055_microROS
idf.py build

5. Flash the Firmware

Connect your ESP32 via USB and flash:

idf.py -p /dev/ttyUSB0 flash

6. Set Up ROS 2 Host

Install 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-agent

7. Configure Network

Update 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.

8. Run the micro-ROS Agent

Start the agent on the host PC:

source /opt/ros/humble/setup.bash
ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888

For serial communication:

ros2 run micro_ros_agent micro_ros_agent serial --dev /dev/ttyUSB0

Usage

  1. Monitor Serial Output (optional): View logs from the ESP32:

    idf.py -p /dev/ttyUSB0 monitor

    Logs include BNO055 initialization status and IMU data.

  2. Verify Published Topics: On the ROS 2 host, check for the /imu_data topic:

    source /opt/ros/humble/setup.bash
    ros2 topic list

    Expected output includes /imu_data (type: sensor_msgs/Imu).

  3. Visualize IMU Data:

    • RViz:
      rviz2
      Add an Imu display, set the topic to /imu_data, and configure visualization (e.g., orientation arrows).
    • rqt:
      rqt
      Use rqt_plot to plot fields like /imu_data/linear_acceleration/x.

Code Structure

  • 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_data using micro-ROS.
    • Uses a mutex for thread-safe data access.
  • components/micro_ros_espidf_component: micro-ROS ESP-IDF component (submodule).

Troubleshooting

  • Git Submodule Warning: If you see a warning about components/micro_ros_espidf_component being 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_IP and CONFIG_MICRO_ROS_AGENT_PORT.
  • BNO055 Initialization Failure: Check power supply (3.3V) and I2C pull-up resistors.

Notes

  • 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/Imu are placeholders; adjust based on sensor specifications.
  • For serial communication, modify the micro-ROS transport in main.c and agent settings.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

developing FreeRTOS firmware for IMU data collection, implementing micro-ROS, and visualizing the data on a ROS 2 host. The steps are based on official micro-ROS documentation and examples.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors