diff --git a/packages/roslib/src/core/Ros.ts b/packages/roslib/src/core/Ros.ts index 9c993cb87..1ca49726a 100644 --- a/packages/roslib/src/core/Ros.ts +++ b/packages/roslib/src/core/Ros.ts @@ -633,6 +633,103 @@ export default class Ros extends EventEmitter< ); } + /** + * Retrieve the details of a ROS action goal interface. + * + * @param type - The type of the action. + * @param callback - Function with the following params: + * @param [failedCallback] - The callback function when the service call failed with params: + */ + public getActionGoalDetails( + type: string, + callback: (typedefs: rosapi.TypeDef[]) => void, + failedCallback: (error: string) => void = console.error, + ) { + this.callActionInterfaceDetails< + rosapi.ActionGoalDetailsRequest, + rosapi.ActionGoalDetailsResponse + >( + "rosapi/action_goal_details", + "rosapi/ActionGoalDetails", + { type }, + (result) => { + callback(result.typedefs); + }, + failedCallback, + ); + } + + /** + * Retrieve the details of a ROS action result interface. + * + * @param type - The type of the action. + * @param callback - Function with the following params: + * @param [failedCallback] - The callback function when the service call failed with params: + */ + public getActionResultDetails( + type: string, + callback: (typedefs: rosapi.TypeDef[]) => void, + failedCallback: (error: string) => void = console.error, + ) { + this.callActionInterfaceDetails< + rosapi.ActionResultDetailsRequest, + rosapi.ActionResultDetailsResponse + >( + "rosapi/action_result_details", + "rosapi/ActionResultDetails", + { type }, + (result) => { + callback(result.typedefs); + }, + failedCallback, + ); + } + + /** + * Retrieve the details of a ROS action feedback interface. + * + * @param type - The type of the action. + * @param callback - Function with the following params: + * @param [failedCallback] - The callback function when the service call failed with params: + */ + public getActionFeedbackDetails( + type: string, + callback: (typedefs: rosapi.TypeDef[]) => void, + failedCallback: (error: string) => void = console.error, + ) { + this.callActionInterfaceDetails< + rosapi.ActionFeedbackDetailsRequest, + rosapi.ActionFeedbackDetailsResponse + >( + "rosapi/action_feedback_details", + "rosapi/ActionFeedbackDetails", + { type }, + (result) => { + callback(result.typedefs); + }, + failedCallback, + ); + } + + private callActionInterfaceDetails< + TReq extends { type: string }, + TRes extends { typedefs: rosapi.TypeDef[] }, + >( + srv: string, + srvType: string, + request: TReq, + callback: (result: TRes) => void, + failedCallback: (error: string) => void, + ): Service { + const client = new Service({ + ros: this, + name: srv, + serviceType: srvType, + }); + client.callService(request, callback, failedCallback); + return client; + } + /** * Decode a typedef array into a dictionary like `rosmsg show foo/bar`. * diff --git a/packages/roslib/src/types/rosapi.ts b/packages/roslib/src/types/rosapi.ts index a46ab4f90..b407a0744 100644 --- a/packages/roslib/src/types/rosapi.ts +++ b/packages/roslib/src/types/rosapi.ts @@ -145,4 +145,22 @@ export namespace rosapi { types: string[]; typedefs_full_text: string[]; } + export interface ActionGoalDetailsRequest { + type: string; + } + export interface ActionGoalDetailsResponse { + typedefs: TypeDef[]; + } + export interface ActionResultDetailsRequest { + type: string; + } + export interface ActionResultDetailsResponse { + typedefs: TypeDef[]; + } + export interface ActionFeedbackDetailsRequest { + type: string; + } + export interface ActionFeedbackDetailsResponse { + typedefs: TypeDef[]; + } }