|
| 1 | +import unittest |
| 2 | + |
| 3 | +from pylabrobot.arms.precise_flex.precise_flex_backend import PreciseFlexBackend |
| 4 | +import asyncio |
| 5 | + |
| 6 | + |
| 7 | +class PreciseFlexBackendHardwareTests(unittest.IsolatedAsyncioTestCase): |
| 8 | + """Integration tests for PreciseFlex robot - RUNS ON ACTUAL HARDWARE""" |
| 9 | + |
| 10 | + async def asyncSetUp(self): |
| 11 | + """Connect to actual PreciseFlex robot""" |
| 12 | + self.robot = PreciseFlexBackend("192.168.0.1", 10100) |
| 13 | + await self.robot.setup() |
| 14 | + |
| 15 | + async def asyncTearDown(self): |
| 16 | + """Cleanup robot connection""" |
| 17 | + if hasattr(self, 'robot'): |
| 18 | + await self.robot.stop() |
| 19 | + |
| 20 | + async def test_set_speed(self): |
| 21 | + await self.robot.set_speed(50) |
| 22 | + speed = await self.robot.get_speed() |
| 23 | + self.assertEqual(speed, 50) |
| 24 | + |
| 25 | + async def test_open_close_gripper(self): |
| 26 | + await self.robot.close_gripper() |
| 27 | + closed = await self.robot.is_gripper_closed() |
| 28 | + self.assertTrue(closed) |
| 29 | + |
| 30 | + await self.robot.open_gripper() |
| 31 | + closed = await self.robot.is_gripper_closed() |
| 32 | + self.assertFalse(closed) |
| 33 | + |
| 34 | + async def test_home(self): |
| 35 | + await self.robot.home() |
| 36 | + |
| 37 | + async def test_move_to_safe(self): |
| 38 | + await self.robot.move_to_safe() |
| 39 | + |
| 40 | + async def test_approach_j(self): |
| 41 | + current_c = await self.robot.get_position_c() |
| 42 | + # create a position that is very close to current position for each dimension |
| 43 | + target_c = ( |
| 44 | + current_c[0] + 0.01, current_c[1] + 0.01, current_c[2] + 0.01, |
| 45 | + current_c[3] + 0.01, current_c[4] + 0.01, current_c[5] + 0.01 |
| 46 | + ) |
| 47 | + await self.robot.approach_c(target_c, 10, current_c[-1]) |
| 48 | + |
| 49 | + async def test_pick_plate_j(self): |
| 50 | + current_c = await self.robot.get_position_c() |
| 51 | + # create a position that is very close to current position for each dimension |
| 52 | + target_c = ( |
| 53 | + current_c[0] + 0.01, current_c[1] + 0.01, current_c[2] + 0.01, |
| 54 | + current_c[3] + 0.01, current_c[4] + 0.01, current_c[5] + 0.01 |
| 55 | + ) |
| 56 | + await self.robot.pick_plate_c(target_c, 10, current_c[-1]) |
| 57 | + |
| 58 | + async def test_place_plate_j(self): |
| 59 | + current_c = await self.robot.get_position_c() |
| 60 | + # create a position that is very close to current position for each dimension |
| 61 | + target_c = ( |
| 62 | + current_c[0] + 0.01, current_c[1] + 0.01, current_c[2] + 0.01, |
| 63 | + current_c[3] + 0.01, current_c[4] + 0.01, current_c[5] + 0.01 |
| 64 | + ) |
| 65 | + await self.robot.place_plate_c(target_c, 10, current_c[-1]) |
| 66 | + |
| 67 | + async def test_move_to_j(self): |
| 68 | + current_c = await self.robot.get_position_c() |
| 69 | + # create a position that is very close to current position for each dimension |
| 70 | + target_c = ( |
| 71 | + current_c[0] + 0.01, current_c[1] + 0.01, current_c[2] + 0.01, |
| 72 | + current_c[3] + 0.01, current_c[4] + 0.01, current_c[5] + 0.01 |
| 73 | + ) |
| 74 | + await self.robot.move_to_c(target_c, current_c[-1]) |
| 75 | + |
| 76 | + async def test_get_position_j(self): |
| 77 | + """Test getting joint position""" |
| 78 | + position_j = await self.robot.get_position_j() |
| 79 | + self.assertIsInstance(position_j, tuple) |
| 80 | + self.assertEqual(len(position_j), 6) |
| 81 | + |
| 82 | + async def test_get_position_c(self): |
| 83 | + """Test getting cartesian position""" |
| 84 | + position_c = await self.robot.get_position_c() |
| 85 | + self.assertIsInstance(position_c, tuple) |
| 86 | + self.assertEqual(len(position_c), 6) |
| 87 | + |
| 88 | + async def test_move_to_j_joints(self): |
| 89 | + """Test joint movement""" |
| 90 | + current_j = await self.robot.get_position_j() |
| 91 | + # Small joint movements |
| 92 | + target_j = ( |
| 93 | + current_j[0] + 0.1, current_j[1] + 0.1, current_j[2] + 0.1, |
| 94 | + current_j[3] + 0.1, current_j[4] + 0.1, current_j[5] + 0.1, current_j[6] + 0.1 |
| 95 | + ) |
| 96 | + await self.robot.move_to_j(target_j) |
| 97 | + |
| 98 | + async def test_approach_j_joints(self): |
| 99 | + """Test joint approach movement""" |
| 100 | + current_j = await self.robot.get_position_j() |
| 101 | + target_j = ( |
| 102 | + current_j[0] + 0.1, current_j[1] + 0.1, current_j[2] + 0.1, |
| 103 | + current_j[3] + 0.1, current_j[4] + 0.1, current_j[5] + 0.1, current_j[6] + 0.1 |
| 104 | + ) |
| 105 | + await self.robot.approach_j(target_j, 10) |
| 106 | + |
| 107 | + async def test_pick_plate_j_joints(self): |
| 108 | + """Test joint pick plate movement""" |
| 109 | + current_j = await self.robot.get_position_j() |
| 110 | + target_j = ( |
| 111 | + current_j[0] + 0.1, current_j[1] + 0.1, current_j[2] + 0.1, |
| 112 | + current_j[3] + 0.1, current_j[4] + 0.1, current_j[5] + 0.1, current_j[6] + 0.1 |
| 113 | + ) |
| 114 | + await self.robot.pick_plate_j(target_j, 10) |
| 115 | + |
| 116 | + async def test_place_plate_j_joints(self): |
| 117 | + """Test joint place plate movement""" |
| 118 | + current_j = await self.robot.get_position_j() |
| 119 | + target_j = ( |
| 120 | + current_j[0] + 0.1, current_j[1] + 0.1, current_j[2] + 0.1, |
| 121 | + current_j[3] + 0.1, current_j[4] + 0.1, current_j[5] + 0.1, current_j[6] + 0.1 |
| 122 | + ) |
| 123 | + await self.robot.place_plate_j(target_j, 10) |
0 commit comments