InfoDisplay.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #include "InfoDisplay.h"
00029 #include "rtabmap_ros/MsgConversion.h"
00030 
00031 namespace rtabmap_ros
00032 {
00033 
00034 InfoDisplay::InfoDisplay()
00035   : spinner_(1, &cbqueue_),
00036     globalCount_(0),
00037     localCount_(0)
00038 {
00039         update_nh_.setCallbackQueue( &cbqueue_ );
00040 }
00041 
00042 InfoDisplay::~InfoDisplay()
00043 {
00044         spinner_.stop();
00045 }
00046 
00047 void InfoDisplay::onInitialize()
00048 {
00049         MFDClass::onInitialize();
00050 
00051         this->setStatusStd(rviz::StatusProperty::Ok, "Info", "");
00052         this->setStatusStd(rviz::StatusProperty::Ok, "Position (XYZ)", "");
00053         this->setStatusStd(rviz::StatusProperty::Ok, "Orientation (RPY)", "");
00054         this->setStatusStd(rviz::StatusProperty::Ok, "Loop closures", "0");
00055         this->setStatusStd(rviz::StatusProperty::Ok, "Proximity detections", "0");
00056 
00057         spinner_.start();
00058 }
00059 
00060 void InfoDisplay::processMessage( const rtabmap_ros::InfoConstPtr& msg )
00061 {
00062         {
00063                 boost::mutex::scoped_lock lock(info_mutex_);
00064                 if(msg->loopClosureId)
00065                 {
00066                         info_ = QString("%1->%2").arg(msg->refId).arg(msg->loopClosureId);
00067                         globalCount_ += 1;
00068                 }
00069                 else if(msg->proximityDetectionId)
00070                 {
00071                         info_ = QString("%1->%2 [Proximity]").arg(msg->refId).arg(msg->proximityDetectionId);
00072                         localCount_ += 1;
00073                 }
00074                 else
00075                 {
00076                         info_ = "";
00077                 }
00078                 loopTransform_ = rtabmap_ros::transformFromGeometryMsg(msg->loopClosureTransform);
00079 
00080                 rtabmap::Statistics stat;
00081                 rtabmap_ros::infoFromROS(*msg, stat);
00082                 statistics_ = stat.data();
00083         }
00084 
00085 
00086         this->emitTimeSignal(msg->header.stamp);
00087 }
00088 
00089 void InfoDisplay::update( float wall_dt, float ros_dt )
00090 {
00091         {
00092                 boost::mutex::scoped_lock lock(info_mutex_);
00093                 this->setStatusStd(rviz::StatusProperty::Ok, "Info", tr("%1").arg(info_).toStdString());
00094                 if(loopTransform_.isNull())
00095                 {
00096                         this->setStatusStd(rviz::StatusProperty::Ok, "Position (XYZ)", "");
00097                         this->setStatusStd(rviz::StatusProperty::Ok, "Orientation (RPY)", "");
00098                 }
00099                 else
00100                 {
00101                         float x,y,z, roll,pitch,yaw;
00102                         loopTransform_.getTranslationAndEulerAngles(x,y,z, roll,pitch,yaw);
00103                         this->setStatusStd(rviz::StatusProperty::Ok, "Position (XYZ)", tr("%1;%2;%3").arg(x).arg(y).arg(z).toStdString());
00104                         this->setStatusStd(rviz::StatusProperty::Ok, "Orientation (RPY)", tr("%1;%2;%3").arg(roll).arg(pitch).arg(yaw).toStdString());
00105                 }
00106                 this->setStatusStd(rviz::StatusProperty::Ok, "Loop closures", tr("%1").arg(globalCount_).toStdString());
00107                 this->setStatusStd(rviz::StatusProperty::Ok, "Proximity detections", tr("%1").arg(localCount_).toStdString());
00108 
00109                 for(std::map<std::string, float>::const_iterator iter=statistics_.begin(); iter!=statistics_.end(); ++iter)
00110                 {
00111                         this->setStatus(rviz::StatusProperty::Ok, iter->first.c_str(), tr("%1").arg(iter->second));
00112                 }
00113         }
00114 }
00115 
00116 void InfoDisplay::reset()
00117 {
00118         MFDClass::reset();
00119         {
00120                 boost::mutex::scoped_lock lock(info_mutex_);
00121                 info_.clear();
00122                 globalCount_ = 0;
00123                 localCount_ = 0;
00124                 statistics_.clear();
00125         }
00126 }
00127 
00128 } // namespace rtabmap_ros
00129 
00130 #include <pluginlib/class_list_macros.h>
00131 PLUGINLIB_EXPORT_CLASS( rtabmap_ros::InfoDisplay, rviz::Display )


rtabmap_ros
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:30:49