From bd9846efbb56e227147bb1b69b712f8037cdf4d8 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 18 Jul 2023 08:12:11 -0500 Subject: [PATCH 01/27] Adds bindings for the world convenience class Signed-off-by: Voldivh --- python/src/gz/sim/World.cc | 72 ++++++++++++++++++++++++++++++++++---- python/test/world_TEST.py | 26 ++++++++++++++ 2 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 python/test/world_TEST.py diff --git a/python/src/gz/sim/World.cc b/python/src/gz/sim/World.cc index d21187bdf0..9a2fa68ce1 100644 --- a/python/src/gz/sim/World.cc +++ b/python/src/gz/sim/World.cc @@ -22,6 +22,8 @@ #include "World.hh" +namespace py = pybind11; + namespace gz { namespace sim @@ -32,13 +34,69 @@ void defineSimWorld(pybind11::object module) { pybind11::class_(module, "World") .def(pybind11::init()) - .def( - "model_by_name", &gz::sim::World::ModelByName, - "Get the ID of a model entity which is an immediate child of " - " this world.") - .def( - "gravity", &gz::sim::World::Gravity, - "Get the gravity in m/s^2."); + // Make get methods as read_only_property? + .def( "entity", &gz::sim::World::Entity, + "Get the entity which this World is related to.") + .def("valid", &gz::sim::World::Valid, + py::arg("ecm"), + "Check whether this world correctly refers to an entity that" + "has a components::World.") + .def("name", &gz::sim::World::Name, + py::arg("ecm"), + "Get the world's unscoped name.") + .def("gravity", &gz::sim::World::Gravity, + py::arg("ecm"), + "Get the gravity in m/s^2.") + .def("magnetic_field", &gz::sim::World::MagneticField, + py::arg("ecm"), + "Get the magnetic field in Tesla.") + .def("atmosphere", &gz::sim::World::Atmosphere, + py::arg("ecm"), + "Get atmosphere information.") + // Make get/set methods as properties? Probably no because of ecm argument + .def("spherical_coordinates", &gz::sim::World::SphericalCoordinates, + py::arg("ecm"), + "Get spherical coordinates for the world origin.") + .def("set_spherical_coordinates", &gz::sim::World::SetSphericalCoordinates, + py::arg("ecm"), + py::arg("spherical_coordinates"), + "Set spherical coordinates for the world origin.") + .def("light_by_name", &gz::sim::World::LightByName, + py::arg("ecm"), + py::arg("name"), + "Get the ID of a light entity which is an immediate child of" + "this world.") + .def("actor_by_name", &gz::sim::World::ActorByName, + py::arg("ecm"), + py::arg("name"), + "Get the ID of a actor entity which is an immediate child of" + "this world.") + .def("model_by_name", &gz::sim::World::ModelByName, + py::arg("ecm"), + py::arg("name"), + "Get the ID of a model entity which is an immediate child of " + " this world.") + .def("lights", &gz::sim::World::Lights, + py::arg("ecm"), + "Get all lights which are immediate children of this world.") + .def("actors", &gz::sim::World::Actors, + py::arg("ecm"), + "Get all actors which are immediate children of this world.") + .def("models", &gz::sim::World::Models, + py::arg("ecm"), + "Get all models which are immediate children of this world.") + .def("light_count", &gz::sim::World::LightCount, + py::arg("ecm"), + "Get the number of lights which are immediate children of this" + "world.") + .def("actor_count", &gz::sim::World::ActorCount, + py::arg("ecm"), + "Get the number of actors which are immediate children of this" + "world.") + .def("model_count", &gz::sim::World::ModelCount, + py::arg("ecm"), + "Get the number of models which are immediate children of this" + "world."); } } // namespace python } // namespace sim diff --git a/python/test/world_TEST.py b/python/test/world_TEST.py new file mode 100644 index 0000000000..85b33e5a6f --- /dev/null +++ b/python/test/world_TEST.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +# 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. + +import unittest + +from gz.common import set_verbosity +from gz.sim8 import TestFixture, World, world_entity +from gz.math7 import Vector3d + +class WorldTEST(unittest.TestCase): + + def test_world(self): + pass + From 1db3735f00b48f883ebd695820ac1a68dbe8e80a Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 18 Jul 2023 15:28:46 -0500 Subject: [PATCH 02/27] Adds initial tests Signed-off-by: Voldivh --- python/CMakeLists.txt | 1 + python/src/gz/sim/World.cc | 6 ++---- python/test/world_TEST.py | 43 +++++++++++++++++++++++++++++++------- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index bd025f0959..1250c1827a 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -87,6 +87,7 @@ endif() if (BUILD_TESTING) set(python_tests testFixture_TEST + world_TEST ) execute_process(COMMAND "${GZ_PYTHON_EXECUTABLE}" -m pytest --version diff --git a/python/src/gz/sim/World.cc b/python/src/gz/sim/World.cc index 9a2fa68ce1..23e4c8078c 100644 --- a/python/src/gz/sim/World.cc +++ b/python/src/gz/sim/World.cc @@ -34,8 +34,7 @@ void defineSimWorld(pybind11::object module) { pybind11::class_(module, "World") .def(pybind11::init()) - // Make get methods as read_only_property? - .def( "entity", &gz::sim::World::Entity, + .def("entity", &gz::sim::World::Entity, "Get the entity which this World is related to.") .def("valid", &gz::sim::World::Valid, py::arg("ecm"), @@ -53,7 +52,6 @@ void defineSimWorld(pybind11::object module) .def("atmosphere", &gz::sim::World::Atmosphere, py::arg("ecm"), "Get atmosphere information.") - // Make get/set methods as properties? Probably no because of ecm argument .def("spherical_coordinates", &gz::sim::World::SphericalCoordinates, py::arg("ecm"), "Get spherical coordinates for the world origin.") @@ -75,7 +73,7 @@ void defineSimWorld(pybind11::object module) py::arg("ecm"), py::arg("name"), "Get the ID of a model entity which is an immediate child of " - " this world.") + "this world.") .def("lights", &gz::sim::World::Lights, py::arg("ecm"), "Get all lights which are immediate children of this world.") diff --git a/python/test/world_TEST.py b/python/test/world_TEST.py index 85b33e5a6f..63cfc57775 100644 --- a/python/test/world_TEST.py +++ b/python/test/world_TEST.py @@ -15,12 +15,41 @@ import unittest -from gz.common import set_verbosity -from gz.sim8 import TestFixture, World, world_entity -from gz.math7 import Vector3d +from gz.sim8 import EntityComponentManager, World, world_entity +from gz.math7 import SphericalCoordinates -class WorldTEST(unittest.TestCase): - - def test_world(self): - pass +class WorldTEST(unittest.TestCase): + def setUp(self): + self.ecm = EntityComponentManager() + self.world_e = world_entity(self.ecm) + self.world = World(self.world_e) + + def test_world_entity(self): + self.assertEqual(self.world_e, self.world.entity()) + + def test_world_valid(self): + self.assertFalse(self.world.valid(self.ecm)) + # Missing a way to set up the world component in the entity + + def test_world_name(self): + self.assertEqual(None, self.world.name(self.ecm)) + # Missing a way to set up the name for the world + + def test_world_gravity(self): + self.assertEqual(None, self.world.gravity(self.ecm)) + # Missing a way to set up the gravity for the world + + def test_world_atmosphere(self): + self.assertEqual(None, self.world.atmosphere(self.ecm)) + # Missing a way to set up the atmosphere for the world + + def test_world_magnetic_field(self): + self.assertEqual(None, self.world.magnetic_field(self.ecm)) + # Missing a way to set up the magnetic field for the world + + def test_world_spherical_coordinates(self): + self.assertEqual(None, self.world.spherical_coordinates(self.ecm)) + self.world.set_spherical_coordinates(self.ecm, SphericalCoordinates()) + # This assertion should be `self.assertEqual(SphericalCoordinates(), self.world.spherical_coordinates(self.ecm))` + self.assertEqual(None, self.world.spherical_coordinates(self.ecm)) From df9608ef7ed5970eccd6d91537d05f955cc99765 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Wed, 19 Jul 2023 14:10:36 -0500 Subject: [PATCH 03/27] Use alias on bindings Signed-off-by: Voldivh --- python/src/gz/sim/World.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/src/gz/sim/World.cc b/python/src/gz/sim/World.cc index 23e4c8078c..24d9ce8e27 100644 --- a/python/src/gz/sim/World.cc +++ b/python/src/gz/sim/World.cc @@ -30,10 +30,10 @@ namespace sim { namespace python { -void defineSimWorld(pybind11::object module) +void defineSimWorld(py::object module) { - pybind11::class_(module, "World") - .def(pybind11::init()) + py::class_(module, "World") + .def(py::init()) .def("entity", &gz::sim::World::Entity, "Get the entity which this World is related to.") .def("valid", &gz::sim::World::Valid, From 40423f8fad7bc607751059a72a5d0f0385682504 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 25 Jul 2023 18:58:37 -0500 Subject: [PATCH 04/27] Adds test to this class Signed-off-by: Voldivh --- python/src/gz/sim/World.cc | 12 +++--- python/test/world.sdf | 27 ++++++++++++ python/test/world_TEST.py | 84 ++++++++++++++++++++++++-------------- 3 files changed, 87 insertions(+), 36 deletions(-) create mode 100644 python/test/world.sdf diff --git a/python/src/gz/sim/World.cc b/python/src/gz/sim/World.cc index 24d9ce8e27..06595fb732 100644 --- a/python/src/gz/sim/World.cc +++ b/python/src/gz/sim/World.cc @@ -38,7 +38,7 @@ void defineSimWorld(py::object module) "Get the entity which this World is related to.") .def("valid", &gz::sim::World::Valid, py::arg("ecm"), - "Check whether this world correctly refers to an entity that" + "Check whether this world correctly refers to an entity that " "has a components::World.") .def("name", &gz::sim::World::Name, py::arg("ecm"), @@ -62,12 +62,12 @@ void defineSimWorld(py::object module) .def("light_by_name", &gz::sim::World::LightByName, py::arg("ecm"), py::arg("name"), - "Get the ID of a light entity which is an immediate child of" + "Get the ID of a light entity which is an immediate child of " "this world.") .def("actor_by_name", &gz::sim::World::ActorByName, py::arg("ecm"), py::arg("name"), - "Get the ID of a actor entity which is an immediate child of" + "Get the ID of a actor entity which is an immediate child of " "this world.") .def("model_by_name", &gz::sim::World::ModelByName, py::arg("ecm"), @@ -85,15 +85,15 @@ void defineSimWorld(py::object module) "Get all models which are immediate children of this world.") .def("light_count", &gz::sim::World::LightCount, py::arg("ecm"), - "Get the number of lights which are immediate children of this" + "Get the number of lights which are immediate children of this " "world.") .def("actor_count", &gz::sim::World::ActorCount, py::arg("ecm"), - "Get the number of actors which are immediate children of this" + "Get the number of actors which are immediate children of this " "world.") .def("model_count", &gz::sim::World::ModelCount, py::arg("ecm"), - "Get the number of models which are immediate children of this" + "Get the number of models which are immediate children of this " "world."); } } // namespace python diff --git a/python/test/world.sdf b/python/test/world.sdf new file mode 100644 index 0000000000..2359a0bb58 --- /dev/null +++ b/python/test/world.sdf @@ -0,0 +1,27 @@ + + + + + 0.01 + 1.0 + + + + 0 0 -10 + 1 2 3 + + 300 + 100000 + -0.005 + + + EARTH_WGS84 + 10 + 15 + 20 + 25 + + + \ No newline at end of file diff --git a/python/test/world_TEST.py b/python/test/world_TEST.py index 63cfc57775..2249b79b32 100644 --- a/python/test/world_TEST.py +++ b/python/test/world_TEST.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# Copyright (C) 2023 Open Source Robotics Foundation +# 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. @@ -13,43 +13,67 @@ # See the License for the specific language governing permissions and # limitations under the License. +import os import unittest -from gz.sim8 import EntityComponentManager, World, world_entity -from gz.math7 import SphericalCoordinates +from gz.common import set_verbosity +from gz.sim8 import TestFixture, World, world_entity +from gz.math7 import Vector3d, SphericalCoordinates +from sdformat13 import Atmosphere +post_iterations = 0 +iterations = 0 +pre_iterations = 0 -class WorldTEST(unittest.TestCase): - def setUp(self): - self.ecm = EntityComponentManager() - self.world_e = world_entity(self.ecm) - self.world = World(self.world_e) +class TestWorld(unittest.TestCase): - def test_world_entity(self): - self.assertEqual(self.world_e, self.world.entity()) + def test_world(self): + set_verbosity(4) - def test_world_valid(self): - self.assertFalse(self.world.valid(self.ecm)) - # Missing a way to set up the world component in the entity + file_path = os.path.dirname(os.path.realpath(__file__)) + fixture = TestFixture(os.path.join(file_path, 'world.sdf')) - def test_world_name(self): - self.assertEqual(None, self.world.name(self.ecm)) - # Missing a way to set up the name for the world + def on_post_udpate_cb(_info, _ecm): + global post_iterations + post_iterations += 1 - def test_world_gravity(self): - self.assertEqual(None, self.world.gravity(self.ecm)) - # Missing a way to set up the gravity for the world + def on_pre_udpate_cb(_info, _ecm): + global pre_iterations + pre_iterations += 1 + world_e = world_entity(_ecm) + self.assertEqual(1, world_e) + world = World(world_e) + # Valid Test + self.assertTrue(world.valid(_ecm)) + # Name Test + self.assertEqual('world_test', world.name(_ecm)) + # Gravity Test + self.assertEqual(Vector3d(0, 0, -10), world.gravity(_ecm)) + # Magnetic Field Test + self.assertEqual(Vector3d(1, 2, 3), world.magnetic_field(_ecm)) + # Atmosphere Test + atmosphere = world.atmosphere(_ecm) + self.assertEqual(300, atmosphere.temperature()) + self.assertEqual(100000, atmosphere.pressure()) + self.assertEqual(-0.005, atmosphere.temperature_gradient()) + # Spherical Coordinates Test + self.assertTrue(world.spherical_coordinates(_ecm)) - def test_world_atmosphere(self): - self.assertEqual(None, self.world.atmosphere(self.ecm)) - # Missing a way to set up the atmosphere for the world + def on_udpate_cb(_info, _ecm): + global iterations + iterations += 1 - def test_world_magnetic_field(self): - self.assertEqual(None, self.world.magnetic_field(self.ecm)) - # Missing a way to set up the magnetic field for the world + fixture.on_post_update(on_post_udpate_cb) + fixture.on_update(on_udpate_cb) + fixture.on_pre_update(on_pre_udpate_cb) + fixture.finalize() - def test_world_spherical_coordinates(self): - self.assertEqual(None, self.world.spherical_coordinates(self.ecm)) - self.world.set_spherical_coordinates(self.ecm, SphericalCoordinates()) - # This assertion should be `self.assertEqual(SphericalCoordinates(), self.world.spherical_coordinates(self.ecm))` - self.assertEqual(None, self.world.spherical_coordinates(self.ecm)) + server = fixture.server() + server.run(True, 1000, False) + + self.assertEqual(1000, pre_iterations) + self.assertEqual(1000, iterations) + self.assertEqual(1000, post_iterations) + +if __name__ == '__main__': + unittest.main() From 4a013a6fdbac8b42c0cd6fa06691dc38d643a539 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Wed, 26 Jul 2023 09:34:00 -0500 Subject: [PATCH 05/27] Adds missing dependency for CI Signed-off-by: Voldivh --- CMakeLists.txt | 5 +++++ python/test/world_TEST.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f75b0d492e..9e2c8eeff9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,6 +169,11 @@ set(GZ_RENDERING_VER ${gz-rendering8_VERSION_MAJOR}) gz_find_package(gz-math7 REQUIRED COMPONENTS eigen3) set(GZ_MATH_VER ${gz-math7_VERSION_MAJOR}) +#-------------------------------------- +# Find sdformat +gz_find_package(sdformat13 REQUIRED) +set(SDF_VER ${sdformat13_VERSION_MAJOR}) + #-------------------------------------- # Find if gz command is available find_program(GZ_TOOLS_PROGRAM gz) diff --git a/python/test/world_TEST.py b/python/test/world_TEST.py index 2249b79b32..35a01f3857 100644 --- a/python/test/world_TEST.py +++ b/python/test/world_TEST.py @@ -18,7 +18,7 @@ from gz.common import set_verbosity from gz.sim8 import TestFixture, World, world_entity -from gz.math7 import Vector3d, SphericalCoordinates +from gz.math7 import Vector3d from sdformat13 import Atmosphere post_iterations = 0 From 55e5bb75b99ee15abb3994196b76c387fcfe7016 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Wed, 26 Jul 2023 09:34:32 -0500 Subject: [PATCH 06/27] Adds dependency to packages.apt Signed-off-by: Voldivh --- .github/ci/packages.apt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ci/packages.apt b/.github/ci/packages.apt index e3bec904ba..da34a699a6 100644 --- a/.github/ci/packages.apt +++ b/.github/ci/packages.apt @@ -32,6 +32,7 @@ python3-distutils python3-gz-math7 python3-pybind11 python3-pytest +python3-sdformat13 qml-module-qt-labs-folderlistmodel qml-module-qt-labs-settings qml-module-qtgraphicaleffects From 863b61bf5f16bd51811db3aa8355d6659a3a8377 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Wed, 26 Jul 2023 09:38:36 -0500 Subject: [PATCH 07/27] Adds newline at the end of file Signed-off-by: Voldivh --- python/test/world.sdf | 2 +- python/test/world_TEST.py | 0 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 python/test/world_TEST.py diff --git a/python/test/world.sdf b/python/test/world.sdf index 2359a0bb58..9772a4a7db 100644 --- a/python/test/world.sdf +++ b/python/test/world.sdf @@ -24,4 +24,4 @@ 25 - \ No newline at end of file + diff --git a/python/test/world_TEST.py b/python/test/world_TEST.py old mode 100644 new mode 100755 From e7c955b59cf38abf2c5b268b8aebb5d95067178c Mon Sep 17 00:00:00 2001 From: Voldivh Date: Thu, 27 Jul 2023 09:47:53 -0500 Subject: [PATCH 08/27] Renames the world sdf file Signed-off-by: Voldivh --- python/test/{world.sdf => world_test.sdf} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename python/test/{world.sdf => world_test.sdf} (100%) diff --git a/python/test/world.sdf b/python/test/world_test.sdf similarity index 100% rename from python/test/world.sdf rename to python/test/world_test.sdf From cbcdf3d8a1d24b1825b727a6b38cf88e234b807d Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 1 Aug 2023 12:53:22 -0500 Subject: [PATCH 09/27] Adds the rest of the test Signed-off-by: Voldivh --- python/test/world_TEST.py | 26 +++++++++++++++++++++++--- python/test/world_test.sdf | 12 ++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/python/test/world_TEST.py b/python/test/world_TEST.py index 35a01f3857..2f1e9b1e96 100755 --- a/python/test/world_TEST.py +++ b/python/test/world_TEST.py @@ -18,7 +18,7 @@ from gz.common import set_verbosity from gz.sim8 import TestFixture, World, world_entity -from gz.math7 import Vector3d +from gz.math7 import Angle, SphericalCoordinates, Vector3d from sdformat13 import Atmosphere post_iterations = 0 @@ -31,7 +31,7 @@ def test_world(self): set_verbosity(4) file_path = os.path.dirname(os.path.realpath(__file__)) - fixture = TestFixture(os.path.join(file_path, 'world.sdf')) + fixture = TestFixture(os.path.join(file_path, 'world_test.sdf')) def on_post_udpate_cb(_info, _ecm): global post_iterations @@ -57,7 +57,27 @@ def on_pre_udpate_cb(_info, _ecm): self.assertEqual(100000, atmosphere.pressure()) self.assertEqual(-0.005, atmosphere.temperature_gradient()) # Spherical Coordinates Test - self.assertTrue(world.spherical_coordinates(_ecm)) + self.assertEqual(SphericalCoordinates.SurfaceType.EARTH_WGS84, world.spherical_coordinates(_ecm).surface()) + if pre_iterations <= 1: + self.assertAlmostEqual(float(10), world.spherical_coordinates(_ecm).latitude_reference().degree()) + self.assertAlmostEqual(float(15), world.spherical_coordinates(_ecm).longitude_reference().degree()) + self.assertAlmostEqual(float(20), world.spherical_coordinates(_ecm).elevation_reference()) + self.assertAlmostEqual(float(25), world.spherical_coordinates(_ecm).heading_offset().degree()) + world.set_spherical_coordinates(_ecm, SphericalCoordinates()) + else: + self.assertAlmostEqual(float(0), world.spherical_coordinates(_ecm).latitude_reference().degree()) + self.assertAlmostEqual(float(0), world.spherical_coordinates(_ecm).longitude_reference().degree()) + self.assertAlmostEqual(float(0), world.spherical_coordinates(_ecm).elevation_reference()) + self.assertAlmostEqual(float(0), world.spherical_coordinates(_ecm).heading_offset().degree()) + # Light Test + self.assertEqual(7, world.light_by_name(_ecm, 'light_point_test')) + self.assertEqual(1, world.light_count(_ecm)) + # Actor test + self.assertEqual(6, world.actor_by_name(_ecm, 'actor_test')) + self.assertEqual(1, world.actor_count(_ecm)) + # Model Test + self.assertEqual(4, world.model_by_name(_ecm, 'model_test')) + self.assertEqual(1, world.model_count(_ecm)) def on_udpate_cb(_info, _ecm): global iterations diff --git a/python/test/world_test.sdf b/python/test/world_test.sdf index 9772a4a7db..e3c301ccbc 100644 --- a/python/test/world_test.sdf +++ b/python/test/world_test.sdf @@ -23,5 +23,17 @@ 20 25 + + + + + + + + + + 0 0 0 0 0 0 + + From aa435d6f78bb410c19d6aab3c551ceceb65ae3bb Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 1 Aug 2023 12:56:00 -0500 Subject: [PATCH 10/27] Removes trailing whitespace Signed-off-by: Voldivh --- python/test/world_TEST.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/test/world_TEST.py b/python/test/world_TEST.py index 2f1e9b1e96..bef77599d1 100755 --- a/python/test/world_TEST.py +++ b/python/test/world_TEST.py @@ -18,7 +18,7 @@ from gz.common import set_verbosity from gz.sim8 import TestFixture, World, world_entity -from gz.math7 import Angle, SphericalCoordinates, Vector3d +from gz.math7 import SphericalCoordinates, Vector3d from sdformat13 import Atmosphere post_iterations = 0 From a97358d5fcff65c2fc46f546eafa388915079724 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 8 Aug 2023 10:31:05 -0500 Subject: [PATCH 11/27] Adds import dependency files Signed-off-by: Voldivh --- CMakeLists.txt | 5 ----- python/src/gz/sim/World.cc | 2 -- python/test/gz_test_deps/__init__.py | 0 python/test/gz_test_deps/math.py | 1 + python/test/gz_test_deps/sdformat.py | 1 + python/test/gz_test_deps/sim.py | 1 + python/test/world_TEST.py | 6 +++--- 7 files changed, 6 insertions(+), 10 deletions(-) create mode 100644 python/test/gz_test_deps/__init__.py create mode 100644 python/test/gz_test_deps/math.py create mode 100644 python/test/gz_test_deps/sdformat.py create mode 100644 python/test/gz_test_deps/sim.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e2c8eeff9..f75b0d492e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,11 +169,6 @@ set(GZ_RENDERING_VER ${gz-rendering8_VERSION_MAJOR}) gz_find_package(gz-math7 REQUIRED COMPONENTS eigen3) set(GZ_MATH_VER ${gz-math7_VERSION_MAJOR}) -#-------------------------------------- -# Find sdformat -gz_find_package(sdformat13 REQUIRED) -set(SDF_VER ${sdformat13_VERSION_MAJOR}) - #-------------------------------------- # Find if gz command is available find_program(GZ_TOOLS_PROGRAM gz) diff --git a/python/src/gz/sim/World.cc b/python/src/gz/sim/World.cc index 06595fb732..2abfd00252 100644 --- a/python/src/gz/sim/World.cc +++ b/python/src/gz/sim/World.cc @@ -18,8 +18,6 @@ #include #include -#include - #include "World.hh" namespace py = pybind11; diff --git a/python/test/gz_test_deps/__init__.py b/python/test/gz_test_deps/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/python/test/gz_test_deps/math.py b/python/test/gz_test_deps/math.py new file mode 100644 index 0000000000..15296a9b7a --- /dev/null +++ b/python/test/gz_test_deps/math.py @@ -0,0 +1 @@ +from gz.math7 import * \ No newline at end of file diff --git a/python/test/gz_test_deps/sdformat.py b/python/test/gz_test_deps/sdformat.py new file mode 100644 index 0000000000..a8f9336a56 --- /dev/null +++ b/python/test/gz_test_deps/sdformat.py @@ -0,0 +1 @@ +from sdformat13 import * \ No newline at end of file diff --git a/python/test/gz_test_deps/sim.py b/python/test/gz_test_deps/sim.py new file mode 100644 index 0000000000..acd7ffa773 --- /dev/null +++ b/python/test/gz_test_deps/sim.py @@ -0,0 +1 @@ +from gz.sim8 import * \ No newline at end of file diff --git a/python/test/world_TEST.py b/python/test/world_TEST.py index bef77599d1..a2758384f6 100755 --- a/python/test/world_TEST.py +++ b/python/test/world_TEST.py @@ -17,9 +17,9 @@ import unittest from gz.common import set_verbosity -from gz.sim8 import TestFixture, World, world_entity -from gz.math7 import SphericalCoordinates, Vector3d -from sdformat13 import Atmosphere +from gz_test_deps.sim import TestFixture, World, world_entity +from gz_test_deps.math import SphericalCoordinates, Vector3d +from gz_test_deps.sdformat import Atmosphere post_iterations = 0 iterations = 0 From 99c9de07069de28db2e608e26bb9f891038af263 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 8 Aug 2023 10:32:47 -0500 Subject: [PATCH 12/27] Adds newline at end of files Signed-off-by: Voldivh --- python/test/gz_test_deps/math.py | 2 +- python/test/gz_test_deps/sdformat.py | 2 +- python/test/gz_test_deps/sim.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/test/gz_test_deps/math.py b/python/test/gz_test_deps/math.py index 15296a9b7a..cb2860c798 100644 --- a/python/test/gz_test_deps/math.py +++ b/python/test/gz_test_deps/math.py @@ -1 +1 @@ -from gz.math7 import * \ No newline at end of file +from gz.math7 import * diff --git a/python/test/gz_test_deps/sdformat.py b/python/test/gz_test_deps/sdformat.py index a8f9336a56..241e91374f 100644 --- a/python/test/gz_test_deps/sdformat.py +++ b/python/test/gz_test_deps/sdformat.py @@ -1 +1 @@ -from sdformat13 import * \ No newline at end of file +from sdformat13 import * diff --git a/python/test/gz_test_deps/sim.py b/python/test/gz_test_deps/sim.py index acd7ffa773..38c3164e14 100644 --- a/python/test/gz_test_deps/sim.py +++ b/python/test/gz_test_deps/sim.py @@ -1 +1 @@ -from gz.sim8 import * \ No newline at end of file +from gz.sim8 import * From 5414b55ead542485776e0fea9f5d0f65fe26a61e Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Tue, 18 Jul 2023 16:29:25 +0000 Subject: [PATCH 13/27] Address reviewer feedback Signed-off-by: Michael Carroll --- include/ignition/gazebo/Actor.hh | 19 ----------------- include/ignition/gazebo/Joint.hh | 19 ----------------- include/ignition/gazebo/Light.hh | 19 ----------------- include/ignition/gazebo/Sensor.hh | 19 ----------------- .../gazebo/components/BatteryPowerLoad.hh | 19 ----------------- src/cmd/cmdsim.rb.in | 4 ---- src/gz.hh | 21 ++++++++++--------- tutorials/blender_procedural_datasets.md | 2 +- 8 files changed, 12 insertions(+), 110 deletions(-) delete mode 100644 include/ignition/gazebo/Actor.hh delete mode 100644 include/ignition/gazebo/Joint.hh delete mode 100644 include/ignition/gazebo/Light.hh delete mode 100644 include/ignition/gazebo/Sensor.hh delete mode 100644 include/ignition/gazebo/components/BatteryPowerLoad.hh diff --git a/include/ignition/gazebo/Actor.hh b/include/ignition/gazebo/Actor.hh deleted file mode 100644 index a8bd091180..0000000000 --- a/include/ignition/gazebo/Actor.hh +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 -#include diff --git a/include/ignition/gazebo/Joint.hh b/include/ignition/gazebo/Joint.hh deleted file mode 100644 index 8b4269d202..0000000000 --- a/include/ignition/gazebo/Joint.hh +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 -#include diff --git a/include/ignition/gazebo/Light.hh b/include/ignition/gazebo/Light.hh deleted file mode 100644 index 087d73bc21..0000000000 --- a/include/ignition/gazebo/Light.hh +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 -#include diff --git a/include/ignition/gazebo/Sensor.hh b/include/ignition/gazebo/Sensor.hh deleted file mode 100644 index e6325f0464..0000000000 --- a/include/ignition/gazebo/Sensor.hh +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 -#include diff --git a/include/ignition/gazebo/components/BatteryPowerLoad.hh b/include/ignition/gazebo/components/BatteryPowerLoad.hh deleted file mode 100644 index 99f9606b07..0000000000 --- a/include/ignition/gazebo/components/BatteryPowerLoad.hh +++ /dev/null @@ -1,19 +0,0 @@ -/* - * 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 -#include diff --git a/src/cmd/cmdsim.rb.in b/src/cmd/cmdsim.rb.in index 65f606d300..64ee638c7b 100755 --- a/src/cmd/cmdsim.rb.in +++ b/src/cmd/cmdsim.rb.in @@ -609,10 +609,6 @@ See https://github.com/gazebosim/gz-sim/issues/168 for more info." options['wait_gui'], options['render_engine_gui'], options['render_engine_gui_api_backend']) end - rescue - puts "Library error: Problem running [#{options['command']}]() "\ - "from #{plugin}." - # begin end # execute end diff --git a/src/gz.hh b/src/gz.hh index 30bce8fb95..0489510fdc 100644 --- a/src/gz.hh +++ b/src/gz.hh @@ -21,18 +21,18 @@ /// \brief External hook to read the library version. /// \return C-string representing the version. Ex.: 0.1.2 -extern "C" GZ_SIM_VISIBLE char *gzSimVersion(); +extern "C" GZ_SIM_GZ_VISIBLE char *gzSimVersion(); /// \brief Get the Gazebo version header. /// \return C-string containing the Gazebo version information. -extern "C" GZ_SIM_VISIBLE char *simVersionHeader(); +extern "C" GZ_SIM_GZ_VISIBLE char *simVersionHeader(); /// \brief Set verbosity level /// \param[in] _verbosity 0 to 4 -extern "C" GZ_SIM_VISIBLE void cmdVerbosity( +extern "C" GZ_SIM_GZ_VISIBLE void cmdVerbosity( const char *_verbosity); -extern "C" GZ_SIM_VISIBLE const char *worldInstallDir(); +extern "C" GZ_SIM_GZ_VISIBLE const char *worldInstallDir(); /// \brief External hook to run simulation server. /// \param[in] _sdfString SDF file to run, as a string. @@ -62,7 +62,7 @@ extern "C" GZ_SIM_VISIBLE const char *worldInstallDir(); /// \param[in] _recordPeriod --record-period option /// \param[in] _seed --seed value to be used for random number generator. /// \return 0 if successful, 1 if not. -extern "C" GZ_SIM_VISIBLE int runServer(const char *_sdfString, +extern "C" GZ_SIM_GZ_VISIBLE int runServer(const char *_sdfString, int _iterations, int _run, float _hz, double _initialSimTime, int _levels, const char *_networkRole, int _networkSecondaries, int _record, const char *_recordPath, int _recordResources, int _logOverwrite, @@ -82,16 +82,17 @@ extern "C" GZ_SIM_VISIBLE int runServer(const char *_sdfString, /// \param[in] _renderEngine --render-engine-gui option /// \param[in] _renderEngineGuiApiBackend --render-engine-gui-api-backend option /// \return 0 if successful, 1 if not. -extern "C" GZ_SIM_VISIBLE int runGui(const char *_guiConfig, const char *_file, - int _waitGui, - const char *_renderEngine, - const char *_renderEngineGuiApiBackend); +extern "C" GZ_SIM_GZ_VISIBLE +int runGui(const char *_guiConfig, const char *_file, + int _waitGui, + const char *_renderEngine, + const char *_renderEngineGuiApiBackend); /// \brief External hook to find or download a fuel world provided a URL. /// \param[in] _pathToResource Path to the fuel world resource, ie, /// https://staging-fuel.gazebosim.org/1.0/gmas/worlds/ShapesClone /// \return C-string containing the path to the local world sdf file -extern "C" GZ_SIM_VISIBLE const char *findFuelResource( +extern "C" GZ_SIM_GZ_VISIBLE const char *findFuelResource( char *_pathToResource); #endif diff --git a/tutorials/blender_procedural_datasets.md b/tutorials/blender_procedural_datasets.md index 9b9f5edf6b..c0a27f4c84 100644 --- a/tutorials/blender_procedural_datasets.md +++ b/tutorials/blender_procedural_datasets.md @@ -93,7 +93,7 @@ blender [blender options] file.blend 4. Run the script using the *Run script* button in the panel of the *Text Editor* tab at the top of the screen. -@image html https://github.com/gazebosim/gz-sim/tree/main/tutorials/files/blender_procedural_datasets/blender_instructions.png "Instructions in Blender" width=100% +![Instructions in Blender](https://raw.githubusercontent.com/gazebosim/gz-sim/main/tutorials/files/blender_procedural_datasets/blender_instructions.png) Once you follow these steps and configure the script for your `.blend` project, you can save it and use Option B in the future. From d04f3edd01dc46b6dc7904072c4d60b1971fddd6 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Tue, 18 Jul 2023 19:34:00 +0000 Subject: [PATCH 14/27] Include correct export header Signed-off-by: Michael Carroll --- src/gz.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gz.hh b/src/gz.hh index 0489510fdc..d03b37c6e5 100644 --- a/src/gz.hh +++ b/src/gz.hh @@ -17,7 +17,7 @@ #ifndef GZ_SIM_GZ_HH_ #define GZ_SIM_GZ_HH_ -#include "gz/sim/Export.hh" +#include "gz/sim/gz/Export.hh" /// \brief External hook to read the library version. /// \return C-string representing the version. Ex.: 0.1.2 From c15388482279243bcadeb72aaf8efb51c3b01220 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Wed, 19 Jul 2023 15:04:37 -0500 Subject: [PATCH 15/27] Adds bindings for the Light class Signed-off-by: Voldivh --- include/gz/sim/Light.hh | 2 +- python/CMakeLists.txt | 1 + python/src/gz/sim/Light.cc | 154 ++++++++++++++++++++++++++ python/src/gz/sim/Light.hh | 40 +++++++ python/src/gz/sim/_gz_sim_pybind11.cc | 2 + 5 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 python/src/gz/sim/Light.cc create mode 100644 python/src/gz/sim/Light.hh diff --git a/include/gz/sim/Light.hh b/include/gz/sim/Light.hh index 13cad9c3be..e34ca6487e 100644 --- a/include/gz/sim/Light.hh +++ b/include/gz/sim/Light.hh @@ -232,7 +232,7 @@ namespace gz /// \brief Set attenuation range of this light. /// \param[in] _ecm Entity-component manager. /// Light attenuation is not applicable to directional lights. - /// \param[in] _bool True to cast shadows, false to not cast shadows. + /// \param[in] _range Attenuation range value to set. public: void SetAttenuationRange(EntityComponentManager &_ecm, double _range); diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 1250c1827a..47a5815d9b 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -44,6 +44,7 @@ pybind11_add_module(${BINDINGS_MODULE_NAME} MODULE src/gz/sim/_gz_sim_pybind11.cc src/gz/sim/EntityComponentManager.cc src/gz/sim/EventManager.cc + src/gz/sim/Light.cc src/gz/sim/TestFixture.cc src/gz/sim/Server.cc src/gz/sim/ServerConfig.cc diff --git a/python/src/gz/sim/Light.cc b/python/src/gz/sim/Light.cc new file mode 100644 index 0000000000..b312b937e3 --- /dev/null +++ b/python/src/gz/sim/Light.cc @@ -0,0 +1,154 @@ +/* + * 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 +#include + +#include + +#include "Light.hh" + +namespace py = pybind11; + +namespace gz +{ +namespace sim +{ +namespace python +{ +void defineSimLight(py::object module) +{ + py::class_(module, "Light") + .def(py::init()) + .def("entity", &gz::sim::Light::Entity, + "Get the entity which this light is related to.") + .def("reset_entity", &gz::sim::Light::ResetEntity, + "Reset Entity to a new one.") + .def("valid", &gz::sim::Light::Valid, + py::arg("ecm"), + "Check whether this light correctly refers to an entity that" + "has a components::Light.") + .def("name", &gz::sim::Light::Name, + py::arg("ecm"), + "Get the light's unscoped name.") + .def("pose", &gz::sim::Light::Pose, + py::arg("ecm"), + "Get the pose of the light." + "The pose is given w.r.t the light's parent. which can be a world or" + "a link.") + .def("type", &gz::sim::Light::Type, + py::arg("ecm"), + "Get the light type.") + .def("diffuse_color", &gz::sim::Light::DiffuseColor, + py::arg("ecm"), + "Get the light diffuse color.") + .def("specular_color", &gz::sim::Light::SpecularColor, + py::arg("ecm"), + "Get the light specular color.") + .def("cast_shadows", &gz::sim::Light::CastShadows, + py::arg("ecm"), + "Get whether the light casts shadows.") + .def("intensity", &gz::sim::Light::Intensity, + py::arg("ecm"), + "Get the light intensity.") + .def("direction", &gz::sim::Light::Direction, + py::arg("ecm"), + "Get the light direction.") + .def("attenuation_range", &gz::sim::Light::AttenuationRange, + py::arg("ecm"), + "Get the light attenuation range." + "Light attenuation is not applicable to directional lights.") + .def("attenuation_constant", &gz::sim::Light::AttenuationConstant, + py::arg("ecm"), + "Get the light attenuation constant value." + "Light attenuation is not applicable to directional lights.") + .def("attenuation_linear", &gz::sim::Light::AttenuationLinear, + py::arg("ecm"), + "Get the light attenuation linear value." + "Light attenuation is not applicable to directional lights.") + .def("attenuation_quadratic", &gz::sim::Light::AttenuationQuadratic, + py::arg("ecm"), + "Get the light attenuation quadratic value." + "Light attenuation is not applicable to directional lights.") + .def("spot_inner_angle", &gz::sim::Light::SpotInnerAngle, + py::arg("ecm"), + "Get the inner angle of light. Applies to spot lights only.") + .def("spot_outer_angle", &gz::sim::Light::SpotOuterAngle, + py::arg("ecm"), + "Get the outer angle of light. Applies to spot lights only.") + .def("spot_fall_off", &gz::sim::Light::SpotFalloff, + py::arg("ecm"), + "Get the fall off value of light. Applies to spot lights only.") + .def("set_pose", &gz::sim::Light::SetPose, + py::arg("ecm"), + py::arg("pose"), + "Set the pose of this light.") + .def("set_diffuse_color", &gz::sim::Light::SetDiffuseColor, + py::arg("ecm"), + py::arg("color"), + "Set the diffuse color of this light.") + .def("set_specular_color", &gz::sim::Light::SetSpecularColor, + py::arg("ecm"), + py::arg("color"), + "Set the specular color of this light.") + .def("set_cast_shadows", &gz::sim::Light::SetCastShadows, + py::arg("ecm"), + py::arg("cast_shadows"), + "Set whether the light casts shadows.") + .def("set_intensity", &gz::sim::Light::SetIntensity, + py::arg("ecm"), + py::arg("value"), + "Set light intensity.") + .def("set_direction", &gz::sim::Light::SetDirection, + py::arg("ecm"), + py::arg("direction"), + "Set light direction. Applies to directional lights.") + .def("set_attenuation_range", &gz::sim::Light::SetAttenuationRange, + py::arg("ecm"), + py::arg("range"), + "Set attenuation range of this light.") + .def("set_attenuation_constant", &gz::sim::Light::SetAttenuationConstant, + py::arg("ecm"), + py::arg("value"), + "Set attenuation constant value of this light.") + .def("set_attenuation_linear", &gz::sim::Light::SetAttenuationLinear, + py::arg("ecm"), + py::arg("value"), + "Set attenuation linear value of this light.") + .def("set_attenuation_quadratic", &gz::sim::Light::SetAttenuationQuadratic, + py::arg("ecm"), + py::arg("color"), + "Set attenuation quadratic value of this light.") + .def("set_spot_inner_angle", &gz::sim::Light::SetSpotInnerAngle, + py::arg("ecm"), + py::arg("angle"), + "Set inner angle for this light. Applies to spot lights only.") + .def("set_spot_outer_angle", &gz::sim::Light::SetSpotOuterAngle, + py::arg("ecm"), + py::arg("angle"), + "Set outer angle for this light. Applies to spot lights only.") + .def("set_spot_fall_off", &gz::sim::Light::SetSpotFalloff, + py::arg("ecm"), + py::arg("fall_off"), + "Set fall off value for this light. Applies to spot lights only.") + .def("parent", &gz::sim::Light::Parent, + py::arg("ecm"), + "Get the parent entity. This can be a world or a link."); +} +} // namespace python +} // namespace sim +} // namespace gz diff --git a/python/src/gz/sim/Light.hh b/python/src/gz/sim/Light.hh new file mode 100644 index 0000000000..a04bf46aba --- /dev/null +++ b/python/src/gz/sim/Light.hh @@ -0,0 +1,40 @@ +/* + * 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 GZ_SIM_PYTHON__LIGHT_HH_ +#define GZ_SIM_PYTHON__LIGHT_HH_ + +#include + +#include + +namespace gz +{ +namespace sim +{ +namespace python +{ +/// Define a pybind11 wrapper for a gz::sim::World +/** + * \param[in] module a pybind11 module to add the definition to + */ +void +defineSimLight(pybind11::object module); +} // namespace python +} // namespace sim +} // namespace gz + +#endif // GZ_SIM_PYTHON__LIGHT_HH_ diff --git a/python/src/gz/sim/_gz_sim_pybind11.cc b/python/src/gz/sim/_gz_sim_pybind11.cc index c9d556f132..890c0effbe 100644 --- a/python/src/gz/sim/_gz_sim_pybind11.cc +++ b/python/src/gz/sim/_gz_sim_pybind11.cc @@ -18,6 +18,7 @@ #include "EntityComponentManager.hh" #include "EventManager.hh" +#include "Light.hh" #include "Server.hh" #include "ServerConfig.hh" #include "TestFixture.hh" @@ -30,6 +31,7 @@ PYBIND11_MODULE(BINDINGS_MODULE_NAME, m) { gz::sim::python::defineSimEntityComponentManager(m); gz::sim::python::defineSimEventManager(m); + gz::sim::python::defineSimLight(m); gz::sim::python::defineSimServer(m); gz::sim::python::defineSimServerConfig(m); gz::sim::python::defineSimTestFixture(m); From 669d75ade524bdb529a7b5659b46620d37003857 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Thu, 27 Jul 2023 10:44:14 -0500 Subject: [PATCH 16/27] Adds test for the bindings Signed-off-by: Voldivh --- python/CMakeLists.txt | 1 + python/src/gz/sim/Light.cc | 20 +++--- python/src/gz/sim/Light.hh | 2 +- python/test/light_TEST.py | 124 +++++++++++++++++++++++++++++++++++++ python/test/light_test.sdf | 26 ++++++++ 5 files changed, 162 insertions(+), 11 deletions(-) create mode 100755 python/test/light_TEST.py create mode 100644 python/test/light_test.sdf diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 47a5815d9b..e7d4e6dfea 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -87,6 +87,7 @@ endif() if (BUILD_TESTING) set(python_tests + light_TEST testFixture_TEST world_TEST ) diff --git a/python/src/gz/sim/Light.cc b/python/src/gz/sim/Light.cc index b312b937e3..fc884674a9 100644 --- a/python/src/gz/sim/Light.cc +++ b/python/src/gz/sim/Light.cc @@ -40,15 +40,15 @@ void defineSimLight(py::object module) "Reset Entity to a new one.") .def("valid", &gz::sim::Light::Valid, py::arg("ecm"), - "Check whether this light correctly refers to an entity that" + "Check whether this light correctly refers to an entity that " "has a components::Light.") .def("name", &gz::sim::Light::Name, py::arg("ecm"), "Get the light's unscoped name.") .def("pose", &gz::sim::Light::Pose, py::arg("ecm"), - "Get the pose of the light." - "The pose is given w.r.t the light's parent. which can be a world or" + "Get the pose of the light. " + "The pose is given w.r.t the light's parent. which can be a world or " "a link.") .def("type", &gz::sim::Light::Type, py::arg("ecm"), @@ -70,19 +70,19 @@ void defineSimLight(py::object module) "Get the light direction.") .def("attenuation_range", &gz::sim::Light::AttenuationRange, py::arg("ecm"), - "Get the light attenuation range." + "Get the light attenuation range. " "Light attenuation is not applicable to directional lights.") .def("attenuation_constant", &gz::sim::Light::AttenuationConstant, py::arg("ecm"), - "Get the light attenuation constant value." + "Get the light attenuation constant value. " "Light attenuation is not applicable to directional lights.") .def("attenuation_linear", &gz::sim::Light::AttenuationLinear, py::arg("ecm"), - "Get the light attenuation linear value." + "Get the light attenuation linear value. " "Light attenuation is not applicable to directional lights.") .def("attenuation_quadratic", &gz::sim::Light::AttenuationQuadratic, py::arg("ecm"), - "Get the light attenuation quadratic value." + "Get the light attenuation quadratic value. " "Light attenuation is not applicable to directional lights.") .def("spot_inner_angle", &gz::sim::Light::SpotInnerAngle, py::arg("ecm"), @@ -90,7 +90,7 @@ void defineSimLight(py::object module) .def("spot_outer_angle", &gz::sim::Light::SpotOuterAngle, py::arg("ecm"), "Get the outer angle of light. Applies to spot lights only.") - .def("spot_fall_off", &gz::sim::Light::SpotFalloff, + .def("spot_falloff", &gz::sim::Light::SpotFalloff, py::arg("ecm"), "Get the fall off value of light. Applies to spot lights only.") .def("set_pose", &gz::sim::Light::SetPose, @@ -141,9 +141,9 @@ void defineSimLight(py::object module) py::arg("ecm"), py::arg("angle"), "Set outer angle for this light. Applies to spot lights only.") - .def("set_spot_fall_off", &gz::sim::Light::SetSpotFalloff, + .def("set_spot_falloff", &gz::sim::Light::SetSpotFalloff, py::arg("ecm"), - py::arg("fall_off"), + py::arg("falloff"), "Set fall off value for this light. Applies to spot lights only.") .def("parent", &gz::sim::Light::Parent, py::arg("ecm"), diff --git a/python/src/gz/sim/Light.hh b/python/src/gz/sim/Light.hh index a04bf46aba..c6a9a63926 100644 --- a/python/src/gz/sim/Light.hh +++ b/python/src/gz/sim/Light.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Open Source Robotics Foundation + * 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. diff --git a/python/test/light_TEST.py b/python/test/light_TEST.py new file mode 100755 index 0000000000..dd35de539d --- /dev/null +++ b/python/test/light_TEST.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python3 +# 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. + +import os +import unittest + +from gz.common import set_verbosity +from gz.sim8 import Light, TestFixture, World, world_entity +from gz.math7 import Angle, Color, Pose3d, Vector3d + +post_iterations = 0 +iterations = 0 +pre_iterations = 0 + +class TestLight(unittest.TestCase): + + def test_light(self): + set_verbosity(4) + + file_path = os.path.dirname(os.path.realpath(__file__)) + fixture = TestFixture(os.path.join(file_path, 'light_test.sdf')) + + def on_post_udpate_cb(_info, _ecm): + global post_iterations + post_iterations += 1 + + def on_pre_udpate_cb(_info, _ecm): + global pre_iterations + pre_iterations += 1 + world_e = world_entity(_ecm) + self.assertEqual(1, world_e) + w = World(world_e) + light = Light(w.light_by_name(_ecm, 'light_test')) + # Entity Test + self.assertEqual(4, light.entity()) + # Valid Test + self.assertTrue(light.valid(_ecm)) + # Name Test + self.assertEqual('light_test', light.name(_ecm)) + # Pose Test + self.assertEqual(Pose3d(0, 2, 2, 0, 0, 0), light.pose(_ecm)) + light.set_pose(_ecm, Pose3d(4, 2, 2, 0, 0, 0)) + self.assertEqual(Pose3d(0, 2, 2, 0, 0, 0), light.pose(_ecm)) + # Type Test + self.assertEqual('point', light.type(_ecm)) + # Diffuse Color Test + self.assertEqual(Color(1, 0, 0, 1), light.diffuse_color(_ecm)) + light.set_diffuse_color(_ecm, Color(1, 1, 0, 1)) + self.assertEqual(Color(1, 0, 0, 1), light.diffuse_color(_ecm)) + # Specular Color Test + self.assertEqual(Color(0.2, 0, 0, 1), light.specular_color(_ecm)) + light.set_specular_color(_ecm, Color(0.2, 0.2, 0, 1)) + self.assertEqual(Color(0.2, 0, 0, 1), light.specular_color(_ecm)) + # Cast Shadows Test + self.assertTrue(light.cast_shadows(_ecm)) + light.set_cast_shadows(_ecm, False) + self.assertTrue(light.cast_shadows(_ecm)) + # Intensity Test + self.assertEqual(2, light.intensity(_ecm)) + light.set_intensity(_ecm, 5) + self.assertEqual(2, light.intensity(_ecm)) + # Direction Test + self.assertEqual(Vector3d(0, 0, -1), light.direction(_ecm)) + light.set_direction(_ecm, Vector3d(1, 0, -1)) + self.assertEqual(Vector3d(0, 0, -1), light.direction(_ecm)) + # Attenuation Range Test + self.assertEqual(20, light.attenuation_range(_ecm)) + light.set_attenuation_range(_ecm, 30) + self.assertEqual(20, light.attenuation_range(_ecm)) + # Attenuation Constant Test + self.assertEqual(0.8, light.attenuation_constant(_ecm)) + light.set_attenuation_constant(_ecm, 1.2) + self.assertEqual(0.8, light.attenuation_constant(_ecm)) + # Attenuation Linear Test + self.assertEqual(0.2, light.attenuation_linear(_ecm)) + light.set_attenuation_linear(_ecm, 0.5) + self.assertEqual(0.2, light.attenuation_linear(_ecm)) + # Attenuation Quadratric Test + self.assertEqual(0.01, light.attenuation_quadratic(_ecm)) + light.set_attenuation_quadratic(_ecm, 0.05) + self.assertEqual(0.01, light.attenuation_quadratic(_ecm)) + # Spot Inner Angle Test + self.assertEqual(Angle(), light.spot_inner_angle(_ecm)) + light.set_spot_inner_angle(_ecm, Angle(10)) + self.assertEqual(Angle(), light.spot_inner_angle(_ecm)) + # Spot Outer Angle Test + self.assertEqual(Angle(), light.spot_outer_angle(_ecm)) + light.set_spot_outer_angle(_ecm, Angle(5)) + self.assertEqual(Angle(), light.spot_outer_angle(_ecm)) + # Spot Falloff Test + self.assertEqual(0, light.spot_falloff(_ecm)) + light.set_spot_falloff(_ecm, 2) + self.assertEqual(0, light.spot_falloff(_ecm)) + + def on_udpate_cb(_info, _ecm): + global iterations + iterations += 1 + + fixture.on_post_update(on_post_udpate_cb) + fixture.on_update(on_udpate_cb) + fixture.on_pre_update(on_pre_udpate_cb) + fixture.finalize() + + server = fixture.server() + server.run(True, 1000, False) + + self.assertEqual(1000, pre_iterations) + self.assertEqual(1000, iterations) + self.assertEqual(1000, post_iterations) + +if __name__ == '__main__': + unittest.main() diff --git a/python/test/light_test.sdf b/python/test/light_test.sdf new file mode 100644 index 0000000000..21c04c049e --- /dev/null +++ b/python/test/light_test.sdf @@ -0,0 +1,26 @@ + + + + + + 0 2 2 0 0 0 + 1 0 0 1 + 0.2 0 0 1 + 2 + 0.5 0.5 -1 + + 20 + 0.2 + 0.8 + 0.01 + + + 10 + 5 + 2 + + true + + + + From 3c41f7fee2f7f85ba4903faad91c6dcca6306b50 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Fri, 28 Jul 2023 11:03:13 -0500 Subject: [PATCH 17/27] Modifies test to use the appropiate light types (test failing) Signed-off-by: Voldivh --- python/test/light_TEST.py | 110 ++++++++++++++++++++++--------------- python/test/light_test.sdf | 12 +++- 2 files changed, 75 insertions(+), 47 deletions(-) diff --git a/python/test/light_TEST.py b/python/test/light_TEST.py index dd35de539d..5c1792cee6 100755 --- a/python/test/light_TEST.py +++ b/python/test/light_TEST.py @@ -42,67 +42,89 @@ def on_pre_udpate_cb(_info, _ecm): world_e = world_entity(_ecm) self.assertEqual(1, world_e) w = World(world_e) - light = Light(w.light_by_name(_ecm, 'light_test')) + light_point = Light(w.light_by_name(_ecm, 'light_point_test')) + light_directional = Light(w.light_by_name(_ecm, 'light_directional_test')) + light_spot = Light(w.light_by_name(_ecm, 'light_spot_test')) # Entity Test - self.assertEqual(4, light.entity()) + self.assertEqual(4, light_point.entity()) + self.assertEqual(6, light_directional.entity()) + self.assertEqual(8, light_spot.entity()) # Valid Test - self.assertTrue(light.valid(_ecm)) + self.assertTrue(light_point.valid(_ecm)) + self.assertTrue(light_directional.valid(_ecm)) + self.assertTrue(light_spot.valid(_ecm)) # Name Test - self.assertEqual('light_test', light.name(_ecm)) + self.assertEqual('light_point_test', light_point.name(_ecm)) + self.assertEqual('light_directional_test', light_directional.name(_ecm)) + self.assertEqual('light_spot_test', light_spot.name(_ecm)) # Pose Test - self.assertEqual(Pose3d(0, 2, 2, 0, 0, 0), light.pose(_ecm)) - light.set_pose(_ecm, Pose3d(4, 2, 2, 0, 0, 0)) - self.assertEqual(Pose3d(0, 2, 2, 0, 0, 0), light.pose(_ecm)) + self.assertEqual(Pose3d(0, 2, 2, 0, 0, 0), light_point.pose(_ecm)) + light_point.set_pose(_ecm, Pose3d(4, 2, 2, 0, 0, 0)) + self.assertEqual(Pose3d(0, 2, 2, 0, 0, 0), light_point.pose(_ecm)) # Type Test - self.assertEqual('point', light.type(_ecm)) + self.assertEqual('point', light_point.type(_ecm)) + self.assertEqual('directional', light_directional.type(_ecm)) + self.assertEqual('spot', light_spot.type(_ecm)) # Diffuse Color Test - self.assertEqual(Color(1, 0, 0, 1), light.diffuse_color(_ecm)) - light.set_diffuse_color(_ecm, Color(1, 1, 0, 1)) - self.assertEqual(Color(1, 0, 0, 1), light.diffuse_color(_ecm)) + self.assertEqual(Color(1, 0, 0, 1), light_point.diffuse_color(_ecm)) + light_point.set_diffuse_color(_ecm, Color(1, 1, 0, 1)) + self.assertEqual(Color(1, 1, 0, 1), light_point.diffuse_color(_ecm)) + light_point.set_diffuse_color(_ecm, Color(1, 0, 0, 1)) # Specular Color Test - self.assertEqual(Color(0.2, 0, 0, 1), light.specular_color(_ecm)) - light.set_specular_color(_ecm, Color(0.2, 0.2, 0, 1)) - self.assertEqual(Color(0.2, 0, 0, 1), light.specular_color(_ecm)) + self.assertEqual(Color(0.2, 0, 0, 1), light_point.specular_color(_ecm)) + light_point.set_specular_color(_ecm, Color(0.2, 0.2, 0, 1)) + self.assertEqual(Color(0.2, 0.2, 0, 1), light_point.specular_color(_ecm)) + light_point.set_specular_color(_ecm, Color(0.2, 0, 0, 1)) # Cast Shadows Test - self.assertTrue(light.cast_shadows(_ecm)) - light.set_cast_shadows(_ecm, False) - self.assertTrue(light.cast_shadows(_ecm)) + self.assertTrue(light_point.cast_shadows(_ecm)) + light_point.set_cast_shadows(_ecm, False) + self.assertFalse(light_point.cast_shadows(_ecm)) + light_point.set_cast_shadows(_ecm, True) # Intensity Test - self.assertEqual(2, light.intensity(_ecm)) - light.set_intensity(_ecm, 5) - self.assertEqual(2, light.intensity(_ecm)) + self.assertEqual(2, light_point.intensity(_ecm)) + light_point.set_intensity(_ecm, 5) + self.assertEqual(5, light_point.intensity(_ecm)) + light_point.set_intensity(_ecm, 2) # Direction Test - self.assertEqual(Vector3d(0, 0, -1), light.direction(_ecm)) - light.set_direction(_ecm, Vector3d(1, 0, -1)) - self.assertEqual(Vector3d(0, 0, -1), light.direction(_ecm)) + self.assertEqual(Vector3d(0.5, 0.5, -1), light_directional.direction(_ecm)) + light_directional.set_direction(_ecm, Vector3d(1, 0, -1)) + self.assertEqual(Vector3d(1, 0, -1), light_directional.direction(_ecm)) + light_directional.set_direction(_ecm, Vector3d(0.5, 0.5, -1)) # Attenuation Range Test - self.assertEqual(20, light.attenuation_range(_ecm)) - light.set_attenuation_range(_ecm, 30) - self.assertEqual(20, light.attenuation_range(_ecm)) + self.assertEqual(20, light_point.attenuation_range(_ecm)) + light_point.set_attenuation_range(_ecm, 30) + self.assertEqual(30, light_point.attenuation_range(_ecm)) + light_point.set_attenuation_range(_ecm, 20) # Attenuation Constant Test - self.assertEqual(0.8, light.attenuation_constant(_ecm)) - light.set_attenuation_constant(_ecm, 1.2) - self.assertEqual(0.8, light.attenuation_constant(_ecm)) + self.assertEqual(0.8, light_point.attenuation_constant(_ecm)) + light_point.set_attenuation_constant(_ecm, 1.2) + self.assertEqual(1.2, light_point.attenuation_constant(_ecm)) + light_point.set_attenuation_constant(_ecm, 0.8) # Attenuation Linear Test - self.assertEqual(0.2, light.attenuation_linear(_ecm)) - light.set_attenuation_linear(_ecm, 0.5) - self.assertEqual(0.2, light.attenuation_linear(_ecm)) + self.assertEqual(0.2, light_point.attenuation_linear(_ecm)) + light_point.set_attenuation_linear(_ecm, 0.5) + self.assertEqual(0.5, light_point.attenuation_linear(_ecm)) + light_point.set_attenuation_linear(_ecm, 0.2) # Attenuation Quadratric Test - self.assertEqual(0.01, light.attenuation_quadratic(_ecm)) - light.set_attenuation_quadratic(_ecm, 0.05) - self.assertEqual(0.01, light.attenuation_quadratic(_ecm)) + self.assertEqual(0.01, light_point.attenuation_quadratic(_ecm)) + light_point.set_attenuation_quadratic(_ecm, 0.05) + self.assertEqual(0.05, light_point.attenuation_quadratic(_ecm)) + light_point.set_attenuation_quadratic(_ecm, 0.01) # Spot Inner Angle Test - self.assertEqual(Angle(), light.spot_inner_angle(_ecm)) - light.set_spot_inner_angle(_ecm, Angle(10)) - self.assertEqual(Angle(), light.spot_inner_angle(_ecm)) + self.assertEqual(Angle(10), light_spot.spot_inner_angle(_ecm)) + light_spot.set_spot_inner_angle(_ecm, Angle(15)) + self.assertEqual(Angle(15), light_spot.spot_inner_angle(_ecm)) + light_spot.set_spot_inner_angle(_ecm, Angle(10)) # Spot Outer Angle Test - self.assertEqual(Angle(), light.spot_outer_angle(_ecm)) - light.set_spot_outer_angle(_ecm, Angle(5)) - self.assertEqual(Angle(), light.spot_outer_angle(_ecm)) + self.assertEqual(Angle(5), light_spot.spot_outer_angle(_ecm)) + light_spot.set_spot_outer_angle(_ecm, Angle(10)) + self.assertEqual(Angle(10), light_spot.spot_outer_angle(_ecm)) + light_spot.set_spot_outer_angle(_ecm, Angle(5)) # Spot Falloff Test - self.assertEqual(0, light.spot_falloff(_ecm)) - light.set_spot_falloff(_ecm, 2) - self.assertEqual(0, light.spot_falloff(_ecm)) + self.assertEqual(2, light_spot.spot_falloff(_ecm)) + light_spot.set_spot_falloff(_ecm, 4) + self.assertEqual(4, light_spot.spot_falloff(_ecm)) + light_spot.set_spot_falloff(_ecm, 2) def on_udpate_cb(_info, _ecm): global iterations diff --git a/python/test/light_test.sdf b/python/test/light_test.sdf index 21c04c049e..bb53c012e9 100644 --- a/python/test/light_test.sdf +++ b/python/test/light_test.sdf @@ -2,24 +2,30 @@ - + 0 2 2 0 0 0 1 0 0 1 0.2 0 0 1 2 - 0.5 0.5 -1 20 0.2 0.8 0.01 + true + + + + 0.5 0.5 -1 + + + 10 5 2 - true From def4604caaf9e0e74e0b55e4b654ff812a5591ea Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 1 Aug 2023 11:53:48 -0500 Subject: [PATCH 18/27] Remove test for setters methods Signed-off-by: Voldivh --- python/test/light_TEST.py | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/python/test/light_TEST.py b/python/test/light_TEST.py index 5c1792cee6..673f497de2 100755 --- a/python/test/light_TEST.py +++ b/python/test/light_TEST.py @@ -24,6 +24,9 @@ iterations = 0 pre_iterations = 0 +# This class test the Light class API created with pybind11. Since the setters methods +# require other systems to work (eg. Rendering sensors), those methods will not be fully +# tested, just verifying the method is being called. class TestLight(unittest.TestCase): def test_light(self): @@ -60,72 +63,47 @@ def on_pre_udpate_cb(_info, _ecm): # Pose Test self.assertEqual(Pose3d(0, 2, 2, 0, 0, 0), light_point.pose(_ecm)) light_point.set_pose(_ecm, Pose3d(4, 2, 2, 0, 0, 0)) - self.assertEqual(Pose3d(0, 2, 2, 0, 0, 0), light_point.pose(_ecm)) # Type Test self.assertEqual('point', light_point.type(_ecm)) self.assertEqual('directional', light_directional.type(_ecm)) self.assertEqual('spot', light_spot.type(_ecm)) - # Diffuse Color Test + ## Diffuse Color Test self.assertEqual(Color(1, 0, 0, 1), light_point.diffuse_color(_ecm)) light_point.set_diffuse_color(_ecm, Color(1, 1, 0, 1)) - self.assertEqual(Color(1, 1, 0, 1), light_point.diffuse_color(_ecm)) - light_point.set_diffuse_color(_ecm, Color(1, 0, 0, 1)) # Specular Color Test self.assertEqual(Color(0.2, 0, 0, 1), light_point.specular_color(_ecm)) light_point.set_specular_color(_ecm, Color(0.2, 0.2, 0, 1)) - self.assertEqual(Color(0.2, 0.2, 0, 1), light_point.specular_color(_ecm)) - light_point.set_specular_color(_ecm, Color(0.2, 0, 0, 1)) # Cast Shadows Test self.assertTrue(light_point.cast_shadows(_ecm)) light_point.set_cast_shadows(_ecm, False) - self.assertFalse(light_point.cast_shadows(_ecm)) - light_point.set_cast_shadows(_ecm, True) # Intensity Test self.assertEqual(2, light_point.intensity(_ecm)) light_point.set_intensity(_ecm, 5) - self.assertEqual(5, light_point.intensity(_ecm)) - light_point.set_intensity(_ecm, 2) # Direction Test self.assertEqual(Vector3d(0.5, 0.5, -1), light_directional.direction(_ecm)) light_directional.set_direction(_ecm, Vector3d(1, 0, -1)) - self.assertEqual(Vector3d(1, 0, -1), light_directional.direction(_ecm)) - light_directional.set_direction(_ecm, Vector3d(0.5, 0.5, -1)) # Attenuation Range Test self.assertEqual(20, light_point.attenuation_range(_ecm)) light_point.set_attenuation_range(_ecm, 30) - self.assertEqual(30, light_point.attenuation_range(_ecm)) - light_point.set_attenuation_range(_ecm, 20) # Attenuation Constant Test self.assertEqual(0.8, light_point.attenuation_constant(_ecm)) light_point.set_attenuation_constant(_ecm, 1.2) - self.assertEqual(1.2, light_point.attenuation_constant(_ecm)) - light_point.set_attenuation_constant(_ecm, 0.8) # Attenuation Linear Test self.assertEqual(0.2, light_point.attenuation_linear(_ecm)) light_point.set_attenuation_linear(_ecm, 0.5) - self.assertEqual(0.5, light_point.attenuation_linear(_ecm)) - light_point.set_attenuation_linear(_ecm, 0.2) # Attenuation Quadratric Test self.assertEqual(0.01, light_point.attenuation_quadratic(_ecm)) light_point.set_attenuation_quadratic(_ecm, 0.05) - self.assertEqual(0.05, light_point.attenuation_quadratic(_ecm)) - light_point.set_attenuation_quadratic(_ecm, 0.01) # Spot Inner Angle Test self.assertEqual(Angle(10), light_spot.spot_inner_angle(_ecm)) light_spot.set_spot_inner_angle(_ecm, Angle(15)) - self.assertEqual(Angle(15), light_spot.spot_inner_angle(_ecm)) - light_spot.set_spot_inner_angle(_ecm, Angle(10)) # Spot Outer Angle Test self.assertEqual(Angle(5), light_spot.spot_outer_angle(_ecm)) light_spot.set_spot_outer_angle(_ecm, Angle(10)) - self.assertEqual(Angle(10), light_spot.spot_outer_angle(_ecm)) - light_spot.set_spot_outer_angle(_ecm, Angle(5)) # Spot Falloff Test self.assertEqual(2, light_spot.spot_falloff(_ecm)) light_spot.set_spot_falloff(_ecm, 4) - self.assertEqual(4, light_spot.spot_falloff(_ecm)) - light_spot.set_spot_falloff(_ecm, 2) - + def on_udpate_cb(_info, _ecm): global iterations iterations += 1 From be8ec344e7bc30377258ce70ae08dc4162eb776b Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 1 Aug 2023 12:54:37 -0500 Subject: [PATCH 19/27] Removes trailing whitespace Signed-off-by: Voldivh --- python/test/light_TEST.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/test/light_TEST.py b/python/test/light_TEST.py index 673f497de2..0c6895b166 100755 --- a/python/test/light_TEST.py +++ b/python/test/light_TEST.py @@ -26,7 +26,7 @@ # This class test the Light class API created with pybind11. Since the setters methods # require other systems to work (eg. Rendering sensors), those methods will not be fully -# tested, just verifying the method is being called. +# tested, just verifying the method is being called. class TestLight(unittest.TestCase): def test_light(self): From 3f75812349932df98827be9993bc43bde986248e Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 1 Aug 2023 12:56:51 -0500 Subject: [PATCH 20/27] Removes trailing whitespace Signed-off-by: Voldivh --- python/test/light_TEST.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/test/light_TEST.py b/python/test/light_TEST.py index 0c6895b166..8410e7b4e2 100755 --- a/python/test/light_TEST.py +++ b/python/test/light_TEST.py @@ -103,7 +103,7 @@ def on_pre_udpate_cb(_info, _ecm): # Spot Falloff Test self.assertEqual(2, light_spot.spot_falloff(_ecm)) light_spot.set_spot_falloff(_ecm, 4) - + def on_udpate_cb(_info, _ecm): global iterations iterations += 1 From d2cf8f6973e6cab06596d488dcc31510a4271fdd Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 8 Aug 2023 11:04:12 -0500 Subject: [PATCH 21/27] Modifies import dependencies Signed-off-by: Voldivh --- python/test/light_TEST.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/test/light_TEST.py b/python/test/light_TEST.py index 8410e7b4e2..e47f14abc6 100755 --- a/python/test/light_TEST.py +++ b/python/test/light_TEST.py @@ -17,8 +17,8 @@ import unittest from gz.common import set_verbosity -from gz.sim8 import Light, TestFixture, World, world_entity -from gz.math7 import Angle, Color, Pose3d, Vector3d +from gz_test_deps.sim import Light, TestFixture, World, world_entity +from gz_test_deps.math import Angle, Color, Pose3d, Vector3d post_iterations = 0 iterations = 0 From 0abd9b4283ba12ea54dbbc898abef0f3ef886ad4 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Thu, 10 Aug 2023 14:02:10 -0500 Subject: [PATCH 22/27] Adds copy constructor Signed-off-by: Voldivh --- python/src/gz/sim/Light.cc | 13 ++++++++++++- python/test/light_TEST.py | 31 ++++++++++++++----------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/python/src/gz/sim/Light.cc b/python/src/gz/sim/Light.cc index fc884674a9..6e74e6ed0e 100644 --- a/python/src/gz/sim/Light.cc +++ b/python/src/gz/sim/Light.cc @@ -34,6 +34,7 @@ void defineSimLight(py::object module) { py::class_(module, "Light") .def(py::init()) + .def(py::init()) .def("entity", &gz::sim::Light::Entity, "Get the entity which this light is related to.") .def("reset_entity", &gz::sim::Light::ResetEntity, @@ -147,7 +148,17 @@ void defineSimLight(py::object module) "Set fall off value for this light. Applies to spot lights only.") .def("parent", &gz::sim::Light::Parent, py::arg("ecm"), - "Get the parent entity. This can be a world or a link."); + "Get the parent entity. This can be a world or a link.") + .def("__copy__", + [](const gz::sim::Light &self) + { + return gz::sim::Light(self); + }) + .def("__deepcopy__", + [](const gz::sim::Light &self, pybind11::dict) + { + return gz::sim::Light(self); + }); } } // namespace python } // namespace sim diff --git a/python/test/light_TEST.py b/python/test/light_TEST.py index e47f14abc6..a01fc321cd 100755 --- a/python/test/light_TEST.py +++ b/python/test/light_TEST.py @@ -20,14 +20,14 @@ from gz_test_deps.sim import Light, TestFixture, World, world_entity from gz_test_deps.math import Angle, Color, Pose3d, Vector3d -post_iterations = 0 -iterations = 0 -pre_iterations = 0 - # This class test the Light class API created with pybind11. Since the setters methods # require other systems to work (eg. Rendering sensors), those methods will not be fully # tested, just verifying the method is being called. class TestLight(unittest.TestCase): + k_null_entity = 0 + post_iterations = 0 + iterations = 0 + pre_iterations = 0 def test_light(self): set_verbosity(4) @@ -36,22 +36,20 @@ def test_light(self): fixture = TestFixture(os.path.join(file_path, 'light_test.sdf')) def on_post_udpate_cb(_info, _ecm): - global post_iterations - post_iterations += 1 + self.post_iterations += 1 def on_pre_udpate_cb(_info, _ecm): - global pre_iterations - pre_iterations += 1 + self.pre_iterations += 1 world_e = world_entity(_ecm) - self.assertEqual(1, world_e) + self.assertNotEqual(self.k_null_entity, world_e) w = World(world_e) light_point = Light(w.light_by_name(_ecm, 'light_point_test')) light_directional = Light(w.light_by_name(_ecm, 'light_directional_test')) light_spot = Light(w.light_by_name(_ecm, 'light_spot_test')) # Entity Test - self.assertEqual(4, light_point.entity()) - self.assertEqual(6, light_directional.entity()) - self.assertEqual(8, light_spot.entity()) + self.assertNotEqual(self.k_null_entity, light_point.entity()) + self.assertNotEqual(self.k_null_entity, light_directional.entity()) + self.assertNotEqual(self.k_null_entity, light_spot.entity()) # Valid Test self.assertTrue(light_point.valid(_ecm)) self.assertTrue(light_directional.valid(_ecm)) @@ -105,8 +103,7 @@ def on_pre_udpate_cb(_info, _ecm): light_spot.set_spot_falloff(_ecm, 4) def on_udpate_cb(_info, _ecm): - global iterations - iterations += 1 + self.iterations += 1 fixture.on_post_update(on_post_udpate_cb) fixture.on_update(on_udpate_cb) @@ -116,9 +113,9 @@ def on_udpate_cb(_info, _ecm): server = fixture.server() server.run(True, 1000, False) - self.assertEqual(1000, pre_iterations) - self.assertEqual(1000, iterations) - self.assertEqual(1000, post_iterations) + self.assertEqual(1000, self.pre_iterations) + self.assertEqual(1000, self.iterations) + self.assertEqual(1000, self.post_iterations) if __name__ == '__main__': unittest.main() From fb5e2cf07ae3c6073ce042a4f4270ffbdccb1ec3 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 15 Aug 2023 15:48:24 -0500 Subject: [PATCH 23/27] Modifies the use of the null entity variable Signed-off-by: Voldivh --- python/test/light_TEST.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/python/test/light_TEST.py b/python/test/light_TEST.py index a01fc321cd..85d4bde53c 100755 --- a/python/test/light_TEST.py +++ b/python/test/light_TEST.py @@ -17,14 +17,13 @@ import unittest from gz.common import set_verbosity -from gz_test_deps.sim import Light, TestFixture, World, world_entity +from gz_test_deps.sim import K_NULL_ENTITY, Light, TestFixture, World, world_entity from gz_test_deps.math import Angle, Color, Pose3d, Vector3d # This class test the Light class API created with pybind11. Since the setters methods # require other systems to work (eg. Rendering sensors), those methods will not be fully # tested, just verifying the method is being called. class TestLight(unittest.TestCase): - k_null_entity = 0 post_iterations = 0 iterations = 0 pre_iterations = 0 @@ -41,15 +40,15 @@ def on_post_udpate_cb(_info, _ecm): def on_pre_udpate_cb(_info, _ecm): self.pre_iterations += 1 world_e = world_entity(_ecm) - self.assertNotEqual(self.k_null_entity, world_e) + self.assertNotEqual(K_NULL_ENTITY, world_e) w = World(world_e) light_point = Light(w.light_by_name(_ecm, 'light_point_test')) light_directional = Light(w.light_by_name(_ecm, 'light_directional_test')) light_spot = Light(w.light_by_name(_ecm, 'light_spot_test')) # Entity Test - self.assertNotEqual(self.k_null_entity, light_point.entity()) - self.assertNotEqual(self.k_null_entity, light_directional.entity()) - self.assertNotEqual(self.k_null_entity, light_spot.entity()) + self.assertNotEqual(K_NULL_ENTITY, light_point.entity()) + self.assertNotEqual(K_NULL_ENTITY, light_directional.entity()) + self.assertNotEqual(K_NULL_ENTITY, light_spot.entity()) # Valid Test self.assertTrue(light_point.valid(_ecm)) self.assertTrue(light_directional.valid(_ecm)) From 5c5f53ee4a19a82a1ef27575525caec1c72647b4 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 22 Aug 2023 04:50:53 -0500 Subject: [PATCH 24/27] Adds verification test for values after we have set them Signed-off-by: Voldivh --- python/src/gz/sim/Light.hh | 2 +- python/src/gz/sim/Link.cc | 2 -- python/test/light_TEST.py | 56 ++++++++++++++++++++++++++------------ 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/python/src/gz/sim/Light.hh b/python/src/gz/sim/Light.hh index c6a9a63926..1daea7e789 100644 --- a/python/src/gz/sim/Light.hh +++ b/python/src/gz/sim/Light.hh @@ -27,7 +27,7 @@ namespace sim { namespace python { -/// Define a pybind11 wrapper for a gz::sim::World +/// Define a pybind11 wrapper for a gz::sim::Light /** * \param[in] module a pybind11 module to add the definition to */ diff --git a/python/src/gz/sim/Link.cc b/python/src/gz/sim/Link.cc index 96257e9a82..487e217400 100644 --- a/python/src/gz/sim/Link.cc +++ b/python/src/gz/sim/Link.cc @@ -17,8 +17,6 @@ #include #include -#include - #include "Link.hh" namespace py = pybind11; diff --git a/python/test/light_TEST.py b/python/test/light_TEST.py index 85d4bde53c..23671d0c8a 100755 --- a/python/test/light_TEST.py +++ b/python/test/light_TEST.py @@ -17,12 +17,14 @@ import unittest from gz.common import set_verbosity -from gz_test_deps.sim import K_NULL_ENTITY, Light, TestFixture, World, world_entity +from gz_test_deps.sim import (K_NULL_ENTITY, Light, + TestFixture, World, world_entity) from gz_test_deps.math import Angle, Color, Pose3d, Vector3d -# This class test the Light class API created with pybind11. Since the setters methods -# require other systems to work (eg. Rendering sensors), those methods will not be fully -# tested, just verifying the method is being called. + +# This class test the Light class API created with pybind11. Since the setters +# methods require other systems to work (eg. Rendering sensors), those methods +# will not be fully tested, just verifying the method is being called. class TestLight(unittest.TestCase): post_iterations = 0 iterations = 0 @@ -43,32 +45,34 @@ def on_pre_udpate_cb(_info, _ecm): self.assertNotEqual(K_NULL_ENTITY, world_e) w = World(world_e) light_point = Light(w.light_by_name(_ecm, 'light_point_test')) - light_directional = Light(w.light_by_name(_ecm, 'light_directional_test')) + light_dir = Light(w.light_by_name(_ecm, 'light_directional_test')) light_spot = Light(w.light_by_name(_ecm, 'light_spot_test')) # Entity Test self.assertNotEqual(K_NULL_ENTITY, light_point.entity()) - self.assertNotEqual(K_NULL_ENTITY, light_directional.entity()) + self.assertNotEqual(K_NULL_ENTITY, light_dir.entity()) self.assertNotEqual(K_NULL_ENTITY, light_spot.entity()) # Valid Test self.assertTrue(light_point.valid(_ecm)) - self.assertTrue(light_directional.valid(_ecm)) + self.assertTrue(light_dir.valid(_ecm)) self.assertTrue(light_spot.valid(_ecm)) # Name Test self.assertEqual('light_point_test', light_point.name(_ecm)) - self.assertEqual('light_directional_test', light_directional.name(_ecm)) + self.assertEqual('light_dir_test', light_dir.name(_ecm)) self.assertEqual('light_spot_test', light_spot.name(_ecm)) # Pose Test self.assertEqual(Pose3d(0, 2, 2, 0, 0, 0), light_point.pose(_ecm)) light_point.set_pose(_ecm, Pose3d(4, 2, 2, 0, 0, 0)) # Type Test self.assertEqual('point', light_point.type(_ecm)) - self.assertEqual('directional', light_directional.type(_ecm)) + self.assertEqual('directional', light_dir.type(_ecm)) self.assertEqual('spot', light_spot.type(_ecm)) - ## Diffuse Color Test - self.assertEqual(Color(1, 0, 0, 1), light_point.diffuse_color(_ecm)) + # Diffuse Color Test + self.assertEqual(Color(1, 0, 0, 1), + light_point.diffuse_color(_ecm)) light_point.set_diffuse_color(_ecm, Color(1, 1, 0, 1)) # Specular Color Test - self.assertEqual(Color(0.2, 0, 0, 1), light_point.specular_color(_ecm)) + self.assertEqual(Color(0.2, 0, 0, 1), + light_point.specular_color(_ecm)) light_point.set_specular_color(_ecm, Color(0.2, 0.2, 0, 1)) # Cast Shadows Test self.assertTrue(light_point.cast_shadows(_ecm)) @@ -77,8 +81,8 @@ def on_pre_udpate_cb(_info, _ecm): self.assertEqual(2, light_point.intensity(_ecm)) light_point.set_intensity(_ecm, 5) # Direction Test - self.assertEqual(Vector3d(0.5, 0.5, -1), light_directional.direction(_ecm)) - light_directional.set_direction(_ecm, Vector3d(1, 0, -1)) + self.assertEqual(Vector3d(0.5, 0.5, -1), light_dir.direction(_ecm)) + light_dir.set_direction(_ecm, Vector3d(1, 0, -1)) # Attenuation Range Test self.assertEqual(20, light_point.attenuation_range(_ecm)) light_point.set_attenuation_range(_ecm, 30) @@ -100,6 +104,21 @@ def on_pre_udpate_cb(_info, _ecm): # Spot Falloff Test self.assertEqual(2, light_spot.spot_falloff(_ecm)) light_spot.set_spot_falloff(_ecm, 4) + # Check that all the values have been modified. + if self.pre_iterations > 1: + self.assertEqual(Color(1, 1, 0, 1), + light_point.diffuse_color(_ecm)) + self.assertEqual(Color(0.2, 0.2, 0, 1), + light_point.specular_color(_ecm)) + self.assertFalse(light_point.cast_shadows(_ecm)) + self.assertEqual(5, light_point.intensity(_ecm)) + self.assertEqual(Vector3d(1, 0, -1), light_dir.direction(_ecm)) + self.assertEqual(1.2, light_point.attenuation_constant(_ecm)) + self.assertEqual(0.5, light_point.attenuation_linear(_ecm)) + self.assertEqual(0.05, light_point.attenuation_quadratic(_ecm)) + self.assertEqual(Angle(15), light_spot.spot_inner_angle(_ecm)) + self.assertEqual(Angle(10), light_spot.spot_outer_angle(_ecm)) + self.assertEqual(4, light_spot.spot_falloff(_ecm)) def on_udpate_cb(_info, _ecm): self.iterations += 1 @@ -110,11 +129,12 @@ def on_udpate_cb(_info, _ecm): fixture.finalize() server = fixture.server() - server.run(True, 1000, False) + server.run(True, 2, False) + + self.assertEqual(2, self.pre_iterations) + self.assertEqual(2, self.iterations) + self.assertEqual(2, self.post_iterations) - self.assertEqual(1000, self.pre_iterations) - self.assertEqual(1000, self.iterations) - self.assertEqual(1000, self.post_iterations) if __name__ == '__main__': unittest.main() From 209e5562d55cc21186bf11c9d02e15dc216841a7 Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Thu, 24 Aug 2023 22:14:55 -0500 Subject: [PATCH 25/27] Remove checks that require a rendering system, fix name Signed-off-by: Addisu Z. Taddese --- python/test/light_TEST.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/python/test/light_TEST.py b/python/test/light_TEST.py index 23671d0c8a..13b8cd043a 100755 --- a/python/test/light_TEST.py +++ b/python/test/light_TEST.py @@ -57,7 +57,7 @@ def on_pre_udpate_cb(_info, _ecm): self.assertTrue(light_spot.valid(_ecm)) # Name Test self.assertEqual('light_point_test', light_point.name(_ecm)) - self.assertEqual('light_dir_test', light_dir.name(_ecm)) + self.assertEqual('light_directional_test', light_dir.name(_ecm)) self.assertEqual('light_spot_test', light_spot.name(_ecm)) # Pose Test self.assertEqual(Pose3d(0, 2, 2, 0, 0, 0), light_point.pose(_ecm)) @@ -104,21 +104,6 @@ def on_pre_udpate_cb(_info, _ecm): # Spot Falloff Test self.assertEqual(2, light_spot.spot_falloff(_ecm)) light_spot.set_spot_falloff(_ecm, 4) - # Check that all the values have been modified. - if self.pre_iterations > 1: - self.assertEqual(Color(1, 1, 0, 1), - light_point.diffuse_color(_ecm)) - self.assertEqual(Color(0.2, 0.2, 0, 1), - light_point.specular_color(_ecm)) - self.assertFalse(light_point.cast_shadows(_ecm)) - self.assertEqual(5, light_point.intensity(_ecm)) - self.assertEqual(Vector3d(1, 0, -1), light_dir.direction(_ecm)) - self.assertEqual(1.2, light_point.attenuation_constant(_ecm)) - self.assertEqual(0.5, light_point.attenuation_linear(_ecm)) - self.assertEqual(0.05, light_point.attenuation_quadratic(_ecm)) - self.assertEqual(Angle(15), light_spot.spot_inner_angle(_ecm)) - self.assertEqual(Angle(10), light_spot.spot_outer_angle(_ecm)) - self.assertEqual(4, light_spot.spot_falloff(_ecm)) def on_udpate_cb(_info, _ecm): self.iterations += 1 From 801bb087a9426259c83e573d6c7228fcf37f67be Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Fri, 25 Aug 2023 09:40:58 -0500 Subject: [PATCH 26/27] Address reviewer feedback Signed-off-by: Addisu Z. Taddese --- python/src/gz/sim/Light.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/python/src/gz/sim/Light.cc b/python/src/gz/sim/Light.cc index 6e74e6ed0e..5b3eb4792a 100644 --- a/python/src/gz/sim/Light.cc +++ b/python/src/gz/sim/Light.cc @@ -18,8 +18,6 @@ #include #include -#include - #include "Light.hh" namespace py = pybind11; From f0732ebb5ca5094e669271598492e4a8c1f037de Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Fri, 25 Aug 2023 13:19:09 -0500 Subject: [PATCH 27/27] Fix import Signed-off-by: Addisu Z. Taddese --- python/test/light_TEST.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/test/light_TEST.py b/python/test/light_TEST.py index 13b8cd043a..ec1c4f6493 100755 --- a/python/test/light_TEST.py +++ b/python/test/light_TEST.py @@ -16,7 +16,7 @@ import os import unittest -from gz.common import set_verbosity +from gz_test_deps.common import set_verbosity from gz_test_deps.sim import (K_NULL_ENTITY, Light, TestFixture, World, world_entity) from gz_test_deps.math import Angle, Color, Pose3d, Vector3d