Skip to content

ros2-java/ros2_java_examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ROS2 Java examples

This is a collection of examples that use the Java bindings for ROS2. They aim to mimic the rclcpp examples, but using the ROS2 Java bindings. Please follow the instructions on https://github.com/esteve/ros2_java/blob/master/README.md#desktop to build the ROS2 Java bindings, you can try out any of the following examples via the ros2 command line tool:

. ~/ament_ws/install_isolated/local_setup.sh
. ~/ros2_java_ws/install_isolated/local_setup.sh
ros2 run PACKAGE_NAME SCRIPT_NAME

For example, to run the PublisherLambda and SubscriberLambda examples, open two terminals and type this on one of them to run the subscriber example:

. ~/ament_ws/install_isolated/local_setup.sh
. ~/ros2_java_ws/install_isolated/local_setup.sh
ros2 run rcljava_examples subscriber_lambda

and the following to run the publisher examples on the other terminal:

. ~/ament_ws/install_isolated/local_setup.sh
. ~/ros2_java_ws/install_isolated/local_setup.sh
ros2 run rcljava_examples publisher_lambda

you should now see a bunch of messages showing up on the first terminal. A list of all the scripts that can be run can be found in https://github.com/esteve/ros2_java_examples/blob/master/rcljava_examples/build.gradle#L28-L46

Alternatively, you can also run the examples by invoking the java command and the fully-qualified name of the class you wan to run. For example, type the following for running the SubscriberLambda example:

. ~/ros2_java_ws/install_isolated/local_setup.sh
java org.ros2.rcljava.examples.subscriber.SubscriberLambda

and this for the PublisherLambda example:

. ~/ros2_java_ws/install_isolated/local_setup.sh
java org.ros2.rcljava.examples.publisher.PublisherLambda

Publisher

  • PublisherNotComposable. An old-style publisher, resembling the ROS1 API.
  • PublisherLambda. A composable publisher that uses a lambda function and a timer to publish std_msgs.msg.String messages.
  • PublisherMemberFunction. A composable publisher that uses a member function and a timer to publish std_msgs.msg.String messages.

Subscriber

Composition

  • PublisherNode. A composable publisher node that can be reused standalone or as part of a multi-node program.
  • SubscriberNode. A composable subscriber node that can be reused standalone or as part of a multi-node program.
  • Composed. A multi-node program that runs both a SubscriberNode and a PublisherNode.

Timer

  • TimerLambda. A timer that calls a lambda function to print out a message to the console repeatedly.
  • TimerMemberFunction. A timer that calls a member function to print out a message to the console repeatedly.

Service

Client

About

Example Java applications for the ROS2 Java bindings

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages