From bcabfa595ebdf78111acebeb5863c68ad0c85b16 Mon Sep 17 00:00:00 2001 From: Siddharth Kucheria Date: Tue, 21 May 2019 11:31:50 -0700 Subject: [PATCH] user friendly error messages for invalid transitions --- rcl_action/include/rcl_action/goal_handle.h | 4 ++++ rcl_action/include/rcl_action/types.h | 1 + rcl_action/src/rcl_action/goal_handle.c | 13 ++++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/rcl_action/include/rcl_action/goal_handle.h b/rcl_action/include/rcl_action/goal_handle.h index c1410a4c60..c1c2e8e56a 100644 --- a/rcl_action/include/rcl_action/goal_handle.h +++ b/rcl_action/include/rcl_action/goal_handle.h @@ -29,6 +29,10 @@ extern "C" /// Internal rcl action goal implementation struct. struct rcl_action_goal_handle_impl_t; +/// User friendly error messages for invalid trasntions +extern const char * goal_state_descriptions[]; +extern const char * goal_event_descriptions[]; + /// Goal handle for an action. typedef struct rcl_action_goal_handle_t { diff --git a/rcl_action/include/rcl_action/types.h b/rcl_action/include/rcl_action/types.h index 783165b4c5..3d69972202 100644 --- a/rcl_action/include/rcl_action/types.h +++ b/rcl_action/include/rcl_action/types.h @@ -93,6 +93,7 @@ typedef int8_t rcl_action_goal_state_t; #define GOAL_STATE_ABORTED action_msgs__msg__GoalStatus__STATUS_ABORTED #define GOAL_STATE_NUM_STATES 7 + /// Goal state transition events typedef enum rcl_action_goal_event_t { diff --git a/rcl_action/src/rcl_action/goal_handle.c b/rcl_action/src/rcl_action/goal_handle.c index e456042bfe..06c9ec7811 100644 --- a/rcl_action/src/rcl_action/goal_handle.c +++ b/rcl_action/src/rcl_action/goal_handle.c @@ -22,6 +22,13 @@ extern "C" #include "rcl/rcl.h" #include "rcl/error_handling.h" +const char * goal_state_descriptions[] = +{"UNKNOWN", "ACCEPTED", "EXECUTING", "CANCELING", "SUCCEEDED", "CANCELED", "ABORTED"}; + +const char * goal_event_descriptions[] = +{"EXECUTE", "CANCEL_GOAL", "SUCCEED", "ABORT", "CANCELED", "NUM_EVENTS"}; + + typedef struct rcl_action_goal_handle_impl_t { rcl_action_goal_info_t info; @@ -89,9 +96,9 @@ rcl_action_update_goal_state( goal_handle->impl->state, goal_event); if (GOAL_STATE_UNKNOWN == new_state) { RCL_SET_ERROR_MSG_WITH_FORMAT_STRING( - "goal_handle attempted invalid transition from state %d with event %d", - goal_handle->impl->state, - goal_event); + "goal_handle attempted invalid transition from state %s with event %s", + goal_state_descriptions[goal_handle->impl->state], + goal_event_descriptions[goal_event]); return RCL_RET_ACTION_GOAL_EVENT_INVALID; } goal_handle->impl->state = new_state;