Mission

Class to handle missions.

class pymirokai.mission.Mission(robot, skill, **kwargs)

Bases: object

Represent a robot mission, managing its lifecycle and completion.

The Mission object encapsulates the state of a skill execution — from creation to completion or cancellation — and provides methods to track and control its progress asynchronously.

Parameters:
  • robot (Robot)

  • skill (str)

  • kwargs (Any)

robot

The robot instance executing this mission.

skill

The name of the skill being executed.

kwargs

Keyword arguments passed to the skill.

mission_id

Future resolving to the mission’s unique ID.

result

Future resolving to the final mission result.

start_result

Future resolving to the mission start status.

async cancel(ignore_exceptions=False)

Cancel the current mission.

Parameters:

ignore_exceptions (bool) – If True, suppresses exceptions on failure.

Return type:

bool

Returns:

True if successfully cancelled, False otherwise.

Raises:

MissionCancelledError – If cancellation fails and ignore_exceptions is False.

async cancel_and_complete(ignore_exceptions=False)

Cancel the mission and wait until it is fully completed.

Parameters:

ignore_exceptions (bool) – If True, suppresses exceptions on failure.

Return type:

bool

Returns:

True if cancellation completed successfully, False otherwise.

Raises:

MissionCancelledError – If cancellation fails and ignore_exceptions is False.

async completed(ignore_exceptions=False)

Wait for the mission to complete.

Parameters:

ignore_exceptions (bool) – If True, suppresses exceptions during completion.

Return type:

dict | None

Returns:

The mission result dictionary, or None if ignored.

Raises:

MissionError – If the mission result cannot be retrieved.

async started(ignore_exceptions=False)

Wait until the mission has started.

Parameters:

ignore_exceptions (bool) – If True, suppresses exceptions if mission start fails.

Return type:

Mission

Returns:

The Mission instance if start succeeded.

Raises:

MissionError – If the mission failed to start or was not found.

exception pymirokai.mission.MissionCancelledError

Bases: Exception

Exception raised when a cancel mission command fails.

exception pymirokai.mission.MissionError

Bases: Exception

Exception raised when an await for a mission command fails.

pymirokai.mission.serialize_kwargs(**kwargs)

Serialize keyword arguments, converting timedelta values to dictionaries.

Parameters:

**kwargs (Any) – Arbitrary keyword arguments.

Return type:

dict[str, Any]

Returns:

A dictionary where timedelta values are replaced by serialized dicts.

pymirokai.mission.serialize_timedelta(td)

Serialize a timedelta into a dictionary.

Parameters:

td (timedelta) – The timedelta instance to serialize.

Return type:

dict[str, Any]

Returns:

A dictionary containing days, seconds, and microseconds.

pymirokai.mission.start_loop(loop)

Start the asyncio event loop in a separate thread.

Parameters:

loop (asyncio.AbstractEventLoop) – The event loop to run.

Return type:

None