-
[Android] ROS2 for Android 빌드 방법ROS 2022. 4. 3. 09:11
* 환경 : Ubuntu 20.04
* ROS2 설치 버전: foxy1. ROS2 설치
1) Locale 설정
sudo apt update && sudo apt install locales sudo locale-gen en_US en_US.UTF-8 sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 export LANG=en_US.UTF-8
2) ROS2 Repository 추가
sudo apt update && sudo apt install curl gnupg2 lsb-release curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add - sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'
3) ROS2 패키지 설치
sudo apt update sudo apt install ros-foxy-desktop
4) ROS2 실행
source /opt/ros/foxy/setup.bash
// ~/.bashrc에 등록하려면 아래 명령어 입력
echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc
5) ROS2 테스트
2개의 터미널을 열어서 각 터미널에서 아래 명령어를 실행하여 정상적으로 메세지가 송/수신 되는지 확인합니다.
// 터미널1
ros2 run demo_nodes_cpp talker
// 터미널2
ros2 run demo_nodes_py listener
2. Java & SDK 설치
sudo apt install default-jdk
3. Gradle 설치 (Gradle 3.2 이상)
sudo apt install gradle
4. Build Tool 설치
sudo apt install curl python3-colcon-common-extensions python3-pip python3-vcstool
5. Gradle extensions for colcon 설치
python3 -m pip install -U git+https://github.com/colcon/colcon-gradle python3 -m pip install --no-deps -U git+https://github.com/colcon/colcon-ros-gradle
6.
Download and Build ROS 2 Java for Android1) Android NDK 다운로드 및 설정
- Android NDK 다운로드 : https://developer.android.com/ndk/downloads/index.html
- 압축 풀기 후, 해당 경로 ANDROID_NDK 로 저장ANDROID_NDK=~/Android/Ndk
2) Android SDK 다운로드 및 설정
- Android SDK 다운로드 : https://developer.android.com/studio/#downloads
- 압축 풀기 후, 해당 경로 ANDROID_HOME 로 저장ANDROID_HOME=~/Android/Sdk
3) Clone ROS2, ROS2 Java source code
mkdir -p $HOME/ros2_android_ws/src cd $HOME/ros2_android_ws curl https://raw.githubusercontent.com/ros2-java/ros2_java/main/ros2_java_android.repos | vcs import src
4) Android Build Configuation 설정
export PYTHON3_EXEC="$( which python3 )" export PYTHON3_LIBRARY="$( ${PYTHON3_EXEC} -c 'import os.path; from distutils import sysconfig; print(os.path.realpath(os.path.join(sysconfig.get_config_var("LIBPL"), sysconfig.get_config_var("LDLIBRARY"))))' )" export PYTHON3_INCLUDE_DIR="$( ${PYTHON3_EXEC} -c 'from distutils import sysconfig; print(sysconfig.get_config_var("INCLUDEPY"))' )" export ANDROID_ABI=armeabi-v7a export ANDROID_NATIVE_API_LEVEL=android-21 export ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-clang
5) Build
colcon build \ --packages-ignore cyclonedds rcl_logging_log4cxx rosidl_generator_py \ --packages-up-to rcljava \ --cmake-args \ -DPYTHON_EXECUTABLE=${PYTHON3_EXEC} \ -DPYTHON_LIBRARY=${PYTHON3_LIBRARY} \ -DPYTHON_INCLUDE_DIR=${PYTHON3_INCLUDE_DIR} \ -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \ -DANDROID_FUNCTION_LEVEL_LINKING=OFF \ -DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_API_LEVEL} \ -DANDROID_TOOLCHAIN_NAME=${ANDROID_TOOLCHAIN_NAME} \ -DANDROID_STL=c++_shared \ -DANDROID_ABI=${ANDROID_ABI} \ -DANDROID_NDK=${ANDROID_NDK} \ -DTHIRDPARTY=ON \ -DCOMPILE_EXAMPLES=OFF \ -DCMAKE_FIND_ROOT_PATH="${PWD}/install"
[출처]
https://omorobot.gitbook.io/manual/product/omo-r1mini/ros/ros2-foxy/ros2-ubuntu-20.04https://github.com/ros2-java/ros2_java
https://github.com/ros2-java/ros2_android_examples