Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added altimeter sensor inspector #1172

Merged
merged 27 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions src/gui/plugins/component_inspector/Altimeter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <sdf/Altimeter.hh>

#include <ignition/common/Console.hh>
#include <ignition/gazebo/components/Altimeter.hh>

#include "Altimeter.hh"
#include "ComponentInspector.hh"
nkoenig marked this conversation as resolved.
Show resolved Hide resolved
#include "Types.hh"

using namespace ignition;
using namespace gazebo;

/////////////////////////////////////////////////
Altimeter::Altimeter(ComponentInspector *_inspector)
{
_inspector->Context()->setContextProperty("AltimeterImpl", this);
this->inspector = _inspector;

ComponentCreator creator =
[=](EntityComponentManager &_ecm, Entity _entity, QStandardItem *_item)
{
auto comp = _ecm.Component<components::Altimeter>(_entity);
if (nullptr == _item || nullptr == comp)
return;
const sdf::Altimeter *alt = comp->Data().AltimeterSensor();

_item->setData(QString("Altimeter"),
ComponentsModel::RoleNames().key("dataType"));
_item->setData(QList({
QVariant(alt->VerticalPositionNoise().Mean()),
QVariant(alt->VerticalPositionNoise().BiasMean()),
QVariant(alt->VerticalPositionNoise().StdDev()),
QVariant(alt->VerticalPositionNoise().BiasStdDev()),
QVariant(alt->VerticalPositionNoise().DynamicBiasStdDev()),
QVariant(alt->VerticalPositionNoise().DynamicBiasCorrelationTime()),

QVariant(alt->VerticalVelocityNoise().Mean()),
QVariant(alt->VerticalVelocityNoise().BiasMean()),
QVariant(alt->VerticalVelocityNoise().StdDev()),
QVariant(alt->VerticalVelocityNoise().BiasStdDev()),
QVariant(alt->VerticalVelocityNoise().DynamicBiasStdDev()),
QVariant(alt->VerticalVelocityNoise().DynamicBiasCorrelationTime()),
}), ComponentsModel::RoleNames().key("data"));
};

this->inspector->RegisterComponentCreator(
components::Altimeter::typeId, creator);
}
/////////////////////////////////////////////////
Q_INVOKABLE void Altimeter::OnAltimeterPositionNoise(
double _mean, double _meanBias, double _stdDev,
double _stdDevBias, double _dynamicBiasStdDev,
double _dynamicBiasCorrelationTime)
{
ignition::gazebo::UpdateCallback cb =
[=](EntityComponentManager &_ecm)
{
auto comp = _ecm.Component<components::Altimeter>(
this->inspector->Entity());
if (comp)
{
sdf::Altimeter *altimeter = comp->Data().AltimeterSensor();
if (altimeter)
{
sdf::Noise noise = altimeter->VerticalPositionNoise();

setNoise(noise, _mean, _meanBias, _stdDev, _stdDevBias,
_dynamicBiasStdDev, _dynamicBiasCorrelationTime);

altimeter->SetVerticalPositionNoise(noise);
}
else
ignerr << "Unable to get the altimeter data.\n";
}
else
{
ignerr << "Unable to get the altimeter component.\n";
}
};
this->inspector->AddUpdateCallback(cb);
}

/////////////////////////////////////////////////
Q_INVOKABLE void Altimeter::OnAltimeterVelocityNoise(
double _mean, double _meanBias, double _stdDev,
double _stdDevBias, double _dynamicBiasStdDev,
double _dynamicBiasCorrelationTime)
{
ignition::gazebo::UpdateCallback cb =
[=](EntityComponentManager &_ecm)
{
auto comp = _ecm.Component<components::Altimeter>(
this->inspector->Entity());
if (comp)
{
sdf::Altimeter *altimeter = comp->Data().AltimeterSensor();
if (altimeter)
{
sdf::Noise noise = altimeter->VerticalVelocityNoise();

setNoise(noise, _mean, _meanBias, _stdDev, _stdDevBias,
_dynamicBiasStdDev, _dynamicBiasCorrelationTime);

altimeter->SetVerticalVelocityNoise(noise);
}
else
ignerr << "Unable to get the altimeter data.\n";
}
else
{
ignerr << "Unable to get the altimeter component.\n";
}
};
this->inspector->AddUpdateCallback(cb);
}
71 changes: 71 additions & 0 deletions src/gui/plugins/component_inspector/Altimeter.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef IGNITION_GAZEBO_GUI_COMPONENTINSPECTOR_ALTIMETER_HH_
#define IGNITION_GAZEBO_GUI_COMPONENTINSPECTOR_ALTIMETER_HH_

#include <ignition/gazebo/gui/GuiSystem.hh>

namespace ignition
{
namespace gazebo
{
class ComponentInspector;

/// \brief A class that handles altimeter changes.
class Altimeter : public QObject
{
Q_OBJECT

/// \brief Constructor
/// \param[in] _inspector The component inspector.
public: Altimeter(ComponentInspector *_inspector);

/// \brief This function is called when a user changes values in the
/// altimeter sensor's position noise.
/// \param[in] _mean Mean value
/// \param[in] _meanBias Bias mean value
/// \param[in] _stdDev Standard deviation value
/// \param[in] _stdDevBias Bias standard deviation value
/// \param[in] _dynamicBiasStdDev Dynamic bias standard deviation value
/// \param[in] _dynamicBiasCorrelationTime Dynamic bias correlation time
/// value
public: Q_INVOKABLE void OnAltimeterPositionNoise(
double _mean, double _meanBias, double _stdDev,
double _stdDevBias, double _dynamicBiasStdDev,
double _dynamicBiasCorrelationTime);

/// \brief This function is called when a user changes values in the
/// altimeter sensor's velocity noise.
/// \param[in] _mean Mean value
/// \param[in] _meanBias Bias mean value
/// \param[in] _stdDev Standard deviation value
/// \param[in] _stdDevBias Bias standard deviation value
/// \param[in] _dynamicBiasStdDev Dynamic bias standard deviation value
/// \param[in] _dynamicBiasCorrelationTime Dynamic bias correlation time
/// value
public: Q_INVOKABLE void OnAltimeterVelocityNoise(
double _mean, double _meanBias, double _stdDev,
double _stdDevBias, double _dynamicBiasStdDev,
double _dynamicBiasCorrelationTime);

/// \brief Pointer to the component inspector. This is used to add
/// update callbacks that modify the ECM.
private: ComponentInspector *inspector{nullptr};
};
}
}
#endif
144 changes: 144 additions & 0 deletions src/gui/plugins/component_inspector/Altimeter.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import QtQuick 2.9
import QtQuick.Controls 1.4
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.1
import QtQuick.Dialogs 1.0
import QtQuick.Layouts 1.3
import QtQuick.Controls.Styles 1.4
import "qrc:/ComponentInspector"
import "qrc:/qml"

// Item displaying altimeter noise information.
Rectangle {
height: header.height + content.height
width: componentInspector.width
color: index % 2 == 0 ? lightGrey : darkGrey

Column {
anchors.fill: parent

// The expanding header. Make sure that the content to expand has an id set
// to the value "content".
ExpandingTypeHeader {
id: header

// Set the 'expandingHeaderText' value to override the default header
// values, which is based on the model.
expandingHeaderText: "Altimeter noise"
expandingHeaderToolTip: "Altimeter noise properties"
}

// This is the content that will be expanded/contracted using the
// ExpandingHeader above. Note the "id: content" attribute.
Rectangle {
id: content
property bool show: false
width: parent.width
height: show ? layout.height : 0
clip: true
color: "transparent"
Layout.leftMargin: 4

Behavior on height {
NumberAnimation {
duration: 200;
easing.type: Easing.InOutQuad
}
}

ColumnLayout {
id: layout
width: parent.width

// Space out the section header.
Rectangle {
id: verticalPositionNoiseTextRect
width: parent.width
height: childrenRect.height
Layout.leftMargin: 10
Layout.topMargin: 10
color: "transparent"

Text {
id: verticalPositionNoiseText
text: "Vertical Position Noise"
color: "dimgrey"
font.pointSize: 12
}
}

// Show the position noise values.
Noise {
id: verticalPositionNoise
Layout.fillWidth: true
Layout.leftMargin: 20

meanValue: model.data[0]
meanBias: model.data[1]
stdDevValue: model.data[2]
stdDevBias: model.data[3]
dynamicBiasStdDev: model.data[4]
dynamicBiasCorrelationTime: model.data[5]

// Connect to the onNoiseUpdate signal in Noise.qml
Component.onCompleted: {
verticalPositionNoise.onNoiseUpdate.connect(
AltimeterImpl.OnAltimeterPositionNoise)
}
}

// Space out the section header.
Rectangle {
id: verticalVelocityNoiseTextRect
width: parent.width
height: childrenRect.height
Layout.leftMargin: 10
Layout.topMargin: 10
color: "transparent"

Text {
text: "Vertical Velocity Noise"
color: "dimgrey"
font.pointSize: 12
}
}

// Show the velocity noise values.
Noise {
id: verticalVelocityNoise
Layout.fillWidth: true
Layout.leftMargin: 20

meanValue: model.data[6]
meanBias: model.data[7]
stdDevValue: model.data[8]
stdDevBias: model.data[9]
dynamicBiasStdDev: model.data[10]
dynamicBiasCorrelationTime: model.data[11]

// Connect to the onNoiseUpdate signal in Noise.qml
Component.onCompleted: {
verticalVelocityNoise.onNoiseUpdate.connect(
AltimeterImpl.OnAltimeterVelocityNoise)
}
}
}
}
}
}
2 changes: 2 additions & 0 deletions src/gui/plugins/component_inspector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
gz_add_gui_plugin(ComponentInspector
SOURCES
AirPressure.cc
Altimeter.cc
ComponentInspector.cc
ModelEditor.cc
Types.cc
QT_HEADERS
AirPressure.hh
Altimeter.hh
ComponentInspector.hh
ModelEditor.hh
Types.hh
Expand Down
7 changes: 7 additions & 0 deletions src/gui/plugins/component_inspector/ComponentInspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "ignition/gazebo/gui/GuiEvents.hh"

#include "AirPressure.hh"
#include "Altimeter.hh"
#include "ComponentInspector.hh"
#include "ModelEditor.hh"

Expand Down Expand Up @@ -117,6 +118,9 @@ namespace ignition::gazebo
/// \brief Air pressure sensor inspector elements
public: std::unique_ptr<ignition::gazebo::AirPressure> airPressure;

/// \brief Altimeter sensor inspector elements
public: std::unique_ptr<ignition::gazebo::Altimeter> altimeter;

/// \brief Set of callbacks to execute during the Update function.
public: std::vector<
std::function<void(EntityComponentManager &)>> updateCallbacks;
Expand Down Expand Up @@ -432,6 +436,9 @@ void ComponentInspector::LoadConfig(const tinyxml2::XMLElement *)

// Create air pressure
this->dataPtr->airPressure = std::make_unique<AirPressure>(this);

// Create altimeter
this->dataPtr->altimeter = std::make_unique<Altimeter>(this);
}

//////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions src/gui/plugins/component_inspector/ComponentInspector.qrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="ComponentInspector/">
<file>AirPressure.qml</file>
<file>Altimeter.qml</file>
<file>Boolean.qml</file>
<file>ComponentInspector.qml</file>
<file>ExpandingTypeHeader.qml</file>
Expand Down