Autoware.Auto
state_estimation_node.hpp
Go to the documentation of this file.
1 // Copyright 2020 Apex.AI, 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 
17 
18 
19 #ifndef STATE_ESTIMATION_NODES__STATE_ESTIMATION_NODE_HPP_
20 #define STATE_ESTIMATION_NODES__STATE_ESTIMATION_NODE_HPP_
21 
22 
23 #include <common/types.hpp>
24 #include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
25 #include <geometry_msgs/msg/twist_with_covariance_stamped.hpp>
26 #include <geometry_msgs/msg/quaternion_stamped.hpp>
27 #include <kalman_filter/esrcf.hpp>
29 #include <nav_msgs/msg/odometry.hpp>
30 #include <rclcpp/publisher.hpp>
31 #include <rclcpp/rclcpp.hpp>
32 #include <rclcpp/subscription.hpp>
36 
37 #include <tf2/buffer_core.h>
38 #include <tf2_ros/transform_listener.h>
39 #include <tf2_ros/transform_broadcaster.h>
40 
41 #include <Eigen/Geometry>
42 
43 #include <string>
44 #include <vector>
45 #include <memory>
46 
47 namespace autoware
48 {
49 namespace prediction
50 {
51 namespace state_estimation_nodes
52 {
53 
57 class STATE_ESTIMATION_NODES_PUBLIC StateEstimationNode : public rclcpp::Node
58 {
59 public:
65  explicit StateEstimationNode(
66  const rclcpp::NodeOptions & node_options);
67 
68 private:
69  using OdomMsgT = nav_msgs::msg::Odometry;
70  using PoseMsgT = geometry_msgs::msg::PoseWithCovarianceStamped;
71  using TwistMsgT = geometry_msgs::msg::TwistWithCovarianceStamped;
72  using TfMsgT = tf2_msgs::msg::TFMessage;
73 
74  template<std::int32_t kDim>
75  using VectorT = Eigen::Matrix<float32_t, kDim, 1>;
76 
81  void odom_callback(const OdomMsgT::SharedPtr msg);
82 
87  void pose_callback(const PoseMsgT::SharedPtr msg);
88 
93  void twist_callback(const TwistMsgT::SharedPtr msg);
94 
96  void predict_and_publish_current_state();
97 
99  void publish_current_state();
100 
102  void update_latest_orientation_if_needed(const geometry_msgs::msg::QuaternionStamped & rotation);
103 
105  geometry_msgs::msg::TransformStamped get_transform(const std_msgs::msg::Header & header);
106 
107  template<typename MessageT>
108  using CallbackFnT = void (StateEstimationNode::*)(const typename MessageT::SharedPtr);
109 
110  template<typename MessageT>
111  void create_subscriptions(
112  const std::vector<std::string> & input_topics,
113  std::vector<typename rclcpp::Subscription<MessageT>::SharedPtr> * subscribers,
114  CallbackFnT<MessageT> callback);
115 
116  template<std::int32_t kNumOfStates, std::int32_t kProcessNoiseDim>
117  static Eigen::Matrix<float32_t, kNumOfStates, kProcessNoiseDim> create_GQ_factor(
118  const std::chrono::nanoseconds & expected_delta_t,
119  const VectorT<kProcessNoiseDim> & process_noise_variances);
120 
121  std::vector<rclcpp::Subscription<OdomMsgT>::SharedPtr> m_odom_subscribers;
122  std::vector<rclcpp::Subscription<PoseMsgT>::SharedPtr> m_pose_subscribers;
123  std::vector<rclcpp::Subscription<TwistMsgT>::SharedPtr> m_twist_subscribers;
124 
125  std::shared_ptr<rclcpp::Publisher<OdomMsgT>> m_publisher{};
126  std::shared_ptr<rclcpp::Publisher<TfMsgT>> m_tf_publisher{};
127 
128  rclcpp::TimerBase::SharedPtr m_wall_timer{};
129 
130  common::types::bool8_t m_filter_initialized{};
131  common::types::bool8_t m_publish_data_driven{};
132  common::types::float64_t m_publish_frequency{};
133 
134  std::string m_frame_id{};
135  std::string m_child_frame_id{};
136 
137  // TODO(igor): we can replace the unique_ptr here with std::variant or alike at a later time to
138  // allow configuring which filter to use at runtime.
139  std::unique_ptr<ConstantAccelerationFilter> m_ekf{};
140 
141  tf2::BufferCore m_tf_buffer;
142  tf2_ros::TransformListener m_tf_listener;
143 
144  geometry_msgs::msg::QuaternionStamped m_latest_orientation{};
145  common::types::float64_t m_min_speed_to_use_speed_orientation{};
146 };
147 
148 } // namespace state_estimation_nodes
149 } // namespace prediction
150 } // namespace autoware
151 
152 #endif // STATE_ESTIMATION_NODES__STATE_ESTIMATION_NODE_HPP_
motion::motion_testing_nodes::TFMessage
tf2_msgs::msg::TFMessage TFMessage
Definition: motion_testing_publisher.hpp:34
types.hpp
This file includes common type definition.
autoware::perception::filters::point_cloud_filter_transform_nodes::get_transform
TransformStamped get_transform(const std::string &input_frame_id, const std::string &output_frame_id, float64_t r_x, float64_t r_y, float64_t r_z, float64_t r_w, float64_t t_x, float64_t t_y, float64_t t_z)
Definition: point_cloud_filter_transform_node.cpp:42
autoware::common::types::bool8_t
bool bool8_t
Definition: types.hpp:33
kalman_filter_wrapper.hpp
autoware::drivers::vehicle_interface::Odometry
autoware_auto_msgs::msg::VehicleOdometry Odometry
Definition: safety_state_machine.hpp:43
autoware
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
measurement.hpp
motion::motion_testing_nodes::TransformStamped
geometry_msgs::msg::TransformStamped TransformStamped
Definition: motion_testing_publisher.hpp:37
esrcf.hpp
This file defines a class for extended square root covariance filter.
visibility_control.hpp
autoware::common::types::float64_t
double float64_t
Definition: types.hpp:37
constant_acceleration.hpp
This file defines the constant velocity motion model.
autoware::prediction::state_estimation_nodes::StateEstimationNode
Definition: state_estimation_node.hpp:57