void ParametersToolBox::addParameter(
		QVBoxLayout * layout,
		const std::string & key,
		const std::string & value)
{
	std::string type = Parameters::getType(key);
	if(type.compare("string") == 0)
	{
		addParameter(layout, key.c_str(), QString::fromStdString(value));
	}
	else if(type.compare("int") == 0)
	{
		addParameter(layout, key.c_str(), uStr2Int(value));
	}
	else if(type.compare("uint") == 0)
	{
		addParameter(layout, key.c_str(), uStr2Int(value));
	}
	else if(type.compare("double") == 0)
	{
		addParameter(layout, key.c_str(), uStr2Double(value));
	}
	else if(type.compare("float") == 0)
	{
		addParameter(layout, key.c_str(), uStr2Double(value));
	}
	else if(type.compare("bool") == 0)
	{
		addParameter(layout, key.c_str(), uStr2Bool(value));
	}
}
QStringList ParametersToolBox::resetPage(int index)
{
	QStringList paramChanged;
	const QObjectList & children = stackedWidget_->widget(index)->children().first()->children().first()->children();
	for(int j=0; j<children.size();++j)
	{
		QString key = children.at(j)->objectName();
		// ignore working memory
		QString group = key.split("/").first();
		if(parameters_.find(key.toStdString())!=parameters_.end())
		{
			UASSERT_MSG(parameters_.find(key.toStdString()) != parameters_.end(), uFormat("key=%s", key.toStdString().c_str()).c_str());
			std::string value = Parameters::getDefaultParameters().at(key.toStdString());
			parameters_.at(key.toStdString()) = value;

			if(qobject_cast<QComboBox*>(children.at(j)))
			{
				if(((QComboBox*)children.at(j))->currentIndex() != QString::fromStdString(value).split(':').first().toInt())
				{
					((QComboBox*)children.at(j))->setCurrentIndex(QString::fromStdString(value).split(':').first().toInt());
					paramChanged.append(key);
				}
			}
			else if(qobject_cast<QSpinBox*>(children.at(j)))
			{
				if(((QSpinBox*)children.at(j))->value() != uStr2Int(value))
				{
					((QSpinBox*)children.at(j))->setValue(uStr2Int(value));
					paramChanged.append(key);
				}
			}
			else if(qobject_cast<QDoubleSpinBox*>(children.at(j)))
			{
				if(((QDoubleSpinBox*)children.at(j))->value() != uStr2Double(value))
				{
					((QDoubleSpinBox*)children.at(j))->setValue(uStr2Double(value));
					paramChanged.append(key);
				}
			}
			else if(qobject_cast<QCheckBox*>(children.at(j)))
			{
				if(((QCheckBox*)children.at(j))->isChecked() != uStr2Bool(value))
				{
					((QCheckBox*)children.at(j))->setChecked(uStr2Bool(value));
					paramChanged.append(key);
				}
			}
			else if(qobject_cast<QLineEdit*>(children.at(j)))
			{
				if(((QLineEdit*)children.at(j))->text().compare(QString::fromStdString(value)) != 0)
				{
					((QLineEdit*)children.at(j))->setText(QString::fromStdString(value));
					paramChanged.append(key);
				}
			}
		}
	}
	return paramChanged;
}
void ParametersToolBox::updateParameter(const std::string & key, const std::string & value)
{
	QString group = QString::fromStdString(key).split("/").first();
	if(!ignoredGroups_.contains(group))
	{
		if(parameters_.find(key) == parameters_.end())
		{
			UWARN("key=\"%s\" doesn't exist", key.c_str());
		}
		else
		{
			parameters_.at(key) = value;
			QWidget * widget = this->findChild<QWidget*>(key.c_str());
			QString type = QString::fromStdString(Parameters::getType(key));
			if(type.compare("string") == 0)
			{
				QString valueQt = QString::fromStdString(value);
				if(valueQt.contains(';'))
				{
					// It's a list, just change the index
					QStringList splitted = valueQt.split(':');
					((QComboBox*)widget)->setCurrentIndex(splitted.first().toInt());
				}
				else
				{
					((QLineEdit*)widget)->setText(valueQt);
				}
			}
			else if(type.compare("int") == 0)
			{
				((QSpinBox*)widget)->setValue(uStr2Int(value));
			}
			else if(type.compare("uint") == 0)
			{
				((QSpinBox*)widget)->setValue(uStr2Int(value));
			}
			else if(type.compare("double") == 0)
			{
				((QDoubleSpinBox*)widget)->setValue(uStr2Double(value));
			}
			else if(type.compare("float") == 0)
			{
				((QDoubleSpinBox*)widget)->setValue(uStr2Float(value));
			}
			else if(type.compare("bool") == 0)
			{
				((QCheckBox*)widget)->setChecked(uStr2Bool(value));
			}
		}
	}
}
Exemple #4
0
void IMUThread::mainLoop()
{
	UTimer totalTime;
	UDEBUG("");

	if(rate_>0 || captureDelay_)
	{
		double delay = rate_>0?1000.0/double(rate_):1000.0f*captureDelay_;
		int sleepTime = delay - 1000.0f*frameRateTimer_.getElapsedTime();
		if(sleepTime > 2)
		{
			uSleep(sleepTime-2);
		}

		// Add precision at the cost of a small overhead
		delay/=1000.0;
		while(frameRateTimer_.getElapsedTime() < delay-0.000001)
		{
			//
		}

		frameRateTimer_.start();
	}
	captureDelay_ = 0.0;

	std::string line;
	if (std::getline(imuFile_, line))
	{
		std::stringstream stream(line);
		std::string s;
		std::getline(stream, s, ',');
		std::string nanoseconds = s.substr(s.size() - 9, 9);
		std::string seconds = s.substr(0, s.size() - 9);

		cv::Vec3d gyr;
		for (int j = 0; j < 3; ++j) {
			std::getline(stream, s, ',');
			gyr[j] = uStr2Double(s);
		}

		cv::Vec3d acc;
		for (int j = 0; j < 3; ++j) {
			std::getline(stream, s, ',');
			acc[j] = uStr2Double(s);
		}

		double stamp = double(uStr2Int(seconds)) + double(uStr2Int(nanoseconds))*1e-9;
		if(previousStamp_>0 && stamp > previousStamp_)
		{
			captureDelay_ = stamp - previousStamp_;
		}
		previousStamp_ = stamp;

		IMU imu(gyr, cv::Mat(), acc, cv::Mat(), localTransform_);
		this->post(new IMUEvent(imu, stamp));
	}
	else if(!this->isKilled())
	{
		UWARN("no more imu data...");
		this->kill();
		this->post(new IMUEvent());
	}
}