Git Product home page Git Product logo

ros2_java's Introduction

ROS 2 Java client library

Build status

Target Status
ROS Galactic - Ubuntu Focal (OpenJDK) Build Status

Introduction

This is a set of projects (bindings, code generator, examples and more) that enables developers to write ROS 2 applications for the JVM and Android.

Besides this repository itself, there's also:

Is this Java only?

No, any language that targets the JVM can be used to write ROS 2 applications.

Including Android?

Yep! Make sure to use Fast-RTPS as your DDS vendor and at least this revision.

Features

The current set of features include:

  • Generation of all builtin and complex ROS types, including arrays, strings, nested types, constants, etc.
  • Support for publishers and subscriptions
  • Tunable Quality of Service (e.g. lossy networks, reliable delivery, etc.)
  • Clients and services
  • Timers
  • Composition (i.e. more than one node per process)
  • Time handling (system and steady, ROS time not yet supported ros2-java#122)
  • Support for Android
  • Parameters services and clients (both asynchronous and synchronous)

Sounds great, how can I try this out?

Install dependencies

Note: While the following instructions use a Linux shell the same can be done on other platforms like Windows with slightly adjusted commands.

  1. Install ROS 2.

  2. Install Java and a JDK.

    On Ubuntu, you can install OpenJDK with:

     sudo apt install default-jdk
    
  3. Install Gradle. Make sure you have Gradle 3.2 (or later) installed.

    Ubuntu Bionic or later

     sudo apt install gradle
    

    macOS

     brew install gradle
    

    Note: if run into compatibily issues between gradle 3.x and Java 9, try using Java 8,

     brew tap caskroom/versions
     brew cask install java8
     export JAVA_HOME=/Library/Java/JavaVirtualMachines/1.8.0.jdk/Contents/Home
    

    Windows

     choco install gradle
    
  4. Install build tools:

     sudo apt install curl python3-colcon-common-extensions python3-pip python3-vcstool
    
  5. Install 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
    

Download and Build ROS 2 Java for Desktop

  1. Source your ROS 2 installation, for example:

     source /opt/ros/galactic/setup.bash
    
  2. Download the ROS 2 Java repositories into a workspace:

     mkdir -p ros2_java_ws/src
     cd ros2_java_ws
     curl -skL https://raw.githubusercontent.com/ros2-java/ros2_java/main/ros2_java_desktop.repos | vcs import src
    
  3. Linux only Install ROS dependencies:

     rosdep install --from-paths src -y -i --skip-keys "ament_tools"
    
  4. Build desktop packages:

     colcon build --symlink-install
    

    Note, on Windows we have to use --merge-install

     colcon build --merge-install
    

Download and Build ROS 2 Java for Android

The Android setup is slightly more complex, you'll need the SDK and NDK installed, and an Android device where you can run the examples.

Make sure to download at least the SDK for Android Lollipop (or greater), the examples require the API level 21 at least and NDK 14.

You may download the Android NDK from the official website, let's assume you've downloaded 16b (the latest stable version as of 2018-04-28) and you unpack it to ~/android_ndk

We'll also need to have the Android SDK installed, for example, in ~/android_sdk and set the ANDROID_HOME environment variable pointing to it.

Although the ros2_java_android.repos file contains all the repositories for the Android bindings to compile, we'll have to disable certain packages (python_cmake_module, rosidl_generator_py, test_msgs) that are included the repositories and that we either don't need or can't cross-compile properly (e.g. the Python generator)

  1. Download the Android NDK and set the environment variable ANDROID_NDK to the path where it is extracted.

  2. Download the Android SDK and set the environment variable ANDROID_HOME to the path where it is extracted.

  3. Clone ROS 2 and ROS 2 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. Set Android build configuration:

     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 (skipping packages that we don't need or can't cross-compile):

     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"
    

You can find more information about the Android examples at https://github.com/ros2-java/ros2_android_examples

Contributing

Contributions are more than welcome! If you'd like to contribute to the project, please read CONTRIBUTING for contributing guidelines.

ros2_java's People

Contributors

esteve avatar ivanpauno avatar jacobperron avatar sung-goo-kim avatar nielstiben avatar clalancette avatar mhubii avatar azure-pipelines[bot] avatar jayhou avatar konczg avatar pluris avatar qh-huang avatar talregev avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.