-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathgantry.py
More file actions
187 lines (132 loc) · 6.73 KB
/
gantry.py
File metadata and controls
187 lines (132 loc) · 6.73 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import abc
from typing import Any, Dict, Final, List, Optional, Tuple
from viam.components.arm import KinematicsFileFormat
from viam.resource.types import API, RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_COMPONENT
from ..component_base import ComponentBase
class Gantry(ComponentBase):
"""
Gantry represents a physical Gantry and can be used for controlling gantries of N axes.
This acts as an abstract base class for any drivers representing specific
gantry implementations. This cannot be used on its own. If the ``__init__()`` function is
overridden, it must call the ``super().__init__()`` function.
::
from viam.components.gantry import Gantry
For more information, see `Gantry component <https://docs.viam.com/dev/reference/apis/components/gantry/>`_.
"""
API: Final = API( # pyright: ignore [reportIncompatibleVariableOverride]
RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_COMPONENT, "gantry"
)
@abc.abstractmethod
async def get_position(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[float]:
"""
Get the positions of the axes of the gantry in millimeters.
::
my_gantry = Gantry.from_robot(robot=machine, name="my_gantry")
# Get the current positions of the axes of the gantry in millimeters.
positions = await my_gantry.get_position()
Returns:
List[float]: A list of the position of the axes of the gantry in millimeters.
For more information, see `Gantry component <https://docs.viam.com/dev/reference/apis/components/gantry/#getposition>`_.
"""
...
@abc.abstractmethod
async def move_to_position(
self,
positions: List[float],
speeds: List[float],
*,
extra: Optional[Dict[str, Any]] = None,
timeout: Optional[float] = None,
**kwargs,
):
"""
Move the axes of the gantry to the desired positions (mm) at the requested speeds (mm/sec).
::
my_gantry = Gantry.from_robot(robot=machine, name="my_gantry")
# Create a list of positions for the axes of the gantry to move to. Assume in
# this example that the gantry is multi-axis, with 3 axes.
examplePositions = [1, 2, 3]
exampleSpeeds = [3, 9, 12]
# Move the axes of the gantry to the positions specified.
await my_gantry.move_to_position(
positions=examplePositions, speeds=exampleSpeeds)
Args:
positions (List[float]): A list of positions for the axes of the gantry to move to, in millimeters.
speeds (List[float]): A list of speeds in millimeters per second for the gantry to move at respective to each axis.
For more information, see `Gantry component <https://docs.viam.com/dev/reference/apis/components/gantry/#movetoposition>`_.
"""
...
@abc.abstractmethod
async def home(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> bool:
"""
Run the homing sequence of the gantry to re-calibrate the axes with respect to the limit switches.
::
my_gantry = Gantry.from_robot(robot=machine, name="my_gantry")
await my_gantry.home()
Returns:
bool: Whether the gantry has run the homing sequence successfully.
For more information, see `Gantry component <https://docs.viam.com/dev/reference/apis/components/gantry/#home>`_.
"""
@abc.abstractmethod
async def get_lengths(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[float]:
"""
Get the lengths of the axes of the gantry in millimeters.
::
my_gantry = Gantry.from_robot(robot=machine, name="my_gantry")
# Get the lengths of the axes of the gantry in millimeters.
lengths_mm = await my_gantry.get_lengths()
Returns:
List[float]: A list of the lengths of the axes of the gantry in millimeters.
For more information, see `Gantry component <https://docs.viam.com/dev/reference/apis/components/gantry/#getlengths>`_.
"""
...
@abc.abstractmethod
async def stop(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs):
"""
Stop all motion of the gantry. It is assumed that the gantry stops immediately.
::
my_gantry = Gantry.from_robot(robot=machine, name="my_gantry")
# Stop all motion of the gantry. It is assumed that the gantry stops
# immediately.
await my_gantry.stop()
For more information, see `Gantry component <https://docs.viam.com/dev/reference/apis/components/gantry/#stop>`_.
"""
...
@abc.abstractmethod
async def is_moving(self) -> bool:
"""
Get if the gantry is currently moving.
::
my_gantry = Gantry.from_robot(robot=machine, name="my_gantry")
# Stop all motion of the gantry. It is assumed that the
# gantry stops immediately.
await my_gantry.stop()
# Print if the gantry is currently moving.
print(await my_gantry.is_moving())
Returns:
bool: Whether the gantry is moving.
For more information, see `Gantry component <https://docs.viam.com/dev/reference/apis/components/gantry/#ismoving>`_.
"""
...
@abc.abstractmethod
async def get_kinematics(
self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs
) -> Tuple[KinematicsFileFormat.ValueType, bytes]:
"""
Get the kinematics information associated with the gantry.
::
my_gantry = Gantry.from_robot(robot=machine, name="my_gantry")
# Get the kinematics information associated with the gantry.
kinematics = await my_gantry.get_kinematics()
# Get the format of the kinematics file.
k_file = kinematics[0]
# Get the byte contents of the file.
k_bytes = kinematics[1]
Returns:
Tuple[KinematicsFileFormat.ValueType, bytes]: A tuple containing two values; the first [0] value represents the format of the
file, either in URDF format (``KinematicsFileFormat.KINEMATICS_FILE_FORMAT_URDF``) or
Viam's kinematic parameter format (spatial vector algebra) (``KinematicsFileFormat.KINEMATICS_FILE_FORMAT_SVA``),
and the second [1] value represents the byte contents of the file.
For more information, see `Arm component <https://docs.viam.com/dev/reference/apis/components/arm/#getkinematics>`_.
"""
...