Skip to content

Commit

Permalink
[Action Designator] Added doc for pre and post perform callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigul committed Jan 23, 2025
1 parent c157804 commit 51b2f21
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/pycram/designator.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,14 @@ class Action:
The type of the robot at the start of the action.
"""
_pre_perform_callbacks = []
"""
List of callback functions that will be called before the action is performed.
"""

_post_perform_callbacks = []
"""
List of callback functions that will be called after the action is performed.
"""

def __post_init__(self):
self.robot_position = World.robot.get_pose()
Expand Down Expand Up @@ -258,20 +264,32 @@ def get_type_hints(cls) -> Dict[str, Any]:
return get_type_hints(cls)

@classmethod
def pre_perform(cls, func):
def pre_perform(cls, func) -> Callable:
"""
Decorator to execute the decorated function before performing the action.
:param func: The function to be decorated.
:return: The decorated function.
"""
cls._pre_perform_callbacks.append(func)

def wrapper(*args, **kwargs):
func(*args, **kwargs)
return func(*args, **kwargs)

return wrapper

@classmethod
def post_perform(cls, func):
def post_perform(cls, func) -> Callable:
"""
Decorator to execute the decorated function after performing the action.
:param func: The function to be decorated.
:return: The decorated function.
"""
cls._post_perform_callbacks.append(func)

def wrapper(*args, **kwargs):
func(*args, **kwargs)
return func(*args, **kwargs)

return wrapper

Expand Down

0 comments on commit 51b2f21

Please sign in to comment.