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_NAMEFor 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_lambdaand 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_lambdayou 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.SubscriberLambdaand this for the PublisherLambda example:
. ~/ros2_java_ws/install_isolated/local_setup.sh
java org.ros2.rcljava.examples.publisher.PublisherLambda- 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.Stringmessages. - PublisherMemberFunction. A composable publisher that uses a member function and a timer to publish
std_msgs.msg.Stringmessages.
- SubscrberNotComposable. An old-style subscriber, resembling the ROS1 API.
- SubscriberLambda. A composable subscriber that uses a lambda function to process
std_msgs.msg.Stringmessages. - SubscriberMemberFunction. A composable subscriber that uses a member function to process
std_msgs.msg.Stringmessages.
- 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
SubscriberNodeand aPublisherNode.
- 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.
- AddTwoIntsService. A service that will return the sum of two integers.
- AddTwoIntsClient. A client that will submit a request to the AddTwoIntsService to sum two integers.