33
44import hypothesis
55import numpy as np
6+ import numpy .typing as npt
67from hypothesis import given
78from hypothesis .extra .numpy import arrays
89from hypothesis .strategies import floats
1415from pybotics .robot import Robot
1516
1617
17- def test_fk (resources_path : Path ):
18+ def test_fk (resources_path : Path ) -> None :
1819 """
1920 Test robot.
2021
@@ -23,7 +24,7 @@ def test_fk(resources_path: Path):
2324 """
2425 # get resource
2526 path = resources_path / "ur10-joints-poses.csv"
26- data = np .loadtxt (str (path ), delimiter = "," )
27+ data = np .loadtxt (str (path ), delimiter = "," ) # type: ignore
2728
2829 # load robot
2930 robot = Robot .from_parameters (ur10 ())
@@ -38,23 +39,23 @@ def test_fk(resources_path: Path):
3839
3940 # test with position argument
4041 actual_pose = robot .fk (q = joints )
41- np .testing .assert_allclose (actual_pose , desired_pose , atol = atol )
42+ np .testing .assert_allclose (actual_pose , desired_pose , atol = atol ) # type: ignore
4243
4344 # test with internal position attribute
4445 robot .joints = joints
4546 actual_pose = robot .fk ()
46- np .testing .assert_allclose (actual_pose , desired_pose , atol = atol )
47+ np .testing .assert_allclose (actual_pose , desired_pose , atol = atol ) # type: ignore
4748
4849
49- def test_home_position ():
50+ def test_home_position () -> None :
5051 """Test."""
5152 robot = Robot .from_parameters (ur10 ())
5253 x = np .ones (len (robot ))
5354 robot .home_position = x
54- np .testing .assert_allclose (robot .home_position , x )
55+ np .testing .assert_allclose (robot .home_position , x ) # type: ignore
5556
5657
57- def test_joint_limits ():
58+ def test_joint_limits () -> None :
5859 """Test."""
5960 robot = Robot .from_parameters (ur10 ())
6061
@@ -69,7 +70,7 @@ def test_joint_limits():
6970 robot .joints = robot .joint_limits .copy ()[1 ] + 10
7071
7172
72- def test_compute_joint_torques (planar_robot : Robot ):
73+ def test_compute_joint_torques (planar_robot : Robot ) -> None :
7374 """
7475 Test.
7576
@@ -79,9 +80,9 @@ def test_compute_joint_torques(planar_robot: Robot):
7980 :return:
8081 """
8182 # set test force and angles
82- force = [- 100 , - 200 , 0 ]
83- moment = [ 0 ] * 3
84- wrench = force + moment
83+ force = np . array ( [- 100 , - 200 , 0 ])
84+ moment = np . zeros ( 3 )
85+ wrench = force + moment # type: npt.NDArray[np.float64]
8586 joint_angles = np .deg2rad ([30 , 60 , 0 ])
8687
8788 # get link lengths
@@ -102,11 +103,11 @@ def test_compute_joint_torques(planar_robot: Robot):
102103
103104 # test
104105 actual_torques = planar_robot .compute_joint_torques (q = joint_angles , wrench = wrench )
105- np .testing .assert_allclose (actual_torques , expected_torques )
106+ np .testing .assert_allclose (actual_torques , expected_torques ) # type: ignore
106107
107108 planar_robot .joints = joint_angles
108109 actual_torques = planar_robot .compute_joint_torques (wrench = wrench )
109- np .testing .assert_allclose (actual_torques , expected_torques )
110+ np .testing .assert_allclose (actual_torques , expected_torques ) # type: ignore
110111
111112
112113@given (
@@ -118,7 +119,7 @@ def test_compute_joint_torques(planar_robot: Robot):
118119 ),
119120 )
120121)
121- def test_jacobian_world (q : npt .NDArray [np .float64 ], planar_robot : Robot ):
122+ def test_jacobian_world (q : npt .NDArray [np .float64 ], planar_robot : Robot ) -> None :
122123 """Test."""
123124 # get link lengths
124125 # FIXME: "Link" has no attribute "a"
@@ -145,15 +146,15 @@ def test_jacobian_world(q: npt.NDArray[np.float64], planar_robot: Robot):
145146 expected [- 1 , :] = 1
146147
147148 actual = planar_robot .jacobian_world (q )
148- np .testing .assert_allclose (actual , expected , atol = 1e-3 )
149+ np .testing .assert_allclose (actual , expected , atol = 1e-3 ) # type: ignore
149150
150151
151152@given (
152153 q = arrays (
153154 shape = (3 ,), dtype = float , elements = floats (allow_nan = False , allow_infinity = False )
154155 )
155156)
156- def test_jacobian_flange (q : npt .NDArray [np .float64 ], planar_robot : Robot ):
157+ def test_jacobian_flange (q : npt .NDArray [np .float64 ], planar_robot : Robot ) -> None :
157158 """Test."""
158159 # get link lengths
159160 # FIXME: "Link" has no attribute "a"
@@ -176,7 +177,7 @@ def test_jacobian_flange(q: npt.NDArray[np.float64], planar_robot: Robot):
176177 expected [- 1 , :] = 1
177178
178179 actual = planar_robot .jacobian_flange (q )
179- np .testing .assert_allclose (actual , expected , atol = 1e-6 )
180+ np .testing .assert_allclose (actual , expected , atol = 1e-6 ) # type: ignore
180181
181182
182183@given (
@@ -199,7 +200,7 @@ def test_jacobian_flange(q: npt.NDArray[np.float64], planar_robot: Robot):
199200 ),
200201)
201202@hypothesis .settings (deadline = None )
202- def test_ik (q : npt .NDArray [np .float64 ], q_offset : npt .NDArray [np .float64 ]):
203+ def test_ik (q : npt .NDArray [np .float64 ], q_offset : npt .NDArray [np .float64 ]) -> None :
203204 """Test."""
204205 robot = Robot .from_parameters (ur10 ())
205206 pose = robot .fk (q )
@@ -216,22 +217,22 @@ def test_ik(q: npt.NDArray[np.float64], q_offset: npt.NDArray[np.float64]):
216217
217218 # test the matrix with lower accuracy
218219 # rotation components are hard to achieve when x0 isn't good
219- np .testing .assert_allclose (actual_pose , pose , atol = 1 )
220+ np .testing .assert_allclose (actual_pose , pose , atol = 1 ) # type: ignore
220221
221222 # test the position with higher accuracy
222223 desired_position = pose [:- 1 , - 1 ]
223224 actual_position = actual_pose [:- 1 , - 1 ]
224- np .testing .assert_allclose (actual_position , desired_position , atol = 1e-1 )
225+ np .testing .assert_allclose (actual_position , desired_position , atol = 1e-1 ) # type: ignore
225226
226227
227- def test_random_joints ():
228+ def test_random_joints () -> None :
228229 """Test."""
229230 robot = Robot .from_parameters (ur10 ())
230231 robot .random_joints ()
231232 robot .random_joints (in_place = True )
232233
233234
234- def test_to_json ():
235+ def test_to_json () -> None :
235236 """Test."""
236237 robot = Robot .from_parameters (ur10 ())
237238 robot .to_json ()
0 commit comments