-
Notifications
You must be signed in to change notification settings - Fork 745
Expand file tree
/
Copy pathant_test.py
More file actions
100 lines (84 loc) · 2.99 KB
/
ant_test.py
File metadata and controls
100 lines (84 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Copyright 2020 The dm_control Authors.
#
# 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.
# ============================================================================
"""Tests for the Ant."""
from absl.testing import absltest
from absl.testing import parameterized
from dm_control import composer
from dm_control import mjcf
from dm_control.composer.observation.observable import base as observable_base
from dm_control.locomotion.arenas import corridors as corr_arenas
from dm_control.locomotion.tasks import corridors as corr_tasks
from dm_control.locomotion.walkers import ant
import numpy as np
_CONTROL_TIMESTEP = .02
_PHYSICS_TIMESTEP = 0.005
def _get_ant_corridor_physics():
walker = ant.Ant()
arena = corr_arenas.EmptyCorridor()
task = corr_tasks.RunThroughCorridor(
walker=walker,
arena=arena,
walker_spawn_position=(5, 0, 0),
walker_spawn_rotation=0,
physics_timestep=_PHYSICS_TIMESTEP,
control_timestep=_CONTROL_TIMESTEP)
env = composer.Environment(
time_limit=30,
task=task,
strip_singleton_obs_buffer_dim=True)
return walker, env
class AntTest(parameterized.TestCase):
def test_can_compile_and_step_simulation(self):
_, env = _get_ant_corridor_physics()
physics = env.physics
for _ in range(100):
physics.step()
@parameterized.parameters([
'egocentric_camera',
'root_body',
])
def test_get_element_property(self, name):
attribute_value = getattr(ant.Ant(), name)
self.assertIsInstance(attribute_value, mjcf.Element)
@parameterized.parameters([
'actuators',
'end_effectors',
'observable_joints',
])
def test_get_element_tuple_property(self, name):
attribute_value = getattr(ant.Ant(), name)
self.assertNotEmpty(attribute_value)
for item in attribute_value:
self.assertIsInstance(item, mjcf.Element)
def test_set_name(self):
name = 'fred'
walker = ant.Ant(name=name)
self.assertEqual(walker.mjcf_model.model, name)
@parameterized.parameters(
'appendages_pos',
'sensors_touch',
)
def test_evaluate_observable(self, name):
walker, env = _get_ant_corridor_physics()
physics = env.physics
observable = getattr(walker.observables, name)
observation = observable(physics)
self.assertIsInstance(observation, (float, np.ndarray))
def test_proprioception(self):
walker = ant.Ant()
for item in walker.observables.proprioception:
self.assertIsInstance(item, observable_base.Observable)
if __name__ == '__main__':
absltest.main()