Skip to content

Commit 8d32ae4

Browse files
committed
feat: move response status handling utilily
Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
1 parent ea009b8 commit 8d32ae4

File tree

7 files changed

+48
-43
lines changed

7 files changed

+48
-43
lines changed

common/component_interface_utils/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ project(component_interface_utils)
44
find_package(autoware_cmake REQUIRED)
55
autoware_package()
66

7+
ament_auto_add_library(${PROJECT_NAME} SHARED
8+
src/service_utils.cpp
9+
)
10+
711
include_directories(
812
include
913
SYSTEM

planning/mission_planner/src/mission_planner/service_utils.hpp common/component_interface_utils/include/component_interface_utils/service_utils.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef MISSION_PLANNER__SERVICE_UTILS_HPP_
16-
#define MISSION_PLANNER__SERVICE_UTILS_HPP_
15+
#ifndef COMPONENT_INTERFACE_UTILS__SERVICE_UTILS_HPP_
16+
#define COMPONENT_INTERFACE_UTILS__SERVICE_UTILS_HPP_
1717

1818
#include <autoware_common_msgs/msg/response_status.hpp>
1919

2020
#include <stdexcept>
2121
#include <string>
2222

23-
namespace service_utils
23+
namespace component_interface_utils
2424
{
2525

2626
using ResponseStatus = autoware_common_msgs::msg::ResponseStatus;
@@ -75,6 +75,6 @@ ResponseStatus sync_call(T & client, Req req)
7575
return future.get()->status;
7676
}
7777

78-
} // namespace service_utils
78+
} // namespace component_interface_utils
7979

80-
#endif // MISSION_PLANNER__SERVICE_UTILS_HPP_
80+
#endif // COMPONENT_INTERFACE_UTILS__SERVICE_UTILS_HPP_

planning/mission_planner/src/mission_planner/service_utils.cpp common/component_interface_utils/src/service_utils.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "service_utils.hpp"
15+
#include "component_interface_utils/service_utils.hpp"
1616

1717
#include <string>
1818

19-
namespace service_utils
19+
namespace component_interface_utils
2020
{
2121

2222
ServiceException ServiceUnready(const std::string & message)
@@ -29,4 +29,4 @@ ServiceException TransformError(const std::string & message)
2929
return ServiceException(ResponseStatus::TRANSFORM_ERROR, message, false);
3030
};
3131

32-
} // namespace service_utils
32+
} // namespace component_interface_utils

planning/mission_planner/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ rclcpp_components_register_node(goal_pose_visualizer_component
1515

1616
ament_auto_add_library(${PROJECT_NAME}_component SHARED
1717
src/mission_planner/arrival_checker.cpp
18-
src/mission_planner/service_utils.cpp
1918
src/mission_planner/mission_planner.cpp
2019
src/mission_planner/route_selector.cpp
2120
)

planning/mission_planner/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<depend>autoware_adapi_v1_msgs</depend>
2121
<depend>autoware_auto_mapping_msgs</depend>
2222
<depend>autoware_planning_msgs</depend>
23+
<depend>component_interface_utils</depend>
2324
<depend>geometry_msgs</depend>
2425
<depend>lanelet2_extension</depend>
2526
<depend>motion_utils</depend>

planning/mission_planner/src/mission_planner/mission_planner.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
#include "mission_planner.hpp"
1616

17-
#include "service_utils.hpp"
18-
17+
#include <component_interface_utils/service_utils.hpp>
1918
#include <lanelet2_extension/utility/message_conversion.hpp>
2019
#include <lanelet2_extension/utility/query.hpp>
2120
#include <lanelet2_extension/utility/route_checker.hpp>
@@ -69,13 +68,14 @@ MissionPlanner::MissionPlanner(const rclcpp::NodeOptions & options)
6968
sub_modified_goal_ = create_subscription<PoseWithUuidStamped>(
7069
"~/input/modified_goal", durable_qos, std::bind(&MissionPlanner::on_modified_goal, this, _1));
7170
srv_clear_route = create_service<ClearRoute>(
72-
"~/clear_route", service_utils::handle_exception(&MissionPlanner::on_clear_route, this));
71+
"~/clear_route",
72+
component_interface_utils::handle_exception(&MissionPlanner::on_clear_route, this));
7373
srv_set_lanelet_route = create_service<SetLaneletRoute>(
7474
"~/set_lanelet_route",
75-
service_utils::handle_exception(&MissionPlanner::on_set_lanelet_route, this));
75+
component_interface_utils::handle_exception(&MissionPlanner::on_set_lanelet_route, this));
7676
srv_set_waypoint_route = create_service<SetWaypointRoute>(
7777
"~/set_waypoint_route",
78-
service_utils::handle_exception(&MissionPlanner::on_set_waypoint_route, this));
78+
component_interface_utils::handle_exception(&MissionPlanner::on_set_waypoint_route, this));
7979
pub_route_ = create_publisher<LaneletRoute>("~/route", durable_qos);
8080
pub_state_ = create_publisher<RouteState>("~/state", durable_qos);
8181

@@ -157,7 +157,7 @@ Pose MissionPlanner::transform_pose(const Pose & pose, const Header & header)
157157
tf2::doTransform(pose, result, transform);
158158
return result;
159159
} catch (tf2::TransformException & error) {
160-
throw service_utils::TransformError(error.what());
160+
throw component_interface_utils::TransformError(error.what());
161161
}
162162
}
163163

@@ -222,19 +222,19 @@ void MissionPlanner::on_set_lanelet_route(
222222
const auto is_reroute = state_.state == RouteState::SET;
223223

224224
if (state_.state != RouteState::UNSET && state_.state != RouteState::SET) {
225-
throw service_utils::ServiceException(
225+
throw component_interface_utils::ServiceException(
226226
ResponseCode::ERROR_INVALID_STATE, "The route cannot be set in the current state.");
227227
}
228228
if (!planner_->ready()) {
229-
throw service_utils::ServiceException(
229+
throw component_interface_utils::ServiceException(
230230
ResponseCode::ERROR_PLANNER_UNREADY, "The planner is not ready.");
231231
}
232232
if (!odometry_) {
233-
throw service_utils::ServiceException(
233+
throw component_interface_utils::ServiceException(
234234
ResponseCode::ERROR_PLANNER_UNREADY, "The vehicle pose is not received.");
235235
}
236236
if (is_reroute && !reroute_availability_->availability) {
237-
throw service_utils::ServiceException(
237+
throw component_interface_utils::ServiceException(
238238
ResponseCode::ERROR_INVALID_STATE, "Cannot reroute as the planner is not in lane following.");
239239
}
240240

@@ -244,14 +244,14 @@ void MissionPlanner::on_set_lanelet_route(
244244
if (route.segments.empty()) {
245245
cancel_route();
246246
change_state(is_reroute ? RouteState::SET : RouteState::UNSET);
247-
throw service_utils::ServiceException(
247+
throw component_interface_utils::ServiceException(
248248
ResponseCode::ERROR_PLANNER_FAILED, "The planned route is empty.");
249249
}
250250

251251
if (is_reroute && !check_reroute_safety(*current_route_, route)) {
252252
cancel_route();
253253
change_state(RouteState::SET);
254-
throw service_utils::ServiceException(
254+
throw component_interface_utils::ServiceException(
255255
ResponseCode::ERROR_REROUTE_FAILED, "New route is not safe. Reroute failed.");
256256
}
257257

@@ -270,19 +270,19 @@ void MissionPlanner::on_set_waypoint_route(
270270
const auto is_reroute = state_.state == RouteState::SET;
271271

272272
if (state_.state != RouteState::UNSET && state_.state != RouteState::SET) {
273-
throw service_utils::ServiceException(
273+
throw component_interface_utils::ServiceException(
274274
ResponseCode::ERROR_INVALID_STATE, "The route cannot be set in the current state.");
275275
}
276276
if (!planner_->ready()) {
277-
throw service_utils::ServiceException(
277+
throw component_interface_utils::ServiceException(
278278
ResponseCode::ERROR_PLANNER_UNREADY, "The planner is not ready.");
279279
}
280280
if (!odometry_) {
281-
throw service_utils::ServiceException(
281+
throw component_interface_utils::ServiceException(
282282
ResponseCode::ERROR_PLANNER_UNREADY, "The vehicle pose is not received.");
283283
}
284284
if (is_reroute && !reroute_availability_->availability) {
285-
throw service_utils::ServiceException(
285+
throw component_interface_utils::ServiceException(
286286
ResponseCode::ERROR_INVALID_STATE, "Cannot reroute as the planner is not in lane following.");
287287
}
288288

@@ -292,14 +292,14 @@ void MissionPlanner::on_set_waypoint_route(
292292
if (route.segments.empty()) {
293293
cancel_route();
294294
change_state(is_reroute ? RouteState::SET : RouteState::UNSET);
295-
throw service_utils::ServiceException(
295+
throw component_interface_utils::ServiceException(
296296
ResponseCode::ERROR_PLANNER_FAILED, "The planned route is empty.");
297297
}
298298

299299
if (is_reroute && !check_reroute_safety(*current_route_, route)) {
300300
cancel_route();
301301
change_state(RouteState::SET);
302-
throw service_utils::ServiceException(
302+
throw component_interface_utils::ServiceException(
303303
ResponseCode::ERROR_REROUTE_FAILED, "New route is not safe. Reroute failed.");
304304
}
305305

planning/mission_planner/src/mission_planner/route_selector.cpp

+17-16
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "route_selector.hpp"
1616

17-
#include "service_utils.hpp"
17+
#include <component_interface_utils/service_utils.hpp>
1818

1919
#include <array>
2020
#include <memory>
@@ -96,25 +96,26 @@ RouteSelector::RouteSelector(const rclcpp::NodeOptions & options)
9696
// Init main route interface.
9797
main_.srv_clear_route = create_service<ClearRoute>(
9898
"~/main/clear_route",
99-
service_utils::handle_exception(&RouteSelector::on_clear_route_main, this));
99+
component_interface_utils::handle_exception(&RouteSelector::on_clear_route_main, this));
100100
main_.srv_set_waypoint_route = create_service<SetWaypointRoute>(
101101
"~/main/set_waypoint_route",
102-
service_utils::handle_exception(&RouteSelector::on_set_waypoint_route_main, this));
102+
component_interface_utils::handle_exception(&RouteSelector::on_set_waypoint_route_main, this));
103103
main_.srv_set_lanelet_route = create_service<SetLaneletRoute>(
104104
"~/main/set_lanelet_route",
105-
service_utils::handle_exception(&RouteSelector::on_set_lanelet_route_main, this));
105+
component_interface_utils::handle_exception(&RouteSelector::on_set_lanelet_route_main, this));
106106
main_.pub_state_ = create_publisher<RouteState>("~/main/state", durable_qos);
107107
main_.pub_route_ = create_publisher<LaneletRoute>("~/main/route", durable_qos);
108108

109109
// Init mrm route interface.
110110
mrm_.srv_clear_route = create_service<ClearRoute>(
111-
"~/mrm/clear_route", service_utils::handle_exception(&RouteSelector::on_clear_route_mrm, this));
111+
"~/mrm/clear_route",
112+
component_interface_utils::handle_exception(&RouteSelector::on_clear_route_mrm, this));
112113
mrm_.srv_set_waypoint_route = create_service<SetWaypointRoute>(
113114
"~/mrm/set_waypoint_route",
114-
service_utils::handle_exception(&RouteSelector::on_set_waypoint_route_mrm, this));
115+
component_interface_utils::handle_exception(&RouteSelector::on_set_waypoint_route_mrm, this));
115116
mrm_.srv_set_lanelet_route = create_service<SetLaneletRoute>(
116117
"~/mrm/set_lanelet_route",
117-
service_utils::handle_exception(&RouteSelector::on_set_lanelet_route_mrm, this));
118+
component_interface_utils::handle_exception(&RouteSelector::on_set_lanelet_route_mrm, this));
118119
mrm_.pub_state_ = create_publisher<RouteState>("~/mrm/state", durable_qos);
119120
mrm_.pub_route_ = create_publisher<LaneletRoute>("~/mrm/route", durable_qos);
120121

@@ -169,7 +170,7 @@ void RouteSelector::on_clear_route_main(
169170
}
170171

171172
// Forward the request if not in MRM.
172-
res->status = service_utils::sync_call(cli_clear_route_, req);
173+
res->status = component_interface_utils::sync_call(cli_clear_route_, req);
173174
}
174175

175176
void RouteSelector::on_set_waypoint_route_main(
@@ -188,7 +189,7 @@ void RouteSelector::on_set_waypoint_route_main(
188189
}
189190

190191
// Forward the request if not in MRM.
191-
res->status = service_utils::sync_call(cli_set_waypoint_route_, req);
192+
res->status = component_interface_utils::sync_call(cli_set_waypoint_route_, req);
192193
}
193194

194195
void RouteSelector::on_set_lanelet_route_main(
@@ -207,7 +208,7 @@ void RouteSelector::on_set_lanelet_route_main(
207208
}
208209

209210
// Forward the request if not in MRM.
210-
res->status = service_utils::sync_call(cli_set_lanelet_route_, req);
211+
res->status = component_interface_utils::sync_call(cli_set_lanelet_route_, req);
211212
}
212213

213214
void RouteSelector::on_clear_route_mrm(
@@ -225,7 +226,7 @@ void RouteSelector::on_set_waypoint_route_mrm(
225226
SetWaypointRoute::Request::SharedPtr req, SetWaypointRoute::Response::SharedPtr res)
226227
{
227228
req->uuid = uuid::generate_if_empty(req->uuid);
228-
res->status = service_utils::sync_call(cli_set_waypoint_route_, req);
229+
res->status = component_interface_utils::sync_call(cli_set_waypoint_route_, req);
229230

230231
if (res->status.success) {
231232
mrm_operating_ = true;
@@ -239,7 +240,7 @@ void RouteSelector::on_set_lanelet_route_mrm(
239240
SetLaneletRoute::Request::SharedPtr req, SetLaneletRoute::Response::SharedPtr res)
240241
{
241242
req->uuid = uuid::generate_if_empty(req->uuid);
242-
res->status = service_utils::sync_call(cli_set_lanelet_route_, req);
243+
res->status = component_interface_utils::sync_call(cli_set_lanelet_route_, req);
243244

244245
if (res->status.success) {
245246
mrm_operating_ = true;
@@ -273,25 +274,25 @@ ResponseStatus RouteSelector::resume_main_route(ClearRoute::Request::SharedPtr r
273274

274275
// Clear the route if there is no request for the main route.
275276
if (std::holds_alternative<std::monostate>(main_request_)) {
276-
return service_utils::sync_call(cli_clear_route_, req);
277+
return component_interface_utils::sync_call(cli_clear_route_, req);
277278
}
278279

279280
// Attempt to resume the main route if there is a planned route.
280281
if (const auto route = main_.get_route()) {
281282
const auto r = create_lanelet_request(route.value());
282-
const auto status = service_utils::sync_call(cli_set_lanelet_route_, r);
283+
const auto status = component_interface_utils::sync_call(cli_set_lanelet_route_, r);
283284
if (status.success) return status;
284285
}
285286

286287
// If resuming fails, replan main route using the goal.
287288
// NOTE: Clear the waypoints to avoid returning. Remove this once resuming is supported.
288289
if (const auto request = std::get_if<WaypointRequest>(&main_request_)) {
289290
const auto r = create_goal_request(*request);
290-
return service_utils::sync_call(cli_set_waypoint_route_, r);
291+
return component_interface_utils::sync_call(cli_set_waypoint_route_, r);
291292
}
292293
if (const auto request = std::get_if<LaneletRequest>(&main_request_)) {
293294
const auto r = create_goal_request(*request);
294-
return service_utils::sync_call(cli_set_waypoint_route_, r);
295+
return component_interface_utils::sync_call(cli_set_waypoint_route_, r);
295296
}
296297
throw std::logic_error("route_selector: unknown main route request");
297298
}

0 commit comments

Comments
 (0)