|
26 | 26 | from itertools import product, combinations, count, cycle, islice |
27 | 27 | from multiprocessing import TimeoutError |
28 | 28 | from contextlib import contextmanager |
| 29 | +from typing import List, Tuple |
29 | 30 |
|
30 | 31 | from pybullet_utils.transformations import quaternion_from_matrix, unit_vector, euler_from_quaternion, quaternion_slerp, \ |
31 | 32 | random_quaternion, quaternion_about_axis |
32 | 33 |
|
| 34 | +VEC3 = Tuple[float, float, float] |
| 35 | +QUATERNION = Tuple[float, float, float, float] |
| 36 | +POSE = Tuple[VEC3, QUATERNION] |
| 37 | + |
33 | 38 | def join_paths(*paths): |
34 | 39 | return os.path.abspath(os.path.join(*paths)) |
35 | 40 |
|
@@ -118,8 +123,9 @@ def get_parent_dir(file): # __file__ |
118 | 123 |
|
119 | 124 | inf_generator = count # count | lambda: iter(int, 1) |
120 | 125 |
|
121 | | -List = lambda *args: list(args) |
122 | | -Tuple = lambda *args: tuple(args) |
| 126 | +# Disable these lines because they prevent developers from using type hints |
| 127 | +# List = lambda *args: list(args) |
| 128 | +# Tuple = lambda *args: tuple(args) |
123 | 129 |
|
124 | 130 | def empty_sequence(): |
125 | 131 | return iter([]) |
@@ -1619,26 +1625,26 @@ def Point(x=0., y=0., z=0.): |
1619 | 1625 | def Euler(roll=0., pitch=0., yaw=0.): |
1620 | 1626 | return np.array([roll, pitch, yaw]) |
1621 | 1627 |
|
1622 | | -def Pose(point=None, euler=None): |
| 1628 | +def Pose(point=None, euler=None) -> POSE: |
1623 | 1629 | point = Point() if point is None else point |
1624 | 1630 | euler = Euler() if euler is None else euler |
1625 | 1631 | return point, quat_from_euler(euler) |
1626 | 1632 |
|
1627 | 1633 | def Pose2d(x=0., y=0., yaw=0.): |
1628 | 1634 | return np.array([x, y, yaw]) |
1629 | 1635 |
|
1630 | | -def invert(pose): |
| 1636 | +def invert(pose: POSE) -> POSE: |
1631 | 1637 | point, quat = pose |
1632 | 1638 | return p.invertTransform(point, quat) |
1633 | 1639 |
|
1634 | | -def multiply(*poses): |
1635 | | - pose = poses[0] |
| 1640 | +def multiply(*poses) -> POSE: |
| 1641 | + pose: POSE = poses[0] |
1636 | 1642 | for next_pose in poses[1:]: |
1637 | 1643 | pose = p.multiplyTransforms(pose[0], pose[1], *next_pose) |
1638 | 1644 | return pose |
1639 | 1645 |
|
1640 | | -def invert_quat(quat): |
1641 | | - pose = (unit_point(), quat) |
| 1646 | +def invert_quat(quat: QUATERNION) -> QUATERNION: |
| 1647 | + pose: POSE = (unit_point(), quat) |
1642 | 1648 | return quat_from_pose(invert(pose)) |
1643 | 1649 |
|
1644 | 1650 | def multiply_quats(*quats): |
@@ -2162,17 +2168,17 @@ def get_joint_limits(body, joint): |
2162 | 2168 |
|
2163 | 2169 | get_joint_interval = get_joint_limits # TODO: get box limits? |
2164 | 2170 |
|
2165 | | -def get_min_limit(body, joint): |
| 2171 | +def get_min_limit(body, joint) -> float: |
2166 | 2172 | # TODO: rename to min_position |
2167 | 2173 | return get_joint_limits(body, joint)[0] |
2168 | 2174 |
|
2169 | | -def get_min_limits(body, joints): |
| 2175 | +def get_min_limits(body, joints) -> List[float]: |
2170 | 2176 | return [get_min_limit(body, joint) for joint in joints] |
2171 | 2177 |
|
2172 | | -def get_max_limit(body, joint): |
| 2178 | +def get_max_limit(body, joint) -> float: |
2173 | 2179 | return get_joint_limits(body, joint)[1] |
2174 | 2180 |
|
2175 | | -def get_max_limits(body, joints): |
| 2181 | +def get_max_limits(body, joints) -> List[float]: |
2176 | 2182 | return [get_max_limit(body, joint) for joint in joints] |
2177 | 2183 |
|
2178 | 2184 | def get_joint_intervals(body, joints): |
@@ -4626,7 +4632,7 @@ def end_effector_from_body(body_pose, grasp_pose): |
4626 | 4632 | def approach_from_grasp(approach_pose, end_effector_pose): |
4627 | 4633 | return multiply(approach_pose, end_effector_pose) |
4628 | 4634 |
|
4629 | | -def get_grasp_pose(constraint): |
| 4635 | +def get_grasp_pose(constraint) -> POSE: |
4630 | 4636 | """ |
4631 | 4637 | Grasps are parent_from_child |
4632 | 4638 | """ |
|
0 commit comments