-
Notifications
You must be signed in to change notification settings - Fork 32
/
effector.py
65 lines (52 loc) · 2.08 KB
/
effector.py
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
# Copyright 2020 DeepMind Technologies Limited.
#
# 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.
"""Abstract effector interface definition."""
import abc
from dm_control import mjcf
from dm_env import specs
import numpy as np
class Effector(abc.ABC):
"""Abstract effector interface, a controllable element of the environment.
An effector provides an interface for an agent to interact in some way with
the environment. eg: a robot arm, a gripper, a pan tilt unit, etc. The
effector is defined by its action spec, a control method, and a prefix that
marks the control components of the effector in the wider task action spec.
"""
def close(self):
"""Clean up after we are done using the effector.
Called to clean up when we are done using the effector. This is
mainly used for real effectors that might need to close all the connections
to the robot.
"""
def after_compile(self, mjcf_model: mjcf.RootElement,
physics: mjcf.Physics) -> None:
"""Method called after the MJCF model has been compiled and finalized.
Args:
mjcf_model: The root element of the scene MJCF model.
physics: Compiled physics.
"""
@abc.abstractmethod
def initialize_episode(self, physics: mjcf.Physics,
random_state: np.random.RandomState) -> None:
pass
@abc.abstractmethod
def action_spec(self, physics: mjcf.Physics) -> specs.BoundedArray:
pass
@abc.abstractmethod
def set_control(self, physics: mjcf.Physics, command: np.ndarray) -> None:
pass
@property
@abc.abstractmethod
def prefix(self) -> str:
pass