@@ -104,7 +104,8 @@ namespace rviz_mesh_tools_plugins
104104MeshDisplay::MeshDisplay ()
105105: rviz_common::Display()
106106, m_ignoreMsgs(false )
107- , m_timeSinceLastUpdateApply(0.0 )
107+ , m_timeSinceLastUpdateApply(0 )
108+ , m_invUpdateFreq(std::chrono::nanoseconds(long (1e9 )) / 10 )
108109, m_meshQos(rclcpp::QoS(1 ).transient_local())
109110, m_vertexColorsQos(rclcpp::QoS(5 ))
110111, m_vertexCostsQos(rclcpp::QoS(5 ))
@@ -200,6 +201,15 @@ MeshDisplay::MeshDisplay()
200201 );
201202 m_vertexCostUpdateTopicQos = new rviz_common::properties::QosProfileProperty (m_vertexCostUpdateTopic, m_vertexCostUpdateQos);
202203
204+ m_vertexCostsRefreshRate = new rviz_common::properties::IntProperty (
205+ " Visualization Update Rate" , 10 ,
206+ " Sets the frequency (Hz) with which vertex cost updates are applied to the visual." ,
207+ m_displayType,
208+ SLOT (updateVertexCostUpdateFrequency ()),
209+ this ,
210+ 1 // Min value: This is 1 since we want at least one update per second
211+ );
212+
203213 m_selectVertexCostMap = new rviz_common::properties::EnumProperty (" Vertex Costs Type" , " -- None --" ,
204214 " Select the type of vertex cost map to be displayed. New types "
205215 " will appear here when a new message arrives." ,
@@ -320,16 +330,18 @@ void MeshDisplay::onInitialize()
320330
321331void MeshDisplay::update (float wall_dt, float ros_dt)
322332{
333+ // NOTE: In rolling the update function uses std::chrono::nanoseconds instead of float
323334 (void ) ros_dt;
324335
325- if (m_timeSinceLastUpdateApply >= 1.0e9 )
336+ // Determine current configured update freq
337+ if (m_timeSinceLastUpdateApply >= m_invUpdateFreq)
326338 {
327339 this ->applyCachedCostUpdates ();
328- m_timeSinceLastUpdateApply = 0.0 ;
340+ m_timeSinceLastUpdateApply = std::chrono::nanoseconds ( 0 ) ;
329341 }
330342 else
331343 {
332- m_timeSinceLastUpdateApply += wall_dt;
344+ m_timeSinceLastUpdateApply += std::chrono::nanoseconds ( long ( wall_dt)) ;
333345 }
334346
335347 this ->transformMesh ();
@@ -634,6 +646,8 @@ void MeshDisplay::updateDisplayType()
634646 m_textureServiceName->hide ();
635647 m_costColorType->hide ();
636648 m_vertexCostsTopic->hide ();
649+ m_vertexCostUpdateTopic->hide ();
650+ m_vertexCostsRefreshRate->hide ();
637651 m_selectVertexCostMap->hide ();
638652 m_costUseCustomLimits->hide ();
639653 m_costLowerLimit->hide ();
@@ -669,11 +683,13 @@ void MeshDisplay::updateDisplayType()
669683 if (!m_ignoreMsgs)
670684 {
671685 m_vertexCostsTopic->show ();
686+ m_vertexCostUpdateTopic->show ();
672687 if (!m_costsMsgCache) // checks whether we are not subscribed yet, avoids resetting the subscription when something else changes in the display type
673688 {
674689 updateVertexCostsSubscription ();
675690 }
676691 }
692+ m_vertexCostsRefreshRate->show ();
677693 m_selectVertexCostMap->show ();
678694 m_costUseCustomLimits->show ();
679695 if (m_costUseCustomLimits->getBool ())
@@ -944,6 +960,33 @@ void MeshDisplay::updateCullingMode()
944960 emit signalCullingModeChanged (static_cast <Ogre::CullingMode>(m_cullingMode->getOptionInt ()));
945961}
946962
963+ void MeshDisplay::updateVertexCostUpdateFrequency ()
964+ {
965+ const int freq = m_vertexCostsRefreshRate->getInt ();
966+
967+ // IntProperty::getInt returns 0 if invalid data was entered
968+ // We set the min value to 1 so a 0 return is always an error
969+ if (0 == freq)
970+ {
971+ RCLCPP_ERROR (
972+ rclcpp::get_logger (" rviz_mesh_tools_plugins" ),
973+ " [MeshDisplay::updateVertexCostUpdateFrequency] Invalid update frequency entered!"
974+ );
975+ m_vertexCostsRefreshRate->setInt (1 );
976+ m_invUpdateFreq = std::chrono::seconds (1 );
977+ return ;
978+ }
979+
980+ using namespace std ::chrono_literals;
981+ m_invUpdateFreq = std::chrono::nanoseconds (1s) / freq;
982+
983+ RCLCPP_DEBUG (
984+ rclcpp::get_logger (" rviz_mesh_tools_plugins" ),
985+ " [MeshDisplay::updateVertexCostUpdateFrequency] Update frequency set to %i, delta t is %lu nanoseconds" ,
986+ freq, m_invUpdateFreq.count ()
987+ );
988+ }
989+
947990// =====================================================================================================================
948991// Data loading
949992void MeshDisplay::initialServiceCall ()
0 commit comments