UNPKG

roslib

Version:

The standard ROS Javascript Library

83 lines (82 loc) 2.97 kB
import { default as Ros } from './Ros.ts'; /** * A ROS 2 action client. */ export default class Action<TGoal = unknown, TFeedback = unknown, TResult = unknown> { #private; isAdvertised: boolean; ros: Ros; name: string; actionType: string; /** * @param options * @param options.ros - The ROSLIB.Ros connection handle. * @param options.name - The action name, like '/fibonacci'. * @param options.actionType - The action type, like 'example_interfaces/Fibonacci'. */ constructor({ ros, name, actionType, }: { ros: Ros; name: string; actionType: string; }); /** * Sends an action goal. Returns the feedback in the feedback callback while the action is running * and the result in the result callback when the action is completed. * Does nothing if this action is currently advertised. * * @param goal - The action goal to send. * @param resultCallback - The callback function when the action is completed. * @param [feedbackCallback] - The callback function when the action publishes feedback. * @param [failedCallback] - The callback function when the action failed. */ sendGoal(goal: TGoal, resultCallback: (result: TResult) => void, feedbackCallback?: (feedback: TFeedback) => void, failedCallback?: (error: string) => void): string | undefined; /** * Cancels an action goal. * * @param id - The ID of the action goal to cancel. */ cancelGoal(id: string): void; /** * Cancels all action goals. */ cancelAllGoals(): void; /** * Advertise the action. This turns the Action object from a client * into a server. The callback will be called with every goal sent to this action. * * @param actionCallback - This works similarly to the callback for a C++ action. * @param cancelCallback - A callback function to execute when the action is canceled. */ advertise(actionCallback: (goal: TGoal, id: string) => void, cancelCallback: (id: string) => void): void; /** * Unadvertise a previously advertised action. */ unadvertise(): void; /** * Helper function to send action feedback inside an action handler. * * @param id - The action goal ID. * @param feedback - The feedback to send. */ sendFeedback(id: string, feedback: TFeedback): void; /** * Helper function to set an action as succeeded. * * @param id - The action goal ID. * @param result - The result to set. */ setSucceeded(id: string, result: TResult): void; /** * Helper function to set an action as canceled. * * @param id - The action goal ID. * @param result - The result to set. */ setCanceled(id: string, result: TResult): void; /** * Helper function to set an action as failed. * * @param id - The action goal ID. */ setFailed(id: string): void; }