ActionClient

An action client can be used to send goals to an ActionServer. One ActionClient has to have a single type of action but can send multiple goals simultaneously. Process can be tracked using either a goal handle manually or using callbacks.

An ActionClient can be created using the Ros Singleton as follows:

Item {
  // ...
  property var fibonacciClient: Ros.createActionClient("actionlib_tutorials/FibonacciAction", "fibonacci")
  // ...
}

In this example an action client is created using the actionlib_tutorials/FibonacciAction action (it is important to use the complete action type here, not any part like the ActionGoal) using the name fibonacci on which an ActionServer should be registered (You can use the actionlib_tutorials fibonacci_server).

To send a goal, you can use the sendGoal function:

goal_handle = fibonacciClient.sendGoal({ order: numberInput.value }, function (goal_handle) {
  // Do something when the goal transitions, e.g., update the status
  if (goal_handle.commState == ActionCommStates.DONE) {
    // Goal is terminated, we can access the terminalState
    switch (handle.terminalState.state) {
      case ActionTerminalStates.RECALLED:
        // Handle recalled
        break
      case ActionTerminalStates.REJECTED:
        // Handle rejected
        break
      case ActionTerminalStates.PREEMPTED:
        // Handle preempted
        break
      case ActionTerminalStates.ABORTED:
        // Handle aborted
        break
      case ActionTerminalStates.SUCCEEDED:
        // Handle succeeded
        break
      case ActionTerminalStates.LOST:
        // Handle lost
        break
    }
  }
}, function (goal_handle, feedback) {
  // Feedback callback. Called whenever feedback is received from the action server
})

The sendGoal function takes 3 parameters: the goal, a transition callback and a feedback callback. Both callbacks are optional. It returns a GoalHandle which can be used query to state of the goal or to cancel the goal. The goal_handle passed to the callbacks and the one returned are the same.

API

class ActionClient : public QObjectRos

Public Functions

ActionClient(NodeHandle::Ptr nh, const QString &action_type, const QString &name)

True if the ActionClient is connected to the ActionServer, false otherwise.

The type of the action. Example: actionlib_tutorials/FibonacciAction

QObject *sendGoal(const QVariantMap &goal, QJSValue transition_cb = QJSValue(), QJSValue feedback_cb = QJSValue())

Sends a goal to the action server if it is connected.

Parameters
  • goal – The goal that is sent to the action server.

  • transition_cb – A callback that is called on every client state transition.

  • feedback_cb – A callback that is called whenever feedback for this goal is received.

Returns

null if the action server is not connected, otherwise a GoalHandle keeping track of the state of the goal.

void cancelAllGoals()

Cancels all goals that are currently tracked by this client.

void cancelGoalsAtAndBeforeTime(const QDateTime &time)

Cancels all goals that were sent at and before the given ROS time by this client. Use Time.now() to obtain the current ROS time which can differ from the actual time.

Signals

void connectedChanged()

Emitted when the connected status changes, e.g., when the client connected to the server.

class GoalHandle : public QObjectRos

Public Functions

explicit GoalHandle(std::shared_ptr<actionlib::ActionClient<ros_babel_fish::BabelFishAction>> client, const actionlib::ActionClient<ros_babel_fish::BabelFishAction>::GoalHandle &handle)

True if this handle is not tracking a goal, false otherwise.

The terminal state of this goal. Only valid if commstate == ActionCommStates.DONE. The state of this goal’s communication state machine. Possible states: WAITING_FOR_GOAL_ACK, PENDING, ACTIVE, WAITING_FOR_RESULT, WAITING_FOR_CANCEL_ACK, RECALLING, PREEMPTING, DONE

void cancel()

Sends a cancellation request to the ActionServer. Transitions to WAITING_FOR_CANCEL_ACK.

void resend()

Resends this goal with the same id to the ActionServer. Useful if you have reason to think that the goal was lost in transit.

QVariant getResult()

Can be used to obtain the result returned by the ActionServer. Empty if no result received.

class TerminalState

Public Functions

inline TerminalState()

An optional text that was returned by the ActionServer in combination with the terminal state.

The terminal state in form of an ActionTerminalStates enum value: RECALLED, REJECTED, PREEMPTED, ABORTED, SUCCEEDED, LOST