Ask Your Question
0

Using custom messages and service in ROSJAVA

asked 2013-12-28 07:53:27 -0600

updated 2014-01-02 05:40:34 -0600

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:-

  1. 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 ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-01-01 20:08:50 -0600

Daniel Stonier gravatar image

1) myjava_pkgs/pub_sub is a sibling project of myjava_pkgs/foo. pub_sub itself shouldn't need much of an update after running catkin_create_rosjava_project pub_sub but the key part if you want to use your foo artifact is listing it as a dependency. That appears to be missing in your build.gradle where the only dependency you have listed is rosjava_core: dependencies { compile 'org.ros.rosjava_core:rosjava:[0.1,)' } There are two kinds of dependencies - that one for rosjava_core is an external dependency, but since foo here is a sibling project then it needs to be expressed as an internal dependency, e.g.:

dependencies { compile 'org.ros.rosjava_core:rosjava:[0.1,)' compile project(':foo') }

otherwise foo imports will never get very far.

2) It should never actually try to pull rosjava_test_msgs in any shape or form. Maybe it's something stray in your setup, or something in the build - I'd need to test. Anyway, try and fix 1) and see if you still have a problem here.

3) These scripts are driven by the code and templates at https://github.com/rosjava/rosjava_build_tools/tree/hydro/src/rosjava_build_tools. You can play around with them locally by putting a hydro fork of that repo in your source workspace, or just directly editing files in /opt/ros/hydro/lib/python2.7/dist-packages/rosjava_build_tools. Send me a pull request if you make anything useful!

edit flag offensive delete link more

Comments

Thnx a lot 4 d sol, now I am able to compile, and able to run server with my custom written service (didn't check client so far), However, I am still not able to use my custom message 'foo' in Talker.java. When I try to set a string to object of foo, I get a type cast error. I have updated d Q.

aknirala gravatar image aknirala  ( 2014-01-02 05:28:19 -0600 )edit

Provide it a std_msgs/String object instead of a java string?

Daniel Stonier gravatar image Daniel Stonier  ( 2014-01-13 13:51:52 -0600 )edit

How would I do this?

Rabe gravatar image Rabe  ( 2014-05-14 05:12:14 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-12-28 07:53:27 -0600

Seen: 2,101 times

Last updated: Jan 02 '14