Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add conversion for particle scatter ratio field #791

Merged
merged 6 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/Conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ msgs::ParticleEmitter ignition::gazebo::convert(const sdf::ParticleEmitter &_in)
{
msgs::ParticleEmitter out;
out.set_name(_in.Name());
switch(_in.Type())
switch (_in.Type())
{
default:
case sdf::ParticleEmitterType::POINT:
Expand Down Expand Up @@ -1390,6 +1390,13 @@ msgs::ParticleEmitter ignition::gazebo::convert(const sdf::ParticleEmitter &_in)
header->add_value(_in.Topic());
}

// todo(anyone) Use particle_scatter_ratio in particle_emitter.proto from
// Fortress on.
auto header = out.mutable_header()->add_data();
header->set_key("particle_scatter_ratio");
std::string *value = header->add_value();
*value = std::to_string(_in.ScatterRatio());

return out;
}

Expand All @@ -1400,7 +1407,7 @@ sdf::ParticleEmitter ignition::gazebo::convert(const msgs::ParticleEmitter &_in)
{
sdf::ParticleEmitter out;
out.SetName(_in.name());
switch(_in.type())
switch (_in.type())
{
default:
case msgs::ParticleEmitter::POINT:
Expand Down Expand Up @@ -1449,6 +1456,10 @@ sdf::ParticleEmitter ignition::gazebo::convert(const msgs::ParticleEmitter &_in)
{
out.SetTopic(data.value(0));
}
else if (data.key() == "particle_scatter_ratio" && data.value_size() > 0)
{
out.SetScatterRatio(std::stof(data.value(0)));
}
}

return out;
Expand Down
6 changes: 6 additions & 0 deletions src/Conversions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ TEST(Conversions, ParticleEmitter)
emitter.SetColorRangeImage("range_image");
emitter.SetTopic("my_topic");
emitter.SetRawPose(math::Pose3d(1, 2, 3, 0, 0, 0));
emitter.SetScatterRatio(0.9f);

sdf::Material material;
sdf::Pbr pbr;
Expand Down Expand Up @@ -828,6 +829,10 @@ TEST(Conversions, ParticleEmitter)
EXPECT_EQ("topic", header.key());
EXPECT_EQ("my_topic", header.value(0));

auto headerScatterRatio = emitterMsg.header().data(1);
EXPECT_EQ("particle_scatter_ratio", headerScatterRatio.key());
EXPECT_FLOAT_EQ(0.9f, std::stof(headerScatterRatio.value(0)));

EXPECT_EQ(math::Pose3d(1, 2, 3, 0, 0, 0), msgs::Convert(emitterMsg.pose()));

auto pbrMsg = emitterMsg.material().pbr();
Expand All @@ -852,4 +857,5 @@ TEST(Conversions, ParticleEmitter)
EXPECT_EQ(emitter2.ColorRangeImage(), emitter.ColorRangeImage());
EXPECT_EQ(emitter2.Topic(), emitter.Topic());
EXPECT_EQ(emitter2.RawPose(), emitter.RawPose());
EXPECT_FLOAT_EQ(emitter2.ScatterRatio(), emitter.ScatterRatio());
}
1 change: 0 additions & 1 deletion src/systems/particle_emitter2/ParticleEmitter2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ void ParticleEmitter2::PreUpdate(const ignition::gazebo::UpdateInfo &_info,
components::ParticleEmitterCmd::typeId,
ComponentState::OneTimeChange);
}

}
this->dataPtr->userCmd.clear();
}
Expand Down
19 changes: 18 additions & 1 deletion test/integration/particle_emitter2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ TEST_F(ParticleEmitter2Test, SDFLoad)
const components::Name *_name,
const components::Pose *_pose) -> bool
{

if (_name->Data() == "smoke_emitter")
{
updateCustomChecked = true;
Expand Down Expand Up @@ -118,6 +117,24 @@ TEST_F(ParticleEmitter2Test, SDFLoad)
// will not be able to find a file that does not exist
EXPECT_EQ("/path/to/dummy_image.png",
_emitter->Data().color_range_image().data());

// particle scatter ratio is temporarily stored in header
bool hasParticleScatterRatio = false;
for (int i = 0; i < _emitter->Data().header().data_size(); ++i)
{
for (int j = 0;
j < _emitter->Data().header().data(i).value_size(); ++j)
{
if (_emitter->Data().header().data(i).key() ==
"particle_scatter_ratio")
{
EXPECT_DOUBLE_EQ(0.01, math::parseFloat(
_emitter->Data().header().data(i).value(0)));
hasParticleScatterRatio = true;
}
}
}
EXPECT_TRUE(hasParticleScatterRatio);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion test/integration/thermal_sensor_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ TEST_F(ThermalSensorTest,
// Run server
server.Run(true, 1, false);

// verify camera properties from sdf
// verify camera properties from sdf
unsigned int width = 320u;
unsigned int height = 240u;
EXPECT_EQ("thermal_camera_invalid", name);
Expand Down
1 change: 0 additions & 1 deletion test/integration/thermal_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ TEST_F(ThermalTest, IGN_UTILS_TEST_DISABLED_ON_MAC(ThermalSensorSystem))
maxTemp = info.max.Kelvin();
return true;
});

});
server.AddSystem(testSystem.systemPtr);

Expand Down
1 change: 1 addition & 0 deletions test/worlds/particle_emitter2.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<color_end>0 1 0</color_end>
<scale_rate>10</scale_rate>
<color_range_image>/path/to/dummy_image.png</color_range_image>
<particle_scatter_ratio>0.01</particle_scatter_ratio>
</particle_emitter>
</link>

Expand Down