> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Publish the IMU data with qrb_ros_imu

> The qrb_ros_imu sample application publishes the inertial measurement unit (IMU) data collected from the ICM-42688 hardware on Qualcomm Robotics Platforms.

The [qrb\_ros\_imu](https://github.com/qualcomm-qrb-ros/qrb_ros_imu) sample application publishes the inertial measurement unit (IMU) data collected from the ICM-42688 hardware on Qualcomm Robotics Platforms. It provides the following:

* Composable ROS Node support.

* Zero-Copy transport powered by [QRB ROS Transport](https://github.com/qualcomm-qrb-ros/qrb_ros_transport).

## Pipeline flow for `qrb_ros_imu`

The following figure shows the pipeline flow for `qrb_ros_imu`.

<Frame caption="qrb_ros_imu pipeline.">
  <img src="https://mintcdn.com/qualcomm-prod/EDJV-hu6qJhZi4pm/SDKs/QIR-SDK-Ubuntu/images/image15.svg?fit=max&auto=format&n=EDJV-hu6qJhZi4pm&q=85&s=c61411e1a893acc09a360d8ee575d5bb" alt="Inertial measurement unit hardware feeding the QRB-ROS-IMU node, which gets the data from SLPI and publishes it to a ROS topic." width="586" height="362" data-path="SDKs/QIR-SDK-Ubuntu/images/image15.svg" />
</Frame>

The [qrb\_ros\_imu](https://github.com/qualcomm-qrb-ros/qrb_ros_imu/tree/main/qrb_ros_imu) is a ROS 2 package. It creates a publisher with `qrb_ros_transport` for zero-copy transport. It supports node composition, making it possible to improve performance using ROS intra-process communication.

## `qrb_ros_imu` APIs

The `qrb_ros_imu` package exposes ROS interfaces, ROS parameters, and the `qrb_sensor_client` library APIs. Use them to subscribe to the published inertial measurement unit (IMU) data and to configure how the node reads the sensor.

### ROS interfaces

The following table describes the ROS interfaces provided by `qrb_ros_imu`.

| Interface   | Name   | Type                  | Description                                       |
| ----------- | ------ | --------------------- | ------------------------------------------------- |
| `Publisher` | `/imu` | `sensor_msgs/msg/Imu` | Outputs the inertial measurement unit (IMU) data. |

### ROS parameters

The following table describes the ROS parameters for `qrb_ros_imu`.

| Name    | Type   | Description                                                                    | Default value |
| ------- | ------ | ------------------------------------------------------------------------------ | ------------- |
| `debug` | `bool` | To measure the latency from IMU data generation to its output by the ROS node. | `false`       |

### `qrb_sensor_client` APIs

The following table describes the `qrb_sensor_client` APIs.

| Function                                                                                               | Parameters                                                                                                                                   | Description                                                                                                                                                                        |
| ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `bool create_connection()`                                                                             | Empty                                                                                                                                        | Connect with sensor service, return `true` means create successfully.                                                                                                              |
| `void disconnect_server()`                                                                             | Empty                                                                                                                                        | Disconnect with sensor service.                                                                                                                                                    |
| `bool get_imu_data(sensors_event_t ** accel_ptr, sensors_event_t ** gyro_ptr, int32_t * sample_count)` | • `accel_ptr`: Pointer to accelerometer data<br />• `gyro_ptr`: Pointer to gyroscope data<br />• `sample_count`: Number of samples available | Retrieves IMU data. Returns `true` if successful. If `true`, `accel_ptr` and `gyro_ptr` point to the latest IMU data, and `sample_count` specifies how many samples are retrieved. |

## Prerequisites

You have set up the device, installed ROS2 Jazzy and Qualcomm Intelligent Robotics (QIR) SDK on the device according to [Install the QIR SDK](./install-the-qir-sdk).

## Run out-of-the-box `qrb_ros_imu`

<Steps>
  <Step title="Install the qrb_ros_transport packages">
    ```bash Install the packages theme={null}
    sudo apt install ros-jazzy-qrb-ros-imu
    sudo apt install qcom-sensor\*
    reboot
    ```
  </Step>

  <Step title="Use the IMU node">
    ```bash Run the IMU node theme={null}
    source /opt/ros/jazzy/setup.bash
    ros2 run qrb_ros_imu imu_node
    ```
  </Step>

  <Step title="Check ROS topics with the topic /imu">
    ```bash theme={null}
    source /opt/ros/jazzy/setup.bash
    ros2 topic echo /imu
    ```
  </Step>
</Steps>

## Build and run `qrb_ros_imu`

<Steps>
  <Step title="Install dependencies">
    ```bash Install the dependencies theme={null}
    sudo apt install ros-jazzy-qrb-ros-transport-imu-type \
    ros-dev-tools
    ```
  </Step>

  <Step title="Clone the repository to the device">
    ```bash Download the source code theme={null}
    mkdir -p ~/qrb_ros_ws/src
    cd ~/qrb_ros_ws/src
    git clone https://github.com/qualcomm-qrb-ros/qrb_ros_imu.git
    ```
  </Step>

  <Step title="Build and run qrb_ros_imu">
    ```bash Build and run theme={null}
    cd ~/qrb_ros_ws
    colcon build
    source install/setup.bash
    ros2 run qrb_ros_imu imu_node
    ```
  </Step>
</Steps>
