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
- 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.
- SubscrberNotComposable. An old-style subscriber, resembling the ROS1 API.
- SubscriberLambda. A composable subscriber that uses a lambda function to process
std_msgs.msg.String
messages. - SubscriberMemberFunction. A composable subscriber that uses a member function to process
std_msgs.msg.String
messages.
- 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 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.