Using custom messages and service in ROSJAVA
Hi,
I have been trying to understand ROSJAVA from a while, seems a bit difficult as I couldn't find good tutorials (last week tutorials for Hydro were updated which was v v helpful (many many thanks for that), though they are not sufficient :-( ).
I am using Ubuntu 12.04 and Hydro.
I manage to run ROSJAVA Publishers and subscribers as directed at: http://rosjava.github.io/rosjava_core/latest/getting_started.html
I was able to run Talker from java end and listen it from C++ end, however I am still struggling to find out, how can I use my custom message. Here is my directory structure
~/catkin_ws (catkin workspace, in setup.sh I am doing source ~/catkin_ws/devel/setup.bash) ~/catkin_ws/src/foo_msgs/msg/foo.msg (contains std_msgs/String data) ~/catkin_ws/src/foo_msgs/srv/AddTwoInts.srv (for checking service, to be checked once I manage to run cutsom messgaes) ~/catkin_ws/src/foo_msgs/CMakeLists.txt (contains entries to generate message as directed at : http://wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv) ~/catkin_ws/src/foo_msgs/package.xml ~/catkin_ws/src/myjava_pkgs (ROSJAVA package, created using : catkin_create_rosjava_pkg myjava_pkgs rosjava_bootstrap rosjava_messages foo_msgs) ~/catkin_ws/src/myjava_pkgs/foo_msgs (cretaed by : catkin_create_rosjava_msg_project foo_msgs as given at : http://wiki.ros.org/rosjava/Tutorials/hydro/Unofficial%20Messages) ~/catkin_ws/src/myjava_pkgs/pub_sub (using: catkin_create_rosjava_project pub_sub, as given at: http://wiki.ros.org/rosjava_build_tools/Tutorials/hydro/Creating%20Rosjava%20Packages This automatically created : ~/catkin_ws/src/myjava_pkgs/pub_sub/src/main/java/com/github/rosjava/pub_sub/Dude.java)
Then I created Talker.java and Listener.java in:-
~/catkin_ws/src/myjava_pkgs/pub_sub/src/main/java/org/ros/rosjava_tutorial_pubsub/
as given at: http://rosjava.github.io/rosjava_core/latest/getting_started.html
settings.gradle at ~/catkin_ws/src/myjava_pkgs contains:-
include 'foo_msgs' include 'pub_sub'
I updated ~/catkin_ws/src/myjava_pkgs/pub_sub/build.gradle seeing http://wiki.ros.org/rosjava_core/graveyard/rosjava_tutorial_pubsub The exact content of build.gradle is:-
apply plugin: 'application' mainClassName = 'org.ros.RosRun' apply plugin: 'java' apply plugin: 'maven' apply plugin: 'eclipse' // uncomment to create an eclipse project using 'gradle eclipse' //apply plugin: 'eclipse' sourceCompatibility = 1.6 targetCompatibility = 1.6 // custom maven repository for some rosjava dependencies repositories { mavenLocal() maven { url 'http://robotbrains.hideho.org/nexus/content/groups/ros-public' } } // we need this for maven installation version = '0.0.0-SNAPSHOT' group = 'ros.my_stack' dependencies { compile 'org.ros.rosjava_core:rosjava:[0.1,)' }
Now, I am able to compile it from: /catkin_ws/src/myjava_pkgs/pub_sub$ using: ../gradlew installApp
and able to run Talker using: ./build/install/pub_sub/bin/pub_sub org.ros.rosjava_tutorial_pubsub.Talker
My questions are:-
- How can I use my custom message, which is in foo.msg?
On compiling I can see that header files for foo.msg and service are generated at:
/home/aknirala/catkin_ws/devel/include/foo_msgs and java files are generated at:-
/home/aknirala/catkin_ws/src/myjava_pkgs/foo_msgs/build/generated-src/foo_msgs
But how w=can I include it? If I include the line:-import foo_msgs.foo;
I get compilation error as:-/home/aknirala/catkin_ws/src/myjava_pkgs/pub_sub/src/main/java/org/ros/rosjava_tutorial_pubsub/Talker.java:10: package foo_msgs does ...