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

Add IMU component inspector #1191

Merged
merged 36 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
18b26c2
Support editing air pressure sensor in the GUI
Nov 6, 2021
1477a68
Add noise to qrc
Nov 6, 2021
92bed4e
Add noise to qrc
Nov 6, 2021
da30432
Added altimeter sensor inspector
Nov 6, 2021
81962c7
Added magnetometer inspector
Nov 6, 2021
d553e8f
Merge branch 'ign-gazebo6' into air_pressure_component_inspector
mjcarroll Nov 8, 2021
103cdf0
Fix lint
mjcarroll Nov 8, 2021
c4eb390
Merge branch 'ign-gazebo6' into air_pressure_component_inspector
Nov 8, 2021
2029d2b
Update sensor icon
Nov 8, 2021
9fa9a84
Merge branch 'air_pressure_component_inspector' of github.com:ignitio…
Nov 8, 2021
2d8d50f
Move AirPressure functions out of ComponentInspector (#1179)
chapulina Nov 9, 2021
1a3b5ee
Fix get decimals, and address comments
Nov 9, 2021
8d0b08d
merged
Nov 9, 2021
5c0a4c0
cleanup and simplification
Nov 9, 2021
9e7250d
Require sdf 12.1.0
Nov 9, 2021
d552603
missign width
Nov 9, 2021
686d384
Merge branch 'air_pressure_component_inspector' of github.com:ignitio…
Nov 10, 2021
00ecb2b
Merge branch 'ign-gazebo6' into air_pressure_component_inspector
Nov 10, 2021
fbfbe49
Added simulation state aware spin box
Nov 10, 2021
736318c
merged
Nov 10, 2021
2dba44f
Merged
Nov 11, 2021
f901480
Merged
Nov 11, 2021
30bec80
merged
Nov 11, 2021
8e4c87b
Remove console output
Nov 11, 2021
4d934fb
Merge branch 'air_pressure_component_inspector' into altimeter_inspector
Nov 11, 2021
a4f8336
alphabetize
Nov 11, 2021
cd8bb01
Merged
Nov 11, 2021
da05b4c
Fix build
Nov 11, 2021
345755f
Add IMU component inspector
Nov 11, 2021
1b808e7
merged with model editor
Nov 18, 2021
0c7d62c
alphabetize
Nov 18, 2021
5bde160
Cleanup build
Nov 18, 2021
747f595
Missing print call
Nov 18, 2021
22c8644
merged and addressed comments
Nov 18, 2021
c8d4a26
merged
Nov 19, 2021
5f9e897
Fix all codecheck issues
Nov 19, 2021
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
# as protobuf could be find transitively by any dependency
set(protobuf_MODULE_COMPATIBLE TRUE)

ign_find_package(sdformat12 REQUIRED)
ign_find_package(sdformat12 REQUIRED VERSION 12.1)
set(SDF_VER ${sdformat12_VERSION_MAJOR})

#--------------------------------------
Expand Down
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 "AirPressure.hh"
#include "ComponentInspector.hh"
#include "Types.hh"

using namespace ignition;
using namespace gazebo;

/////////////////////////////////////////////////
AirPressure::AirPressure(ComponentInspector *_inspector)
{
_inspector->Context()->setContextProperty("AirPressureImpl", 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);
}
63 changes: 63 additions & 0 deletions src/gui/plugins/component_inspector/AirPressure.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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: explicit 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);

/// \brief This function is called when a user changes the air pressure
/// reference altitude.
/// \param[in] _referenceAltitude New reference altitude value.
public: Q_INVOKABLE void OnAirPressureReferenceAltitude(
double _referenceAltitude);

/// \brief Pointer to the component inspector. This is used to add
/// update callbacks that modify the ECM.
private: ComponentInspector *inspector{nullptr};
};
}
}
#endif
134 changes: 134 additions & 0 deletions src/gui/plugins/component_inspector/AirPressure.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* 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
}
StateAwareSpin {
id: referenceAltitudeSpin
Layout.fillWidth: true
height: 40
numberValue: model.data[0]
minValue: 0
maxValue: 100000
stepValue: 0.1
// Connect to the onNoiseUpdate signal in Noise.qml
Component.onCompleted: {
referenceAltitudeSpin.onChange.connect(
AirPressureImpl.OnAirPressureReferenceAltitude)
}
}
}

// 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(
AirPressureImpl.OnAirPressureNoise)
}
}
}
}
}
}
Loading