From bd9846efbb56e227147bb1b69b712f8037cdf4d8 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 18 Jul 2023 08:12:11 -0500 Subject: [PATCH 01/31] 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/31] 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/31] 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/31] 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/31] 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/31] 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/31] 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/31] 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/31] 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/31] 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/31] 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/31] 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 786edbff50f4f7c7c5ac5567fc8b05a8e1b6a317 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Tue, 18 Jul 2023 16:29:25 +0000 Subject: [PATCH 13/31] 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 4289f003a9e12785fc1e22cbeda9b3fc1f6bb569 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Tue, 18 Jul 2023 19:34:00 +0000 Subject: [PATCH 14/31] 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 5b48e807f4cfc8a24dfb42bc27413a87c16be4fa Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 18 Jul 2023 16:32:37 -0500 Subject: [PATCH 15/31] Adds model bindings Signed-off-by: Voldivh --- python/CMakeLists.txt | 1 + python/src/gz/sim/Model.cc | 97 +++++++++++++++++++++++++++ python/src/gz/sim/Model.hh | 40 +++++++++++ python/src/gz/sim/_gz_sim_pybind11.cc | 2 + 4 files changed, 140 insertions(+) create mode 100644 python/src/gz/sim/Model.cc create mode 100644 python/src/gz/sim/Model.hh diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 1250c1827a..d36e0dc4b1 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/Model.cc src/gz/sim/TestFixture.cc src/gz/sim/Server.cc src/gz/sim/ServerConfig.cc diff --git a/python/src/gz/sim/Model.cc b/python/src/gz/sim/Model.cc new file mode 100644 index 0000000000..5b89d2680e --- /dev/null +++ b/python/src/gz/sim/Model.cc @@ -0,0 +1,97 @@ +/* + * 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 "Model.hh" + +namespace py = pybind11; + +namespace gz +{ +namespace sim +{ +namespace python +{ +void defineSimModel(pybind11::object module) +{ + pybind11::class_(module, "Model") + .def(pybind11::init()) + .def("entity", &gz::sim::Model::Entity, + "Get the entity which this Model is related to.") + .def("valid", &gz::sim::Model::Valid, + py::arg("ecm"), + "Check whether this model correctly refers to an entity that" + "has a components::Model.") + .def("name", &gz::sim::Model::Name, + py::arg("ecm"), + "Get the model's unscoped name.") + .def("static", &gz::sim::Model::Static, + py::arg("ecm"), + "Get whether this model is static.") + .def("self_collide", &gz::sim::Model::SelfCollide, + py::arg("ecm"), + "Get whether this model has self-collide enabled.") + .def("wind_mode", &gz::sim::Model::WindMode, + py::arg("ecm"), + "Get whether this model has wind enabled.") + .def("source_file_path", &gz::sim::Model::SourceFilePath, + py::arg("ecm"), + "Get the source file where this model came from. If empty," + "the model wasn't loaded directly from a file, probably from an SDF" + "string.") + .def("joint_by_name", &gz::sim::Model::JointByName, + py::arg("ecm"), + py::arg("name"), + "Get the ID of a joint entity which is an immediate child of" + "this model.") + .def("link_by_name", &gz::sim::Model::LinkByName, + py::arg("ecm"), + py::arg("name"), + "Get the ID of a link entity which is an immediate child of" + "this model.") + .def("joints", &gz::sim::Model::Joints, + py::arg("ecm"), + "Get all joints which are immediate children of this model.") + .def("links", &gz::sim::Model::Links, + py::arg("ecm"), + "Get all links which are immediate children of this model.") + .def("models", &gz::sim::Model::Models, + py::arg("ecm"), + "Get all models which are immediate children of this model.") + .def("joint_count", &gz::sim::Model::JointCount, + py::arg("ecm"), + "Get the number of joints which are immediate children of this" + "model.") + .def("link_count", &gz::sim::Model::LinkCount, + py::arg("ecm"), + "Get the number of links which are immediate children of this" + "model.") + .def("set_world_pose_cmd", &gz::sim::Model::SetWorldPoseCmd, + py::arg("ecm"), + py::arg("pose"), + "Set a command to change the model's pose.") + .def("canonical_link", &gz::sim::Model::CanonicalLink, + py::arg("ecm"), + "Get the model's canonical link entity."); +} +} // namespace python +} // namespace sim +} // namespace gz diff --git a/python/src/gz/sim/Model.hh b/python/src/gz/sim/Model.hh new file mode 100644 index 0000000000..2807f84b8e --- /dev/null +++ b/python/src/gz/sim/Model.hh @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2023 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GZ_SIM_PYTHON__MODEL_HH_ +#define GZ_SIM_PYTHON__MODEL_HH_ + +#include + +#include + +namespace gz +{ +namespace sim +{ +namespace python +{ +/// Define a pybind11 wrapper for a gz::sim::Model +/** + * \param[in] module a pybind11 module to add the definition to + */ +void +defineSimModel(pybind11::object module); +} // namespace python +} // namespace sim +} // namespace gz + +#endif // GZ_SIM_PYTHON__MODEL_HH_ diff --git a/python/src/gz/sim/_gz_sim_pybind11.cc b/python/src/gz/sim/_gz_sim_pybind11.cc index c9d556f132..6ec71b055a 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 "Model.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::defineSimModel(m); gz::sim::python::defineSimServer(m); gz::sim::python::defineSimServerConfig(m); gz::sim::python::defineSimTestFixture(m); From db2d81585026b8080275d58bc07b9aecf4547a8f Mon Sep 17 00:00:00 2001 From: Voldivh Date: Wed, 19 Jul 2023 14:11:20 -0500 Subject: [PATCH 16/31] Use alias on bindings Signed-off-by: Voldivh --- python/src/gz/sim/Model.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/src/gz/sim/Model.cc b/python/src/gz/sim/Model.cc index 5b89d2680e..2db5f117e5 100644 --- a/python/src/gz/sim/Model.cc +++ b/python/src/gz/sim/Model.cc @@ -30,10 +30,10 @@ namespace sim { namespace python { -void defineSimModel(pybind11::object module) +void defineSimModel(py::object module) { - pybind11::class_(module, "Model") - .def(pybind11::init()) + py::class_(module, "Model") + .def(py::init()) .def("entity", &gz::sim::Model::Entity, "Get the entity which this Model is related to.") .def("valid", &gz::sim::Model::Valid, From 1aeeb53a84e92f44a968a5741236ded8bc36de99 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Wed, 26 Jul 2023 10:25:25 -0500 Subject: [PATCH 17/31] Adds test and fixes documentation Signed-off-by: Voldivh --- python/CMakeLists.txt | 1 + python/src/gz/sim/Model.cc | 12 +++--- python/test/model_TEST.py | 82 ++++++++++++++++++++++++++++++++++++++ python/test/model_test.sdf | 25 ++++++++++++ 4 files changed, 114 insertions(+), 6 deletions(-) create mode 100755 python/test/model_TEST.py create mode 100644 python/test/model_test.sdf diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index d36e0dc4b1..559947a652 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -87,6 +87,7 @@ endif() if (BUILD_TESTING) set(python_tests + model_TEST testFixture_TEST world_TEST ) diff --git a/python/src/gz/sim/Model.cc b/python/src/gz/sim/Model.cc index 2db5f117e5..7c17010deb 100644 --- a/python/src/gz/sim/Model.cc +++ b/python/src/gz/sim/Model.cc @@ -38,7 +38,7 @@ void defineSimModel(py::object module) "Get the entity which this Model is related to.") .def("valid", &gz::sim::Model::Valid, py::arg("ecm"), - "Check whether this model correctly refers to an entity that" + "Check whether this model correctly refers to an entity that " "has a components::Model.") .def("name", &gz::sim::Model::Name, py::arg("ecm"), @@ -55,17 +55,17 @@ void defineSimModel(py::object module) .def("source_file_path", &gz::sim::Model::SourceFilePath, py::arg("ecm"), "Get the source file where this model came from. If empty," - "the model wasn't loaded directly from a file, probably from an SDF" + "the model wasn't loaded directly from a file, probably from an SDF " "string.") .def("joint_by_name", &gz::sim::Model::JointByName, py::arg("ecm"), py::arg("name"), - "Get the ID of a joint entity which is an immediate child of" + "Get the ID of a joint entity which is an immediate child of " "this model.") .def("link_by_name", &gz::sim::Model::LinkByName, py::arg("ecm"), py::arg("name"), - "Get the ID of a link entity which is an immediate child of" + "Get the ID of a link entity which is an immediate child of " "this model.") .def("joints", &gz::sim::Model::Joints, py::arg("ecm"), @@ -78,11 +78,11 @@ void defineSimModel(py::object module) "Get all models which are immediate children of this model.") .def("joint_count", &gz::sim::Model::JointCount, py::arg("ecm"), - "Get the number of joints which are immediate children of this" + "Get the number of joints which are immediate children of this " "model.") .def("link_count", &gz::sim::Model::LinkCount, py::arg("ecm"), - "Get the number of links which are immediate children of this" + "Get the number of links which are immediate children of this " "model.") .def("set_world_pose_cmd", &gz::sim::Model::SetWorldPoseCmd, py::arg("ecm"), diff --git a/python/test/model_TEST.py b/python/test/model_TEST.py new file mode 100755 index 0000000000..a26c64329f --- /dev/null +++ b/python/test/model_TEST.py @@ -0,0 +1,82 @@ +#!/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 TestFixture, Model, World, world_entity + +post_iterations = 0 +iterations = 0 +pre_iterations = 0 + +class TestModel(unittest.TestCase): + + def test_model(self): + set_verbosity(4) + + file_path = os.path.dirname(os.path.realpath(__file__)) + fixture = TestFixture(os.path.join(file_path, 'model_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) + model = Model(w.model_by_name(_ecm, 'model_test')) + # Entity Test + self.assertEqual(4, model.entity()) + # Valid Test + self.assertTrue(model.valid(_ecm)) + # Name Test + self.assertEqual('model_test', model.name(_ecm)) + # Static Test + self.assertTrue(model.static(_ecm)) + # Self Collide Test + self.assertTrue(model.self_collide(_ecm)) + # Wind Mode Test + self.assertTrue(model.wind_mode(_ecm)) + # Get Joints Test + self.assertEqual(7, model.joint_by_name(_ecm, 'model_joint_test')) + self.assertEqual(1, model.joint_count(_ecm)) + # Get Links Test + self.assertEqual(5, model.link_by_name(_ecm, 'model_link_test_1')) + self.assertEqual(6, model.link_by_name(_ecm, 'model_link_test_2')) + self.assertEqual(2, model.link_count(_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/model_test.sdf b/python/test/model_test.sdf new file mode 100644 index 0000000000..31c6b3f935 --- /dev/null +++ b/python/test/model_test.sdf @@ -0,0 +1,25 @@ + + + + + 0.2 0.1 0.5 0.1 0.3 0.4 + true + true + true + + + 0 0 0 0 0 0 + + + + 0 0 0 0 0 0 + + + + model_link_test_1 + model_link_test_2 + + + + + From 4989d237b6b69213e1d973adc4e702a4ff828198 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Thu, 27 Jul 2023 09:45:16 -0500 Subject: [PATCH 18/31] Fixes identation on sdf file Signed-off-by: Voldivh --- python/test/model_test.sdf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/test/model_test.sdf b/python/test/model_test.sdf index 31c6b3f935..ae351aa010 100644 --- a/python/test/model_test.sdf +++ b/python/test/model_test.sdf @@ -16,8 +16,8 @@ - model_link_test_1 - model_link_test_2 + model_link_test_1 + model_link_test_2 From af115a1b94f519118932b0915c6dda522bd64a24 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 8 Aug 2023 10:47:06 -0500 Subject: [PATCH 19/31] Modifies the use of import dependencies Signed-off-by: Voldivh --- python/src/gz/sim/Model.cc | 2 -- python/test/model_TEST.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/python/src/gz/sim/Model.cc b/python/src/gz/sim/Model.cc index 7c17010deb..47f30645a6 100644 --- a/python/src/gz/sim/Model.cc +++ b/python/src/gz/sim/Model.cc @@ -18,8 +18,6 @@ #include #include -#include - #include "Model.hh" namespace py = pybind11; diff --git a/python/test/model_TEST.py b/python/test/model_TEST.py index a26c64329f..8d72eeeaf1 100755 --- a/python/test/model_TEST.py +++ b/python/test/model_TEST.py @@ -17,7 +17,7 @@ import unittest from gz.common import set_verbosity -from gz.sim8 import TestFixture, Model, World, world_entity +from gz_test_deps.sim import TestFixture, Model, World, world_entity post_iterations = 0 iterations = 0 From 8824ad0c2a750fced666c14375cbb0bb718b5113 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Wed, 19 Jul 2023 14:07:51 -0500 Subject: [PATCH 20/31] Adds the bindings for the joint class Signed-off-by: Voldivh --- include/gz/sim/Joint.hh | 2 +- python/CMakeLists.txt | 1 + python/src/gz/sim/Joint.cc | 141 ++++++++++++++++++++++++++ python/src/gz/sim/Joint.hh | 40 ++++++++ python/src/gz/sim/_gz_sim_pybind11.cc | 2 + 5 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 python/src/gz/sim/Joint.cc create mode 100644 python/src/gz/sim/Joint.hh diff --git a/include/gz/sim/Joint.hh b/include/gz/sim/Joint.hh index 8de460c544..302da37fdd 100644 --- a/include/gz/sim/Joint.hh +++ b/include/gz/sim/Joint.hh @@ -260,7 +260,7 @@ namespace gz public: std::optional> Position( const EntityComponentManager &_ecm) const; - /// \brief Get the position of the joint + /// \brief Get the transmitted wrench of the joint /// \param[in] _ecm Entity-component manager. /// \return Transmitted wrench of the joint or nullopt if transmitted /// wrench check is not enabled. diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 559947a652..9153d0d5a8 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/Joint.cc src/gz/sim/Model.cc src/gz/sim/TestFixture.cc src/gz/sim/Server.cc diff --git a/python/src/gz/sim/Joint.cc b/python/src/gz/sim/Joint.cc new file mode 100644 index 0000000000..37dc3acd7e --- /dev/null +++ b/python/src/gz/sim/Joint.cc @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2021 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include + +#include + +#include "Joint.hh" + +namespace py = pybind11; + +namespace gz +{ +namespace sim +{ +namespace python +{ +void defineSimJoint(py::object module) +{ + py::class_(module, "Joint") + .def(py::init()) + .def("entity", &gz::sim::Joint::Entity, + "Get the entity which this Joint is related to.") + .def("reset_entity", &gz::sim::Joint::ResetEntity, + py::arg("new_entity"), + "Reset Entity to a new one.") + .def("valid", &gz::sim::Joint::Valid, + py::arg("ecm"), + "Check whether this joint correctly refers to an entity that" + "has a components::Joint.") + .def("name", &gz::sim::Joint::Name, + py::arg("ecm"), + "Get the joint's unscoped name.") + .def("parent_link_name", &gz::sim::Joint::ParentLinkName, + py::arg("ecm"), + "Get the parent link name.") + .def("child_link_name", &gz::sim::Joint::ChildLinkName, + py::arg("ecm"), + "Get the child link name.") + .def("pose", &gz::sim::Joint::Pose, + py::arg("ecm"), + "Get the pose of the joint.") + .def("thread_pitch", &gz::sim::Joint::ThreadPitch, + py::arg("ecm"), + "Get the thread pitch of the joint.") + .def("axis", &gz::sim::Joint::Axis, + py::arg("ecm"), + "Get the joint axis.") + .def("type", &gz::sim::Joint::Type, + py::arg("ecm"), + "Get the joint type.") + .def("sensor_by_name", &gz::sim::Joint::SensorByName, + py::arg("ecm"), + py::arg("name"), + "Get the ID of a sensor entity which is an immediate child of" + "this joint.") + .def("sensors", &gz::sim::Joint::Sensors, + py::arg("ecm"), + "Get all sensors which are immediate children of this joint.") + .def("sensor_count", &gz::sim::Joint::SensorCount, + py::arg("ecm"), + "Get the number of sensors which are immediate children of this" + "joint.") + .def("set_velocity", &gz::sim::Joint::SetVelocity, + py::arg("ecm"), + py::arg("velocities"), + "Set velocity on this joint. Only applied if no forces are set.") + .def("set_force", &gz::sim::Joint::SetForce, + py::arg("ecm"), + py::arg("forces"), + "Set force on this joint. If both forces and velocities are set," + "only forces are applied.") + .def("set_velocity_limits", &gz::sim::Joint::SetVelocityLimits, + py::arg("ecm"), + py::arg("limits"), + "Set the velocity limits on a joint axis.") + .def("set_effort_limits", &gz::sim::Joint::SetEffortLimits, + py::arg("ecm"), + py::arg("limits"), + "Set the effort limits on a joint axis.") + .def("set_position_imits", &gz::sim::Joint::SetPositionLimits, + py::arg("ecm"), + py::arg("limits"), + "Set the position limits on a joint axis.") + .def("reset_position", &gz::sim::Joint::ResetPosition, + py::arg("ecm"), + py::arg("positions"), + "Reset the joint positions.") + .def("reset_velocity", &gz::sim::Joint::ResetVelocity, + py::arg("ecm"), + py::arg("velocities"), + "Reset the joint velocities.") + .def("enable_velocity_check", &gz::sim::Joint::EnableVelocityCheck, + py::arg("ecm"), + py::arg("enable") = true, + "By default, Gazebo will not report velocities for a joint, so" + "functions like `Velocity` will return nullopt. This" + "function can be used to enable joint velocity check.") + .def("enable_position_check", &gz::sim::Joint::EnablePositionCheck, + py::arg("ecm"), + py::arg("enable") = true, + "By default, Gazebo will not report positions for a joint, so" + "functions like `Position` will return nullopt. This" + "function can be used to enable joint position check.") + .def("enable_transmitted_wrench_check", &gz::sim::Joint::EnableTransmittedWrenchCheck, + py::arg("ecm"), + py::arg("enable") = true, + "By default, Gazebo will not report transmitted wrench for a" + "joint, so functions like `TransmittedWrench` will return nullopt. This" + "function can be used to enable joint transmitted wrench check.") + .def("velocity", &gz::sim::Joint::Velocity, + py::arg("ecm"), + "Get the velocity of the joint.") + .def("position", &gz::sim::Joint::Position, + py::arg("ecm"), + "Get the position of the joint.") + .def("transmitted_wrench", &gz::sim::Joint::TransmittedWrench, + py::arg("ecm"), + "Get the transmitted wrench of the joint.") + .def("parent_model", &gz::sim::Joint::ParentModel, + py::arg("ecm"), + "Get the parent model of the joint."); +} +} // namespace python +} // namespace sim +} // namespace gz diff --git a/python/src/gz/sim/Joint.hh b/python/src/gz/sim/Joint.hh new file mode 100644 index 0000000000..8e0fd77cce --- /dev/null +++ b/python/src/gz/sim/Joint.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__JOINT_HH_ +#define GZ_SIM_PYTHON__JOINT_HH_ + +#include + +#include + +namespace gz +{ +namespace sim +{ +namespace python +{ +/// Define a pybind11 wrapper for a gz::sim::Joint +/** + * \param[in] module a pybind11 module to add the definition to + */ +void +defineSimJoint(pybind11::object module); +} // namespace python +} // namespace sim +} // namespace gz + +#endif // GZ_SIM_PYTHON__JOINT_HH_ diff --git a/python/src/gz/sim/_gz_sim_pybind11.cc b/python/src/gz/sim/_gz_sim_pybind11.cc index 6ec71b055a..6158c7976a 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 "Joint.hh" #include "Model.hh" #include "Server.hh" #include "ServerConfig.hh" @@ -31,6 +32,7 @@ PYBIND11_MODULE(BINDINGS_MODULE_NAME, m) { gz::sim::python::defineSimEntityComponentManager(m); gz::sim::python::defineSimEventManager(m); + gz::sim::python::defineSimJoint(m); gz::sim::python::defineSimModel(m); gz::sim::python::defineSimServer(m); gz::sim::python::defineSimServerConfig(m); From e68a009e16be520f62e40a6f1f934e7e2a9bfd9a Mon Sep 17 00:00:00 2001 From: Voldivh Date: Thu, 27 Jul 2023 07:23:13 -0500 Subject: [PATCH 21/31] Adds test for the bindings Signed-off-by: Voldivh --- python/CMakeLists.txt | 1 + python/test/joint_TEST.py | 99 ++++++++++++++++++++++++++++++++++++++ python/test/joint_test.sdf | 25 ++++++++++ 3 files changed, 125 insertions(+) create mode 100644 python/test/joint_TEST.py create mode 100644 python/test/joint_test.sdf diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 9153d0d5a8..cb50a6af09 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -88,6 +88,7 @@ endif() if (BUILD_TESTING) set(python_tests + joint_TEST model_TEST testFixture_TEST world_TEST diff --git a/python/test/joint_TEST.py b/python/test/joint_TEST.py new file mode 100644 index 0000000000..efd93872ab --- /dev/null +++ b/python/test/joint_TEST.py @@ -0,0 +1,99 @@ +#!/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 TestFixture, Joint, Model, World, world_entity +from gz.math7 import Pose3d +from sdformat13 import JointAxis, JointType + +post_iterations = 0 +iterations = 0 +pre_iterations = 0 + +class TestJoint(unittest.TestCase): + + def test_model(self): + set_verbosity(4) + + file_path = os.path.dirname(os.path.realpath(__file__)) + fixture = TestFixture(os.path.join(file_path, 'joint_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) + m = Model(w.model_by_name(_ecm, 'model_test')) + joint = Joint(m.joint_by_name(_ecm, 'joint_test')) + # Entity Test + self.assertEqual(7, joint.entity()) + # Valid Test + self.assertTrue(joint.valid(_ecm)) + # Name Test + self.assertEqual('joint_test', joint.name(_ecm)) + # Parent Link Name Test + self.assertEqual('link_test_1', joint.parent_link_name(_ecm)) + # Child Link Name Test + self.assertEqual('link_test_2', joint.child_link_name(_ecm)) + # Pose Test + self.assertEqual(Pose3d(0, 0.5, 0, 0, 0, 0), joint.pose(_ecm)) + # Thread Pitch Test + self.assertEqual(2, joint.thread_pitch(_ecm)) + # Axis Test + self.assertEqual(JointAxis().xyz(), joint.axis(_ecm)[0].xyz()) + # Type Test + self.assertEqual(JointType.REVOLUTE, joint.type(_ecm)) + # Sensors Test + self.assertEqual(8, joint.sensor_by_name(_ecm, 'sensor_test')) + self.assertEqual(1, joint.sensor_count(_ecm)) + # Velocity Test + self.assertEqual(None, joint.velocity(_ecm)) + joint.enable_velocity_check(_ecm, True) + joint.set_velocity(_ecm, [10]) + # This should be 'self.assertEqual([10], joint.velocity(_ecm))' + self.assertEqual([], joint.velocity(_ecm)) + joint.enable_velocity_check(_ecm, False) + # Position Test + self.assertEqual(None, joint.position(_ecm)) + joint.enable_position_check(_ecm, True) + self.assertEqual([], joint.position(_ecm)) + joint.enable_position_check(_ecm, False) + + 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/joint_test.sdf b/python/test/joint_test.sdf new file mode 100644 index 0000000000..b4258418f6 --- /dev/null +++ b/python/test/joint_test.sdf @@ -0,0 +1,25 @@ + + + + + + + + + + + + + link_test_1 + link_test_2 + 0 0.5 0 0 0 0 + 2 + + 0 0 1 + + + + + + + \ No newline at end of file From 80a0d5e96b4ef5c6ba023dd45b184308f02c5de2 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Thu, 27 Jul 2023 07:29:53 -0500 Subject: [PATCH 22/31] Adds empty line at the end of file Signed-off-by: Voldivh --- python/test/joint_test.sdf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/test/joint_test.sdf b/python/test/joint_test.sdf index b4258418f6..02de1fc61d 100644 --- a/python/test/joint_test.sdf +++ b/python/test/joint_test.sdf @@ -22,4 +22,4 @@ - \ No newline at end of file + From 916f0614eabe35bc15a82681f1ddd5b43a7741a8 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Thu, 27 Jul 2023 07:36:52 -0500 Subject: [PATCH 23/31] Give executable permission to test Signed-off-by: Voldivh --- python/test/joint_TEST.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 python/test/joint_TEST.py diff --git a/python/test/joint_TEST.py b/python/test/joint_TEST.py old mode 100644 new mode 100755 From 4858939bbe0f7079aeb4a98a9f2f463964871a0b Mon Sep 17 00:00:00 2001 From: Voldivh Date: Thu, 27 Jul 2023 09:52:54 -0500 Subject: [PATCH 24/31] Modifies documentation Signed-off-by: Voldivh --- python/src/gz/sim/Joint.cc | 20 ++++++++++---------- python/src/gz/sim/Joint.hh | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/python/src/gz/sim/Joint.cc b/python/src/gz/sim/Joint.cc index 37dc3acd7e..f33024f8a2 100644 --- a/python/src/gz/sim/Joint.cc +++ b/python/src/gz/sim/Joint.cc @@ -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. @@ -67,14 +67,14 @@ void defineSimJoint(py::object module) .def("sensor_by_name", &gz::sim::Joint::SensorByName, py::arg("ecm"), py::arg("name"), - "Get the ID of a sensor entity which is an immediate child of" + "Get the ID of a sensor entity which is an immediate child of " "this joint.") .def("sensors", &gz::sim::Joint::Sensors, py::arg("ecm"), "Get all sensors which are immediate children of this joint.") .def("sensor_count", &gz::sim::Joint::SensorCount, py::arg("ecm"), - "Get the number of sensors which are immediate children of this" + "Get the number of sensors which are immediate children of this " "joint.") .def("set_velocity", &gz::sim::Joint::SetVelocity, py::arg("ecm"), @@ -83,7 +83,7 @@ void defineSimJoint(py::object module) .def("set_force", &gz::sim::Joint::SetForce, py::arg("ecm"), py::arg("forces"), - "Set force on this joint. If both forces and velocities are set," + "Set force on this joint. If both forces and velocities are set, " "only forces are applied.") .def("set_velocity_limits", &gz::sim::Joint::SetVelocityLimits, py::arg("ecm"), @@ -108,20 +108,20 @@ void defineSimJoint(py::object module) .def("enable_velocity_check", &gz::sim::Joint::EnableVelocityCheck, py::arg("ecm"), py::arg("enable") = true, - "By default, Gazebo will not report velocities for a joint, so" - "functions like `Velocity` will return nullopt. This" + "By default, Gazebo will not report velocities for a joint, so " + "functions like `Velocity` will return nullopt. This " "function can be used to enable joint velocity check.") .def("enable_position_check", &gz::sim::Joint::EnablePositionCheck, py::arg("ecm"), py::arg("enable") = true, - "By default, Gazebo will not report positions for a joint, so" - "functions like `Position` will return nullopt. This" + "By default, Gazebo will not report positions for a joint, so " + "functions like `Position` will return nullopt. This " "function can be used to enable joint position check.") .def("enable_transmitted_wrench_check", &gz::sim::Joint::EnableTransmittedWrenchCheck, py::arg("ecm"), py::arg("enable") = true, - "By default, Gazebo will not report transmitted wrench for a" - "joint, so functions like `TransmittedWrench` will return nullopt. This" + "By default, Gazebo will not report transmitted wrench for a " + "joint, so functions like `TransmittedWrench` will return nullopt. This " "function can be used to enable joint transmitted wrench check.") .def("velocity", &gz::sim::Joint::Velocity, py::arg("ecm"), diff --git a/python/src/gz/sim/Joint.hh b/python/src/gz/sim/Joint.hh index 8e0fd77cce..4fc179eb26 100644 --- a/python/src/gz/sim/Joint.hh +++ b/python/src/gz/sim/Joint.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. From 37b883fea220104d52f187ed4c3ff3242894c71a Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 1 Aug 2023 13:21:08 -0500 Subject: [PATCH 25/31] Modifies velocity test Signed-off-by: Voldivh --- python/test/joint_TEST.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/test/joint_TEST.py b/python/test/joint_TEST.py index efd93872ab..67a75312ae 100755 --- a/python/test/joint_TEST.py +++ b/python/test/joint_TEST.py @@ -66,13 +66,13 @@ def on_pre_udpate_cb(_info, _ecm): # Sensors Test self.assertEqual(8, joint.sensor_by_name(_ecm, 'sensor_test')) self.assertEqual(1, joint.sensor_count(_ecm)) - # Velocity Test - self.assertEqual(None, joint.velocity(_ecm)) + # Velocity Test. joint.enable_velocity_check(_ecm, True) joint.set_velocity(_ecm, [10]) - # This should be 'self.assertEqual([10], joint.velocity(_ecm))' - self.assertEqual([], joint.velocity(_ecm)) - joint.enable_velocity_check(_ecm, False) + if pre_iterations == 0: + self.assertEqual(None, joint.velocity(_ecm)) + elif pre_iterations > 1: + self.assertAlmostEqual(10, joint.velocity(_ecm)[0]) # Position Test self.assertEqual(None, joint.position(_ecm)) joint.enable_position_check(_ecm, True) From 6795ee4061149dd5117aeb3f8648a9062fba79d3 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 8 Aug 2023 10:56:44 -0500 Subject: [PATCH 26/31] Modifies import dependencies Signed-off-by: Voldivh --- python/test/joint_TEST.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/test/joint_TEST.py b/python/test/joint_TEST.py index 67a75312ae..1ff702d1db 100755 --- a/python/test/joint_TEST.py +++ b/python/test/joint_TEST.py @@ -17,9 +17,9 @@ import unittest from gz.common import set_verbosity -from gz.sim8 import TestFixture, Joint, Model, World, world_entity -from gz.math7 import Pose3d -from sdformat13 import JointAxis, JointType +from gz_test_deps.sim import TestFixture, Joint, Model, World, world_entity +from gz_test_deps.math import Pose3d +from gz_test_deps.sdformat import JointAxis, JointType post_iterations = 0 iterations = 0 From 7de886c92bc1785ded1a59281c3dfffe178a1b98 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Thu, 10 Aug 2023 13:19:09 -0500 Subject: [PATCH 27/31] Adds copy constructor Signed-off-by: Voldivh --- python/src/gz/sim/Joint.cc | 13 ++++++++++++- python/test/joint_TEST.py | 14 ++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/python/src/gz/sim/Joint.cc b/python/src/gz/sim/Joint.cc index f33024f8a2..1162ab7477 100644 --- a/python/src/gz/sim/Joint.cc +++ b/python/src/gz/sim/Joint.cc @@ -34,6 +34,7 @@ void defineSimJoint(py::object module) { py::class_(module, "Joint") .def(py::init()) + .def(py::init()) .def("entity", &gz::sim::Joint::Entity, "Get the entity which this Joint is related to.") .def("reset_entity", &gz::sim::Joint::ResetEntity, @@ -134,7 +135,17 @@ void defineSimJoint(py::object module) "Get the transmitted wrench of the joint.") .def("parent_model", &gz::sim::Joint::ParentModel, py::arg("ecm"), - "Get the parent model of the joint."); + "Get the parent model of the joint.") + .def("__copy__", + [](const gz::sim::Joint &self) + { + return gz::sim::Joint(self); + }) + .def("__deepcopy__", + [](const gz::sim::Joint &self, pybind11::dict) + { + return gz::sim::Joint(self); + }); } } // namespace python } // namespace sim diff --git a/python/test/joint_TEST.py b/python/test/joint_TEST.py index 1ff702d1db..6b9822f0d5 100755 --- a/python/test/joint_TEST.py +++ b/python/test/joint_TEST.py @@ -21,11 +21,13 @@ from gz_test_deps.math import Pose3d from gz_test_deps.sdformat import JointAxis, JointType -post_iterations = 0 -iterations = 0 -pre_iterations = 0 + class TestJoint(unittest.TestCase): + k_null_entity = 0 + post_iterations = 0 + iterations = 0 + pre_iterations = 0 def test_model(self): set_verbosity(4) @@ -41,12 +43,12 @@ def on_pre_udpate_cb(_info, _ecm): global pre_iterations 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) m = Model(w.model_by_name(_ecm, 'model_test')) joint = Joint(m.joint_by_name(_ecm, 'joint_test')) # Entity Test - self.assertEqual(7, joint.entity()) + self.assertNotEqual(self.k_null_entity, joint.entity()) # Valid Test self.assertTrue(joint.valid(_ecm)) # Name Test @@ -64,7 +66,7 @@ def on_pre_udpate_cb(_info, _ecm): # Type Test self.assertEqual(JointType.REVOLUTE, joint.type(_ecm)) # Sensors Test - self.assertEqual(8, joint.sensor_by_name(_ecm, 'sensor_test')) + self.assertNotEqual(self.k_null_entity, joint.sensor_by_name(_ecm, 'sensor_test')) self.assertEqual(1, joint.sensor_count(_ecm)) # Velocity Test. joint.enable_velocity_check(_ecm, True) From 06081353008f2fb717f4498f4a98bbbb3ef029e9 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Thu, 10 Aug 2023 13:34:49 -0500 Subject: [PATCH 28/31] Removes whitespace Signed-off-by: Voldivh --- python/src/gz/sim/Joint.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/src/gz/sim/Joint.cc b/python/src/gz/sim/Joint.cc index 1162ab7477..7c31c518ac 100644 --- a/python/src/gz/sim/Joint.cc +++ b/python/src/gz/sim/Joint.cc @@ -136,7 +136,7 @@ void defineSimJoint(py::object module) .def("parent_model", &gz::sim::Joint::ParentModel, py::arg("ecm"), "Get the parent model of the joint.") - .def("__copy__", + .def("__copy__", [](const gz::sim::Joint &self) { return gz::sim::Joint(self); From 5237f1b9fd5e9a8ca3bda8607bdf5d7169d8d79c Mon Sep 17 00:00:00 2001 From: Voldivh Date: Tue, 15 Aug 2023 15:36:01 -0500 Subject: [PATCH 29/31] Modifies the use of the null entity variable Signed-off-by: Voldivh --- python/test/joint_TEST.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/python/test/joint_TEST.py b/python/test/joint_TEST.py index 6b9822f0d5..7a4ce785b6 100755 --- a/python/test/joint_TEST.py +++ b/python/test/joint_TEST.py @@ -17,14 +17,13 @@ import unittest from gz.common import set_verbosity -from gz_test_deps.sim import TestFixture, Joint, Model, World, world_entity +from gz_test_deps.sim import K_NULL_ENTITY, TestFixture, Joint, Model, World, world_entity from gz_test_deps.math import Pose3d from gz_test_deps.sdformat import JointAxis, JointType class TestJoint(unittest.TestCase): - k_null_entity = 0 post_iterations = 0 iterations = 0 pre_iterations = 0 @@ -43,12 +42,12 @@ def on_pre_udpate_cb(_info, _ecm): global pre_iterations 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) m = Model(w.model_by_name(_ecm, 'model_test')) joint = Joint(m.joint_by_name(_ecm, 'joint_test')) # Entity Test - self.assertNotEqual(self.k_null_entity, joint.entity()) + self.assertNotEqual(K_NULL_ENTITY, joint.entity()) # Valid Test self.assertTrue(joint.valid(_ecm)) # Name Test @@ -66,7 +65,7 @@ def on_pre_udpate_cb(_info, _ecm): # Type Test self.assertEqual(JointType.REVOLUTE, joint.type(_ecm)) # Sensors Test - self.assertNotEqual(self.k_null_entity, joint.sensor_by_name(_ecm, 'sensor_test')) + self.assertNotEqual(K_NULL_ENTITY, joint.sensor_by_name(_ecm, 'sensor_test')) self.assertEqual(1, joint.sensor_count(_ecm)) # Velocity Test. joint.enable_velocity_check(_ecm, True) From 75c2f6f3084bba27024b0ae5f06310fcd3c26ec8 Mon Sep 17 00:00:00 2001 From: Voldivh Date: Wed, 16 Aug 2023 11:34:23 -0500 Subject: [PATCH 30/31] Applies format code style to files Signed-off-by: Voldivh --- python/src/gz/sim/Joint.cc | 3 ++- python/test/joint_TEST.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/python/src/gz/sim/Joint.cc b/python/src/gz/sim/Joint.cc index 7c31c518ac..307289ec44 100644 --- a/python/src/gz/sim/Joint.cc +++ b/python/src/gz/sim/Joint.cc @@ -118,7 +118,8 @@ void defineSimJoint(py::object module) "By default, Gazebo will not report positions for a joint, so " "functions like `Position` will return nullopt. This " "function can be used to enable joint position check.") - .def("enable_transmitted_wrench_check", &gz::sim::Joint::EnableTransmittedWrenchCheck, + .def("enable_transmitted_wrench_check", + &gz::sim::Joint::EnableTransmittedWrenchCheck, py::arg("ecm"), py::arg("enable") = true, "By default, Gazebo will not report transmitted wrench for a " diff --git a/python/test/joint_TEST.py b/python/test/joint_TEST.py index 7a4ce785b6..d7869b9d23 100755 --- a/python/test/joint_TEST.py +++ b/python/test/joint_TEST.py @@ -17,12 +17,12 @@ import unittest from gz.common import set_verbosity -from gz_test_deps.sim import K_NULL_ENTITY, TestFixture, Joint, Model, World, world_entity +from gz_test_deps.sim import (K_NULL_ENTITY, TestFixture, + Joint, Model, World, world_entity) from gz_test_deps.math import Pose3d from gz_test_deps.sdformat import JointAxis, JointType - class TestJoint(unittest.TestCase): post_iterations = 0 iterations = 0 @@ -65,7 +65,8 @@ def on_pre_udpate_cb(_info, _ecm): # Type Test self.assertEqual(JointType.REVOLUTE, joint.type(_ecm)) # Sensors Test - self.assertNotEqual(K_NULL_ENTITY, joint.sensor_by_name(_ecm, 'sensor_test')) + self.assertNotEqual(K_NULL_ENTITY, + joint.sensor_by_name(_ecm, 'sensor_test')) self.assertEqual(1, joint.sensor_count(_ecm)) # Velocity Test. joint.enable_velocity_check(_ecm, True) @@ -96,5 +97,6 @@ def on_udpate_cb(_info, _ecm): self.assertEqual(1000, iterations) self.assertEqual(1000, post_iterations) + if __name__ == '__main__': unittest.main() From 0e10d7334e88e4822797e74cf9e7a698581aea2e Mon Sep 17 00:00:00 2001 From: Voldivh Date: Wed, 16 Aug 2023 17:28:25 -0500 Subject: [PATCH 31/31] Modifies the iteration amount Signed-off-by: Voldivh --- python/test/joint_TEST.py | 32 ++++++++++++++------------------ python/test/joint_test.sdf | 3 +-- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/python/test/joint_TEST.py b/python/test/joint_TEST.py index d7869b9d23..78e15b0dc1 100755 --- a/python/test/joint_TEST.py +++ b/python/test/joint_TEST.py @@ -35,12 +35,10 @@ def test_model(self): fixture = TestFixture(os.path.join(file_path, 'joint_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.assertNotEqual(K_NULL_ENTITY, world_e) w = World(world_e) @@ -58,8 +56,6 @@ def on_pre_udpate_cb(_info, _ecm): self.assertEqual('link_test_2', joint.child_link_name(_ecm)) # Pose Test self.assertEqual(Pose3d(0, 0.5, 0, 0, 0, 0), joint.pose(_ecm)) - # Thread Pitch Test - self.assertEqual(2, joint.thread_pitch(_ecm)) # Axis Test self.assertEqual(JointAxis().xyz(), joint.axis(_ecm)[0].xyz()) # Type Test @@ -71,19 +67,19 @@ def on_pre_udpate_cb(_info, _ecm): # Velocity Test. joint.enable_velocity_check(_ecm, True) joint.set_velocity(_ecm, [10]) - if pre_iterations == 0: + if self.pre_iterations == 0: self.assertEqual(None, joint.velocity(_ecm)) - elif pre_iterations > 1: + elif self.pre_iterations > 1: self.assertAlmostEqual(10, joint.velocity(_ecm)[0]) # Position Test - self.assertEqual(None, joint.position(_ecm)) - joint.enable_position_check(_ecm, True) - self.assertEqual([], joint.position(_ecm)) - joint.enable_position_check(_ecm, False) + if self.pre_iterations <= 1: + self.assertEqual(None, joint.position(_ecm)) + joint.enable_position_check(_ecm, True) + else: + self.assertNotEqual(None, joint.position(_ecm)) 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) @@ -91,11 +87,11 @@ def on_udpate_cb(_info, _ecm): fixture.finalize() server = fixture.server() - server.run(True, 1000, False) + server.run(True, 2, False) - self.assertEqual(1000, pre_iterations) - self.assertEqual(1000, iterations) - self.assertEqual(1000, post_iterations) + self.assertEqual(2, self.pre_iterations) + self.assertEqual(2, self.iterations) + self.assertEqual(2, self.post_iterations) if __name__ == '__main__': diff --git a/python/test/joint_test.sdf b/python/test/joint_test.sdf index 02de1fc61d..f4c780c35b 100644 --- a/python/test/joint_test.sdf +++ b/python/test/joint_test.sdf @@ -13,11 +13,10 @@ link_test_1 link_test_2 0 0.5 0 0 0 0 - 2 0 0 1 - +