LoginSignup
17
19

More than 5 years have passed since last update.

RosJavaを入れた記録

Posted at

ソース元

Ubuntu 14.04 + indigoでインストールした際のメモ
すでにROSの環境がインストールされている前提。

rosjavaのパッケージをapt-getでインストールする。

sudo apt-get install ros-indigo-rosjava

新しいソースパッケージを作る

この辺はいつもどおり

mkdir -p ~/ros/myjava/src
cd ~/ros/myjava/src
source /opt/ros/indigo/setup.bash
catkin_init_workspace
cd ..
catkin_make

そうすると以下のメッセージみたいなのが出て、~/ros/myjava以下に、build、devel、srcが出来上がる

Base path: /home/ros/ros/myjava
Source space: /home/ros/ros/myjava/src
Build space: /home/ros/ros/myjava/build
Devel space: /home/ros/ros/myjava/devel
Install space: /home/ros/ros/myjava/install
####
#### Running command: "cmake /home/ros/ros/myjava/src -DCATKIN_DEVEL_PREFIX=/home/ros/ros/myjava/devel -DCMAKE_INSTALL_PREFIX=/home/ros/ros/myjava/install -G Unix Makefiles" in "/home/ros/ros/myjava/build"
####
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Using CATKIN_DEVEL_PREFIX: /home/ros/ros/myjava/devel
-- Using CMAKE_PREFIX_PATH: /home/ros/ros/roskotlin/devel;/opt/ros/indigo
-- This workspace overlays: /home/ros/ros/roskotlin/devel;/opt/ros/indigo
-- Found PythonInterp: /usr/bin/python (found version "2.7.6") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/ros/ros/myjava/build/test_results
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.14
-- BUILD_SHARED_LIBS is on
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ros/ros/myjava/build
####
#### Running command: "make -j8 -l8" in "/home/ros/ros/myjava/build"
####

RosJavaのパッケージを作る

javaで言うところのパッケージを作る。さっきのはROSのパッケージ。

cd ~/ros/myjava/src
catkin_create_rosjava_pkg <Package>

部分は好きなパッケージ名。今回はiwatanでやる。
すると以下のようなメッセージが出る。

Created repo file: /home/ros/ros/myjava/src/iwatan/settings.gradle
Created repo file: /home/ros/ros/myjava/src/iwatan/build.gradle
Created repo file: /home/ros/ros/myjava/src/iwatan/CMakeLists.txt
Created repo file: /home/ros/ros/myjava/src/iwatan/package.xml
Creating gradle wrapper: /opt/ros/indigo/lib/python2.7/dist-packages/rosjava_build_tools/gradle/gradlew -p /home/ros/ros/myjava/src/iwatan wrapper
:wrapper

BUILD SUCCESSFUL

Total time: 7.033 secs

また、ビルドしてみる。

cd ~/ros/myjava
catkin_make

そうすると、さきほどのcatkin_makeと違って以下のようなメッセージがでる。

Base path: /home/ros/ros/myjava
Source space: /home/ros/ros/myjava/src
Build space: /home/ros/ros/myjava/build
Devel space: /home/ros/ros/myjava/devel
Install space: /home/ros/ros/myjava/install
####
#### Running command: "cmake /home/ros/ros/myjava/src -DCATKIN_DEVEL_PREFIX=/home/ros/ros/myjava/devel -DCMAKE_INSTALL_PREFIX=/home/ros/ros/myjava/install -G Unix Makefiles" in "/home/ros/ros/myjava/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/ros/ros/myjava/devel
-- Using CMAKE_PREFIX_PATH: /home/ros/ros/roskotlin/devel;/opt/ros/indigo
-- This workspace overlays: /home/ros/ros/roskotlin/devel;/opt/ros/indigo
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/ros/ros/myjava/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.14
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - iwatan
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'iwatan'
-- ==> add_subdirectory(iwatan)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ros/ros/myjava/build
####
#### Running command: "make -j8 -l8" in "/home/ros/ros/myjava/build"
####

実行形式のプロジェクトを作る

パッケージの中に実行できるプロジェクトを作る。

cd ~/ros/myjava/src/iwatan/
catkin_create_rosjava_project sample

sampleという名前でプロジェクトを作る。実効すると以下のようなメッセージが出る。

Creating rosjava project 
  Name      : sample
  File      : build.gradle
  File      : settings.gradle
  File      : Talker.java
  File      : Listener.java
  File      : CMakeLists.txt (gradle task update)

また、おもむろにビルドする

cd ~/ros/myjava
catkin_make

先ほどのメッセージと同様なメッセージが出るが、最後にちょっと違うメッセージが出てくる。gradleが動いてるみたい。

Base path: /home/ros/ros/myjava
# ... 先ほどと同じなので省略
#### Running command: "make -j8 -l8" in "/home/ros/ros/myjava/build"
####
Scanning dependencies of target gradle-iwatan
[100%] Gradling tasks for iwatan
Uploading: com/github/rosjava/iwatan/sample/0.1.0/sample-0.1.0.jar to repository remote at file:/home/ros/ros/myjava/devel/share/maven
Transferring 4K from remote
Uploaded 4K
[100%] Built target gradle-iwatan

実行する

これでRosJavaでパッケージのビルドができてるみたいなので、実行してみる

まずはいつもどおりにroscoreを起動。チュートリアルではワンライナーで動かしてる。

roscore

別のコンソールで、Talkerを起動する。

cd ~/ros/myjava/src/iwatan/sample/build/install/sample/bin
./sample com.githurosjava.iwatan.sample.Talker

更に別のコンソールで、Listenerを起動する。

cd ~/ros/myjava/src/iwatan/sample/build/install/sample/bin
./sample com.github.rosja.iwatan.sample.Listener

メッセージがちゃんと出てくる

Aug 08, 2015 11:31:26 PM org.ros.internal.node.RosoutLogger info
INFO: I heard: "Hello world! 252"
Aug 08, 2015 11:31:27 PM org.ros.internal.node.RosoutLogger info
INFO: I heard: "Hello world! 253"
Aug 08, 2015 11:31:28 PM org.ros.internal.node.RosoutLogger info
INFO: I heard: "Hello world! 254"

これで、rqt_graphで確認するとちゃんとトピックのやりとりができてるのが確認出来る。

スクリーンショット 2015-08-08 23.30.29.png

まとめ

やることとしては、

  1. rosのパッケージを作る
  2. rosjavaのパッケージを作る
  3. rosjavaのプロジェクトを作る
  4. ビルドする

をすればとりあえずは作れる。

実行時にパッケージ名を指定する必要があるが、デフォルトだとcom.github.rosjava..<プロジェクト名>となる。
多分、ソースのパッケージ名を変えればオリジナルのに変えられると思うので試してみる

17
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
19