|
13 | 13 |
|
14 | 14 | from .cri_errors import CRICommandError, CRICommandTimeOutError, CRIConnectionError |
15 | 15 | from .cri_protocol_parser import CRIProtocolParser |
16 | | -from .robot_state import KinematicsState, RobotState |
| 16 | +from .robot_state import KinematicsState, ReplayMode, RobotState |
17 | 17 |
|
18 | 18 | logger = logging.getLogger(__name__) |
19 | 19 |
|
@@ -1351,15 +1351,52 @@ async def load_logic_programm_async(self, program_name: str) -> bool: |
1351 | 1351 | else: |
1352 | 1352 | return True |
1353 | 1353 |
|
1354 | | - async def start_programm_async(self) -> bool: |
1355 | | - """Start currently loaded Program |
| 1354 | + async def set_replay_mode_async(self, replay_mode: ReplayMode) -> None: |
| 1355 | + """Set the main program replay mode. |
| 1356 | +
|
| 1357 | + Parameters |
| 1358 | + ---------- |
| 1359 | + replay_mode |
| 1360 | + Which mode to apply if the ``robot_state`` is not already in it. |
| 1361 | +
|
| 1362 | + Raises |
| 1363 | + ------ |
| 1364 | + CRICommandError |
| 1365 | + If the ``replay_mode`` could not be applied. |
| 1366 | + """ |
| 1367 | + while self.robot_state.main_replay_mode != replay_mode: |
| 1368 | + msg_id = self.send_command( |
| 1369 | + f"CMD ProgramReplayMode {replay_mode.value}", True |
| 1370 | + ) |
| 1371 | + if (error_msg := await self._wait_for_answer_async(msg_id)) is not None: |
| 1372 | + raise CRICommandError(f"Could not set replay mode: {error_msg}") |
| 1373 | + await asyncio.sleep(0.05) |
| 1374 | + |
| 1375 | + async def start_programm_async( |
| 1376 | + self, *, replay_mode: ReplayMode | None = None |
| 1377 | + ) -> bool: |
| 1378 | + """Start currently loaded Program. |
| 1379 | +
|
| 1380 | + Parameters |
| 1381 | + ---------- |
| 1382 | + replay_mode |
| 1383 | + Which replay mode to apply before starting. |
| 1384 | + If not provided, the currently set mode is kept. |
1356 | 1385 |
|
1357 | 1386 | Returns |
1358 | 1387 | ------- |
1359 | 1388 | bool |
1360 | 1389 | `True` if request was successful |
1361 | 1390 | `False` if request was not successful |
| 1391 | +
|
| 1392 | + Raises |
| 1393 | + ------ |
| 1394 | + CRICommandError |
| 1395 | + If the ``replay_mode`` could not be applied. |
1362 | 1396 | """ |
| 1397 | + if replay_mode is not None: |
| 1398 | + await self.set_replay_mode_async(replay_mode) |
| 1399 | + |
1363 | 1400 | command = "CMD StartProgram" |
1364 | 1401 |
|
1365 | 1402 | msg_id = self._send_command(command, True) |
@@ -1781,9 +1818,11 @@ def load_logic_programm(self, program_name: str) -> bool: |
1781 | 1818 | self.load_logic_programm_async(program_name) |
1782 | 1819 | ) |
1783 | 1820 |
|
1784 | | - def start_programm(self) -> bool: |
| 1821 | + def start_programm(self, *, replay_mode: ReplayMode | None = None) -> bool: |
1785 | 1822 | """Blocking wrapper around :func:`CRIController.start_programm_async`.""" |
1786 | | - return asyncio.get_event_loop().run_until_complete(self.start_programm_async()) |
| 1823 | + return asyncio.get_event_loop().run_until_complete( |
| 1824 | + self.start_programm_async(replay_mode=replay_mode) |
| 1825 | + ) |
1787 | 1826 |
|
1788 | 1827 | def stop_programm(self) -> bool: |
1789 | 1828 | """Blocking wrapper around :func:`CRIController.stop_programm_async`.""" |
|
0 commit comments