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.
arbitrator.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 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
17#ifndef __ARBITRATOR_INCLUDE_ARBITRATOR_HPP__
18#define __ARBITRATOR_INCLUDE_ARBITRATOR_HPP__
19
20#include <rclcpp/rclcpp.hpp>
21#include <carma_ros2_utils/carma_lifecycle_node.hpp>
22#include <carma_planning_msgs/msg/guidance_state.hpp>
24#include <geometry_msgs/msg/pose_stamped.hpp>
25#include <geometry_msgs/msg/twist_stamped.hpp>
26#include <tf2_ros/transform_listener.h>
27#include <tf2_ros/buffer.h>
28#include <tf2/LinearMath/Transform.h>
29#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
30#include <boost/uuid/uuid.hpp>
31#include <boost/uuid/uuid_io.hpp>
32#include <boost/uuid/uuid_generators.hpp>
33#include "vehicle_state.hpp"
35#include "planning_strategy.hpp"
37
38namespace arbitrator
39{
45 inline std::string guidance_state_to_string(uint8_t state) {
46 switch(state) {
47 case carma_planning_msgs::msg::GuidanceState::STARTUP:
48 return "STARTUP";
49 case carma_planning_msgs::msg::GuidanceState::DRIVERS_READY:
50 return "DRIVERS_READY";
52 return "ACTIVE";
54 return "ENGAGED";
56 return "INACTIVE";
58 return "SHUTDOWN";
59 default:
60 return "UNKNOWN";
61 }
62 }
63
72 {
73 public:
84 Arbitrator(std::shared_ptr<carma_ros2_utils::CarmaLifecycleNode> nh,
85 std::shared_ptr<ArbitratorStateMachine> sm,
86 std::shared_ptr<CapabilitiesInterface> ci,
87 std::shared_ptr<PlanningStrategy> planning_strategy,
88 rclcpp::Duration min_plan_duration,
89 double planning_period,
91 sm_(sm),
92 nh_(nh),
93 min_plan_duration_(min_plan_duration),
94 time_between_plans_(rclcpp::Duration::from_seconds(planning_period)),
96 planning_strategy_(planning_strategy),
97 initialized_(false),
98 wm_(wm),
99 tf2_buffer_(nh_->get_clock()) {};
100
106 void run();
107
112 void twist_cb(geometry_msgs::msg::TwistStamped::UniquePtr msg);
113
117 void bumper_pose_cb();
118
123
124 protected:
128 void initial_state();
129
133 void planning_state();
134
139 void waiting_state();
140
145 void paused_state();
146
150 void shutdown_state();
151
156 void guidance_state_cb(carma_planning_msgs::msg::GuidanceState::UniquePtr msg);
157
158 private:
159
160 VehicleState vehicle_state_; // The current state of the vehicle for populating planning requests
161
162 std::shared_ptr<ArbitratorStateMachine> sm_;
163 carma_ros2_utils::PubPtr<carma_planning_msgs::msg::ManeuverPlan> final_plan_pub_;
164 carma_ros2_utils::SubPtr<carma_planning_msgs::msg::GuidanceState> guidance_state_sub_;
165 std::shared_ptr<carma_ros2_utils::CarmaLifecycleNode> nh_;
166 rclcpp::Duration min_plan_duration_;
167 rclcpp::Duration time_between_plans_;
169 std::shared_ptr<CapabilitiesInterface> capabilities_interface_;
170 std::shared_ptr<PlanningStrategy> planning_strategy_;
173
174 geometry_msgs::msg::TransformStamped tf_;
175 // TF listenser
176 tf2_ros::Buffer tf2_buffer_;
177 std::unique_ptr<tf2_ros::TransformListener> tf2_listener_;
178 // transform from front bumper to map
179 tf2::Stamped<tf2::Transform> bumper_transform_;
181 carma_planning_msgs::msg::GuidanceState::_state_type previous_guidance_state_ =
182 carma_planning_msgs::msg::GuidanceState::STARTUP; // Initialize to default value
183 };
184}
185
186#endif
void planning_state()
Function to be called when the Arbitrator begins planning.
Definition: arbitrator.cpp:136
tf2::Stamped< tf2::Transform > bumper_transform_
Definition: arbitrator.hpp:179
rclcpp::Time next_planning_process_start_
Definition: arbitrator.hpp:168
carma_planning_msgs::msg::GuidanceState::_state_type previous_guidance_state_
Definition: arbitrator.hpp:181
void shutdown_state()
Function to be executed when the Arbitrator is to clean up and shutdown.
Definition: arbitrator.cpp:181
void paused_state()
Function to be executed when the Arbitrator is not planning but also not awaiting a new plan cycle.
Definition: arbitrator.cpp:176
Arbitrator(std::shared_ptr< carma_ros2_utils::CarmaLifecycleNode > nh, std::shared_ptr< ArbitratorStateMachine > sm, std::shared_ptr< CapabilitiesInterface > ci, std::shared_ptr< PlanningStrategy > planning_strategy, rclcpp::Duration min_plan_duration, double planning_period, carma_wm::WorldModelConstPtr wm)
Constructor for arbitrator class taking in dependencies via dependency injection.
Definition: arbitrator.hpp:84
void initial_state()
Function to be executed during the initial state of the Arbitrator.
Definition: arbitrator.cpp:121
rclcpp::Duration min_plan_duration_
Definition: arbitrator.hpp:166
carma_ros2_utils::PubPtr< carma_planning_msgs::msg::ManeuverPlan > final_plan_pub_
Definition: arbitrator.hpp:163
std::shared_ptr< carma_ros2_utils::CarmaLifecycleNode > nh_
Definition: arbitrator.hpp:165
void twist_cb(geometry_msgs::msg::TwistStamped::UniquePtr msg)
Callback for the twist subscriber, which will store latest twist locally.
Definition: arbitrator.cpp:223
tf2_ros::Buffer tf2_buffer_
Definition: arbitrator.hpp:176
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::GuidanceState > guidance_state_sub_
Definition: arbitrator.hpp:164
void waiting_state()
Function to be executed when the Arbitrator has finished planning and is awaiting another planning cy...
Definition: arbitrator.cpp:171
carma_wm::WorldModelConstPtr wm_
Definition: arbitrator.hpp:172
rclcpp::Duration time_between_plans_
Definition: arbitrator.hpp:167
std::shared_ptr< PlanningStrategy > planning_strategy_
Definition: arbitrator.hpp:170
void initializeBumperTransformLookup()
Initialize transform Lookup from front bumper to map.
Definition: arbitrator.cpp:228
std::unique_ptr< tf2_ros::TransformListener > tf2_listener_
Definition: arbitrator.hpp:177
void run()
Begin the operation of the arbitrator.
Definition: arbitrator.cpp:27
std::shared_ptr< CapabilitiesInterface > capabilities_interface_
Definition: arbitrator.hpp:169
VehicleState vehicle_state_
Definition: arbitrator.hpp:160
geometry_msgs::msg::TransformStamped tf_
Definition: arbitrator.hpp:174
void bumper_pose_cb()
Callback for the front bumper pose transform.
Definition: arbitrator.cpp:187
void guidance_state_cb(carma_planning_msgs::msg::GuidanceState::UniquePtr msg)
Callback for receiving Guidance state machine updates.
Definition: arbitrator.cpp:67
std::shared_ptr< ArbitratorStateMachine > sm_
Definition: arbitrator.hpp:162
std::string guidance_state_to_string(uint8_t state)
Convert guidance state enum to string representation.
Definition: arbitrator.hpp:45
std::shared_ptr< const WorldModel > WorldModelConstPtr
Definition: WorldModel.hpp:454
Struct defining the vehicle state required for maneuver planning.