Skip to content

Commit ebc4bb0

Browse files
committed
Clean up a bit
1 parent 5882a9b commit ebc4bb0

File tree

1 file changed

+59
-77
lines changed

1 file changed

+59
-77
lines changed

crates/store/re_data_loader/src/loader_urdf.rs

Lines changed: 59 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
use ahash::{HashMap, HashMapExt as _, HashSet, HashSetExt as _};
77
use anyhow::{Context as _, bail};
88
use itertools::Itertools as _;
9-
use urdf_rs::{Geometry, Joint, Link, LinkName, Material, Robot, Vec3, Vec4};
9+
use urdf_rs::{Geometry, Joint, Link, Material, Robot, Vec3, Vec4};
1010

1111
use re_chunk::{ChunkBuilder, ChunkId, EntityPath, RowId, TimePoint};
1212
use re_log_types::{EntityPathPart, StoreId};
@@ -282,7 +282,7 @@ fn log_robot(
282282
.map(|prefix| prefix / EntityPath::from_single_string(urdf_tree.name.clone()))
283283
.unwrap_or_else(|| EntityPath::from_single_string(urdf_tree.name.clone()));
284284

285-
// Log the robot's root coordinate frame_id.
285+
// The robot's root coordinate frame_id.
286286
send_archetype(
287287
tx,
288288
store_id,
@@ -379,8 +379,8 @@ fn log_joint(
379379
joint_path.clone(),
380380
origin,
381381
timepoint,
382-
Some(parent),
383-
Some(child),
382+
parent.link.clone(),
383+
child.link.clone(),
384384
)?;
385385

386386
log_debug_format(
@@ -432,21 +432,17 @@ fn log_joint(
432432

433433
fn transform_from_pose(
434434
origin: &urdf_rs::Pose,
435-
parent: Option<&LinkName>,
436-
child: Option<&LinkName>,
435+
parent_frame: String,
436+
child_frame: String,
437437
) -> Transform3D {
438438
let urdf_rs::Pose { xyz, rpy } = origin;
439439
let translation = [xyz[0] as f32, xyz[1] as f32, xyz[2] as f32];
440440
let quaternion = quat_xyzw_from_roll_pitch_yaw(rpy[0] as f32, rpy[1] as f32, rpy[2] as f32);
441-
let transform = Transform3D::update_fields()
441+
Transform3D::update_fields()
442442
.with_translation(translation)
443-
.with_quaternion(quaternion);
444-
if let (Some(parent), Some(child)) = (parent, child) {
445-
return transform
446-
.with_parent_frame(parent.link.clone())
447-
.with_child_frame(child.link.clone());
448-
}
449-
transform
443+
.with_quaternion(quaternion)
444+
.with_parent_frame(parent_frame)
445+
.with_child_frame(child_frame)
450446
}
451447

452448
fn send_transform(
@@ -455,31 +451,24 @@ fn send_transform(
455451
entity_path: EntityPath,
456452
origin: &urdf_rs::Pose,
457453
timepoint: &TimePoint,
458-
parent: Option<&LinkName>,
459-
child: Option<&LinkName>,
454+
parent_frame: String,
455+
child_frame: String,
460456
) -> anyhow::Result<()> {
461-
let urdf_rs::Pose { xyz, rpy } = origin;
462-
let is_identity = xyz.0 == [0.0, 0.0, 0.0] && rpy.0 == [0.0, 0.0, 0.0];
463-
464-
if is_identity {
465-
Ok(()) // avoid noise
466-
} else {
467-
// TODO: remove axis log this after debugging
468-
send_archetype(
469-
tx,
470-
store_id,
471-
entity_path.clone(),
472-
timepoint,
473-
&TransformAxes3D::update_fields().with_axis_length(0.1),
474-
)?;
475-
send_archetype(
476-
tx,
477-
store_id,
478-
entity_path,
479-
timepoint,
480-
&transform_from_pose(origin, parent, child),
481-
)
482-
}
457+
// TODO: remove axis log this after debugging
458+
send_archetype(
459+
tx,
460+
store_id,
461+
entity_path.clone(),
462+
timepoint,
463+
&TransformAxes3D::update_fields().with_axis_length(0.1),
464+
)?;
465+
send_archetype(
466+
tx,
467+
store_id,
468+
entity_path,
469+
timepoint,
470+
&transform_from_pose(origin, parent_frame, child_frame),
471+
)
483472
}
484473

485474
/// Log the given value using its `Debug` formatting.
@@ -540,19 +529,15 @@ fn log_link(
540529
&CoordinateFrame::update_fields().with_frame_id(link.name.clone()),
541530
)?;
542531

543-
let link_parent = urdf_tree
544-
.get_parent_of_link(&link.name)
545-
.map(|joint| &joint.child);
546-
547532
for (i, visual) in visual.iter().enumerate() {
548533
let urdf_rs::Visual {
549534
name,
550535
origin,
551536
geometry,
552537
material,
553538
} = visual;
554-
let name = name.clone().unwrap_or_else(|| format!("visual_{i}"));
555-
let vis_entity = link_entity / EntityPathPart::new(name.clone());
539+
let visual_name = name.clone().unwrap_or_else(|| format!("visual_{i}"));
540+
let visual_entity = link_entity / EntityPathPart::new(visual_name.clone());
556541

557542
// Prefer inline defined material properties if present, otherwise fall back to global material.
558543
let material = material.as_ref().and_then(|mat| {
@@ -563,32 +548,33 @@ fn log_link(
563548
}
564549
});
565550

566-
let link_child = urdf_rs::LinkName { link: name };
567-
// TODO
568551
send_transform(
569552
tx,
570553
store_id,
571-
vis_entity.clone(),
554+
visual_entity.clone(),
572555
origin,
573556
timepoint,
574-
link_parent,
575-
Some(&link_child),
557+
link.name.clone(),
558+
visual_name,
576559
)?;
577560

578-
if let Some(parent) = link_parent {
579-
let coordinate_frame =
580-
CoordinateFrame::update_fields().with_frame_id(parent.link.clone());
581-
send_archetype(
582-
tx,
583-
store_id,
584-
vis_entity.clone(),
585-
timepoint,
586-
&coordinate_frame,
587-
)?;
588-
}
561+
let coordinate_frame = CoordinateFrame::update_fields().with_frame_id(link.name.clone());
562+
send_archetype(
563+
tx,
564+
store_id,
565+
visual_entity.clone(),
566+
timepoint,
567+
&coordinate_frame,
568+
)?;
589569

590570
log_geometry(
591-
urdf_tree, tx, store_id, vis_entity, geometry, material, timepoint,
571+
urdf_tree,
572+
tx,
573+
store_id,
574+
visual_entity,
575+
geometry,
576+
material,
577+
timepoint,
592578
)?;
593579
}
594580

@@ -598,31 +584,27 @@ fn log_link(
598584
origin,
599585
geometry,
600586
} = collision;
601-
let name = name.clone().unwrap_or_else(|| format!("collision_{i}"));
602-
let collision_entity = link_entity / EntityPathPart::new(name.clone());
587+
let collision_name = name.clone().unwrap_or_else(|| format!("collision_{i}"));
588+
let collision_entity = link_entity / EntityPathPart::new(collision_name.clone());
603589

604-
let link_child = urdf_rs::LinkName { link: name };
605590
send_transform(
606591
tx,
607592
store_id,
608593
collision_entity.clone(),
609594
origin,
610595
timepoint,
611-
link_parent,
612-
Some(&link_child),
596+
link.name.clone(),
597+
collision_name,
613598
)?;
614599

615-
if let Some(parent) = link_parent {
616-
let coordinate_frame =
617-
CoordinateFrame::update_fields().with_frame_id(parent.link.clone());
618-
send_archetype(
619-
tx,
620-
store_id,
621-
collision_entity.clone(),
622-
timepoint,
623-
&coordinate_frame,
624-
)?;
625-
}
600+
let coordinate_frame = CoordinateFrame::update_fields().with_frame_id(link.name.clone());
601+
send_archetype(
602+
tx,
603+
store_id,
604+
collision_entity.clone(),
605+
timepoint,
606+
&coordinate_frame,
607+
)?;
626608

627609
log_geometry(
628610
urdf_tree,

0 commit comments

Comments
 (0)