Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
route_state_worker.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020-2022 LEIDOS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
18
19namespace route {
20
22 return state_;
23 }
24
26
27 auto old_state = state_;
28
29 switch (state_)
30 {
31 case RouteState::LOADING:
32 if(event == RouteEvent::ROUTE_LOADED)
33 {
34 state_ = RouteState::SELECTION;
35 }
36 break;
37 case RouteState::SELECTION:
38 if(event == RouteEvent::ROUTE_SELECTED)
39 {
40 state_ = RouteState::ROUTING;
41 }
42 break;
43 case RouteState::ROUTING:
44 if(event == RouteEvent::ROUTE_STARTED)
45 {
46 state_ = RouteState::FOLLOWING;
47 } else if(event == RouteEvent::ROUTE_GEN_FAILED)
48 {
49 state_ = RouteState::SELECTION;
50 }
51 break;
52 case RouteState::FOLLOWING:
53 if(event == RouteEvent::ROUTE_COMPLETED || event == RouteEvent::ROUTE_DEPARTED || event == RouteEvent::ROUTE_ABORTED)
54 {
55 state_ = RouteState::LOADING;
56 }
57 else if(event == RouteEvent::ROUTE_INVALIDATION)
58 {
59 state_ = RouteState::ROUTING;
60 }
61 break;
62 default:
63 // should not reach here
64 throw std::invalid_argument("Current state is illegal: " + std::to_string(state_));
65 }
66
67 RCLCPP_INFO_STREAM(logger_->get_logger(), "Received Route Event: " << event << " transitioning from: " << old_state << " to: " << state_);
68 }
69
70 void RouteStateWorker::setLoggerInterface(rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger)
71 {
72 logger_ = logger;
73 }
74
75} // route
RouteState getRouteState() const
Get current route state machine state.
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_
void setLoggerInterface(rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger)
void onRouteEvent(RouteEvent event)
Process route event based on designed state machine diagram.
auto to_string(const UtmZone &zone) -> std::string
Definition: utm_zone.cpp:21