Skip to content

Commit

Permalink
[sq] update test
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoferigo committed Apr 28, 2021
1 parent fcdfeda commit a755e70
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions tests/test_scenario/test_physics_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,26 @@ def test_pendulum(gazebo: scenario_gazebo.GazeboSimulator):
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)
# Note: this is not yet implemented in the bullet plugin
# assert pendulum_dart.get_joint(joint_name="pivot").to_gazebo().\
# reset_position(position=0.01)
# assert pendulum_bullet.get_joint(joint_name="pivot").to_gazebo().\
# reset_position(position=0.01)

# Control the joints in force
assert pendulum_dart.set_joint_control_mode(scenario_core.JointControlMode_force)
assert pendulum_bullet.set_joint_control_mode(scenario_core.JointControlMode_force)

# Give a small push to the pole
assert pendulum_dart.get_joint(joint_name="pivot").\
set_generalized_force_target(force=50.0)
assert pendulum_bullet.get_joint(joint_name="pivot").\
set_generalized_force_target(force=50.0)
gazebo.run()
assert pendulum_dart.get_joint(joint_name="pivot").\
set_generalized_force_target(force=0.0)
assert pendulum_bullet.get_joint(joint_name="pivot").\
set_generalized_force_target(force=0.0)

# Integration time
dt = gazebo.step_size() * gazebo.steps_per_run()
Expand All @@ -64,9 +80,9 @@ def test_pendulum(gazebo: scenario_gazebo.GazeboSimulator):

# Check that both worlds evolve similarly
assert pendulum_dart.joint_positions() == \
pytest.approx(pendulum_bullet.joint_positions())
pytest.approx(pendulum_bullet.joint_positions(), abs=1e-03)
assert pendulum_dart.joint_velocities() == \
pytest.approx(pendulum_bullet.joint_velocities())
pytest.approx(pendulum_bullet.joint_velocities(), abs=1e-02)


@pytest.mark.parametrize("gazebo",
Expand Down Expand Up @@ -112,16 +128,29 @@ def test_bouncing_ball(gazebo: scenario_gazebo.GazeboSimulator):
# Integration time
dt = gazebo.step_size() * gazebo.steps_per_run()

# Enable contacts
sphere_dart.enable_contacts(True)
# sphere_bullet.enable_contacts(True)

for _ in np.arange(start=0.0, stop=3.0, step=dt):

# Run the simulator
assert gazebo.run()

# Bullet does not have bouncing yet
if len(sphere_dart.contacts()) > 0:
break

# print(sphere_dart.base_position(),
# sphere_bullet.base_position())
# print(sphere_dart.base_world_linear_velocity(),
# sphere_bullet.base_world_linear_velocity())

# Check that both worlds evolve similarly
assert sphere_dart.base_position() == \
pytest.approx(sphere_bullet.base_position())
pytest.approx(sphere_bullet.base_position(), abs=0.005)
assert sphere_dart.base_world_linear_velocity() == \
pytest.approx(sphere_bullet.base_world_linear_velocity())
pytest.approx(sphere_bullet.base_world_linear_velocity(), abs=0.001)
assert sphere_dart.base_world_angular_velocity() == \
pytest.approx(sphere_bullet.base_world_angular_velocity())

Expand Down

0 comments on commit a755e70

Please sign in to comment.