2011-06-20 16:49:22 +00:00
|
|
|
/*
|
2016-07-17 22:06:11 -04:00
|
|
|
Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
2014-08-11 17:03:39 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
2011-06-20 16:49:22 +00:00
|
|
|
|
2023-02-19 18:55:24 -08:00
|
|
|
#include "rtabmap_viz/PreferencesDialogROS.h"
|
2011-06-20 16:49:22 +00:00
|
|
|
#include <rtabmap/core/Parameters.h>
|
2016-05-04 17:07:40 -04:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QLabel>
|
2011-06-20 16:49:22 +00:00
|
|
|
#include <rtabmap/core/RtabmapEvent.h>
|
2016-05-04 17:07:40 -04:00
|
|
|
#include <QMessageBox>
|
2011-06-20 16:49:22 +00:00
|
|
|
#include <ros/exceptions.h>
|
2016-04-13 11:59:46 -04:00
|
|
|
#include <rtabmap/utilite/UStl.h>
|
2021-02-27 21:34:09 -05:00
|
|
|
#include <rtabmap/utilite/UTimer.h>
|
2022-01-26 15:42:07 -05:00
|
|
|
#include <rtabmap/utilite/UThread.h>
|
2011-06-20 16:49:22 +00:00
|
|
|
|
|
|
|
|
using namespace rtabmap;
|
|
|
|
|
|
2021-09-08 15:24:37 -04:00
|
|
|
PreferencesDialogROS::PreferencesDialogROS(const QString & configFile, const std::string & rtabmapNodeName) :
|
|
|
|
|
configFile_(configFile),
|
|
|
|
|
rtabmapNodeName_(rtabmapNodeName)
|
2011-06-20 16:49:22 +00:00
|
|
|
{
|
2013-01-29 20:33:08 +00:00
|
|
|
|
2011-06-20 16:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PreferencesDialogROS::~PreferencesDialogROS()
|
|
|
|
|
{
|
2015-02-16 17:15:10 -05:00
|
|
|
QFile::remove(getTmpIniFilePath());
|
2011-06-20 16:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
QString PreferencesDialogROS::getIniFilePath() const
|
2013-01-29 20:33:08 +00:00
|
|
|
{
|
|
|
|
|
if(configFile_.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return PreferencesDialog::getIniFilePath();
|
|
|
|
|
}
|
|
|
|
|
return configFile_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-16 17:15:10 -05:00
|
|
|
QString PreferencesDialogROS::getTmpIniFilePath() const
|
|
|
|
|
{
|
|
|
|
|
return QDir::homePath()+"/.ros/"+QFileInfo(configFile_).fileName()+".tmp";
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 15:42:07 -05:00
|
|
|
void PreferencesDialogROS::readRtabmapNodeParameters()
|
|
|
|
|
{
|
|
|
|
|
readCoreSettings(getTmpIniFilePath());
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-20 16:49:22 +00:00
|
|
|
void PreferencesDialogROS::readCameraSettings(const QString & filePath)
|
|
|
|
|
{
|
2012-06-26 14:58:42 +00:00
|
|
|
this->setInputRate(0);
|
2011-06-20 16:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString PreferencesDialogROS::getParamMessage()
|
|
|
|
|
{
|
|
|
|
|
return tr("Reading parameters from the ROS server...");
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 15:42:07 -05:00
|
|
|
bool PreferencesDialogROS::hasAllParameters()
|
|
|
|
|
{
|
|
|
|
|
ros::NodeHandle nh(rtabmapNodeName_);
|
|
|
|
|
rtabmap::ParametersMap parameters = rtabmap::Parameters::getDefaultParameters();
|
|
|
|
|
for(rtabmap::ParametersMap::const_iterator i=parameters.begin(); i!=parameters.end(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if(i->first.compare(rtabmap::Parameters::kRtabmapWorkingDirectory()) != 0 && !nh.hasParam(i->first))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PreferencesDialogROS::hasAllParameters(const ros::NodeHandle & nh, const rtabmap::ParametersMap & parameters)
|
|
|
|
|
{
|
|
|
|
|
for(rtabmap::ParametersMap::const_iterator i=parameters.begin(); i!=parameters.end(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if(i->first.compare(rtabmap::Parameters::kRtabmapWorkingDirectory()) != 0 && !nh.hasParam(i->first))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-26 14:58:42 +00:00
|
|
|
bool PreferencesDialogROS::readCoreSettings(const QString & filePath)
|
2011-06-20 16:49:22 +00:00
|
|
|
{
|
2016-04-13 11:59:46 -04:00
|
|
|
QString path = getIniFilePath();
|
|
|
|
|
if(!filePath.isEmpty())
|
2011-06-20 16:49:22 +00:00
|
|
|
{
|
2016-04-13 11:59:46 -04:00
|
|
|
path = filePath;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 15:24:37 -04:00
|
|
|
ros::NodeHandle rnh(rtabmapNodeName_);
|
2023-03-04 14:24:18 -08:00
|
|
|
ROS_INFO("rtabmap_viz: %s", this->getParamMessage().toStdString().c_str());
|
2016-04-13 11:59:46 -04:00
|
|
|
bool validParameters = true;
|
|
|
|
|
int readCount = 0;
|
|
|
|
|
rtabmap::ParametersMap parameters = rtabmap::Parameters::getDefaultParameters();
|
2018-10-17 13:01:14 -04:00
|
|
|
// remove Odom parameters
|
|
|
|
|
for(ParametersMap::iterator iter=parameters.begin(); iter!=parameters.end();)
|
|
|
|
|
{
|
|
|
|
|
if(iter->first.find("Odom") == 0)
|
|
|
|
|
{
|
|
|
|
|
parameters.erase(iter++);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
++iter;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-27 21:34:09 -05:00
|
|
|
|
2022-01-26 15:42:07 -05:00
|
|
|
// Wait rtabmap parameters to appear (if gui node has been launched at the same time than rtabmap)
|
2021-02-27 21:34:09 -05:00
|
|
|
if(!this->isVisible())
|
|
|
|
|
{
|
|
|
|
|
double stamp = UTimer::now();
|
|
|
|
|
std::string tmp;
|
|
|
|
|
bool warned = false;
|
2022-01-26 15:42:07 -05:00
|
|
|
while(!hasAllParameters(rnh, parameters) && UTimer::now()-stamp < 5.0)
|
2021-02-27 21:34:09 -05:00
|
|
|
{
|
|
|
|
|
if(!warned)
|
|
|
|
|
{
|
2023-03-04 14:24:18 -08:00
|
|
|
ROS_INFO("rtabmap_viz: Cannot get rtabmap's parameters, waiting max 5 seconds in case the node has just been launched.");
|
2021-02-27 21:34:09 -05:00
|
|
|
warned = true;
|
|
|
|
|
}
|
2022-01-26 15:42:07 -05:00
|
|
|
uSleep(100);
|
2021-02-27 21:34:09 -05:00
|
|
|
}
|
2022-01-26 15:42:07 -05:00
|
|
|
if(warned)
|
2021-02-27 21:34:09 -05:00
|
|
|
{
|
2022-01-26 15:42:07 -05:00
|
|
|
if(UTimer::now()-stamp < 5.0)
|
|
|
|
|
{
|
2023-03-04 14:24:18 -08:00
|
|
|
ROS_INFO("rtabmap_viz: rtabmap's parameters seem now there! continuing...");
|
2022-01-26 15:42:07 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-03-04 14:24:18 -08:00
|
|
|
ROS_WARN("rtabmap_viz: rtabmap's parameters seem not all there yet! continuing with those there if some...");
|
2022-01-26 15:42:07 -05:00
|
|
|
}
|
2021-02-27 21:34:09 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-13 11:59:46 -04:00
|
|
|
for(rtabmap::ParametersMap::iterator i=parameters.begin(); i!=parameters.end(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if(i->first.compare(rtabmap::Parameters::kRtabmapWorkingDirectory()) == 0)
|
|
|
|
|
{
|
|
|
|
|
// use working directory of the GUI, not the one on rosparam server
|
|
|
|
|
QSettings settings(path, QSettings::IniFormat);
|
|
|
|
|
settings.beginGroup("Core");
|
|
|
|
|
QString value = settings.value(rtabmap::Parameters::kRtabmapWorkingDirectory().c_str(), "").toString();
|
|
|
|
|
if(!value.isEmpty() && QDir(value).exists())
|
|
|
|
|
{
|
|
|
|
|
this->setParameter(rtabmap::Parameters::kRtabmapWorkingDirectory(), value.toStdString());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// use default one
|
2018-10-17 11:43:38 -04:00
|
|
|
char * rosHomePath = getenv("ROS_HOME");
|
|
|
|
|
std::string workingDir = rosHomePath?rosHomePath:(QDir::homePath()+"/.ros").toStdString();
|
|
|
|
|
this->setParameter(rtabmap::Parameters::kRtabmapWorkingDirectory(), workingDir);
|
2016-04-13 11:59:46 -04:00
|
|
|
}
|
|
|
|
|
settings.endGroup();
|
|
|
|
|
}
|
|
|
|
|
else
|
2011-06-20 16:49:22 +00:00
|
|
|
{
|
|
|
|
|
std::string value;
|
2021-09-08 15:24:37 -04:00
|
|
|
if(rnh.getParam(i->first,value))
|
2011-06-20 16:49:22 +00:00
|
|
|
{
|
2021-03-27 15:12:41 -04:00
|
|
|
//backward compatibility
|
|
|
|
|
if(i->first.compare(Parameters::kIcpStrategy()) == 0)
|
|
|
|
|
{
|
|
|
|
|
if(value.compare("true") == 0)
|
|
|
|
|
{
|
|
|
|
|
value = "1";
|
|
|
|
|
}
|
|
|
|
|
else if(value.compare("false") == 0)
|
|
|
|
|
{
|
|
|
|
|
value = "0";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-13 11:59:46 -04:00
|
|
|
PreferencesDialog::setParameter(i->first, value);
|
2013-01-29 18:01:25 +00:00
|
|
|
++readCount;
|
2011-06-20 16:49:22 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-03-04 14:24:18 -08:00
|
|
|
ROS_WARN("rtabmap_viz: Parameter %s not found", i->first.c_str());
|
2011-06-20 16:49:22 +00:00
|
|
|
validParameters = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-13 11:59:46 -04:00
|
|
|
}
|
2011-06-20 16:49:22 +00:00
|
|
|
|
2023-03-04 14:24:18 -08:00
|
|
|
ROS_INFO("rtabmap_viz: Parameters read = %d", readCount);
|
2013-01-29 18:01:25 +00:00
|
|
|
|
2016-04-13 11:59:46 -04:00
|
|
|
if(validParameters)
|
|
|
|
|
{
|
2023-03-04 14:24:18 -08:00
|
|
|
ROS_INFO("rtabmap_viz: Parameters successfully read.");
|
2011-06-20 16:49:22 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-04-13 11:59:46 -04:00
|
|
|
if(this->isVisible())
|
|
|
|
|
{
|
|
|
|
|
QString warning = tr("Failed to get some RTAB-Map parameters from ROS server, the rtabmap node may be not started or some parameters won't work...");
|
|
|
|
|
ROS_WARN("%s", warning.toStdString().c_str());
|
|
|
|
|
QMessageBox::warning(this, tr("Can't read parameters from ROS server."), warning);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PreferencesDialogROS::writeCoreSettings(const QString & filePath) const
|
|
|
|
|
{
|
|
|
|
|
QString path = getIniFilePath();
|
|
|
|
|
if(!filePath.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
path = filePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(QFile::exists(path))
|
|
|
|
|
{
|
|
|
|
|
rtabmap::ParametersMap parameters = this->getAllParameters();
|
|
|
|
|
|
|
|
|
|
std::string workingDir = uValue(parameters, Parameters::kRtabmapWorkingDirectory(), std::string(""));
|
|
|
|
|
|
|
|
|
|
if(!workingDir.empty())
|
|
|
|
|
{
|
|
|
|
|
//Just update GUI working directory
|
|
|
|
|
QSettings settings(path, QSettings::IniFormat);
|
|
|
|
|
settings.beginGroup("Core");
|
|
|
|
|
settings.remove("");
|
|
|
|
|
settings.setValue(Parameters::kRtabmapWorkingDirectory().c_str(), workingDir.c_str());
|
|
|
|
|
settings.endGroup();
|
|
|
|
|
}
|
2011-06-20 16:49:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|