Skip to content

Commit 9c2d19b

Browse files
Fix field mark association detected objects type (#2786)
* Fix field mark association detected objects type * FIx TimeWrapper in robot viewer * Decomplexify type
1 parent 22fa56e commit 9c2d19b

5 files changed

Lines changed: 31 additions & 16 deletions

File tree

crates/nodes/field_mark_association/src/frame_processing.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ use crate::{
2121

2222
const MAX_CAMERA_MATRIX_TIME_DISTANCE: Duration = Duration::from_millis(100);
2323

24+
type DetectedObjects = TimeWrapper<Vec<Object<RobocupObjectLabel>>>;
25+
type DetectedObjectsItem<'a> = FutureItem<'a, (Option<DetectedObjects>,)>;
26+
2427
pub(crate) struct DetectionProcessingContext<'a> {
2528
pub(crate) parameters: &'a NodeParameters<FieldMarkAssociationParameters>,
2629
pub(crate) camera_matrix_cache: &'a Cache<TimeWrapper<CameraMatrix>>,
@@ -50,7 +53,7 @@ struct ProcessedDetectionFrame {
5053
}
5154

5255
pub(crate) async fn process_detected_objects(
53-
item: FutureItem<'_, (Option<Vec<Object<RobocupObjectLabel>>>,)>,
56+
item: DetectedObjectsItem<'_>,
5457
ctx: DetectionProcessingContext<'_>,
5558
) -> Result<()> {
5659
for (image_time, (objects,)) in item.persistent {
@@ -98,7 +101,7 @@ pub(crate) async fn process_detected_objects(
98101

99102
fn prepare_detection_frame(
100103
image_time: Time,
101-
objects: Option<Vec<Object<RobocupObjectLabel>>>,
104+
objects: Option<DetectedObjects>,
102105
ctx: &DetectionProcessingContext<'_>,
103106
) -> Option<PreparedDetectionFrame> {
104107
let camera_matrix = ctx.camera_matrix_cache.get_nearest(image_time)?;
@@ -113,7 +116,7 @@ fn prepare_detection_frame(
113116

114117
Some(PreparedDetectionFrame {
115118
image_time,
116-
objects: objects.unwrap_or_default(),
119+
objects: objects.map(|item| item.inner).unwrap_or_default(),
117120
robot_to_camera: robot_to_camera(&camera_matrix),
118121
camera_matrix,
119122
field_dimensions: *field_dimensions.as_ref(),

crates/nodes/field_mark_association/src/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub async fn run(ctx: Arc<Context>) -> Result<()> {
8383

8484
let mut detected_objects = node
8585
.create_future_map_builder()
86-
.create_future_subscriber::<Vec<Object<RobocupObjectLabel>>>(
86+
.create_future_subscriber::<TimeWrapper<Vec<Object<RobocupObjectLabel>>>>(
8787
"detected_objects",
8888
DETECTED_OBJECTS_SAFETY_LAG,
8989
)

tools/robot_viewer/src/state/alignment.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ mod tests {
9898
use linear_algebra::Isometry3;
9999
use projection::camera_matrix::CameraMatrix;
100100
use ros_z::time::Time;
101-
use types::visual_localization::VisualLocalizationFrame as FieldMarkAssociations;
101+
use types::{
102+
object_detection::{Object, RobocupObjectLabel},
103+
visual_localization::VisualLocalizationFrame as FieldMarkAssociations,
104+
};
102105

103106
use super::*;
104107
use crate::state::{MAX_NEAREST_SAMPLE_DISTANCE, ViewerState};
@@ -111,6 +114,13 @@ mod tests {
111114
}
112115
}
113116

117+
fn empty_detected_objects(time: Time) -> TimeWrapper<Vec<Object<RobocupObjectLabel>>> {
118+
TimeWrapper {
119+
time,
120+
inner: Vec::new(),
121+
}
122+
}
123+
114124
#[test]
115125
fn high_rate_alignment_streams_retain_delayed_render_samples() {
116126
let mut state = ViewerState::default();
@@ -149,7 +159,7 @@ mod tests {
149159
state.push_camera_frame(association_time, CameraFrame::default());
150160
state.push_camera_frame(detection_time, CameraFrame::default());
151161
state.push_field_mark_associations(association_time, empty_associations());
152-
state.push_detected_objects(detection_time, Vec::new());
162+
state.push_detected_objects(empty_detected_objects(detection_time));
153163

154164
let aligned = state.aligned_snapshot();
155165

@@ -235,7 +245,7 @@ mod tests {
235245
state.push_camera_frame(displayed_time, CameraFrame::default());
236246
assert_eq!(state.aligned_snapshot().anchor_time, Some(displayed_time));
237247

238-
state.push_detected_objects(displayed_time, Vec::new());
248+
state.push_detected_objects(empty_detected_objects(displayed_time));
239249
state.push_camera_frame(latest_camera_time, CameraFrame::default());
240250
let aligned = state.aligned_snapshot();
241251

@@ -255,7 +265,7 @@ mod tests {
255265

256266
state.objects_status.update_publishers(1);
257267
state.push_camera_frame(first_time, CameraFrame::default());
258-
state.push_detected_objects(first_time, Vec::new());
268+
state.push_detected_objects(empty_detected_objects(first_time));
259269
assert_eq!(state.aligned_snapshot().anchor_time, Some(first_time));
260270

261271
state.push_camera_frame(second_time, CameraFrame::default());
@@ -264,7 +274,7 @@ mod tests {
264274
assert_eq!(aligned.anchor_time, Some(first_time));
265275
assert!(aligned.detected_objects.is_some());
266276

267-
state.push_detected_objects(second_time, Vec::new());
277+
state.push_detected_objects(empty_detected_objects(second_time));
268278
let aligned = state.aligned_snapshot();
269279

270280
assert_eq!(aligned.anchor_time, Some(second_time));

tools/robot_viewer/src/state/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,9 @@ impl ViewerState {
101101

102102
pub(crate) fn push_detected_objects(
103103
&mut self,
104-
time: Time,
105-
value: Vec<Object<RobocupObjectLabel>>,
104+
value: TimeWrapper<Vec<Object<RobocupObjectLabel>>>,
106105
) {
107-
self.detected_objects.insert(time, value);
106+
self.detected_objects.insert(value.time, value.inner);
108107
}
109108

110109
pub(crate) fn push_field_mark_associations(

tools/robot_viewer/src/subscriptions/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use ros_z_debug::{TopicObserver, TopicObserverOptions};
77
use ros_z_streams::{CreateFutureQueue, QueueEvent};
88
use ros2::sensor_msgs::image::Image as RosImage;
99
use tokio::runtime::Runtime;
10-
use types::object_detection::{Object, RobocupObjectLabel};
10+
use types::{
11+
object_detection::{Object, RobocupObjectLabel},
12+
time_wrapper::TimeWrapper,
13+
};
1114

1215
use crate::{
1316
cli::Arguments,
@@ -75,7 +78,7 @@ async fn run(arguments: Arguments, state: SharedState, egui_context: EguiContext
7578
.build()
7679
.await?;
7780
let mut objects = node
78-
.create_future_subscriber::<Vec<Object<RobocupObjectLabel>>>(
81+
.create_future_subscriber::<TimeWrapper<Vec<Object<RobocupObjectLabel>>>>(
7982
DETECTED_OBJECTS_TOPIC,
8083
DETECTED_OBJECTS_SAFETY_LAG,
8184
)
@@ -119,8 +122,8 @@ async fn run(arguments: Arguments, state: SharedState, egui_context: EguiContext
119122
}),
120123
},
121124
message = objects.recv() => match message {
122-
Ok(QueueEvent::Data(time, message)) => update_state(&state, &egui_context, |state| {
123-
state.push_detected_objects(time, message);
125+
Ok(QueueEvent::Data(_, message)) => update_state(&state, &egui_context, |state| {
126+
state.push_detected_objects(message);
124127
state.objects_status.mark_live(objects.publisher_count());
125128
}),
126129
Ok(QueueEvent::Announcement) => {}

0 commit comments

Comments
 (0)