4141
4242namespace rviz
4343{
44- ImageDisplayBase::ImageDisplayBase () : Display(), sub_(), tf_filter_(), messages_received_(0 ), timeout_tm_( 0 ), is_img_up_( false )
44+ ImageDisplayBase::ImageDisplayBase () : Display(), sub_(), tf_filter_(), messages_received_(0 )
4545{
4646 topic_property_ = new RosTopicProperty (
4747 " Image Topic" , " " , QString::fromStdString (ros::message_traits::datatype<sensor_msgs::Image>()),
@@ -66,17 +66,15 @@ ImageDisplayBase::ImageDisplayBase() : Display(), sub_(), tf_filter_(), messages
6666 unreliable_property_ = new BoolProperty (" Unreliable" , false , " Prefer UDP topic transport" , this ,
6767 &ImageDisplayBase::updateTopic);
6868
69- reset_to_property_ = new BoolProperty (" Reset When Timed Out" , false ,
70- " Reset when new image has not been received for Timeout [sec]." ,
71- this , &ImageDisplayBase::updateResetTO);
72-
7369 timeout_property_ =
7470 new FloatProperty (" Timeout" , 1.0 ,
75- " Seconds to wait before resetting when new image has not been received." ,
76- this , &ImageDisplayBase::updateResetTO);
71+ " Seconds to wait before resetting when no new image has been received.\n "
72+ " Zero disables the feature." ,
73+ this , &ImageDisplayBase::updateResetTimeout);
7774
78- reset_to_timer_ = new QTimer (this );
79- connect (reset_to_timer_, &QTimer::timeout, this , &ImageDisplayBase::onResetTOTimer);
75+ reset_timer_ = new QTimer (this );
76+ connect (reset_timer_, &QTimer::timeout, this , &ImageDisplayBase::onResetTimer);
77+ updateResetTimeout ();
8078}
8179
8280ImageDisplayBase::~ImageDisplayBase ()
@@ -125,10 +123,9 @@ void ImageDisplayBase::incomingMessage(const sensor_msgs::Image::ConstPtr& msg)
125123 setStatus (StatusProperty::Ok, " Image" , QString::number (messages_received_) + " images received" );
126124
127125 emitTimeSignal (msg->header .stamp );
126+ last_received_ = ros::Time::now ();
128127
129128 processMessage (msg);
130-
131- is_img_up_ = true ;
132129}
133130
134131
@@ -152,8 +149,7 @@ void ImageDisplayBase::reset()
152149 messages_received_ = 0 ;
153150 setStatus (StatusProperty::Warn, " Image" , " No Image received" );
154151
155- timeout_tm_ = ros::Time (0 );
156- is_img_up_ = false ;
152+ last_received_ = ros::Time ();
157153}
158154
159155void ImageDisplayBase::updateQueueSize ()
@@ -278,16 +274,12 @@ void ImageDisplayBase::updateTopic()
278274 context_->queueRender ();
279275}
280276
281- void ImageDisplayBase::updateResetTO ()
277+ void ImageDisplayBase::updateResetTimeout ()
282278{
283- if (reset_to_property_->getBool ())
284- {
285- reset_to_timer_->start (33 );
286- }
279+ if (timeout_property_->getFloat () > 0 )
280+ reset_timer_->start (33 ); // frequently check for receive timeout
287281 else
288- {
289- reset_to_timer_->stop ();
290- }
282+ reset_timer_->stop ();
291283}
292284
293285void ImageDisplayBase::fillTransportOptionList (EnumProperty* property)
@@ -334,20 +326,11 @@ void ImageDisplayBase::fillTransportOptionList(EnumProperty* property)
334326 }
335327}
336328
337- void ImageDisplayBase::onResetTOTimer ()
329+ void ImageDisplayBase::onResetTimer ()
338330{
339- if (is_img_up_)
340- {
341- is_img_up_ = false ;
342- timeout_tm_ = ros::Time::now () + ros::Duration (timeout_property_->getFloat ());
343- }
344- else
345- {
346- if ((timeout_tm_ != ros::Time (0 )) && (ros::Time::now () > timeout_tm_))
347- {
348- reset ();
349- }
350- }
331+ ros::Time last = last_received_;
332+ if (!last.isZero () && ros::Time::now () > last + ros::Duration (timeout_property_->getFloat ()))
333+ reset ();
351334}
352335
353336} // end namespace rviz
0 commit comments