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

Support editing air pressure sensor in the GUI #1171

Merged
merged 23 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
28 changes: 28 additions & 0 deletions src/cmd/ModelCommandAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <vector>
#include <map>

#include <sdf/AirPressure.hh>
#include <sdf/Altimeter.hh>
#include <sdf/Camera.hh>
#include <sdf/Imu.hh>
Expand All @@ -34,6 +35,7 @@
#include <ignition/common/Console.hh>
#include <ignition/common/Filesystem.hh>
#include <ignition/gazebo/EntityComponentManager.hh>
#include <ignition/gazebo/components/AirPressureSensor.hh>
#include <ignition/gazebo/components/Altimeter.hh>
#include <ignition/gazebo/components/Camera.hh>
#include <ignition/gazebo/components/ChildLinkName.hh>
Expand Down Expand Up @@ -182,6 +184,31 @@ void printNoise(const sdf::Noise &_noise, int _spaces)
<< _noise.DynamicBiasCorrelationTime() << std::endl;
}

//////////////////////////////////////////////////
/// \brief Print info about an air pressure sensor.
/// \param[in] _entity Entity to print information for. Nothing is
/// printed if the entity is not an air pressure sensor.
/// \param[in] _ecm The entity component manager.
/// \param[in] _spaces Number of spaces to indent for every line
void printAirPressure(const uint64_t _entity,
const EntityComponentManager &_ecm, int _spaces)
{
// Get the type and return if the _entity does not have the correct
// component.
auto comp = _ecm.Component<components::AirPressureSensor>(_entity);
if (!comp)
return;

const sdf::Sensor &sensor = comp->Data();
const sdf::AirPressure *air = sensor.AirPressureSensor();

std::cout << std::string(_spaces, ' ') << "- Reference altitude: "
<< air->ReferenceAltitude() << "\n";

std::cout << std::string(_spaces, ' ') << "- Pressure noise:\n";
printNoise(air->PressureNoise(), _spaces + 2);
}

//////////////////////////////////////////////////
/// \brief Print info about an altimeter sensor.
/// \param[in] _entity Entity to print information for. Nothing is
Expand Down Expand Up @@ -603,6 +630,7 @@ void printLinks(const uint64_t _modelEntity,

// Run through all the sensor print statements. Each function will
// exit early if the the sensor is the wrong type.
printAirPressure(sensor, _ecm, spaces + 2);
printAltimeter(sensor, _ecm, spaces + 2);
printCamera(sensor, _ecm, spaces + 2);
printImu(sensor, _ecm, spaces + 2);
Expand Down
120 changes: 120 additions & 0 deletions src/gui/plugins/component_inspector/AirPressure.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* 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/AirPressure.hh>

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

#include "ComponentInspector.hh"
chapulina marked this conversation as resolved.
Show resolved Hide resolved
#include "Types.hh"
#include "AirPressure.hh"

using namespace ignition;
using namespace gazebo;

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

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

_item->setData(QString("AirPressure"),
ComponentsModel::RoleNames().key("dataType"));
_item->setData(QList({
QVariant(air->ReferenceAltitude()),
QVariant(air->PressureNoise().Mean()),
QVariant(air->PressureNoise().BiasMean()),
QVariant(air->PressureNoise().StdDev()),
QVariant(air->PressureNoise().BiasStdDev()),
QVariant(air->PressureNoise().DynamicBiasStdDev()),
QVariant(air->PressureNoise().DynamicBiasCorrelationTime()),
}), ComponentsModel::RoleNames().key("data"));
};

this->inspector->RegisterComponentCreator(
components::AirPressureSensor::typeId, creator);
}

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

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

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

/////////////////////////////////////////////////
Q_INVOKABLE void AirPressure::OnAirPressureReferenceAltitude(
double _referenceAltitude)
{
ignition::gazebo::UpdateCallback cb =
[=](EntityComponentManager &_ecm)
{
auto comp = _ecm.Component<components::AirPressureSensor>(
this->inspector->Entity());
if (comp)
{
sdf::AirPressure *airpressure = comp->Data().AirPressureSensor();
if (airpressure)
{
airpressure->SetReferenceAltitude(_referenceAltitude);
}
else
ignerr << "Unable to get the air pressure data.\n";
}
else
{
ignerr << "Unable to get the air pressure component.\n";
}
};
this->inspector->AddUpdateCallback(cb);
}
60 changes: 60 additions & 0 deletions src/gui/plugins/component_inspector/AirPressure.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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_AIRPRESSURE_HH_
#define IGNITION_GAZEBO_GUI_COMPONENTINSPECTOR_AIRPRESSURE_HH_

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

namespace ignition
{
namespace gazebo
{
class ComponentInspector;

/// \brief A class that handles air pressure changes.
class AirPressure : public QObject
{
Q_OBJECT

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

/// \brief This function is called when a user changes values in the
/// air pressure sensor.
/// \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 OnAirPressureNoise(
double _mean, double _meanBias, double _stdDev,
double _stdDevBias, double _dynamicBiasStdDev,
double _dynamicBiasCorrelationTime);

public: Q_INVOKABLE void OnAirPressureReferenceAltitude(
chapulina marked this conversation as resolved.
Show resolved Hide resolved
double _referenceAltitude);

/// \brief Pointer to the component inspector. This is used to add
/// update callbacks that modify the ECM.
private: ComponentInspector *inspector{nullptr};
};
}
}
#endif
136 changes: 136 additions & 0 deletions src/gui/plugins/component_inspector/AirPressure.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* 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 air pressure 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: "Air pressure"
expandingHeaderToolTip: "Air pressure 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

RowLayout {
id: rowLayout
width: layout.width

Text {
leftPadding: 10
id: referenceAltitudeText
text: "Reference altitude (m)"
color: "dimgrey"
font.pointSize: 12
}
IgnSpinBox {
id: referenceAltitudeSpin
Layout.fillWidth: true
height: 40
property double refAltitude: model.data[0]
value: referenceAltitudeSpin.activeFocus ? referenceAltitudeSpin.value : refAltitude

minimumValue: 0
maximumValue: 100000
decimals:4
chapulina marked this conversation as resolved.
Show resolved Hide resolved
stepSize: 0.1
onEditingFinished: {
refAltitude = referenceAltitudeSpin.value
componentInspector.onAirPressureReferenceAltitude(refAltitude);
}
}
}

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

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

// Show the pressure noise values.
Noise {
id: pressureNoise
Layout.fillWidth: true
Layout.leftMargin: 20

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

// Connect to the onNoiseUpdate signal in Noise.qml
Component.onCompleted: {
pressureNoise.onNoiseUpdate.connect(
componentInspector.onAirPressureNoise)
}
}
}
}
}
}
10 changes: 8 additions & 2 deletions src/gui/plugins/component_inspector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
gz_add_gui_plugin(ComponentInspector
SOURCES ComponentInspector.cc
QT_HEADERS ComponentInspector.hh
SOURCES
AirPressure.cc
ComponentInspector.cc
Types.cc
QT_HEADERS
AirPressure.hh
ComponentInspector.hh
Types.hh
)
Loading