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

Airflow/Wind Sensor #1349

Open
wants to merge 7 commits into
base: sdf13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
93 changes: 93 additions & 0 deletions include/sdf/AirFlow.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2023 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 SDF_AirFlow_HH_
#define SDF_AirFlow_HH_
henrykotze marked this conversation as resolved.
Show resolved Hide resolved

#include <gz/utils/ImplPtr.hh>

#include <sdf/Error.hh>
#include <sdf/Element.hh>
#include <sdf/Noise.hh>
#include <sdf/sdf_config.h>

namespace sdf
{
// Inline bracke to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
/// \brief AirFlow contains information about a general
/// purpose air flow sensor.
/// This sensor can be attached to a link.
class SDFORMAT_VISIBLE AirFlow
{
/// \brief Default constructor
public: AirFlow();

/// \brief Load the air flow based on an element pointer.
/// This is *not* the usual entry point. Typical usage of the SDF DOM is
/// through the Root object.
/// \param[in] _sdf The SDF Element pointer
/// \return Errors, which is a vector of Error objects. Each Error includes
/// an error code and message. An empty vector indicates no error.
public: Errors Load(ElementPtr _sdf);

/// \brief Get a pointer to the SDF element that was used during
/// load.
/// \return SDF element pointer. The value will be nullptr if Load has
/// not been called.
public: sdf::ElementPtr Element() const;

/// \brief Get the noise values.
/// \return Noise values for differential pressure data.
public: const Noise &SpeedNoise() const;

/// \brief Set the noise values related to the differential pressure data.
/// \param[in] _noise Noise values for the pressure data.
public: void SetSpeedNoise(const Noise &_noise);\

/// \brief Get the noise values.
/// \return Noise values for differential pressure data.
public: const Noise &DirectionNoise() const;

/// \brief Set the noise values related to the differential pressure data.
/// \param[in] _noise Noise values for the pressure data.
public: void SetDirectionNoise(const Noise &_noise);

/// \brief Return true if both AirFlow objects contain the
/// same values.
/// \param[_in] _air AirFlow value to compare.
/// \returen True if 'this' == _air.
public: bool operator==(const AirFlow &_air) const;

/// \brief Return true this AirFlow object does not contain
/// the same values as the passed in parameter.
/// \param[_in] _air AirFlow value to compare.
/// \returen True if 'this' != _air.
public: bool operator!=(const AirFlow &_air) const;

/// \brief Create and return an SDF element filled with data from this
/// air pressure sensor.
/// Note that parameter passing functionality is not captured with this
/// function.
/// \return SDF element pointer with updated sensor values.
public: sdf::ElementPtr ToElement() const;

/// \brief Private data pointer.
GZ_UTILS_IMPL_PTR(dataPtr)
};
}
}
#endif
henrykotze marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 22 additions & 0 deletions include/sdf/Sensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace sdf
//

// Forward declarations.
class AirFlow;
class AirPressure;
class AirSpeed;
class Altimeter;
Expand Down Expand Up @@ -134,6 +135,9 @@ namespace sdf

/// \brief An air speed sensor.
AIR_SPEED = 26,

/// \brief An airflow sensor.
AIR_FLOW = 27,
};

/// \brief Information about an SDF sensor.
Expand Down Expand Up @@ -341,6 +345,24 @@ namespace sdf
/// \param[in] _air The air pressure sensor.
public: void SetAirSpeedSensor(const AirSpeed &_air);

/// \brief Get the air flow sensor, or nullptr if this sensor type
/// is not an AirFlow sensor.
/// \return Pointer to the AirFlow sensor, or nullptr if this
/// Sensor is not a AirFlow sensor.
/// \sa SensorType Type() const
public: const AirFlow *AirFlowSensor() const;

/// \brief Get a mutable air flow sensor, or nullptr if this sensor type
/// is not an AirFlow sensor.
/// \return Pointer to the AirFlow sensor, or nullptr if this
/// Sensor is not a AirFlow sensor.
/// \sa SensorType Type() const
public: AirFlow *AirFlowSensor();

/// \brief Set the air pressure sensor.
/// \param[in] _air The air pressure sensor.
public: void SetAirFlowSensor(const AirFlow &_air);

/// \brief Set the camera sensor.
/// \param[in] _cam The camera sensor.
public: void SetCameraSensor(const Camera &_cam);
Expand Down
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ endfunction()
set(BINDINGS_MODULE_NAME "pysdformat${PROJECT_VERSION_MAJOR}")
pybind11_add_module(${BINDINGS_MODULE_NAME} MODULE
src/sdf/_gz_sdformat_pybind11.cc
src/sdf/pyAirFlow.cc
src/sdf/pyAirPressure.cc
src/sdf/pyAirSpeed.cc
src/sdf/pyAltimeter.cc
Expand Down
2 changes: 2 additions & 0 deletions python/src/sdf/_gz_sdformat_pybind11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <pybind11/stl.h>
#include <gz/math/config.hh>

#include "pyAirFlow.hh"
#include "pyAirPressure.hh"
#include "pyAirSpeed.hh"
#include "pyAltimeter.hh"
Expand Down Expand Up @@ -74,6 +75,7 @@ PYBIND11_MODULE(BINDINGS_MODULE_NAME, m) {
std::string("gz.math") + std::to_string(GZ_MATH_MAJOR_VERSION);
pybind11::module::import(gzMathModule.c_str());

sdf::python::defineAirFlow(m);
sdf::python::defineAirPressure(m);
sdf::python::defineAirSpeed(m);
sdf::python::defineAltimeter(m);
Expand Down
61 changes: 61 additions & 0 deletions python/src/sdf/pyAirFlow.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2023 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 "pyAirFlow.hh"

#include <pybind11/operators.h>
#include <pybind11/pybind11.h>

#include "sdf/AirFlow.hh"


using namespace pybind11::literals;
henrykotze marked this conversation as resolved.
Show resolved Hide resolved

namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
namespace python
{
/////////////////////////////////////////////////
void defineAirFlow(pybind11::object module)
{
pybind11::class_<sdf::AirFlow> geometryModule(module, "AirFlow");
geometryModule
.def(pybind11::init<>())
.def(pybind11::init<sdf::AirFlow>())
.def(pybind11::self == pybind11::self)
.def(pybind11::self != pybind11::self)
.def("speed_noise", &sdf::AirFlow::SpeedNoise,

Check warning on line 42 in python/src/sdf/pyAirFlow.cc

View check run for this annotation

Codecov / codecov/patch

python/src/sdf/pyAirFlow.cc#L42

Added line #L42 was not covered by tests
"Get the speed noise values.")
.def("set_speed_noise",
&sdf::AirFlow::SetSpeedNoise,

Check warning on line 45 in python/src/sdf/pyAirFlow.cc

View check run for this annotation

Codecov / codecov/patch

python/src/sdf/pyAirFlow.cc#L45

Added line #L45 was not covered by tests
"Set the noise values related to the speed data.")
.def("dir_noise", &sdf::AirFlow::DirectionNoise,

Check warning on line 47 in python/src/sdf/pyAirFlow.cc

View check run for this annotation

Codecov / codecov/patch

python/src/sdf/pyAirFlow.cc#L47

Added line #L47 was not covered by tests
"Get the direction noise values.")
.def("set_direction_noise",
&sdf::AirFlow::SetDirectionNoise,

Check warning on line 50 in python/src/sdf/pyAirFlow.cc

View check run for this annotation

Codecov / codecov/patch

python/src/sdf/pyAirFlow.cc#L50

Added line #L50 was not covered by tests
"Set the noise values related to the direction data.")
.def("__copy__", [](const sdf::AirFlow &self) {
return sdf::AirFlow(self);

Check warning on line 53 in python/src/sdf/pyAirFlow.cc

View check run for this annotation

Codecov / codecov/patch

python/src/sdf/pyAirFlow.cc#L52-L53

Added lines #L52 - L53 were not covered by tests
})
.def("__deepcopy__", [](const sdf::AirFlow &self, pybind11::dict) {
return sdf::AirFlow(self);

Check warning on line 56 in python/src/sdf/pyAirFlow.cc

View check run for this annotation

Codecov / codecov/patch

python/src/sdf/pyAirFlow.cc#L55-L56

Added lines #L55 - L56 were not covered by tests
}, "memo"_a);
}
} // namespace python
} // namespace SDF_VERSION_NAMESPACE
} // namespace sdf
41 changes: 41 additions & 0 deletions python/src/sdf/pyAirFlow.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2023 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 SDFORMAT_PYTHON_AIRFLOW_HH_
#define SDFORMAT_PYTHON_AIRFLOW_HH_

#include <pybind11/pybind11.h>

#include "sdf/AirFlow.hh"

#include "sdf/config.hh"

namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
namespace python
{
/// Define a pybind11 wrapper for an sdf::AirFlow
/**
* \param[in] module a pybind11 module to add the definition to
*/
void defineAirFlow(pybind11::object module);
} // namespace python
} // namespace SDF_VERSION_NAMESPACE
} // namespace sdf

#endif // SDFORMAT_PYTHON_AirFlow_HH_
67 changes: 67 additions & 0 deletions python/test/pyAirFlow_TEST.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (C) 2023 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.

from gz_test_deps.sdformat import AirFlow, Noise
import gz_test_deps.sdformat as sdf
import unittest

class AirFlowTEST(unittest.TestCase):


def test_default_construction(self):
airflow = AirFlow()
defaultNoise = Noise()
self.assertEqual(defaultNoise, airflow.direction_noise())
self.assertEqual(defaultNoise, airflow.speed_noise())

def test_set(self):
air = AirFlow()
defaultNoise = Noise()
dir_noise = Noise()
speed_noise = Noise()
self.assertEqual(defaultNoise, air.speed_noise())
self.assertEqual(defaultNoise, air.direction_noise())

dir_noise.set_type(sdf.NoiseType.GAUSSIAN)
dir_noise.set_mean(1.2)
dir_noise.set_std_dev(2.3)
dir_noise.set_bias_mean(4.5)
dir_noise.set_bias_std_dev(6.7)
dir_noise.set_precision(8.9)

speed_noise.set_type(sdf.NoiseType.GAUSSIAN)
speed_noise.set_mean(1.2)
speed_noise.set_std_dev(2.3)
speed_noise.set_bias_mean(4.5)
speed_noise.set_bias_std_dev(6.7)
speed_noise.set_precision(8.9)

air.set_direction_noise(dir_noise)
self.assertEqual(dir_noise, air.direction_noise())
self.assertEqual(speed_noise, air.speed_noise())

# Copy Constructor
air2 = AirFlow(air)
self.assertEqual(air, air2)

# Copy operator
air3 = air
self.assertEqual(air, air3)

air4 = AirFlow()
self.assertNotEqual(air3, air4);


if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions sdf/1.10/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set (sdfs
actor.sdf
air_flow.sdf
air_pressure.sdf
air_speed.sdf
altimeter.sdf
Expand Down
18 changes: 18 additions & 0 deletions sdf/1.10/air_flow.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<element name="air_flow" required="0">
<description>These elements are specific to an air flow sensor. This sensor emulates an ultrasonic airflow sensor which determines the airspeed and direction based on the doppler effect.</description>

<element name="speed" required="0">
<description>
Noise parameters for the speed data.
</description>
<include filename="noise.sdf" required="0"/>
</element>

<element name="direction" required="0">
<description>
Noise parameters for the direction data.
</description>
<include filename="noise.sdf" required="0"/>
</element>

</element>
2 changes: 2 additions & 0 deletions sdf/1.10/sensor.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<attribute name="type" type="string" default="__default__" required="1">
<description>The type name of the sensor. By default, SDFormat supports types
air_flow,
air_pressure,
air_speed,
altimeter,
Expand Down Expand Up @@ -61,6 +62,7 @@

<include filename="pose.sdf" required="0"/>
<include filename="plugin.sdf" required="*"/>
<include filename="air_flow.sdf" required="0"/>
<include filename="air_pressure.sdf" required="0"/>
<include filename="air_speed.sdf" required="0"/>
<include filename="altimeter.sdf" required="0"/>
Expand Down
Loading