Autoware.Auto
track_creator.hpp
Go to the documentation of this file.
1 // Copyright 2021 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 //
15 // Co-developed by Tier IV, Inc. and Apex.AI, Inc.
16 
17 #ifndef TRACKING__TRACK_CREATOR_HPP_
18 #define TRACKING__TRACK_CREATOR_HPP_
19 
20 #include <autoware_auto_perception_msgs/msg/classified_roi_array.hpp>
21 #include <autoware_auto_perception_msgs/msg/detected_objects.hpp>
22 #include <common/types.hpp>
23 #include <message_filters/cache.h>
24 #include <tf2/buffer_core.h>
30 
31 #include <memory>
32 #include <string>
33 #include <unordered_map>
34 #include <utility>
35 #include <vector>
36 
37 namespace autoware
38 {
39 namespace perception
40 {
41 namespace tracking
42 {
43 
45 struct TRACKING_PUBLIC VisionPolicyConfig
46 {
47  // Struct defining parameters for vision association
49  // Maximum allowed difference in the timestamp of the two messages being associated
50  std::chrono::milliseconds max_vision_lidar_timestamp_diff{20};
51 };
52 
54 struct TRACKING_PUBLIC TrackCreationResult
55 {
57  std::vector<TrackedObject> tracks;
61  builtin_interfaces::msg::Time related_rois_stamp;
62 };
63 
64 // Class implementing LidarOnly track creation policy
65 class TRACKING_PUBLIC LidarOnlyPolicy
66 {
67 public:
69  const common::types::float64_t default_variance,
70  const common::types::float64_t noise_variance,
71  const tf2::BufferCore & tf_buffer);
72 
73  TrackCreationResult create(const ObjectsWithAssociations & objects) const;
74 
75 private:
76  common::types::float64_t m_default_variance;
77  common::types::float64_t m_noise_variance;
78  const tf2::BufferCore & m_tf_buffer;
79 };
80 
82 class TRACKING_PUBLIC LidarClusterIfVisionPolicy
83 {
84 public:
86  const VisionPolicyConfig & cfg,
87  const common::types::float64_t default_variance,
88  const common::types::float64_t noise_variance,
89  const tf2::BufferCore & tf_buffer);
90 
91  TrackCreationResult create(const ObjectsWithAssociations & objects) const;
92 
93  void add_objects(
94  const autoware_auto_perception_msgs::msg::ClassifiedRoiArray & vision_rois,
95  const AssociatorResult & associator_result);
96 
97 private:
98  using VisionCache =
99  message_filters::Cache<autoware_auto_perception_msgs::msg::ClassifiedRoiArray>;
100 
101  void create_using_cache(
102  const ObjectsWithAssociations & objects,
103  const VisionCache & vision_cache,
104  TrackCreationResult & result) const;
105 
106  static constexpr std::uint32_t kVisionCacheSize = 20U;
107 
108  common::types::float64_t m_default_variance;
109  common::types::float64_t m_noise_variance;
110  const tf2::BufferCore & m_tf_buffer;
111 
112  VisionPolicyConfig m_cfg;
113  GreedyRoiAssociator m_associator;
114 
115  std::unordered_map<std::string, VisionCache> m_vision_cache_map;
116 };
117 
119 template<class PolicyT>
120 class TRACKING_PUBLIC TrackCreator
121 {
122 public:
124  explicit TrackCreator(std::shared_ptr<PolicyT> policy)
125  : m_policy{policy} {}
130  {
131  return m_policy->create(objects);
132  }
133 
137  template<typename ... Ts>
138  inline auto add_objects(Ts && ... args)
139  {
140  return m_policy->add_objects(std::forward<Ts>(args)...);
141  }
142 
143 private:
144  std::shared_ptr<PolicyT> m_policy{};
145 };
146 
147 } // namespace tracking
148 } // namespace perception
149 } // namespace autoware
150 
151 #endif // TRACKING__TRACK_CREATOR_HPP_
autoware::perception::tracking::Associations
std::vector< Association > Associations
Definition: objects_with_associations.hpp:69
autoware::perception::tracking::GreedyRoiAssociator
Class to associate the detections and tracks in euclidean space to ROIs in image space on a first-com...
Definition: greedy_roi_associator.hpp:67
types.hpp
This file includes common type definition.
autoware::perception::tracking::TrackCreationResult::related_rois_stamp
builtin_interfaces::msg::Time related_rois_stamp
Timestamps of msgs from each of the ClassifiedROIArray topics used for track creation.
Definition: track_creator.hpp:61
greedy_roi_associator.hpp
visibility_control.hpp
autoware::perception::tracking::Associated
This class describes an associated object array of a certain message type.
Definition: objects_with_associations.hpp:80
autoware::perception::tracking::TrackCreator::TrackCreator
TrackCreator(std::shared_ptr< PolicyT > policy)
Constructor.
Definition: track_creator.hpp:124
autoware::perception::tracking::VisionPolicyConfig
Struct defining configuration parameters for LidarIfVision policy.
Definition: track_creator.hpp:45
autoware::perception::tracking::VisionPolicyConfig::associator_cfg
GreedyRoiAssociatorConfig associator_cfg
Definition: track_creator.hpp:48
tracker_types.hpp
autoware
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
autoware::perception::tracking::AssociatorResult
Struct to store results after the assignment is done.
Definition: tracker_types.hpp:40
autoware::perception::tracking::TrackCreationResult::tracks
std::vector< TrackedObject > tracks
List of newly created tracks.
Definition: track_creator.hpp:57
autoware::perception::tracking::TrackCreationResult::associations
Associations associations
List of associations that matches an association to each track.
Definition: track_creator.hpp:59
autoware::perception::tracking::LidarClusterIfVisionPolicy
Class implementing LidarIfVision track creation policy.
Definition: track_creator.hpp:82
autoware::perception::tracking::TrackCreator::add_objects
auto add_objects(Ts &&... args)
Definition: track_creator.hpp:138
autoware::perception::tracking::GreedyRoiAssociatorConfig
Definition: greedy_roi_associator.hpp:59
autoware::perception::tracking::TrackCreator::create_tracks
TrackCreationResult create_tracks(const ObjectsWithAssociations &objects)
Create new tracks based on the policy and unassociated detections. Call the appropriate add_unassigne...
Definition: track_creator.hpp:129
objects_with_associations.hpp
tracked_object.hpp
This file defines the multi_object_tracking class.
autoware::perception::tracking::TrackCreationResult
Struct to be used as the return value from track creation process.
Definition: track_creator.hpp:54
autoware::common::types::float64_t
double float64_t
Definition: types.hpp:47
autoware::perception::tracking::TrackCreator
Class to create new tracks based on a predefined policy and unassociated detections.
Definition: track_creator.hpp:120
autoware::perception::tracking::LidarOnlyPolicy
Definition: track_creator.hpp:65