Skip to content

Commit 34a3777

Browse files
committed
feat: remove expected interval
1 parent 840ce95 commit 34a3777

File tree

4 files changed

+56
-55
lines changed

4 files changed

+56
-55
lines changed

perception/multi_object_tracker/config/input_channels.param.yaml

+11-12
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,79 @@
33
input_channels:
44
detected_objects:
55
topic: "/perception/object_recognition/detection/objects"
6-
expected_interval: 0.1
6+
can_spawn_new_tracker: true
77
optional:
88
name: "detected_objects"
99
short_name: "all"
1010
# LIDAR - rule-based
1111
lidar_clustering:
1212
topic: "/perception/object_recognition/detection/clustering/objects"
13-
expected_interval: 0.1
13+
can_spawn_new_tracker: true
1414
optional:
1515
name: "clustering"
1616
short_name: "Lcl"
1717
# LIDAR - DNN
1818
lidar_centerpoint:
1919
topic: "/perception/object_recognition/detection/centerpoint/objects"
20-
expected_interval: 0.1
20+
can_spawn_new_tracker: true
2121
optional:
2222
name: "centerpoint"
2323
short_name: "Lcp"
2424
lidar_centerpoint_validated:
2525
topic: "/perception/object_recognition/detection/centerpoint/validation/objects"
26-
expected_interval: 0.1
26+
can_spawn_new_tracker: true
2727
optional:
2828
name: "centerpoint"
2929
short_name: "Lcp"
3030
lidar_apollo:
3131
topic: "/perception/object_recognition/detection/apollo/objects"
32-
expected_interval: 0.1
32+
can_spawn_new_tracker: true
3333
optional:
3434
name: "apollo"
3535
short_name: "Lap"
3636
lidar_apollo_validated:
3737
topic: "/perception/object_recognition/detection/apollo/validation/objects"
38-
expected_interval: 0.1
38+
can_spawn_new_tracker: true
3939
optional:
4040
name: "apollo"
4141
short_name: "Lap"
4242
# LIDAR-CAMERA - DNN
4343
# cspell:ignore lidar_pointpainitng pointpainting
4444
lidar_pointpainitng:
4545
topic: "/perception/object_recognition/detection/pointpainting/objects"
46-
expected_interval: 0.1
46+
can_spawn_new_tracker: true
4747
optional:
4848
name: "pointpainting"
4949
short_name: "Lpp"
5050
lidar_pointpainting_validated:
5151
topic: "/perception/object_recognition/detection/pointpainting/validation/objects"
52-
expected_interval: 0.1
5352
optional:
5453
name: "pointpainting"
5554
short_name: "Lpp"
5655
# CAMERA-LIDAR
5756
camera_lidar_fusion:
5857
topic: "/perception/object_recognition/detection/clustering/camera_lidar_fusion/objects"
59-
expected_interval: 0.1
58+
can_spawn_new_tracker: false
6059
optional:
6160
name: "camera_lidar_fusion"
6261
short_name: "CLf"
6362
# CAMERA-LIDAR+TRACKER
6463
detection_by_tracker:
6564
topic: "/perception/object_recognition/detection/detection_by_tracker/objects"
66-
expected_interval: 0.1
65+
can_spawn_new_tracker: false
6766
optional:
6867
name: "detection_by_tracker"
6968
short_name: "dbT"
7069
# RADAR
7170
radar:
7271
topic: "/sensing/radar/detected_objects"
73-
expected_interval: 0.0333
72+
can_spawn_new_tracker: true
7473
optional:
7574
name: "radar"
7675
short_name: "R"
7776
radar_far:
7877
topic: "/perception/object_recognition/detection/radar/far_objects"
79-
expected_interval: 0.0333
78+
can_spawn_new_tracker: true
8079
optional:
8180
name: "radar_far"
8281
short_name: "Rf"

perception/multi_object_tracker/include/multi_object_tracker/processor/input_manager.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ struct InputChannel
3636
std::string input_topic; // topic name of the detection, e.g. "/detection/lidar"
3737
std::string long_name = "Detected Object"; // full name of the detection
3838
std::string short_name = "DET"; // abbreviation of the name
39-
double expected_interval = 0.1; // [s]
40-
double expected_latency = 0.2; // [s]
39+
bool is_spawn_enabled = true; // enable spawn of the object
4140
};
4241

4342
class InputStream
@@ -56,7 +55,7 @@ class InputStream
5655
void onMessage(const autoware_auto_perception_msgs::msg::DetectedObjects::ConstSharedPtr msg);
5756
void updateTimingStatus(const rclcpp::Time & now, const rclcpp::Time & objects_time);
5857

59-
bool isTimeInitialized() const { return is_time_initialized_; }
58+
bool isTimeInitialized() const { return initial_count_ > 0; }
6059
uint getIndex() const { return index_; }
6160
void getObjectsOlderThan(
6261
const rclcpp::Time & object_latest_time, const rclcpp::Time & object_oldest_time,
@@ -99,7 +98,8 @@ class InputStream
9998

10099
std::function<void(const uint &)> func_trigger_;
101100

102-
bool is_time_initialized_{false};
101+
// bool is_time_initialized_{false};
102+
int initial_count_{0};
103103
double expected_interval_;
104104
double latency_mean_;
105105
double latency_var_;

perception/multi_object_tracker/src/multi_object_tracker_core.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ MultiObjectTracker::MultiObjectTracker(const rclcpp::NodeOptions & node_options)
9292
std::vector<std::string> input_topic_names;
9393
std::vector<std::string> input_names_long;
9494
std::vector<std::string> input_names_short;
95-
std::vector<double> input_expected_intervals;
95+
std::vector<bool> input_is_spawn_enabled;
9696

9797
if (selected_input_channels.empty()) {
9898
RCLCPP_ERROR(this->get_logger(), "No input topics are specified.");
@@ -106,10 +106,9 @@ MultiObjectTracker::MultiObjectTracker(const rclcpp::NodeOptions & node_options)
106106
input_topic_names.push_back(input_topic_name);
107107

108108
// required parameter, but can set a default value
109-
const double default_expected_interval = 0.1; // [s]
110-
const double expected_interval = declare_parameter<double>(
111-
"input_channels." + selected_input_channel + ".expected_interval", default_expected_interval);
112-
input_expected_intervals.push_back(expected_interval);
109+
const bool spawn_enabled = declare_parameter<bool>(
110+
"input_channels." + selected_input_channel + ".can_spawn_new_tracker", true);
111+
input_is_spawn_enabled.push_back(spawn_enabled);
113112

114113
// optional parameters
115114
const std::string default_name = selected_input_channel;
@@ -130,7 +129,7 @@ MultiObjectTracker::MultiObjectTracker(const rclcpp::NodeOptions & node_options)
130129
input_channels_[i].input_topic = input_topic_names[i];
131130
input_channels_[i].long_name = input_names_long[i];
132131
input_channels_[i].short_name = input_names_short[i];
133-
input_channels_[i].expected_interval = input_expected_intervals[i];
132+
input_channels_[i].is_spawn_enabled = input_is_spawn_enabled[i];
134133
}
135134

136135
// Initialize input manager

perception/multi_object_tracker/src/processor/input_manager.cpp

+36-33
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ void InputStream::init(const InputChannel & input_channel)
3131
input_topic_ = input_channel.input_topic;
3232
long_name_ = input_channel.long_name;
3333
short_name_ = input_channel.short_name;
34-
expected_interval_ = input_channel.expected_interval; // [s]
3534

3635
// Initialize queue
3736
objects_que_.clear();
3837

3938
// Initialize latency statistics
40-
latency_mean_ = input_channel.expected_latency; // [s]
39+
latency_mean_ = 0.2; // [s] (initial value)
4140
latency_var_ = 0.0;
42-
interval_mean_ = expected_interval_; // [s] (initial value)
41+
interval_mean_ = 0.0; // [s] (initial value)
4342
interval_var_ = 0.0;
4443

4544
latest_measurement_time_ = node_.now();
@@ -49,7 +48,7 @@ void InputStream::init(const InputChannel & input_channel)
4948
bool InputStream::getTimestamps(
5049
rclcpp::Time & latest_measurement_time, rclcpp::Time & latest_message_time) const
5150
{
52-
if (!is_time_initialized_) {
51+
if (!isTimeInitialized()) {
5352
return false;
5453
}
5554
latest_measurement_time = latest_measurement_time_;
@@ -79,35 +78,50 @@ void InputStream::onMessage(
7978

8079
void InputStream::updateTimingStatus(const rclcpp::Time & now, const rclcpp::Time & objects_time)
8180
{
82-
// Filter parameters
83-
constexpr double gain = 0.05;
81+
// Update latency statistics
82+
// skip initial messages for the latency statistics
83+
if (initial_count_ > 4) {
84+
const double latency = (now - objects_time).seconds();
85+
if (initial_count_ < 16) {
86+
// set higher gain for the initial messages
87+
constexpr double initial_gain = 0.5;
88+
latency_mean_ = (1.0 - initial_gain) * latency_mean_ + initial_gain * latency;
89+
} else {
90+
constexpr double gain = 0.05;
91+
latency_mean_ = (1.0 - gain) * latency_mean_ + gain * latency;
92+
const double latency_delta = latency - latency_mean_;
93+
latency_var_ = (1.0 - gain) * latency_var_ + gain * latency_delta * latency_delta;
94+
}
95+
}
8496

8597
// Calculate interval, Update interval statistics
86-
if (is_time_initialized_) {
98+
if (initial_count_ > 4) {
8799
const double interval = (now - latest_message_time_).seconds();
88-
// Check if the interval is regular
89-
// The interval is considered regular if it is within 0.5 and 1.5 times the expected interval
90-
bool is_interval_regular =
91-
interval > 0.5 * expected_interval_ && interval < 1.5 * expected_interval_;
92-
93-
if (is_interval_regular) {
94-
interval_mean_ = (1.0 - gain) * interval_mean_ + gain * interval;
95-
const double interval_delta = interval - interval_mean_;
96-
interval_var_ = (1.0 - gain) * interval_var_ + gain * interval_delta * interval_delta;
100+
if (initial_count_ < 24) {
101+
// Initialization
102+
constexpr double initial_gain = 0.5;
103+
interval_mean_ = (1.0 - initial_gain) * interval_mean_ + initial_gain * interval;
104+
} else {
105+
// The interval is considered regular if it is within 0.5 and 1.5 times the mean interval
106+
bool update_statistics = interval > 0.5 * interval_mean_ && interval < 1.5 * interval_mean_;
107+
if (update_statistics) {
108+
constexpr double gain = 0.05;
109+
interval_mean_ = (1.0 - gain) * interval_mean_ + gain * interval;
110+
const double interval_delta = interval - interval_mean_;
111+
interval_var_ = (1.0 - gain) * interval_var_ + gain * interval_delta * interval_delta;
112+
}
97113
}
98114
}
99115

100116
// Update time
101117
latest_message_time_ = now;
102118
latest_measurement_time_ =
103119
latest_measurement_time_ < objects_time ? objects_time : latest_measurement_time_;
104-
if (!is_time_initialized_) is_time_initialized_ = true;
105120

106-
// Update latency statistics
107-
const double latency = (latest_message_time_ - objects_time).seconds();
108-
latency_mean_ = (1.0 - gain) * latency_mean_ + gain * latency;
109-
const double latency_delta = latency - latency_mean_;
110-
latency_var_ = (1.0 - gain) * latency_var_ + gain * latency_delta * latency_delta;
121+
// Update the initial count, count only first 32 messages
122+
if (initial_count_ < 32) {
123+
initial_count_++;
124+
}
111125
}
112126

113127
void InputStream::getObjectsOlderThan(
@@ -195,17 +209,6 @@ void InputManager::getObjectTimeInterval(
195209
if (input_streams_.at(target_stream_idx_)->isTimeInitialized()) {
196210
rclcpp::Time latest_measurement_time =
197211
input_streams_.at(target_stream_idx_)->getLatestMeasurementTime();
198-
// if the object_latest_time is newer than the next expected message time, set it older
199-
// than the next expected message time
200-
rclcpp::Time next_expected_message_time =
201-
latest_measurement_time +
202-
rclcpp::Duration::from_seconds(
203-
target_stream_interval_ -
204-
1.0 *
205-
target_stream_interval_std_); // next expected message time with 1 sigma safety margin
206-
object_latest_time = object_latest_time > next_expected_message_time
207-
? next_expected_message_time
208-
: object_latest_time;
209212

210213
// if the object_latest_time is older than the latest measurement time, set it as the latest
211214
// object time

0 commit comments

Comments
 (0)