rcl_action  master
C API providing common functionality for ROS actions.
types.h
1 // Copyright 2018 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCL_ACTION__TYPES_H_
16 #define RCL_ACTION__TYPES_H_
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 #include "rcl_action/visibility_control.h"
24 
25 #include "action_msgs/msg/goal_info.h"
26 #include "action_msgs/msg/goal_status.h"
27 #include "action_msgs/msg/goal_status_array.h"
28 #include "action_msgs/srv/cancel_goal.h"
29 
30 #include "rcl/allocator.h"
31 #include "rcl/macros.h"
32 #include "rcl/types.h"
33 
34 #include "rosidl_runtime_c/action_type_support_struct.h"
35 
36 // rcl action specific ret codes in 2XXX
38 #define RCL_RET_ACTION_NAME_INVALID 2000
39 #define RCL_RET_ACTION_GOAL_ACCEPTED 2100
41 #define RCL_RET_ACTION_GOAL_REJECTED 2101
43 #define RCL_RET_ACTION_CLIENT_INVALID 2102
45 #define RCL_RET_ACTION_CLIENT_TAKE_FAILED 2103
47 #define RCL_RET_ACTION_SERVER_INVALID 2200
49 #define RCL_RET_ACTION_SERVER_TAKE_FAILED 2201
51 #define RCL_RET_ACTION_GOAL_HANDLE_INVALID 2300
53 #define RCL_RET_ACTION_GOAL_EVENT_INVALID 2301
55 
56 // TODO(jacobperron): Move these to a common place for UUIDs
57 #define UUID_SIZE 16
58 #define uuidcmp(uuid0, uuid1) (0 == memcmp(uuid0, uuid1, UUID_SIZE))
59 #define zerouuid (uint8_t[UUID_SIZE]) {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
60 #define uuidcmpzero(uuid) uuidcmp(uuid, (zerouuid))
61 
62 // Forward declare
64 
65 // Typedef generated messages for convenience
66 typedef action_msgs__msg__GoalInfo rcl_action_goal_info_t;
67 typedef action_msgs__msg__GoalStatus rcl_action_goal_status_t;
70 {
72  action_msgs__msg__GoalStatusArray msg;
76 typedef action_msgs__srv__CancelGoal_Request rcl_action_cancel_request_t;
79 {
81  action_msgs__srv__CancelGoal_Response msg;
85 
87 // TODO(jacobperron): Let states be defined by action_msgs/msg/goal_status.h
88 // Ideally, we could use an enum type directly from the message when the feature
89 // is available. Issue: https://github.com/ros2/rosidl/issues/260
90 typedef int8_t rcl_action_goal_state_t;
91 #define GOAL_STATE_UNKNOWN action_msgs__msg__GoalStatus__STATUS_UNKNOWN
92 #define GOAL_STATE_ACCEPTED action_msgs__msg__GoalStatus__STATUS_ACCEPTED
93 #define GOAL_STATE_EXECUTING action_msgs__msg__GoalStatus__STATUS_EXECUTING
94 #define GOAL_STATE_CANCELING action_msgs__msg__GoalStatus__STATUS_CANCELING
95 #define GOAL_STATE_SUCCEEDED action_msgs__msg__GoalStatus__STATUS_SUCCEEDED
96 #define GOAL_STATE_CANCELED action_msgs__msg__GoalStatus__STATUS_CANCELED
97 #define GOAL_STATE_ABORTED action_msgs__msg__GoalStatus__STATUS_ABORTED
98 #define GOAL_STATE_NUM_STATES 7
99 
101 // Description variables in types.c should be changed if enum values change
102 extern const char * goal_state_descriptions[];
103 extern const char * goal_event_descriptions[];
104 
106 typedef enum rcl_action_goal_event_t
107 {
108  GOAL_EVENT_EXECUTE = 0,
109  GOAL_EVENT_CANCEL_GOAL,
110  GOAL_EVENT_SUCCEED,
111  GOAL_EVENT_ABORT,
112  GOAL_EVENT_CANCELED,
113  GOAL_EVENT_NUM_EVENTS
114 } rcl_action_goal_event_t;
115 
117 RCL_ACTION_PUBLIC
118 RCL_WARN_UNUSED
119 rcl_action_goal_info_t
120 rcl_action_get_zero_initialized_goal_info(void);
121 
123 
127 RCL_ACTION_PUBLIC
128 RCL_WARN_UNUSED
130 rcl_action_get_zero_initialized_goal_status_array(void);
131 
133 
138 RCL_ACTION_PUBLIC
139 RCL_WARN_UNUSED
140 rcl_action_cancel_request_t
141 rcl_action_get_zero_initialized_cancel_request(void);
142 
144 
148 RCL_ACTION_PUBLIC
149 RCL_WARN_UNUSED
151 rcl_action_get_zero_initialized_cancel_response(void);
152 
154 
196 RCL_ACTION_PUBLIC
197 RCL_WARN_UNUSED
198 rcl_ret_t
199 rcl_action_goal_status_array_init(
200  rcl_action_goal_status_array_t * status_array,
201  const size_t num_status,
202  const rcl_allocator_t allocator);
203 
205 
221 RCL_ACTION_PUBLIC
222 RCL_WARN_UNUSED
223 rcl_ret_t
224 rcl_action_goal_status_array_fini(rcl_action_goal_status_array_t * status_array);
225 
227 
269 RCL_ACTION_PUBLIC
270 RCL_WARN_UNUSED
271 rcl_ret_t
272 rcl_action_cancel_response_init(
273  rcl_action_cancel_response_t * cancel_response,
274  const size_t num_goals_canceling,
275  const rcl_allocator_t allocator);
276 
278 
294 RCL_ACTION_PUBLIC
295 RCL_WARN_UNUSED
296 rcl_ret_t
297 rcl_action_cancel_response_fini(rcl_action_cancel_response_t * cancel_response);
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 
303 #endif // RCL_ACTION__TYPES_H_
rcl_action_server_t
Structure which encapsulates a ROS Action Server.
Definition: action_server.h:36
rcl_action_cancel_response_t
Struct with the action cancel response.
Definition: types.h:78
rcl_action_goal_status_array_t::allocator
rcl_allocator_t allocator
Allocator used to initialize this struct.
Definition: types.h:74
rcl_ret_t
rmw_ret_t rcl_ret_t
rcl_action_goal_status_array_t
Struct with the action goal status array.
Definition: types.h:69
allocator.h
rcl_action_cancel_response_t::allocator
rcl_allocator_t allocator
Allocator used to initialize this struct.
Definition: types.h:83
rcutils_allocator_t
rcl_action_cancel_response_t::msg
action_msgs__srv__CancelGoal_Response msg
Cancel goal response message.
Definition: types.h:81
types.h
rcl_action_goal_status_array_t::msg
action_msgs__msg__GoalStatusArray msg
Goal status array message.
Definition: types.h:72