Skip to content

Commit cae5d98

Browse files
committed
Change to add preservation and restoration to the test setup and tear down
1 parent 37c2f2a commit cae5d98

File tree

1 file changed

+56
-76
lines changed

1 file changed

+56
-76
lines changed

pylabrobot/arms/precise_flex/precise_flex_api_tests.py

Lines changed: 56 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,49 @@ async def asyncSetUp(self):
1717
self.TEST_LOCATION_ID = 20 # Default upper limit of station indices offered by GPL program running the TCS server
1818
self.TEST_PARAMETER_ID = 17018 # last parameter Id of "Custom Calibration Data and Test Results" parameters
1919
self.TEST_SIGNAL_ID = 20064 # unused software I/O
20+
self.SAFE_LOCATION_C = (175, 0.003, 169.995, -0.001, 90, 180, 1)
21+
self.SAFE_LOCATION_J = (170.003, 0, 180, -180, 75.486)
22+
self.TEST_LOCATION_C_RIGHT = (271.692, 115.89, 169.969, 2.473, 90, 180, 1)
23+
self.TEST_LOCATION_J_RIGHT = (169.969, -25.467, 149.758, -121.816, 75.498)
24+
self.TEST_LOCATION_C_LEFT = (246.024, -147.689, 169.955, 6.879, 90, 180, 2)
25+
self.TEST_LOCATION_J_LEFT = (169.955, 4.783, 216.923, -214.827, 75.498)
2026
await self.robot.setup()
2127
await self.robot.attach()
2228
await self.robot.set_power(True, timeout=20)
29+
await self.robot.move_to_safe()
30+
self._original_station_type = await self.robot.get_station_type(self.TEST_LOCATION_ID)
31+
self._original_station_location = await self.robot.get_location(self.TEST_LOCATION_ID)
32+
# if the station location_type was pallet, then also store the pallet configuration
33+
if self._original_station_location[2] == 1:
34+
self._original_pallet_index = await self.robot.get_pallet_index(self.TEST_LOCATION_ID)
35+
self._original_pallet_origin = await self.robot.get_pallet_origin(self.TEST_LOCATION_ID)
36+
self._original_pallet_final_x_pos = await self.robot.get_pallet_x(self.TEST_LOCATION_ID)
37+
self._original_pallet_final_y_pos = await self.robot.get_pallet_y(self.TEST_LOCATION_ID)
38+
self._original_pallet_final_z_pos = await self.robot.get_pallet_z(self.TEST_LOCATION_ID)
2339

2440
async def asyncTearDown(self):
2541
"""Cleanup robot connection"""
2642
if hasattr(self, 'robot'):
43+
# restore the station_type
44+
await self.robot.set_station_type(*self._original_station_type)
45+
# if the station location_type was pallet, then also restore the pallet configuration
46+
if self._original_station_location[2] == 1:
47+
await self.robot.set_pallet_origin(*self._original_pallet_origin)
48+
await self.robot.set_pallet_x(*self._original_pallet_final_x_pos)
49+
await self.robot.set_pallet_y(*self._original_pallet_final_y_pos)
50+
await self.robot.set_pallet_z(*self._original_pallet_final_z_pos)
51+
await self.robot.set_pallet_index(*self._original_pallet_index)
52+
53+
# restore the station location
54+
type_code = self._original_station_location[0]
55+
if type_code == 0: # Cartesian
56+
await self.robot.set_location_xyz(*self._original_station_location[1:8])
57+
else: # Angles
58+
await self.robot.set_location_angles(*self._original_station_location[1:8])
59+
60+
61+
62+
await self.robot.move_to_safe()
2763
await self.robot.stop()
2864

2965
@asynccontextmanager
@@ -900,90 +936,38 @@ async def test_halt(self) -> None:
900936

901937
async def test_move(self) -> None:
902938
"""Test move() command"""
903-
# Record current position for restoration
904-
original_position = await self.robot.where_c()
905-
906-
# Get original location for restoration
907-
original_location = await self.robot.get_location(self.TEST_LOCATION_ID)
908-
909-
try:
910-
# Create a test location with small movement from current position
911-
x, y, z, yaw, pitch, roll, config = original_position
912-
test_x, test_y, test_z = x + 5, y + 5, z + 3 # Small movements (5mm each direction)
913-
test_yaw = yaw + 2.0 # Small rotation change
914939

915-
# Save test location
916-
await self.robot.set_location_xyz(self.TEST_LOCATION_ID, test_x, test_y, test_z, test_yaw, pitch, roll)
940+
# Save test location
941+
await self.robot.set_location_xyz(self.TEST_LOCATION_ID, *self.TEST_LOCATION_C_LEFT[:-1])
917942

918-
# Move to test location
919-
await self.robot.move(self.TEST_LOCATION_ID, self.TEST_PROFILE_ID)
920-
await self.robot.wait_for_eom()
943+
# Move to test location
944+
await self.robot.move(self.TEST_LOCATION_ID, self.TEST_PROFILE_ID)
945+
await self.robot.wait_for_eom()
921946

922-
# Verify we moved to the test location
923-
new_position = await self.robot.where_c()
924-
self.assertLess(abs(new_position[0] - test_x), 2.0)
925-
self.assertLess(abs(new_position[1] - test_y), 2.0)
926-
self.assertLess(abs(new_position[2] - test_z), 2.0)
927-
print(f"Move to location {self.TEST_LOCATION_ID} completed successfully")
947+
# Verify we moved to the test location
948+
new_position = await self.robot.where_c()
949+
self.assertLess(abs(new_position[0] - self.TEST_LOCATION_C_LEFT[0]), 2.0)
950+
self.assertLess(abs(new_position[1] - self.TEST_LOCATION_C_LEFT[1]), 2.0)
951+
self.assertLess(abs(new_position[2] - self.TEST_LOCATION_C_LEFT[2]), 2.0)
952+
print(f"Move to location {self.TEST_LOCATION_ID} completed successfully")
928953

929-
finally:
930-
# Restore original location
931-
type_code = original_location[0]
932-
if type_code == 0: # Was Cartesian type
933-
await self.robot.set_location_xyz(self.TEST_LOCATION_ID, *original_location[2:8])
934-
else: # Was angles type
935-
await self.robot.set_location_angles(self.TEST_LOCATION_ID, *original_location[2:8])
936954

937-
# Return to original position
938-
x, y, z, yaw, pitch, roll, config = original_position
939-
await self.robot.move_c(self.TEST_PROFILE_ID, x, y, z, yaw, pitch, roll)
940-
await self.robot.wait_for_eom()
941955

942956
async def test_move_appro(self) -> None:
943957
"""Test move_appro() command"""
944-
# Record current position for restoration
945-
original_position = await self.robot.where_c()
946958

947-
# Get original location for restoration
948-
original_location = await self.robot.get_location(self.TEST_LOCATION_ID)
959+
test_z_clearance = 20
949960

950-
# Get the Z clearance for the test location
951-
z_clearance_data = await self.robot.get_location_z_clearance(self.TEST_LOCATION_ID)
952-
_, z_clearance, _ = z_clearance_data
953-
try:
954-
# Create a test location with small movement from current position
955-
x, y, z, yaw, pitch, roll, config = original_position
956-
test_x, test_y, test_z = x + 8, y + 8, z + 5 # Small movements (8mm each direction)
957-
test_yaw = yaw + 3.0 # Small rotation change
958-
test_z_clearance = 20
959-
960-
# Save test location
961-
await self.robot.set_location_xyz(self.TEST_LOCATION_ID, test_x, test_y, test_z, test_yaw, pitch, roll)
962-
963-
# Save the z clearance
964-
await self.robot.set_location_z_clearance(self.TEST_LOCATION_ID, test_z_clearance)
965-
966-
# Move to test location with approach
967-
await self.robot.move_appro(self.TEST_LOCATION_ID, self.TEST_PROFILE_ID)
968-
await self.robot.wait_for_eom()
961+
# Save test location & z clearance
962+
await self.robot.set_location_angles(self.TEST_LOCATION_ID, *self.TEST_LOCATION_J_LEFT)
963+
await self.robot.set_location_z_clearance(self.TEST_LOCATION_ID, test_z_clearance)
969964

970-
print(f"Move approach to location {self.TEST_LOCATION_ID} with z-clearance {test_z_clearance} completed successfully")
971-
972-
finally:
973-
# Restore original location
974-
type_code = original_location[0]
975-
if type_code == 0: # Was Cartesian type
976-
await self.robot.set_location_xyz(self.TEST_LOCATION_ID, *original_location[2:8])
977-
else: # Was angles type
978-
await self.robot.set_location_angles(self.TEST_LOCATION_ID, *original_location[2:8])
965+
# Move to test location with approach
966+
await self.robot.move_appro(self.TEST_LOCATION_ID, self.TEST_PROFILE_ID)
967+
await self.robot.wait_for_eom()
979968

980-
# Restore original z clearance
981-
await self.robot.set_location_z_clearance(self.TEST_LOCATION_ID, z_clearance)
969+
print(f"Move approach to location {self.TEST_LOCATION_ID} with z-clearance {test_z_clearance} completed successfully")
982970

983-
# Return to original position
984-
x, y, z, yaw, pitch, roll, config = original_position
985-
await self.robot.move_c(self.TEST_PROFILE_ID, x, y, z, yaw, pitch, roll)
986-
await self.robot.wait_for_eom()
987971

988972
async def test_move_extra_axis(self) -> None:
989973
"""Test move_extra_axis() command"""
@@ -1528,13 +1512,9 @@ async def test_pick_plate_station(self) -> None:
15281512
original_z_clearance = await self.robot.get_location_z_clearance(self.TEST_LOCATION_ID)
15291513

15301514
try:
1531-
# Create a test location with small movement from current position
1532-
x, y, z, yaw, pitch, roll, _ = original_position
1533-
test_x, test_y, test_z = x + 10, y + 10, z + 5 # Small movements for pick test
1534-
test_yaw = yaw + 1.0 # Small rotation change
15351515

15361516
# Save test location - force it to Cartesian type for this test
1537-
await self.robot.set_location_xyz(self.TEST_LOCATION_ID, test_x, test_y, test_z, test_yaw, pitch, roll)
1517+
await self.robot.set_location_xyz(self.TEST_LOCATION_ID, *self.TEST_LOCATION_C_LEFT[:-1])
15381518
await self.robot.set_location_z_clearance(self.TEST_LOCATION_ID, 20.0)
15391519

15401520

0 commit comments

Comments
 (0)