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.
control_plugin.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#pragma once
18
19#include <rclcpp/rclcpp.hpp>
20#include <carma_planning_msgs/msg/trajectory_plan.hpp>
21#include <geometry_msgs/msg/pose_stamped.hpp>
22#include <geometry_msgs/msg/twist_stamped.hpp>
23#include <autoware_msgs/msg/control_command_stamped.hpp>
24
26
28{
29
39 {
40
41 private:
42 // Subscriptions
43 carma_ros2_utils::SubPtr<geometry_msgs::msg::PoseStamped> current_pose_sub_;
44 carma_ros2_utils::SubPtr<geometry_msgs::msg::TwistStamped> current_velocity_sub_;
45 carma_ros2_utils::SubPtr<carma_planning_msgs::msg::TrajectoryPlan> trajectory_plan_sub_;
46
47 // Publishers
48 carma_ros2_utils::PubPtr<autoware_msgs::msg::ControlCommandStamped> vehicle_cmd_pub_;
49
50 // Timers
51 rclcpp::TimerBase::SharedPtr command_timer_;
52
53
54 protected:
55
57 boost::optional<geometry_msgs::msg::PoseStamped> current_pose_;
58
60 // NOTE: Only the twist.linear.x and header are guaranteed to be populated
61 boost::optional<geometry_msgs::msg::TwistStamped> current_twist_;
62
64 boost::optional<carma_planning_msgs::msg::TrajectoryPlan> current_trajectory_;
65
66 // These callbacks do direct assignment into their respective member variables
67 void current_pose_callback(geometry_msgs::msg::PoseStamped::UniquePtr msg);
68 void current_twist_callback(geometry_msgs::msg::TwistStamped::UniquePtr msg);
69
73 virtual void current_trajectory_callback(carma_planning_msgs::msg::TrajectoryPlan::UniquePtr msg);
74
75
76 public:
80 explicit ControlPlugin(const rclcpp::NodeOptions &);
81
83 virtual ~ControlPlugin() = default;
84
93 virtual autoware_msgs::msg::ControlCommandStamped generate_command() = 0;
94
96 // Overrides
98
99 // Non-Final to allow extending plugins to provide more detailed capabilities
100 std::string get_capability() override;
101
102 // Final
103 uint8_t get_type() override final;
104
105 carma_ros2_utils::CallbackReturn handle_on_configure(const rclcpp_lifecycle::State &) override final;
106 carma_ros2_utils::CallbackReturn handle_on_activate(const rclcpp_lifecycle::State &) override final;
107 carma_ros2_utils::CallbackReturn handle_on_deactivate(const rclcpp_lifecycle::State &) override final;
108 carma_ros2_utils::CallbackReturn handle_on_cleanup(const rclcpp_lifecycle::State &) override final;
109 carma_ros2_utils::CallbackReturn handle_on_shutdown(const rclcpp_lifecycle::State &) override final;
110 carma_ros2_utils::CallbackReturn handle_on_error(const rclcpp_lifecycle::State &, const std::string &exception_string) override final;
111 };
112
113} // carma_guidance_plugins
ControlPlugin base class which can be extended by user provided plugins which wish to implement the C...
rclcpp::TimerBase::SharedPtr command_timer_
carma_ros2_utils::CallbackReturn handle_on_error(const rclcpp_lifecycle::State &, const std::string &exception_string) override final
std::string get_capability() override
Get the capability string representing this plugins capabilities Method must be overriden by extendin...
carma_ros2_utils::CallbackReturn handle_on_deactivate(const rclcpp_lifecycle::State &) override final
void current_pose_callback(geometry_msgs::msg::PoseStamped::UniquePtr msg)
boost::optional< geometry_msgs::msg::TwistStamped > current_twist_
The most recent velocity message received by this node.
carma_ros2_utils::CallbackReturn handle_on_cleanup(const rclcpp_lifecycle::State &) override final
virtual void current_trajectory_callback(carma_planning_msgs::msg::TrajectoryPlan::UniquePtr msg)
Extending class provided method which can optionally handle trajectory plan callbacks.
uint8_t get_type() override final
Returns the type of this plugin according to the carma_planning_msgs::Plugin type enum....
carma_ros2_utils::SubPtr< geometry_msgs::msg::PoseStamped > current_pose_sub_
boost::optional< carma_planning_msgs::msg::TrajectoryPlan > current_trajectory_
The most recent trajectory received by this plugin.
carma_ros2_utils::SubPtr< carma_planning_msgs::msg::TrajectoryPlan > trajectory_plan_sub_
carma_ros2_utils::PubPtr< autoware_msgs::msg::ControlCommandStamped > vehicle_cmd_pub_
carma_ros2_utils::CallbackReturn handle_on_activate(const rclcpp_lifecycle::State &) override final
virtual autoware_msgs::msg::ControlCommandStamped generate_command()=0
Extending class provided method which should generate a command message which will be published to th...
carma_ros2_utils::CallbackReturn handle_on_configure(const rclcpp_lifecycle::State &) override final
ControlPlugin(const rclcpp::NodeOptions &)
ControlPlugin constructor.
void current_twist_callback(geometry_msgs::msg::TwistStamped::UniquePtr msg)
carma_ros2_utils::CallbackReturn handle_on_shutdown(const rclcpp_lifecycle::State &) override final
virtual ~ControlPlugin()=default
Virtual destructor for safe deletion.
carma_ros2_utils::SubPtr< geometry_msgs::msg::TwistStamped > current_velocity_sub_
boost::optional< geometry_msgs::msg::PoseStamped > current_pose_
The most recent pose message received by this node.
PluginBaseNode provides default functionality for all carma guidance plugins. This includes basic sta...