-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds bindings for the world convenience class (#2035)
Signed-off-by: Voldivh <[email protected]>
- Loading branch information
Showing
9 changed files
with
209 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from gz.math7 import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from sdformat14 import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from gz.sim8 import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (C) 2021 Open Source Robotics Foundation | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import unittest | ||
|
||
from gz.common import set_verbosity | ||
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 | ||
pre_iterations = 0 | ||
|
||
class TestWorld(unittest.TestCase): | ||
|
||
def test_world(self): | ||
set_verbosity(4) | ||
|
||
file_path = os.path.dirname(os.path.realpath(__file__)) | ||
fixture = TestFixture(os.path.join(file_path, 'world_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) | ||
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.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 | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" ?> | ||
<sdf version="1.6"> | ||
<world name="world_test"> | ||
<physics name="1ms" type="ignored"> | ||
<max_step_size>0.01</max_step_size> | ||
<real_time_factor>1.0</real_time_factor> | ||
</physics> | ||
<plugin | ||
filename="gz-sim-physics-system" | ||
name="gz::sim::systems::Physics"> | ||
</plugin> | ||
<gravity>0 0 -10</gravity> | ||
<magnetic_field>1 2 3</magnetic_field> | ||
<atmosphere type="adiabatic"> | ||
<temperature>300</temperature> | ||
<pressure>100000</pressure> | ||
<temperature_gradient>-0.005</temperature_gradient> | ||
</atmosphere> | ||
<spherical_coordinates> | ||
<surface_model>EARTH_WGS84</surface_model> | ||
<latitude_deg>10</latitude_deg> | ||
<longitude_deg>15</longitude_deg> | ||
<elevation>20</elevation> | ||
<heading_deg>25</heading_deg> | ||
</spherical_coordinates> | ||
|
||
<light type="point" name="light_point_test"> | ||
</light> | ||
|
||
<actor name="actor_test"> | ||
</actor> | ||
|
||
<model name="model_test"> | ||
<link name="model_link_test"> | ||
<pose>0 0 0 0 0 0</pose> | ||
</link> | ||
</model> | ||
</world> | ||
</sdf> |