Skip to content

Commit 19e9e93

Browse files
committed
Better fix for overwriting
Signed-off-by: Xiyu Oh <xiyu@openrobotics.org>
1 parent e8f7bf2 commit 19e9e93

File tree

2 files changed

+39
-47
lines changed

2 files changed

+39
-47
lines changed

crates/rmf_site_editor/src/sdf_loader.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,8 @@ fn load_model<'a, 'b>(
333333
if plugin.name == "slotcar".to_string()
334334
|| plugin.filename == "libslotcar.so".to_string()
335335
{
336-
// Use commands instead of direct access to world as we
337-
// want this to be queued up after robot data has been
338-
// inserted into model descriptions during loading
339336
world
340-
.commands()
341-
.entity(e)
337+
.entity_mut(e)
342338
.insert(DifferentialDrive::from(&plugin.elements))
343339
.insert(Battery::from(&plugin.elements))
344340
.insert(AmbientSystem::from(&plugin.elements))

crates/rmf_site_editor/src/site/slotcar.rs

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ impl Plugin for SlotcarSdfPlugin {
5151
fn insert_slotcar_components(
5252
mut commands: Commands,
5353
mut change_robot_property: EventWriter<Change<ModelProperty<Robot>>>,
54-
is_static: Query<&ModelProperty<IsStatic>, (With<ModelMarker>, With<Group>)>,
5554
robot_property_kinds: Query<
5655
// All 4 components will be present (see sdf_loader.rs)
5756
(
@@ -64,12 +63,15 @@ fn insert_slotcar_components(
6463
(Without<ModelMarker>, Without<Group>),
6564
>,
6665
robot_properties: Query<
66+
&IsStatic,
6767
(
68-
Option<&Mobility>,
69-
Option<&PowerSource>,
70-
Option<&PowerDissipation>,
68+
With<ModelMarker>,
69+
With<Group>,
70+
Without<Mobility>,
71+
Without<Collision>,
72+
Without<PowerSource>,
73+
Without<PowerDissipation>,
7174
),
72-
(With<ModelMarker>, With<Group>),
7375
>,
7476
model_descriptions: Query<&ModelProperty<Robot>, (With<ModelMarker>, With<Group>)>,
7577
model_instances: ModelPropertyQuery<Robot>,
@@ -101,13 +103,14 @@ fn insert_slotcar_components(
101103
// from the earlier system. For now we will process data from Battery/
102104
// DifferentialDrive/MechanicalSystem/AmbientSystem in a single system.
103105

104-
// Only allow overwriting RobotProperties that are not present
105-
let Ok((mobility, power_source, power_dissipation)) = robot_properties.get(desc)
106-
else {
106+
let Ok(is_static) = robot_properties.get(desc) else {
107+
// This description entity has an existing RobotProperty,
108+
// do not allow overwriting
107109
continue;
108110
};
109111

110-
if mobility.is_none() && is_static.get(desc).is_ok_and(|is| !is.0 .0) {
112+
// Only insert Mobility if robot is not static
113+
if !is_static.0 {
111114
if let Ok(mobility_value) = serialize_robot_property_from_kind::<
112115
Mobility,
113116
DifferentialDrive,
@@ -117,45 +120,38 @@ fn insert_slotcar_components(
117120
}
118121
}
119122

120-
if power_source.is_none() {
121-
if let Ok(power_source_value) =
122-
serialize_robot_property_from_kind::<PowerSource, Battery>(battery.clone())
123-
{
124-
robot
125-
.properties
126-
.insert(PowerSource::label(), power_source_value);
127-
}
123+
if let Ok(power_source_value) =
124+
serialize_robot_property_from_kind::<PowerSource, Battery>(battery.clone())
125+
{
126+
robot
127+
.properties
128+
.insert(PowerSource::label(), power_source_value);
128129
}
129130

130-
if power_dissipation.is_none() {
131-
let mut power_dissipation_config = Map::new();
132-
if let Some(power_dissipation_map) = power_dissipation_config
133-
.entry("config")
134-
.or_insert(Value::Object(Map::new()))
135-
.as_object_mut()
131+
let mut power_dissipation_config = Map::new();
132+
if let Some(power_dissipation_map) = power_dissipation_config
133+
.entry("config")
134+
.or_insert(Value::Object(Map::new()))
135+
.as_object_mut()
136+
{
137+
if let Ok(mechanical_system_value) =
138+
serialize_robot_property_kind::<MechanicalSystem>(mechanical_system.clone())
136139
{
137-
if let Ok(mechanical_system_value) =
138-
serialize_robot_property_kind::<MechanicalSystem>(
139-
mechanical_system.clone(),
140-
)
141-
{
142-
power_dissipation_map
143-
.insert(MechanicalSystem::label(), mechanical_system_value);
144-
}
145-
if let Ok(ambient_system_value) =
146-
serialize_robot_property_kind::<AmbientSystem>(ambient_system.clone())
147-
{
148-
power_dissipation_map
149-
.insert(AmbientSystem::label(), ambient_system_value);
150-
}
140+
power_dissipation_map
141+
.insert(MechanicalSystem::label(), mechanical_system_value);
151142
}
152-
if !power_dissipation_config.is_empty() {
153-
robot.properties.insert(
154-
PowerDissipation::label(),
155-
Value::Object(power_dissipation_config),
156-
);
143+
if let Ok(ambient_system_value) =
144+
serialize_robot_property_kind::<AmbientSystem>(ambient_system.clone())
145+
{
146+
power_dissipation_map.insert(AmbientSystem::label(), ambient_system_value);
157147
}
158148
}
149+
if !power_dissipation_config.is_empty() {
150+
robot.properties.insert(
151+
PowerDissipation::label(),
152+
Value::Object(power_dissipation_config),
153+
);
154+
}
159155

160156
change_robot_property.write(Change::new(ModelProperty(robot), desc));
161157
}

0 commit comments

Comments
 (0)