> For the complete documentation index, see [llms.txt](https://robocre8.gitbook.io/robocre8/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://robocre8.gitbook.io/robocre8/tutorials/how-to-use-eimu-with-ros2.md).

# How To Use EIMU With ROS2

Learn how to test and integrate the Easy IMU (EIMU) in your ROS2 project

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2FPRbymz0Q4TyX3jdYsRRX%2Feimu_pic_ros2.png?alt=media&amp;token=2f241d4e-c6a6-4001-9430-276050dbb513" alt=""><figcaption></figcaption></figure>

### Before Running The EIMU ROS2 Package

* Firstly, ensure you have calibrated and set its Madgwick filter gain and computed its orientation, rate, and acceleration variances. If not, follow the instructions here \[[link to the post](https://robocre8.gitbook.io/robocre8/eimu-tutorials/how-to-calibrate-and-setup-the-eimu)]
* Also, before you start, it is worth knowing that you can use it with a PC, Raspberry Pi 4, or any microcomputer running Ubuntu OS and ROS2. You can also use docker (if you can).
* You should also have some experience with ROS2 as a beginner or intermediate user.\
  (e.g. Installing ROS2, setting up ros workspace, building packages with colcon, rosdep, ros topics, rviz, ros transforms, e.t.c)

With the above in mind, follow the instructions from its [**Github repo**](https://github.com/robocre8/eimu_ros) (i.e.[ ](https://github.com/samuko-things-company/sic_mpu9250_ros/tree/humble)[eimu\_ros](https://github.com/robocre8/eimu_ros) package)  to get it up and running.

<figure><img src="https://1813945869-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvaPba1OWKgmXxFGX8DOE%2Fuploads%2FVIhvcC3vCo8v4n0IyR9R%2Feimu_ros2_test.gif?alt=media&amp;token=966e0dda-0ae5-4628-a466-a014e0dbd09e" alt=""><figcaption></figcaption></figure>

***

There are two ways of **using** and **launching** the [**eimu\_ros**](https://github.com/robocre8/eimu_ros) package:

* The first just involves quick test to see if the **Easy IMU** is working with ROS2.
* The Other Involves using it in your robotics projects (with URDF and robot-state-publisher)

### Notes On Testing The Easy IMU (EIMU) With RVIZ

After installing and building the **eimu\_ros** package and connecting the **EIMU Module** to your PC or microcomputer as specified in its [github repo](https://github.com/robocre8/eimu_ros). You can quickly test if it is working by running the test launch file with rviz.

```sh
ros2 launch eimu_ros test.launch.py
```

```sh
rviz2
```

You'll notice the `eimu_ros_test_params.yaml` in the `config` folder with following content:

```yaml
eimu_ros:
  ros__parameters:
    # port: "/dev/serial/by-path/pci-0000:00:14.0-usb-0:1.3:1.0-port0"
    port: "/dev/ttyUSB0"
    frame_id: "imu"
    publish_frequency: 10.0
    eimu_reference_frame_id: 1  # 0 - NWU,  1 - ENU,  2 - NED
    publish_tf_on_map_frame: true
```

the parameters, I believe, are quite self explanatory.  (You can adjust any parameter as you see fit)

You'll notice the `publish_tf_on_map_frame` is set to true. What this does is to publish the imu data transform from the **imu** frame to the **map** frame for quick test view with RVIZ.

all you need to do add TF to the rviz view.

### Notes On Using The Easy IMU (EIMU) In Your ROS2 Robotic Project

The EIMU can also be used in your ROS2 robotic project where you have the robot's **URDF** transform published using the **robot-state-publisher** package.

You'll use the `eimu_ros_start_params.yaml`in the `config` folder with following content:

```yaml
eimu_ros:
  ros__parameters:
    # port: "/dev/serial/by-path/pci-0000:00:14.0-usb-0:1.3:1.0-port0"
    port: "/dev/ttyUSB0"
    frame_id: "imu"
    publish_frequency: 10.0
    eimu_reference_frame_id: 1  # 0 - NWU,  1 - ENU,  2 - NED
    publish_tf_on_map_frame: false
```

the parameters, I believe, are quite self explanatory and are the same as that of the test.  (You can adjust any parameter as you see fit)

You'll notice the `publish_tf_on_map_frame` is set to false. This means that the imu data transforms will not be published on the map frame. Since you would be using it with your robot's URDF, then the robot-state-publisher will handle the transform.

what you need to do before launching is to ensure the `frame_id`  parameter in the param file has the same name/value as that of your imu frame/link in your robot URDF file. e.g

```xml
<!--  IMU LINK -->

<joint name="imu_joint" type="fixed">
    <parent link="chassis"/>
    <child link="imu"/>
    <origin xyz="0 0 ${chassis_height}"/>
</joint>


<link name="imu">
</link>

<!--  ########################### -->
```

Notice that the `<link name="imu">`  and `frame_id: "imu"`  have the same value and `publish_tf_on_map_frame: false`&#x20;

Once this is done you can start/launch your robot-state-publisher to publish the URDF transform and then run the command below to start the Easy IMU.

```
ros2 launch eimu_ros start.launch.py
```

Now the the IMU data will now be published on the IMU link of your robot.

Feel free to use the package launch and config file to your preferred taste.

***

Finally, please chekout the [**mobo\_bot**](https://github.com/robocre8/mobo_bot) package to see proper sample of how combine the **EIMU** with the **EPMC** and ekf sensor-fusion in a mobile robot.
