-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f5e0e1
commit 1dd318b
Showing
2 changed files
with
180 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
# Copyright (C) 2021 Istituto Italiano di Tecnologia (IIT). All rights reserved. | ||
# This software may be modified and distributed under the terms of the | ||
# GNU Lesser General Public License v2.1 or any later version. | ||
|
||
import pytest | ||
pytestmark = pytest.mark.scenario | ||
|
||
import numpy as np | ||
import gym_ignition_models | ||
from ..common import utils | ||
from gym_ignition.utils import misc | ||
from scenario import core as scenario_core | ||
from scenario import gazebo as scenario_gazebo | ||
from ..common.utils import gazebo_fixture as gazebo | ||
|
||
# Set the verbosity | ||
scenario_gazebo.set_verbosity(scenario_gazebo.Verbosity_debug) | ||
|
||
|
||
@pytest.mark.parametrize("gazebo", | ||
[(0.001, 1.0, 1)], | ||
indirect=True, | ||
ids=utils.id_gazebo_fn) | ||
def test_pendulum(gazebo: scenario_gazebo.GazeboSimulator): | ||
|
||
# Load two different worlds | ||
empty_world_sdf = utils.get_empty_world_sdf() | ||
assert gazebo.insert_world_from_sdf(empty_world_sdf, "dart") | ||
assert gazebo.insert_world_from_sdf(empty_world_sdf, "bullet") | ||
|
||
# Initialize the simulator | ||
assert gazebo.initialize() | ||
|
||
pendulum_urdf = gym_ignition_models.get_model_file(robot_name="pendulum") | ||
ground_plane_urdf = gym_ignition_models.get_model_file(robot_name="ground_plane") | ||
|
||
# Populate the DART world | ||
world_dart = gazebo.get_world("dart") | ||
world_dart.set_physics_engine(scenario_gazebo.PhysicsEngine_dart) | ||
world_dart.insert_model(ground_plane_urdf) | ||
world_dart.insert_model(pendulum_urdf) | ||
pendulum_dart = world_dart.get_model(model_name="pendulum") | ||
|
||
# Populate the Bullet world | ||
world_bullet = gazebo.get_world("bullet") | ||
world_bullet.set_physics_engine(scenario_gazebo.PhysicsEngine_bullet) | ||
world_bullet.insert_model(ground_plane_urdf) | ||
world_bullet.insert_model(pendulum_urdf) | ||
pendulum_bullet = world_bullet.get_model(model_name="pendulum") | ||
|
||
# Reset the pole position | ||
pendulum_dart.get_joint(joint_name="pivot").to_gazebo().\ | ||
reset_position(position=0.01) | ||
pendulum_bullet.get_joint(joint_name="pivot").to_gazebo().\ | ||
reset_position(position=0.01) | ||
|
||
# Integration time | ||
dt = gazebo.step_size() * gazebo.steps_per_run() | ||
|
||
for _ in np.arange(start=0.0, stop=1.0, step=dt): | ||
|
||
# Run the simulator | ||
assert gazebo.run() | ||
|
||
# Check that both worlds evolve similarly | ||
assert pendulum_dart.joint_positions() == \ | ||
pytest.approx(pendulum_bullet.joint_positions()) | ||
assert pendulum_dart.joint_velocities() == \ | ||
pytest.approx(pendulum_bullet.joint_velocities()) | ||
|
||
|
||
@pytest.mark.parametrize("gazebo", | ||
[(0.001, 1.0, 1)], | ||
indirect=True, | ||
ids=utils.id_gazebo_fn) | ||
def test_bouncing_ball(gazebo: scenario_gazebo.GazeboSimulator): | ||
|
||
# Load two different worlds | ||
empty_world_sdf = utils.get_empty_world_sdf() | ||
assert gazebo.insert_world_from_sdf(empty_world_sdf, "dart") | ||
assert gazebo.insert_world_from_sdf(empty_world_sdf, "bullet") | ||
|
||
# Initialize the simulator | ||
assert gazebo.initialize() | ||
|
||
# gazebo.gui() | ||
# import time | ||
# time.sleep(1) | ||
# gazebo.run(paused=True) | ||
|
||
sphere_urdf_string = utils.SphereURDF(restitution=0.8).urdf() | ||
sphere_urdf = misc.string_to_file(sphere_urdf_string) | ||
ground_plane_urdf = gym_ignition_models.get_model_file(robot_name="ground_plane") | ||
|
||
# Pose of the sphere | ||
sphere_pose = scenario_core.Pose([0, 0, 0.5], [1, 0, 0, 0]) | ||
|
||
# Populate the DART world | ||
world_dart = gazebo.get_world("dart") | ||
world_dart.set_physics_engine(scenario_gazebo.PhysicsEngine_dart) | ||
world_dart.insert_model(ground_plane_urdf) | ||
world_dart.insert_model(sphere_urdf, sphere_pose) | ||
sphere_dart = world_dart.get_model(model_name="sphere_model") | ||
|
||
# Populate the Bullet world | ||
world_bullet = gazebo.get_world("bullet") | ||
world_bullet.set_physics_engine(scenario_gazebo.PhysicsEngine_bullet) | ||
world_bullet.insert_model(ground_plane_urdf) | ||
world_bullet.insert_model(sphere_urdf, sphere_pose) | ||
sphere_bullet = world_bullet.get_model(model_name="sphere_model") | ||
|
||
# Integration time | ||
dt = gazebo.step_size() * gazebo.steps_per_run() | ||
|
||
for _ in np.arange(start=0.0, stop=3.0, step=dt): | ||
|
||
# Run the simulator | ||
assert gazebo.run() | ||
|
||
# Check that both worlds evolve similarly | ||
assert sphere_dart.base_position() == \ | ||
pytest.approx(sphere_bullet.base_position()) | ||
assert sphere_dart.base_world_linear_velocity() == \ | ||
pytest.approx(sphere_bullet.base_world_linear_velocity()) | ||
assert sphere_dart.base_world_angular_velocity() == \ | ||
pytest.approx(sphere_bullet.base_world_angular_velocity()) | ||
|
||
# time.sleep(3) | ||
|
||
|
||
@pytest.mark.parametrize("gazebo", | ||
[(0.001, 1.0, 1)], | ||
indirect=True, | ||
ids=utils.id_gazebo_fn) | ||
def _test_position_controller(gazebo: scenario_gazebo.GazeboSimulator): | ||
|
||
raise NotImplementedError |