Skip to content

Commit 089964d

Browse files
authored
Merge pull request #67 from quic-penwang/ROS2-IMU-dev
Added IMU ROS2 node sample code
2 parents 98d55f2 + ebd2748 commit 089964d

22 files changed

+2271
-0
lines changed

ROS2-IMU/LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Copyright (c) 2020 Qualcomm Innovation Center, Inc. All Rights Reserved.
2+
3+
Redistribution and use in source and binary forms, with or without modification, are permitted
4+
provided that the following conditions are met:
5+
6+
* Redistributions of source code must retain the above copyright notice, this list of conditions
7+
and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above copyright notice, this list of
9+
conditions and the following disclaimer in the documentation and/or other materials
10+
provided with the distribution.
11+
* Neither the name of the copyright holder nor the names of its contributors may be used to
12+
endorse or promote products derived from this software without specific prior written
13+
permission.
14+
15+
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
16+
LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
20+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22+
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Where there is uncertainty as to how, or
26+
where, to apply marks, open an OSR to escalate to OSG for review.
27+
28+
SPDX-License-Identifier: BSD-3-Clause-Clear

ROS2-IMU/README.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# ROS2-IMU
2+
## Overview
3+
This document shows how to run imu-ros2node with ROS2 environments. And shows the IMUD daemon/library sample code for build own IMU node.
4+
- sensor-daemon: the IMUD service to access IMU data from DSP.
5+
- sensor-client: the library for communicating with IMUD.
6+
- imu-ros2node: the sample implementation of IMU node based on ROS2.
7+
8+
**TIP:** All these components are built-in in RB5 image as binary programs. You can run the imu-ros2node with following steps.
9+
10+
## 1 Set up the WLAN
11+
12+
**1.1 Pull WLAN config to PC**
13+
14+
```bash
15+
adb pull /data/misc/wifi/wpa_supplicant.conf
16+
```
17+
18+
**1.2 Change SSID and password with your Router in wpa_supplicant.conf**
19+
20+
example:
21+
22+
```
23+
network={
24+
ssid="Monkey1"
25+
key_mgmt=WPA-PSK
26+
pairwise=TKIP CCMP
27+
group=TKIP CCMP
28+
psk="MY_PASSWORD"
29+
}
30+
```
31+
32+
**1.3 Push wpa_supplicant.conf to device**
33+
34+
```
35+
adb push wpa_supplicant.conf /data/misc/wifi/
36+
```
37+
38+
**1.4 Reboot device and wait for device boot up**
39+
40+
```
41+
adb reboot
42+
```
43+
44+
**1.5 Wait for 1mins after device boot up, and you will be found device have been auto connected to your Router**
45+
46+
```
47+
adb shell
48+
ifconfig wlan0
49+
```
50+
51+
You will see the ip address if WLAN connected, like this:
52+
53+
```
54+
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
55+
inet 10.91.4.85 netmask 255.255.252.0 broadcast 10.91.7.255
56+
inet6 fe80::dc7a:257b:cf30:3842 prefixlen 64 scopeid 0x20<link>
57+
ether 00:03:7f:12:1e:b3 txqueuelen 3000 (Ethernet)
58+
RX packets 19 bytes 2498 (2.4 KB)
59+
RX errors 0 dropped 0 overruns 0 frame 0
60+
TX packets 37 bytes 3424 (3.4 KB)
61+
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
62+
```
63+
64+
Now the WLAN connected successfully!
65+
66+
## 2 Set up ROS2 environment
67+
68+
The built-in IMU ROS node supports ROS2 Dashing only.
69+
70+
**2.1 Connect RB5 with adb**
71+
72+
```
73+
adb shell
74+
```
75+
76+
**2.2 Install ROS2 via Debian package**
77+
You can reference the official ROS document:
78+
https://docs.ros.org/en/dashing/Installation/Ubuntu-Install-Debians.html
79+
Or you can directly use these commands:
80+
81+
```bash
82+
# update locales
83+
apt update && apt install locales
84+
locale-gen en_US en_US.UTF-8
85+
update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
86+
export LANG=en_US.UTF-8
87+
88+
# add apt source
89+
apt update && apt install curl gnupg2 lsb-release
90+
curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
91+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null
92+
apt update
93+
94+
# install ROS2 package
95+
apt install ros-dashing-ros-base
96+
```
97+
98+
Wait until all ROS2 packages are installed completely.
99+
100+
**2.2 Verify the ROS2 installation**
101+
102+
```bash
103+
source /opt/ros/dashing/setup.bash
104+
ros2
105+
```
106+
107+
Will show the ros2 help message if installation is complete.
108+
109+
## 3 Run IMU ROS node
110+
111+
**3.1 Init ROS2 environment**
112+
113+
```
114+
source /opt/ros/dashing/setup.bash
115+
```
116+
117+
**2.2 Run IMU ROS node with `ros2 run` command**
118+
119+
The IMU ROS node is provided with RB5 ubuntu image. You could run the node directly.
120+
121+
```
122+
ros2 run imu-ros2node imu-ros2node
123+
```
124+
125+
**2.3 Test the IMU ROS node**
126+
127+
Open another terminal
128+
129+
```
130+
adb shell
131+
```
132+
133+
Init ROS2 environment and test IMU node with
134+
135+
```
136+
source /opt/ros/dashing/setup.bash
137+
ros2 topic echo /imu
138+
```
139+
140+
Pick up RB5 and shake it, you could see the IMU data are changing in the log:
141+
142+
![imu-data](image/imu-data.png)
143+
144+
## License
145+
146+
This is licensed under the BSD 3-clause-Clear “New” or “Revised” License. Check out the [LICENSE](LICENSE) for more details.

ROS2-IMU/image/imu-data.png

25.7 KB
Loading
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
cmake_minimum_required(VERSION 3.8.2)
2+
3+
project(imu-ros2node
4+
LANGUAGES C CXX)
5+
6+
# Default to C99
7+
if(NOT CMAKE_C_STANDARD)
8+
set(CMAKE_C_STANDARD 99)
9+
endif()
10+
11+
# Default to C++14
12+
if(NOT CMAKE_CXX_STANDARD)
13+
set(CMAKE_CXX_STANDARD 14)
14+
endif()
15+
16+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
17+
add_compile_options(-Wall -Wextra -Wpedantic)
18+
endif()
19+
20+
include_directories (./include)
21+
22+
if (CMAKE_CROSSCOMPILING)
23+
set(ament_cmake_core_DIR "${DASHING_DIR}/share/ament_cmake_core/cmake")
24+
include (${DASHING_DIR}/share/ament_cmake_core/cmake/ament_cmake_coreConfig.cmake)
25+
include_directories (${SYSROOT_INCDIR})
26+
include_directories (${SYSROOT_INCDIR}/Poco)
27+
include_directories (${DASHING_DIR}/include)
28+
link_directories(${SYSROOT_LIBDIR})
29+
link_directories(${DASHING_DIR}/lib)
30+
else ()
31+
# find dependencies
32+
find_package(ament_cmake REQUIRED)
33+
find_package(rclcpp REQUIRED)
34+
find_package(sensor_msgs REQUIRED)
35+
find_package(geometry_msgs REQUIRED)
36+
endif ()
37+
38+
add_executable(imu-ros2node src/imu_node.cpp)
39+
add_executable(imu-ros2test src/imu_node_test.cpp)
40+
41+
if (CMAKE_CROSSCOMPILING)
42+
set(ROS-DASHING
43+
rclcpp
44+
rcutils
45+
yaml
46+
rcl
47+
rcl_interfaces__rosidl_generator_c
48+
rcl_interfaces__rosidl_typesupport_c
49+
rcl_interfaces__rosidl_typesupport_cpp
50+
rcl_logging_noop
51+
rcl_yaml_param_parser
52+
rosgraph_msgs__rosidl_typesupport_cpp
53+
message_filters
54+
ament_index_cpp
55+
class_loader
56+
rmw
57+
rmw_implementation
58+
rosidl_generator_c
59+
rosidl_typesupport_c
60+
rosidl_typesupport_cpp
61+
std_msgs__rosidl_generator_c
62+
std_msgs__rosidl_typesupport_c
63+
std_msgs__rosidl_typesupport_cpp
64+
sensor_msgs__rosidl_typesupport_cpp
65+
console_bridge
66+
builtin_interfaces__rosidl_generator_c
67+
)
68+
target_link_libraries(imu-ros2node PRIVATE
69+
pthread
70+
imu_client
71+
PocoFoundation
72+
${ROS-DASHING}
73+
)
74+
target_link_libraries(imu-ros2test PRIVATE
75+
imu_client
76+
PocoFoundation
77+
${ROS-DASHING}
78+
)
79+
install(TARGETS imu-ros2node imu-ros2test
80+
RUNTIME DESTINATION ${INSTALL_LIBDIR}/${PROJECT_NAME}
81+
)
82+
else ()
83+
ament_target_dependencies(imu-ros2node
84+
rclcpp
85+
sensor_msgs
86+
geometry_msgs
87+
)
88+
target_link_libraries(imu-ros2node
89+
pthread
90+
imu_client
91+
)
92+
ament_target_dependencies(imu-ros2test
93+
rclcpp
94+
sensor_msgs
95+
geometry_msgs
96+
)
97+
install(TARGETS imu-ros2node imu-ros2test
98+
RUNTIME DESTINATION lib/${PROJECT_NAME}
99+
)
100+
endif()
101+
102+
if (NOT CMAKE_CROSSCOMPILING)
103+
if(BUILD_TESTING)
104+
find_package(ament_lint_auto REQUIRED)
105+
# the following line skips the linter which checks for copyrights
106+
# uncomment the line when a copyright and license is not present in all source files
107+
#set(ament_cmake_copyright_FOUND TRUE)
108+
# the following line skips cpplint (only works in a git repo)
109+
# uncomment the line when this package is not in a git repo
110+
#set(ament_cmake_cpplint_FOUND TRUE)
111+
ament_lint_auto_find_test_dependencies()
112+
endif()
113+
endif()
114+
115+
ament_package()

ROS2-IMU/imu-ros2node/package.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>imu-ros2node</name>
5+
<version>0.1.0</version>
6+
<description>imu ros2node</description>
7+
<maintainer email="penwang@qti.qualcomm.com">Peng Wang</maintainer>
8+
<license>Qualcomm-Technologies-Inc.-Proprietary</license>
9+
10+
<buildtool_depend>ament_cmake</buildtool_depend>
11+
12+
<test_depend>ament_lint_auto</test_depend>
13+
<test_depend>ament_lint_common</test_depend>
14+
15+
<build_depend>rclcpp</build_depend>
16+
<build_depend>sensor_msgs</build_depend>
17+
<build_depend>geometry_msgs</build_depend>
18+
19+
<exec_depend>rclcpp</exec_depend>
20+
<exec_depend>sensor_msgs</exec_depend>
21+
<exec_depend>geometry_msgs</exec_depend>
22+
23+
<export>
24+
<build_type>ament_cmake</build_type>
25+
</export>
26+
</package>

ROS2-IMU/imu-ros2node/readme.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
imu-ros2node is a ROS2 node for publishing IMU sensor data to ROS2 topic.
2+
3+
Development Preparation:
4+
1. Install ROS2 Dashing+. Reference: https://index.ros.org/doc/ros2/Installation/
5+
2. Install colcon: apt install python3-colcon-common-extensions
6+
7+
Create Workspace:
8+
mkdir ~/ros_ws
9+
mv imu-ros2node ~/ros_ws/
10+
11+
Build Code:
12+
cd ~/ros_ws
13+
source /opt/ros/dashing/setup.bash
14+
colcon build
15+
16+
Install:
17+
cd ~/ros_ws
18+
. install/local_setup.sh
19+
20+
Run:
21+
ros2 run imu-ros2node imu-ros2node
22+
23+
Test:
24+
ros2 run imu-ros2node imu-ros2test
25+
# or
26+
ros2 topic echo /imu

0 commit comments

Comments
 (0)