Skip to content

Commit 8ab5469

Browse files
authored
Merge pull request #38 from JuBiotech/start-program-options
Add method to set `replay_mode`, also via a `start_program` kwarg
2 parents cde8bb9 + 959caba commit 8ab5469

1 file changed

Lines changed: 44 additions & 5 deletions

File tree

‎cri_lib/cri_controller.py‎

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from .cri_errors import CRICommandError, CRICommandTimeOutError, CRIConnectionError
1515
from .cri_protocol_parser import CRIProtocolParser
16-
from .robot_state import KinematicsState, RobotState
16+
from .robot_state import KinematicsState, ReplayMode, RobotState
1717

1818
logger = logging.getLogger(__name__)
1919

@@ -1351,15 +1351,52 @@ async def load_logic_programm_async(self, program_name: str) -> bool:
13511351
else:
13521352
return True
13531353

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.
13561385
13571386
Returns
13581387
-------
13591388
bool
13601389
`True` if request was successful
13611390
`False` if request was not successful
1391+
1392+
Raises
1393+
------
1394+
CRICommandError
1395+
If the ``replay_mode`` could not be applied.
13621396
"""
1397+
if replay_mode is not None:
1398+
await self.set_replay_mode_async(replay_mode)
1399+
13631400
command = "CMD StartProgram"
13641401

13651402
msg_id = self._send_command(command, True)
@@ -1781,9 +1818,11 @@ def load_logic_programm(self, program_name: str) -> bool:
17811818
self.load_logic_programm_async(program_name)
17821819
)
17831820

1784-
def start_programm(self) -> bool:
1821+
def start_programm(self, *, replay_mode: ReplayMode | None = None) -> bool:
17851822
"""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+
)
17871826

17881827
def stop_programm(self) -> bool:
17891828
"""Blocking wrapper around :func:`CRIController.stop_programm_async`."""

0 commit comments

Comments
 (0)