-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Atmosphere Python interface (#968)
Signed-off-by: ahcorde <[email protected]>
- Loading branch information
Showing
7 changed files
with
180 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (C) 2022 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 "pyAtmosphere.hh" | ||
|
||
#include <pybind11/operators.h> | ||
#include <pybind11/pybind11.h> | ||
|
||
#include <ignition/math/Temperature.hh> | ||
|
||
#include "sdf/Atmosphere.hh" | ||
|
||
using namespace pybind11::literals; | ||
|
||
namespace sdf | ||
{ | ||
// Inline bracket to help doxygen filtering. | ||
inline namespace SDF_VERSION_NAMESPACE { | ||
namespace python | ||
{ | ||
///////////////////////////////////////////////// | ||
void defineAtmosphere(pybind11::object module) | ||
{ | ||
pybind11::class_<sdf::Atmosphere> atmosphereModule(module, "Atmosphere"); | ||
atmosphereModule | ||
.def(pybind11::init<>()) | ||
.def(pybind11::init<sdf::Atmosphere>()) | ||
.def(pybind11::self == pybind11::self) | ||
.def("type", &sdf::Atmosphere::Type, | ||
"Get the type of the atmospheric model.") | ||
.def("set_type", &sdf::Atmosphere::SetType, | ||
"Set the type of the atmospheric model.") | ||
.def("temperature", &sdf::Atmosphere::Temperature, | ||
"Get the temperature at sea level.") | ||
.def("set_temperature", &sdf::Atmosphere::SetTemperature, | ||
"Set the temperature at sea level") | ||
.def("temperature_gradient", &sdf::Atmosphere::TemperatureGradient, | ||
"Get the temperature gradient with respect to increasing " | ||
"altitude in units of K/m.") | ||
.def("set_temperature_gradient", &sdf::Atmosphere::SetTemperatureGradient, | ||
"Set the temperature gradient with respect to increasing " | ||
"altitude in units of K/m.") | ||
.def("pressure", &sdf::Atmosphere::Pressure, | ||
"Get the pressure at sea level in pascals.") | ||
.def("set_pressure", &sdf::Atmosphere::SetPressure, | ||
"Set the pressure at sea level in pascals.") | ||
.def("__copy__", [](const sdf::Atmosphere &self) { | ||
return sdf::Atmosphere(self); | ||
}) | ||
.def("__deepcopy__", [](const sdf::Atmosphere &self, pybind11::dict) { | ||
return sdf::Atmosphere(self); | ||
}, "memo"_a); | ||
|
||
pybind11::enum_<sdf::AtmosphereType>(atmosphereModule, "AtmosphereType") | ||
.value("ADIABATIC", sdf::AtmosphereType::ADIABATIC); | ||
} | ||
} // namespace python | ||
} // namespace SDF_VERSION_NAMESPACE | ||
} // namespace sdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2022 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_ATMOSPHERE_HH_ | ||
#define SDFORMAT_PYTHON_ATMOSPHERE_HH_ | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
#include "sdf/Atmosphere.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::Atmosphere | ||
/** | ||
* \param[in] module a pybind11 module to add the definition to | ||
*/ | ||
void defineAtmosphere(pybind11::object module); | ||
} // namespace python | ||
} // namespace SDF_VERSION_NAMESPACE | ||
} // namespace sdf | ||
|
||
#endif // SDFORMAT_PYTHON_ATMOSPHERE_HH_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright (C) 2022 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 ignition.math import Pose3d, Temperature | ||
from sdformat import Atmosphere | ||
import unittest | ||
|
||
class AtmosphereTEST(unittest.TestCase): | ||
|
||
|
||
def test_default_construction(self): | ||
atmosphere = Atmosphere() | ||
self.assertEqual(Atmosphere.AtmosphereType.ADIABATIC, atmosphere.type()) | ||
self.assertAlmostEqual(288.15, atmosphere.temperature().kelvin()) | ||
self.assertAlmostEqual(-0.0065, atmosphere.temperature_gradient()) | ||
self.assertAlmostEqual(101325, atmosphere.pressure()) | ||
|
||
|
||
def test_set(self): | ||
atmosphere = Atmosphere() | ||
atmosphere.set_type(Atmosphere.AtmosphereType.ADIABATIC) | ||
self.assertEqual(Atmosphere.AtmosphereType.ADIABATIC, atmosphere.type()) | ||
|
||
atmosphere.set_temperature(Temperature(123.23)) | ||
self.assertAlmostEqual(123.23, atmosphere.temperature().kelvin()) | ||
|
||
atmosphere.set_temperature_gradient(-1.65) | ||
self.assertAlmostEqual(-1.65, atmosphere.temperature_gradient()) | ||
|
||
atmosphere.set_pressure(76531.3) | ||
self.assertAlmostEqual(76531.3, atmosphere.pressure()) | ||
|
||
|
||
def test_copy_assignment(self): | ||
atmosphere = Atmosphere() | ||
atmosphere.set_temperature(Temperature(123.23)) | ||
atmosphere.set_temperature_gradient(-1.65) | ||
atmosphere.set_pressure(76531.3) | ||
|
||
atmosphere2 = atmosphere | ||
self.assertEqual(Atmosphere.AtmosphereType.ADIABATIC, atmosphere2.type()) | ||
self.assertAlmostEqual(123.23, atmosphere2.temperature().kelvin()) | ||
self.assertAlmostEqual(-1.65, atmosphere2.temperature_gradient()) | ||
self.assertAlmostEqual(76531.3, atmosphere2.pressure()) | ||
|
||
self.assertEqual(atmosphere, atmosphere2) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters