Quick Start
CONTENT

Overview

ROS Actions are defined in action/*.action files. For each action ROS requires to have 3 separate messages: Goal, Feedback, Result (see ROS documentation for defining action in ROS2 or ROS1). On top of that ROS will create for each such message an Action message where the original message (Goal, Feedback, Result) + action metadata is stored (goal id, status, etc.).

In order to work with ROS actions from jrosactionlib users need to:

  1. Provide a mapping from ROS *.action file to corresponding jrosactionlib action definition class. Definition class is described by the interfaces: Action2Definition for ROS2 action files, Action1Definition for ROS1 action files.
  2. Define all message classes which are part of action definition class defined above (see jrosclient Defining messages guide).

To simplify this process users are encouraged to use msgmonster application.

Examples

Fibonacci action

In this example we are going to execute actions in Fibonacci action server using Java.

Before moving further we need to create and run Fibonacci action server based on instructions from ROS documentation:

Creating action definition

ROS action file Fibonacci.action looks something like this:

int32 order
---
int32[] sequence
---
int32[] partial_sequence

We need to map it to corresponding jrosactionlib action definitions. Use final results of these definitions for ROS2 or ROS1

Executing actions

Once we have Fibonacci action definitions are ready we can use them to execute actions on Fibonacci action server.

ROS2

Required Java dependencies:

Code:

var clientFactory = new JRos2ClientFactory();
var actionClientFactory = new JRos2ActionClientFactory();
try (var client = clientFactory.createClient();
        var actionClient = actionClientFactory
            .createClient(client, new FibonacciActionDefinition(), "fibonacci")) {
    var goal = new FibonacciGoalMessage().withOrder(new Int32Message().withData(13));
    var result = actionClient.sendGoalAsync(goal).get();
    System.out.println(result);
}

ROS1

Required Java dependencies:

var clientFactory = new JRos1ClientFactory();
var actionClientFactory = new JRos1ActionClientFactory();
try (var client = clientFactory.createClient("http://127.0.0.1:11311/");
       var actionClient = actionClientFactory
           .createClient(client, new FibonacciActionDefinition(), "fibonacci")) {
    var goal = new FibonacciGoalMessage().withOrder(new Int32Message().withData(5));
    var result = actionClient.sendGoalAsync(goal).get();
    System.out.println(result);
}
Free Web Hosting