Function rcl_action_accept_new_goal

Function Documentation

rcl_action_goal_handle_t *rcl_action_accept_new_goal(rcl_action_server_t *action_server, const rcl_action_goal_info_t *goal_info)

Accept a new goal using an action server.

This is a non-blocking call.

Creates and returns a new goal handle. The action server starts tracking it internally. If a failure occurs, NULL is returned and an error message is set. Possible reasons for failure:

  • action server is invalid

  • goal info is invalid

  • goal ID is already being tracked by the action server

  • memory allocation failure

This function should be called after receiving a new goal request with rcl_action_take_goal_request() and before sending a response with rcl_action_send_goal_response().

After calling this function, the action server will start tracking the goal. The pointer to the goal handle becomes invalid after rcl_action_server_fini() is called. The caller becomes responsible for finalizing the goal handle later.

Example usage:

#include <rcl/rcl_action.h>

// ... init an action server
// Take a goal request (client library type)
rcl_ret_t ret = rcl_action_take_goal_request(&action_server, &goal_request);
// ... error handling
// If the goal is accepted, then tell the action server
// First, create a goal info message
rcl_action_goal_info_t goal_info = rcl_action_get_zero_initialized_goal_info();
// ... populate goal_info.uuid (unique_identifier_msgs/UUID)
// ... populate goal_info.stamp (builtin_interfaces/Time)
rcl_action_goal_handle_t * goal_handle = rcl_action_accept_new_goal(&action_server, &goal_info);
// ... error_handling
// ... Populate goal response (client library type)
ret = rcl_action_send_goal_response(&action_server, &goal_response);
// ... error handling, and sometime before shutdown finalize goal info message
ret = rcl_action_goal_info_fini(&goal_info, &action_server);

Attribute

Adherence

Allocates Memory

Yes

Thread-Safe

No

Uses Atomics

No

Lock-Free

Yes

Parameters:
  • action_server[in] handle to the action server that is accepting the goal

  • goal_info[in] a message containing info about the goal being accepted

Returns:

a pointer to a new goal handle representing the accepted goal, or

Returns:

NULL if a failure occured.