Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROS2 version #3

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 51 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,75 +1,73 @@
cmake_minimum_required(VERSION 2.8.3)
cmake_minimum_required(VERSION 3.8)
project(mpu6050_driver)

add_compile_options(-std=c++11)
# add_definitions(-Wall -Werror)
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we put C++17 here to comply with the REP 2000 for Humble release

endif()

set(CATKIN_DEPS
# diagnostic_msgs
roscpp
sensor_msgs
i2c_device_ros
)

find_package(catkin REQUIRED COMPONENTS ${CATKIN_DEPS})
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(eigen3_cmake_module REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(cmake_modules REQUIRED)

catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS ${CATKIN_DEPS}
DEPENDS Eigen
)

include_directories(
include
${catkin_INCLUDE_DIRS}
${Eigen3_INCLUDE_DIRS}
)

set(MPU6050_NODE_LIB mpu6050_node_lib)
add_library(${MPU6050_NODE_LIB}
# Define library target
add_library(mpu6050_node_lib
src/mpu6050_node.cpp
src/mpu6050.cpp
src/i2c_device.cpp
)
ament_target_dependencies(mpu6050_node_lib rclcpp sensor_msgs)

add_executable(mpu6050_node
src/main.cpp
)
# Link against ROS 2 libraries
# target_link_libraries(mpu6050_node_lib
# ${rclcpp_LIBRARIES}
# )
Comment on lines +29 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove commented lines


target_link_libraries(mpu6050_node
${catkin_LIBRARIES}
${MPU6050_NODE_LIB}
)
# Define executable targets
add_executable(mpu6050_node src/main.cpp)
ament_target_dependencies(mpu6050_node rclcpp sensor_msgs)
target_link_libraries(mpu6050_node mpu6050_node_lib)
Comment on lines +35 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
add_executable(mpu6050_node src/main.cpp)
ament_target_dependencies(mpu6050_node rclcpp sensor_msgs)
target_link_libraries(mpu6050_node mpu6050_node_lib)
add_executable(mpu6050_node
src/main.cpp
)
ament_target_dependencies(mpu6050_node
rclcpp
sensor_msgs
)
target_link_libraries(mpu6050_node
mpu6050_node_lib
)

Nitpick to comply with what we do in our internal repositories. Please apply this to the following lines, too.


add_executable(mpu6050_calibration_node
src/main_calibration.cpp
src/mpu6050_calibration_node.cpp
)
add_executable(mpu6050_calibration_node src/main_calibration.cpp src/mpu6050_calibration_node.cpp)
ament_target_dependencies(mpu6050_calibration_node rclcpp sensor_msgs)
target_link_libraries(mpu6050_calibration_node mpu6050_node_lib)

target_link_libraries(mpu6050_calibration_node
${catkin_LIBRARIES}
${MPU6050_NODE_LIB}
ament_export_targets(export_${PROJECT_NAME})
# Install targets
install(
TARGETS mpu6050_node mpu6050_calibration_node mpu6050_node_lib
EXPORT export_${PROJECT_NAME}
DESTINATION lib/${PROJECT_NAME}
)

# install(TARGETS ${PROJECT_NAME}_node
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )
# Install targets
# install(TARGETS
# mpu6050_node
# mpu6050_calibration_node
# mpu6050_node_lib
# DESTINATION lib/${PROJECT_NAME})
Comment on lines +51 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove commented lines


# install(TARGETS ${PROJECT_NAME}
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
# )
install(DIRECTORY include/
DESTINATION include)
Comment on lines +58 to +59
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
install(DIRECTORY include/
DESTINATION include)
install(
DIRECTORY include/
DESTINATION include
)


# install(DIRECTORY include/${PROJECT_NAME}/
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
# FILES_MATCHING PATTERN "*.h"
# PATTERN ".svn" EXCLUDE
# )
# Uncomment if you have package specific launch files, config files or other files to install
install(DIRECTORY
launch
config
DESTINATION share/${PROJECT_NAME}
)

# install(FILES
# # myfile1
# # myfile2
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )
# Export dependencies
ament_export_include_directories(include)
ament_export_libraries(mpu6050_node_lib)
ament_export_dependencies(rclcpp sensor_msgs Eigen3)

ament_package()
43 changes: 15 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# MPU6050 Driver

# Overview
This is a ROS package to use the MPU6050 IMU sensor on platforms with Raspberry
This is a ROS2 package to use the MPU6050 IMU sensor on platforms with Raspberry
boards. The package was developed to be used in the [Doogie Mouse robot]. The
sensor libraries were adapted from the [Arduino Library] of MPU6050 sensor.

Expand All @@ -10,48 +10,36 @@ sensor libraries were adapted from the [Arduino Library] of MPU6050 sensor.
## License
The source code is released under a [MIT license](LICENSE).

**Author:** Mateus Meneses
**Authors:** Mateus Meneses, Mohamed Abdelkader ([email protected])
**Maintainer:** Mateus Meneses, [email protected]

The MPU6050 Driver package has been tested under [ROS] Kinetic and [Raspbian Jessie].
The barnch `ros2_humble` has been tested under [ROS] `humble` and [Raspberry Pi Bookworm] .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The barnch `ros2_humble` has been tested under [ROS] `humble` and [Raspberry Pi Bookworm] .
The branch `ros2_humble` has been tested under [ROS] `Humble Hawksbill` and [Raspberry Pi Bookworm] .

This is research code, expect that it changes often and any fitness for a
particular purpose is disclaimed.

# Installation

## Dependencies

- [Robot Operating System (ROS)](http://wiki.ros.org) (Middleware for robotics),
- [i2c_device_ros] (C++ library to read/write from/to I2C devices)
- [Robot Operating System (ROS)](http://wiki.ros.org) (Middleware for robotics)

## Building

The first step to build this package is install its dependency. To that, clone
the [i2c_device_ros] package into your workspace
Now, clone the latest version from this repository into your ROS workspace

```sh
$ cd <YOUR_WS>/src
$ git clone https://github.com/mateusmenezes95/i2c_device_ros.git
```

Now, clone the latest version from this repository into your catkin workspace

```sh
$ cd <YOUR_WS>/src
$ git clone https://github.com/mateusmenezes95/mpu6050_driver.git
$ git clone -b ros2_humble https://github.com/mateusmenezes95/mpu6050_driver.git
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this PR target the master branch, I suggest remove the branch option from this command

$ cd ../
```

Then, to build the package you could use two options:

- pure catkin
```sh
$ catkin_make -DCATKIN_WHITELIST_PACKAGES="mpu6050_driver;i2c_device_ros;
```
- catkin tool
```sh
$ catkin build mpu6050_driver
$ colcon build
```

# Usage

## Calibration Process
Expand All @@ -64,7 +52,7 @@ sensor on its final place on your robot (this is strongly important!) and then
run the calibration node:

```sh
$ roslaunch mpu6050_driver mpu6050_calibration.launch
$ ros2 launch mpu6050_driver mpu6050_calibration.launch.py
```

The process will take a few minutes to finish. While that, you can see the IMU
Expand All @@ -73,13 +61,13 @@ registers in the topic "imu_offsets". In a new terminal, you can see the imu
messages runnig

```sh
$ rostopic echo /imu -c
$ ros2 topic echo /imu/data_raw
```

and the offsets running on a new terminal

```sh
$ rostopic echo /imu_offsets -c
$ ros2 topic echo /imu_offsets
```

You'll see the angular velocity and linear acceleration values converging to
Expand All @@ -96,7 +84,7 @@ config file.
After to calibrate the MPU sensor, you can run the main node with

```sh
$ roslaunch mpu6050_driver mpu6050_driver.launch
$ ros2 launch mpu6050_driver mpu6050_driver.launch.py
```

# Config files
Expand All @@ -106,10 +94,10 @@ and main node

# Launch files

* **[mpu6050_calibration.launch](launch/mpu6050_calibration.launch):** Launch the
* **[mpu6050_calibration.launch.py](launch/mpu6050_calibration.launch.py):** Launch the
calibration node

* **[mpu6050_driver.launch](launch/mpu6050_driver.launch):** Launch the main node
* **[mpu6050_driver.launch.py](launch/mpu6050_driver.launch.py):** Launch the main node

# Nodes

Expand All @@ -118,7 +106,7 @@ calibration node
Publish the MPU6050 data

### Published Topics
* **`/imu`** ([sensor_msgs/IMU])
* **`/imu/data_raw`** ([sensor_msgs/IMU])
Imu data with the values from MPU6050 accelerometer and gyroscope

### Parameters
Expand Down Expand Up @@ -149,6 +137,5 @@ Please report bugs and request features using the
[Doogie Mouse robot]: https://github.com/Brazilian-Institute-of-Robotics/doogie
[Arduino Library]: https://github.com/ElectronicCats/mpu6050
[Raspbian Jessie]: https://www.raspberrypi.org/downloads/raspbian/
[i2c_device_ros]: https://github.com/Brazilian-Institute-of-Robotics/i2c_device_ros
[The MPU6050 Explained]: https://mjwhite8119.github.io/Robots/mpu6050
[mpu_settings.yaml]: config/mpu_settings.yaml
37 changes: 20 additions & 17 deletions config/mpu_settings.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
# I2C Bus URI used to comunicate with I2C devices (default: "/dev/i2c-1")
bus_uri: "/dev/i2c-1"
# ROS2 parameter file format
mpu6050_node:
ros__parameters:
# I2C Bus URI used to communicate with I2C devices
bus_uri: "/dev/i2c-1"

# I2C address of MPU6050 (default: 0x68)
mpu_address: 0x68
# I2C address of MPU6050
mpu_address: 0x68

# Frequency in Hertz wich IMU data is published (default: 30)
pub_rate: 25
# Frequency in Hertz which IMU data is published
pub_rate: 400.0

# Frame if of IMU message (default: "imu")
frame_id: "imu"
# Frame id of IMU message
frame_id: "imu"

# Offsets to fix wrong values caused by misalignment
# Sequence is (ax, ay, az, gx, gy, gz) (default: [0, 0, 0, 0, 0, 0])
axes_offsets: [-1987, 44, 1210, 75, -10, 7]
# Offsets to fix wrong values caused by misalignment
# Sequence is (ax, ay, az, gx, gy, gz)
axes_offsets: [-2589, -1383, 1628, -20, -34, 53]

# PID constants used in calibration procedure
ki: 0.2 # (default: 0.1)
kp: 0.1 # (default: 0.1)
# PID constants used in calibration procedure
ki: 0.2
kp: 0.1

# The calibration process is finished when the error is aproximate zero with
# the precision set by delta (default: 0.5)
delta: 0.5
# The calibration process is finished when the error is approximate zero with
# the precision set by delta
delta: 0.5
26 changes: 26 additions & 0 deletions config/mpu_settings_calib.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is almost the same for the node. Why should we have both of these two files?

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ROS2 parameter file format
mpu_calibration_node:
ros__parameters:
# I2C Bus URI used to communicate with I2C devices
bus_uri: "/dev/i2c-1"

# I2C address of MPU6050
mpu_address: 0x68

# Frequency in Hertz which IMU data is published
pub_rate: 100.0

# Frame id of IMU message
frame_id: "imu"

# Offsets to fix wrong values caused by misalignment
# Sequence is (ax, ay, az, gx, gy, gz)
axes_offsets: [-1987, 44, 1210, 75, -10, 7]

# PID constants used in calibration procedure
ki: 0.2
kp: 0.1

# The calibration process is finished when the error is approximate zero with
# the precision set by delta
delta: 0.5
Loading