@@ -36,6 +36,10 @@ extern "C"
3636
3737#include "rmw/rmw.h"
3838
39+ extern rcl_ret_t
40+ rcl_action_goal_handle_set_goal_terminal_timestamp (
41+ const rcl_action_goal_handle_t * goal_handle ,
42+ rcl_time_point_value_t timestamp );
3943
4044rcl_action_server_t
4145rcl_action_get_zero_initialized_server (void )
@@ -451,13 +455,17 @@ _recalculate_expire_timer(
451455 if (!rcl_action_goal_handle_is_active (goal_handle )) {
452456 ++ num_inactive_goals ;
453457
454- rcl_action_goal_info_t goal_info ;
455- ret = rcl_action_goal_handle_get_info (goal_handle , & goal_info );
458+ rcl_time_point_value_t goal_terminal_timestamp ;
459+ ret = rcl_action_goal_handle_get_goal_terminal_timestamp (
460+ goal_handle , & goal_terminal_timestamp );
461+ if (RCL_ACTION_RET_NOT_TERMINATED_YET == ret ) {
462+ continue ;
463+ }
456464 if (RCL_RET_OK != ret ) {
457465 return RCL_RET_ERROR ;
458466 }
459467
460- int64_t delta = timeout - (current_time - _goal_info_stamp_to_nanosec ( & goal_info ) );
468+ int64_t delta = timeout - (current_time - goal_terminal_timestamp );
461469 if (delta < minimum_period ) {
462470 minimum_period = delta ;
463471 }
@@ -623,8 +631,7 @@ rcl_action_expire_goals(
623631 rcl_ret_t ret_final = RCL_RET_OK ;
624632 const int64_t timeout = (int64_t )action_server -> impl -> options .result_timeout .nanoseconds ;
625633 rcl_action_goal_handle_t * goal_handle ;
626- rcl_action_goal_info_t goal_info ;
627- int64_t goal_time ;
634+ rcl_time_point_value_t goal_terminal_timestamp ;
628635 size_t num_goal_handles = action_server -> impl -> num_goal_handles ;
629636 for (size_t i = 0u ; i < num_goal_handles ; ++ i ) {
630637 if (output_expired && num_goals_expired >= expired_goals_capacity ) {
@@ -636,17 +643,26 @@ rcl_action_expire_goals(
636643 if (rcl_action_goal_handle_is_active (goal_handle )) {
637644 continue ;
638645 }
639- rcl_action_goal_info_t * info_ptr = & goal_info ;
646+
647+ // Retrieve the information of expired goals for output
640648 if (output_expired ) {
641- info_ptr = & (expired_goals [num_goals_expired ]);
649+ ret = rcl_action_goal_handle_get_info (goal_handle , & (expired_goals [num_goals_expired ]));
650+ if (RCL_RET_OK != ret ) {
651+ ret_final = RCL_RET_ERROR ;
652+ continue ;
653+ }
654+ }
655+
656+ ret = rcl_action_goal_handle_get_goal_terminal_timestamp (goal_handle , & goal_terminal_timestamp );
657+ if (RCL_ACTION_RET_NOT_TERMINATED_YET == ret ) {
658+ continue ;
642659 }
643- ret = rcl_action_goal_handle_get_info (goal_handle , info_ptr );
644660 if (RCL_RET_OK != ret ) {
645661 ret_final = RCL_RET_ERROR ;
646662 continue ;
647663 }
648- goal_time = _goal_info_stamp_to_nanosec ( info_ptr );
649- if ((current_time - goal_time ) > timeout ) {
664+
665+ if ((current_time - goal_terminal_timestamp ) > timeout ) {
650666 // Deallocate space used to store pointer to goal handle
651667 allocator .deallocate (action_server -> impl -> goal_handles [i ], allocator .state );
652668 action_server -> impl -> goal_handles [i ] = NULL ;
@@ -706,6 +722,34 @@ rcl_action_notify_goal_done(
706722 if (!rcl_action_server_is_valid (action_server )) {
707723 return RCL_RET_ACTION_SERVER_INVALID ;
708724 }
725+
726+ // Get current time (nanosec)
727+ int64_t current_time ;
728+ rcl_ret_t ret = rcl_clock_get_now (action_server -> impl -> clock , & current_time );
729+ if (RCL_RET_OK != ret ) {
730+ return RCL_RET_ERROR ;
731+ }
732+
733+ // Set current time to goal_terminal_timestamp of goal which has reached terminal state
734+ for (size_t i = 0 ; i < action_server -> impl -> num_goal_handles ; ++ i ) {
735+ rcl_action_goal_handle_t * goal_handle = action_server -> impl -> goal_handles [i ];
736+ if (!rcl_action_goal_handle_is_active (goal_handle )) {
737+ rcl_time_point_value_t goal_terminal_timestamp ;
738+ rcl_ret_t ret = rcl_action_goal_handle_get_goal_terminal_timestamp (
739+ goal_handle , & goal_terminal_timestamp );
740+ if (RCL_ACTION_RET_NOT_TERMINATED_YET == ret ) {
741+ ret = rcl_action_goal_handle_set_goal_terminal_timestamp (goal_handle , current_time );
742+ if (RCL_RET_OK != ret ) {
743+ return RCL_RET_ERROR ;
744+ }
745+ continue ;
746+ }
747+ if (RCL_RET_OK != ret ) {
748+ return RCL_RET_ERROR ;
749+ }
750+ }
751+ }
752+
709753 return _recalculate_expire_timer (
710754 & action_server -> impl -> expire_timer ,
711755 action_server -> impl -> options .result_timeout .nanoseconds ,
0 commit comments