From 81381f02e282e3c455c4cde9bc8136f16d67efdb Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Mon, 26 Apr 2021 15:11:39 -0700 Subject: [PATCH 1/3] add particle scatter ratio? Signed-off-by: Ian Chen --- include/sdf/ParticleEmitter.hh | 11 +++++++++++ sdf/1.7/particle_emitter.sdf | 10 ++++++++++ src/ParticleEmitter.cc | 23 +++++++++++++++++++++++ src/ParticleEmitter_TEST.cc | 4 ++++ test/integration/particle_emitter_dom.cc | 1 + test/sdf/world_complete.sdf | 1 + 6 files changed, 50 insertions(+) diff --git a/include/sdf/ParticleEmitter.hh b/include/sdf/ParticleEmitter.hh index 251b4ff60..8821ab2c7 100644 --- a/include/sdf/ParticleEmitter.hh +++ b/include/sdf/ParticleEmitter.hh @@ -276,6 +276,17 @@ namespace sdf /// \param[in] _topic The topic used to update the particle emitter. public: void SetTopic(const std::string &_topic); + /// \brief Get the particle scatter ratio. This is used to determine the + /// ratio of particles that will be detected by sensors. + /// \return Particle scatter ratio + /// \sa SetScatterRatio + public: float ScatterRatio() const; + + /// \brief Set the particle scatter ratio. This is used to determine the + /// ratio of particles that will be detected by sensors. + /// \param[in] _ratio Scatter raito. This value should be > 0. + public: void SetScatterRatio(float _ratio); + /// \brief Get the pose of the particle emitter. This is the pose of the /// emitter as specified in SDF /// ( ... ). diff --git a/sdf/1.7/particle_emitter.sdf b/sdf/1.7/particle_emitter.sdf index 428ed251e..e3243f8a7 100644 --- a/sdf/1.7/particle_emitter.sdf +++ b/sdf/1.7/particle_emitter.sdf @@ -104,6 +104,16 @@ + + + This is used to determine the ratio of particles that will be detected + by sensors. Increasing the ratio means there is a higher chance of + particles reflecting and interfering with depth sensing, making the + emitter appear more dense. Decreasing the ratio decreases making it + appear less dense. This value should be > 0. + + + diff --git a/src/ParticleEmitter.cc b/src/ParticleEmitter.cc index e343077e3..51bc120cd 100644 --- a/src/ParticleEmitter.cc +++ b/src/ParticleEmitter.cc @@ -96,6 +96,13 @@ class sdf::ParticleEmitterPrivate /// \brief Topic used to update particle emitter properties at runtime. public: std::string topic = ""; + /// \brief Particle scatter ratio. This is used to determine the ratio of + /// particles that will be detected by sensors. Increasing the ratio + /// means there is a higher chance of particles reflecting and interfering + /// with depth sensing, making the emitter appear more dense. Decreasing the + /// ratio decreases making it appear less dense. This value should be > 0. + public: float scatterRatio = 0.65f; + /// \brief Pose of the emitter public: ignition::math::Pose3d pose = ignition::math::Pose3d::Zero; @@ -136,6 +143,7 @@ ParticleEmitterPrivate::ParticleEmitterPrivate( colorEnd(_private.colorEnd), colorRangeImage(_private.colorRangeImage), topic(_private.topic), + scatterRatio(_private.scatterRatio), pose(_private.pose), poseRelativeTo(_private.poseRelativeTo), xmlParentName(_private.xmlParentName), @@ -272,6 +280,9 @@ Errors ParticleEmitter::Load(ElementPtr _sdf) this->dataPtr->topic = _sdf->Get( "topic", this->dataPtr->topic).first; + this->dataPtr->scatterRatio = _sdf->Get( + "scatter_ratio", this->dataPtr->scatterRatio).first; + if (_sdf->HasElement("material")) { this->dataPtr->material.reset(new sdf::Material()); @@ -487,6 +498,18 @@ void ParticleEmitter::SetTopic(const std::string &_topic) this->dataPtr->topic = _topic; } +///////////////////////////////////////////////// +void ParticleEmitter::SetScatterRatio(float _ratio) +{ + this->dataPtr->scatterRatio = _ratio; +} + +///////////////////////////////////////////////// +float ParticleEmitter::ScatterRatio() const +{ + return this->dataPtr->scatterRatio; +} + ///////////////////////////////////////////////// const ignition::math::Pose3d &ParticleEmitter::RawPose() const { diff --git a/src/ParticleEmitter_TEST.cc b/src/ParticleEmitter_TEST.cc index 8dc350de3..3cc03c85c 100644 --- a/src/ParticleEmitter_TEST.cc +++ b/src/ParticleEmitter_TEST.cc @@ -104,6 +104,10 @@ TEST(DOMParticleEmitter, Construction) emitter.SetTopic("/test/topic"); EXPECT_EQ("/test/topic", emitter.Topic()); + EXPECT_FLOAT_EQ(0.65f, emitter.ScatterRatio()); + emitter.SetScatterRatio(0.5f); + EXPECT_FLOAT_EQ(0.5f, emitter.ScatterRatio()); + EXPECT_EQ(ignition::math::Pose3d::Zero, emitter.RawPose()); emitter.SetRawPose(ignition::math::Pose3d(1, 2, 3, 0, 0, 1.5707)); EXPECT_EQ(ignition::math::Pose3d(1, 2, 3, 0, 0, 1.5707), emitter.RawPose()); diff --git a/test/integration/particle_emitter_dom.cc b/test/integration/particle_emitter_dom.cc index 6071ac184..4590a84cb 100644 --- a/test/integration/particle_emitter_dom.cc +++ b/test/integration/particle_emitter_dom.cc @@ -78,6 +78,7 @@ TEST(DOMWorld, LoadParticleEmitter) EXPECT_DOUBLE_EQ(0.2, linkEmitter->MaxVelocity()); EXPECT_DOUBLE_EQ(0.5, linkEmitter->ScaleRate()); EXPECT_DOUBLE_EQ(5, linkEmitter->Rate()); + EXPECT_FLOAT_EQ(0.2f, linkEmitter->ScatterRatio()); sdf::Material *mat = linkEmitter->Material(); ASSERT_NE(nullptr, mat); diff --git a/test/sdf/world_complete.sdf b/test/sdf/world_complete.sdf index 955b4268d..abe15f5ab 100644 --- a/test/sdf/world_complete.sdf +++ b/test/sdf/world_complete.sdf @@ -90,6 +90,7 @@ materials/textures/fogcolors.png + 0.2 From 2256147881bd7452a82d54c209b7aa0e53e14eed Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Mon, 26 Apr 2021 15:32:12 -0700 Subject: [PATCH 2/3] update field name Signed-off-by: Ian Chen --- sdf/1.7/particle_emitter.sdf | 2 +- src/ParticleEmitter.cc | 2 +- test/sdf/world_complete.sdf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdf/1.7/particle_emitter.sdf b/sdf/1.7/particle_emitter.sdf index e3243f8a7..fe705d04d 100644 --- a/sdf/1.7/particle_emitter.sdf +++ b/sdf/1.7/particle_emitter.sdf @@ -104,7 +104,7 @@ - + This is used to determine the ratio of particles that will be detected by sensors. Increasing the ratio means there is a higher chance of diff --git a/src/ParticleEmitter.cc b/src/ParticleEmitter.cc index 51bc120cd..3c820d055 100644 --- a/src/ParticleEmitter.cc +++ b/src/ParticleEmitter.cc @@ -281,7 +281,7 @@ Errors ParticleEmitter::Load(ElementPtr _sdf) "topic", this->dataPtr->topic).first; this->dataPtr->scatterRatio = _sdf->Get( - "scatter_ratio", this->dataPtr->scatterRatio).first; + "particle_scatter_ratio", this->dataPtr->scatterRatio).first; if (_sdf->HasElement("material")) { diff --git a/test/sdf/world_complete.sdf b/test/sdf/world_complete.sdf index abe15f5ab..211c7f148 100644 --- a/test/sdf/world_complete.sdf +++ b/test/sdf/world_complete.sdf @@ -90,7 +90,7 @@ materials/textures/fogcolors.png - 0.2 + 0.2 From b89e8b3482fa32909d503e0f522027f50c91ee26 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Wed, 5 May 2021 11:50:07 -0700 Subject: [PATCH 3/3] update doc Signed-off-by: Ian Chen --- include/sdf/ParticleEmitter.hh | 2 +- sdf/1.7/particle_emitter.sdf | 5 +++-- src/ParticleEmitter.cc | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/sdf/ParticleEmitter.hh b/include/sdf/ParticleEmitter.hh index 8821ab2c7..ae1dae9a8 100644 --- a/include/sdf/ParticleEmitter.hh +++ b/include/sdf/ParticleEmitter.hh @@ -284,7 +284,7 @@ namespace sdf /// \brief Set the particle scatter ratio. This is used to determine the /// ratio of particles that will be detected by sensors. - /// \param[in] _ratio Scatter raito. This value should be > 0. + /// \param[in] _ratio Scatter ratio. public: void SetScatterRatio(float _ratio); /// \brief Get the pose of the particle emitter. This is the pose of the diff --git a/sdf/1.7/particle_emitter.sdf b/sdf/1.7/particle_emitter.sdf index fe705d04d..d6a2fdf7e 100644 --- a/sdf/1.7/particle_emitter.sdf +++ b/sdf/1.7/particle_emitter.sdf @@ -109,8 +109,9 @@ This is used to determine the ratio of particles that will be detected by sensors. Increasing the ratio means there is a higher chance of particles reflecting and interfering with depth sensing, making the - emitter appear more dense. Decreasing the ratio decreases making it - appear less dense. This value should be > 0. + emitter appear more dense. Decreasing the ratio decreases the chance + of particles reflecting and interfering with depth sensing, making it + appear less dense. diff --git a/src/ParticleEmitter.cc b/src/ParticleEmitter.cc index 3c820d055..195bd09ae 100644 --- a/src/ParticleEmitter.cc +++ b/src/ParticleEmitter.cc @@ -99,8 +99,9 @@ class sdf::ParticleEmitterPrivate /// \brief Particle scatter ratio. This is used to determine the ratio of /// particles that will be detected by sensors. Increasing the ratio /// means there is a higher chance of particles reflecting and interfering - /// with depth sensing, making the emitter appear more dense. Decreasing the - /// ratio decreases making it appear less dense. This value should be > 0. + /// with depth sensing, making the emitter appear more dense. Decreasing + /// the ratio decreases the chance of particles reflecting and interfering + /// with depth sensing, making it appear less dense. public: float scatterRatio = 0.65f; /// \brief Pose of the emitter