mirte_lc_labclean.behaviours module
ROS2 behaviours for the Mirte LabClean application.
This module defines a set of py_trees behaviours used in the LabClean behaviour tree. Behaviours include LED control, coverage navigation, object retrieval, and plan execution using ROS2 action servers and services.
- class mirte_lc_labclean.behaviours.CoverageTask(name: str, planner: str)
Bases:
py_trees.behaviour.BehaviourSend a coverage navigation goal and monitor until complete.
- Args:
name (str): Name of the behaviour. planner (str): Planner type, e.g.
skeleton.
- initialise()
Execute user specified instructions prior to commencement of a new round of activity.
Users should override this method to perform any necessary initialising/clearing/resetting of variables prior to a new round of activity for the behaviour.
This method is automatically called via the
py_trees.behaviour.Behaviour.tick()method whenever the behaviour is notRUNNING.… note:: This method can be called more than once in the lifetime of a tree!
- setup(**kwargs)
Set up and verify infrastructure (middleware connections, etc) is available.
Users should override this method for any configuration and/or validation that is necessary prior to ticking the tree. Such construction is best done here rather than in __init__ since there is no guarantee at __init__ that the infrastructure is ready or even available (e.g. you may be just rendering dot graphs of the trees, no robot around).
- Examples:
establishing a middleware connection to a sensor or driver
ensuring a sensor or driver is in a ‘ready’ state
This method will typically be called before a tree’s first tick as this gives the application time to check and verify that everything is in a ready state before executing. This is especially important given that a tree does not always tick every behaviour and if not checked up-front, it may be some time before discovering a behaviour was in a broken state.
Tip
When to use
__init__(),setup()and when to useinitialise()?Use
__init__()for configuration of non-runtime dependencies (e.g. no middleware).Use
setup()for one-offs or to get early signal that everything (e.g. middleware) is ready to go.Use
initialise()for just-in-time configurations and/or checks.There are times when it makes sense to do all three. For example, pythonic variable configuration in
__init__(), middleware service client creation / server existence checks insetup()and a just-in-time check to ensure the server is still available ininitialise().Tip
Faults are notified to the user of the behaviour via exceptions. Choice of exception to use is left to the user.
Warning
The kwargs argument is for distributing objects at runtime to behaviours before ticking. For example, a simulator instance with which behaviours can interact with the simulator’s python api, a ros2 node for setting up communications. Use sparingly, as this is not proof against keyword conflicts amongst disparate libraries of behaviours.
- Args:
- **kwargs: distribute arguments to this
behaviour and in turn, all of its children
- Raises:
Exception: if this behaviour has a fault in construction or configuration
See also
py_trees.behaviour.Behaviour.shutdown()
- update()
Execute user specified instructions when the behaviour is ticked.
Users should override this method to perform any logic required to arrive at a decision on the behaviour’s new status. It is the primary worker function called by the
tick()mechanism.- Returns:
the behaviour’s new status
Status
Tip
This method should be almost instantaneous and non-blocking
See also
py_trees.behaviour.Behaviour.tick()
- class mirte_lc_labclean.behaviours.FlashLedStrip(name: str, colour: list = [0.0, 0.0, 1.0])
Bases:
py_trees.behaviour.BehaviourFlash the LED strip with a colour command.
- Args:
name (str): Name of the behaviour. colour (list[float]): RGB colour values in range [0.0, 1.0].
- initialise()
Execute user specified instructions prior to commencement of a new round of activity.
Users should override this method to perform any necessary initialising/clearing/resetting of variables prior to a new round of activity for the behaviour.
This method is automatically called via the
py_trees.behaviour.Behaviour.tick()method whenever the behaviour is notRUNNING.… note:: This method can be called more than once in the lifetime of a tree!
- setup(**kwargs)
Set up and verify infrastructure (middleware connections, etc) is available.
Users should override this method for any configuration and/or validation that is necessary prior to ticking the tree. Such construction is best done here rather than in __init__ since there is no guarantee at __init__ that the infrastructure is ready or even available (e.g. you may be just rendering dot graphs of the trees, no robot around).
- Examples:
establishing a middleware connection to a sensor or driver
ensuring a sensor or driver is in a ‘ready’ state
This method will typically be called before a tree’s first tick as this gives the application time to check and verify that everything is in a ready state before executing. This is especially important given that a tree does not always tick every behaviour and if not checked up-front, it may be some time before discovering a behaviour was in a broken state.
Tip
When to use
__init__(),setup()and when to useinitialise()?Use
__init__()for configuration of non-runtime dependencies (e.g. no middleware).Use
setup()for one-offs or to get early signal that everything (e.g. middleware) is ready to go.Use
initialise()for just-in-time configurations and/or checks.There are times when it makes sense to do all three. For example, pythonic variable configuration in
__init__(), middleware service client creation / server existence checks insetup()and a just-in-time check to ensure the server is still available ininitialise().Tip
Faults are notified to the user of the behaviour via exceptions. Choice of exception to use is left to the user.
Warning
The kwargs argument is for distributing objects at runtime to behaviours before ticking. For example, a simulator instance with which behaviours can interact with the simulator’s python api, a ros2 node for setting up communications. Use sparingly, as this is not proof against keyword conflicts amongst disparate libraries of behaviours.
- Args:
- **kwargs: distribute arguments to this
behaviour and in turn, all of its children
- Raises:
Exception: if this behaviour has a fault in construction or configuration
See also
py_trees.behaviour.Behaviour.shutdown()
- update()
Execute user specified instructions when the behaviour is ticked.
Users should override this method to perform any logic required to arrive at a decision on the behaviour’s new status. It is the primary worker function called by the
tick()mechanism.- Returns:
the behaviour’s new status
Status
Tip
This method should be almost instantaneous and non-blocking
See also
py_trees.behaviour.Behaviour.tick()
- class mirte_lc_labclean.behaviours.GetPlanarObjects(name: str, blackboard_key: str = 'planar_objects_detected_array')
Bases:
py_trees.behaviour.BehaviourQuery the planar object detection service and write to the blackboard.
- Args:
name (str): Name of the behaviour. blackboard_key (str): Blackboard key to write detected objects into.
- initialise()
Execute user specified instructions prior to commencement of a new round of activity.
Users should override this method to perform any necessary initialising/clearing/resetting of variables prior to a new round of activity for the behaviour.
This method is automatically called via the
py_trees.behaviour.Behaviour.tick()method whenever the behaviour is notRUNNING.… note:: This method can be called more than once in the lifetime of a tree!
- setup(**kwargs)
Set up and verify infrastructure (middleware connections, etc) is available.
Users should override this method for any configuration and/or validation that is necessary prior to ticking the tree. Such construction is best done here rather than in __init__ since there is no guarantee at __init__ that the infrastructure is ready or even available (e.g. you may be just rendering dot graphs of the trees, no robot around).
- Examples:
establishing a middleware connection to a sensor or driver
ensuring a sensor or driver is in a ‘ready’ state
This method will typically be called before a tree’s first tick as this gives the application time to check and verify that everything is in a ready state before executing. This is especially important given that a tree does not always tick every behaviour and if not checked up-front, it may be some time before discovering a behaviour was in a broken state.
Tip
When to use
__init__(),setup()and when to useinitialise()?Use
__init__()for configuration of non-runtime dependencies (e.g. no middleware).Use
setup()for one-offs or to get early signal that everything (e.g. middleware) is ready to go.Use
initialise()for just-in-time configurations and/or checks.There are times when it makes sense to do all three. For example, pythonic variable configuration in
__init__(), middleware service client creation / server existence checks insetup()and a just-in-time check to ensure the server is still available ininitialise().Tip
Faults are notified to the user of the behaviour via exceptions. Choice of exception to use is left to the user.
Warning
The kwargs argument is for distributing objects at runtime to behaviours before ticking. For example, a simulator instance with which behaviours can interact with the simulator’s python api, a ros2 node for setting up communications. Use sparingly, as this is not proof against keyword conflicts amongst disparate libraries of behaviours.
- Args:
- **kwargs: distribute arguments to this
behaviour and in turn, all of its children
- Raises:
Exception: if this behaviour has a fault in construction or configuration
See also
py_trees.behaviour.Behaviour.shutdown()
- update()
Execute user specified instructions when the behaviour is ticked.
Users should override this method to perform any logic required to arrive at a decision on the behaviour’s new status. It is the primary worker function called by the
tick()mechanism.- Returns:
the behaviour’s new status
Status
Tip
This method should be almost instantaneous and non-blocking
See also
py_trees.behaviour.Behaviour.tick()
- class mirte_lc_labclean.behaviours.MoveArm(name: str, blackboard_key: Optional[str] = None, target_position=None, predefined_pose: Optional[str] = None)
Bases:
py_trees.behaviour.BehaviourMove the robot arm to a named or explicit target pose.
Returns SUCCESS only when the action server confirms the goal succeeded.
- Args:
name (str): Name of the behaviour. blackboard_key (str, optional): Blackboard key holding a target pose. target_position (tuple[float, float, float], optional): Explicit XYZ. predefined_pose (str, optional): Name of a predefined arm pose.
- initialise()
Execute user specified instructions prior to commencement of a new round of activity.
Users should override this method to perform any necessary initialising/clearing/resetting of variables prior to a new round of activity for the behaviour.
This method is automatically called via the
py_trees.behaviour.Behaviour.tick()method whenever the behaviour is notRUNNING.… note:: This method can be called more than once in the lifetime of a tree!
- setup(**kwargs)
Set up and verify infrastructure (middleware connections, etc) is available.
Users should override this method for any configuration and/or validation that is necessary prior to ticking the tree. Such construction is best done here rather than in __init__ since there is no guarantee at __init__ that the infrastructure is ready or even available (e.g. you may be just rendering dot graphs of the trees, no robot around).
- Examples:
establishing a middleware connection to a sensor or driver
ensuring a sensor or driver is in a ‘ready’ state
This method will typically be called before a tree’s first tick as this gives the application time to check and verify that everything is in a ready state before executing. This is especially important given that a tree does not always tick every behaviour and if not checked up-front, it may be some time before discovering a behaviour was in a broken state.
Tip
When to use
__init__(),setup()and when to useinitialise()?Use
__init__()for configuration of non-runtime dependencies (e.g. no middleware).Use
setup()for one-offs or to get early signal that everything (e.g. middleware) is ready to go.Use
initialise()for just-in-time configurations and/or checks.There are times when it makes sense to do all three. For example, pythonic variable configuration in
__init__(), middleware service client creation / server existence checks insetup()and a just-in-time check to ensure the server is still available ininitialise().Tip
Faults are notified to the user of the behaviour via exceptions. Choice of exception to use is left to the user.
Warning
The kwargs argument is for distributing objects at runtime to behaviours before ticking. For example, a simulator instance with which behaviours can interact with the simulator’s python api, a ros2 node for setting up communications. Use sparingly, as this is not proof against keyword conflicts amongst disparate libraries of behaviours.
- Args:
- **kwargs: distribute arguments to this
behaviour and in turn, all of its children
- Raises:
Exception: if this behaviour has a fault in construction or configuration
See also
py_trees.behaviour.Behaviour.shutdown()
- update()
Execute user specified instructions when the behaviour is ticked.
Users should override this method to perform any logic required to arrive at a decision on the behaviour’s new status. It is the primary worker function called by the
tick()mechanism.- Returns:
the behaviour’s new status
Status
Tip
This method should be almost instantaneous and non-blocking
See also
py_trees.behaviour.Behaviour.tick()
Bases:
py_trees.behaviour.BehaviourNavigate the robot to a target position.
Sends a Nav2 goal and monitors progress. Handles TF not ready, Nav2 not ready, feedback dropout, and genuine stuck situations gracefully.
- Args:
name (str): Name of the behaviour. blackboard_key (str, optional): Blackboard key containing a list of
DetectedObject messages. The closest object is used as the target.
- target_position (list[float] | tuple[float, float], optional): Fixed
XY position in the map frame. Used when blackboard_key is None.
- goal_tolerance (float): Distance in metres at which to consider the
goal reached and cancel early. Default 0.5m.
- stuck_timeout (float): Seconds without progress before cancelling.
Default 20.0s.
- nav2_timeout (float): Seconds to wait for Nav2 to become active.
Default 5.0s.
- standoff (float): Metres to stop short of a detected object so the
robot doesn’t drive into it. Default 0.4m.
Execute user specified instructions prior to commencement of a new round of activity.
Users should override this method to perform any necessary initialising/clearing/resetting of variables prior to a new round of activity for the behaviour.
This method is automatically called via the
py_trees.behaviour.Behaviour.tick()method whenever the behaviour is notRUNNING.… note:: This method can be called more than once in the lifetime of a tree!
Set up and verify infrastructure (middleware connections, etc) is available.
Users should override this method for any configuration and/or validation that is necessary prior to ticking the tree. Such construction is best done here rather than in __init__ since there is no guarantee at __init__ that the infrastructure is ready or even available (e.g. you may be just rendering dot graphs of the trees, no robot around).
- Examples:
establishing a middleware connection to a sensor or driver
ensuring a sensor or driver is in a ‘ready’ state
This method will typically be called before a tree’s first tick as this gives the application time to check and verify that everything is in a ready state before executing. This is especially important given that a tree does not always tick every behaviour and if not checked up-front, it may be some time before discovering a behaviour was in a broken state.
Tip
When to use
__init__(),setup()and when to useinitialise()?Use
__init__()for configuration of non-runtime dependencies (e.g. no middleware).Use
setup()for one-offs or to get early signal that everything (e.g. middleware) is ready to go.Use
initialise()for just-in-time configurations and/or checks.There are times when it makes sense to do all three. For example, pythonic variable configuration in
__init__(), middleware service client creation / server existence checks insetup()and a just-in-time check to ensure the server is still available ininitialise().Tip
Faults are notified to the user of the behaviour via exceptions. Choice of exception to use is left to the user.
Warning
The kwargs argument is for distributing objects at runtime to behaviours before ticking. For example, a simulator instance with which behaviours can interact with the simulator’s python api, a ros2 node for setting up communications. Use sparingly, as this is not proof against keyword conflicts amongst disparate libraries of behaviours.
- Args:
- **kwargs: distribute arguments to this
behaviour and in turn, all of its children
- Raises:
Exception: if this behaviour has a fault in construction or configuration
See also
py_trees.behaviour.Behaviour.shutdown()
Execute user specified instructions when the behaviour is ticked.
Users should override this method to perform any logic required to arrive at a decision on the behaviour’s new status. It is the primary worker function called by the
tick()mechanism.- Returns:
the behaviour’s new status
Status
Tip
This method should be almost instantaneous and non-blocking
See also
py_trees.behaviour.Behaviour.tick()
- class mirte_lc_labclean.behaviours.PickObject(name: str, blackboard_key: str = 'planar_objects_detected_array')
Bases:
py_trees.behaviour.BehaviourPick the closest detected object using a multi-step arm sequence.
Steps: approach → open → dive → grip → place → let_go → standby
- Args:
name (str): Name of the behaviour. blackboard_key (str): Blackboard key holding a list of DetectedObject.
- STEPS = ['approach', 'open', 'dive', 'grip', 'place', 'let_go', 'standby']
- blackboards: typing.List[blackboard.Client]
- children: typing.List[Behaviour]
- initialise()
Execute user specified instructions prior to commencement of a new round of activity.
Users should override this method to perform any necessary initialising/clearing/resetting of variables prior to a new round of activity for the behaviour.
This method is automatically called via the
py_trees.behaviour.Behaviour.tick()method whenever the behaviour is notRUNNING.… note:: This method can be called more than once in the lifetime of a tree!
- name: str
- parent: typing.Optional[Behaviour]
- setup(**kwargs)
Set up and verify infrastructure (middleware connections, etc) is available.
Users should override this method for any configuration and/or validation that is necessary prior to ticking the tree. Such construction is best done here rather than in __init__ since there is no guarantee at __init__ that the infrastructure is ready or even available (e.g. you may be just rendering dot graphs of the trees, no robot around).
- Examples:
establishing a middleware connection to a sensor or driver
ensuring a sensor or driver is in a ‘ready’ state
This method will typically be called before a tree’s first tick as this gives the application time to check and verify that everything is in a ready state before executing. This is especially important given that a tree does not always tick every behaviour and if not checked up-front, it may be some time before discovering a behaviour was in a broken state.
Tip
When to use
__init__(),setup()and when to useinitialise()?Use
__init__()for configuration of non-runtime dependencies (e.g. no middleware).Use
setup()for one-offs or to get early signal that everything (e.g. middleware) is ready to go.Use
initialise()for just-in-time configurations and/or checks.There are times when it makes sense to do all three. For example, pythonic variable configuration in
__init__(), middleware service client creation / server existence checks insetup()and a just-in-time check to ensure the server is still available ininitialise().Tip
Faults are notified to the user of the behaviour via exceptions. Choice of exception to use is left to the user.
Warning
The kwargs argument is for distributing objects at runtime to behaviours before ticking. For example, a simulator instance with which behaviours can interact with the simulator’s python api, a ros2 node for setting up communications. Use sparingly, as this is not proof against keyword conflicts amongst disparate libraries of behaviours.
- Args:
- **kwargs: distribute arguments to this
behaviour and in turn, all of its children
- Raises:
Exception: if this behaviour has a fault in construction or configuration
See also
py_trees.behaviour.Behaviour.shutdown()
- update()
Execute user specified instructions when the behaviour is ticked.
Users should override this method to perform any logic required to arrive at a decision on the behaviour’s new status. It is the primary worker function called by the
tick()mechanism.- Returns:
the behaviour’s new status
Status
Tip
This method should be almost instantaneous and non-blocking
See also
py_trees.behaviour.Behaviour.tick()
- class mirte_lc_labclean.behaviours.SetCoverageStatus(name: str, requested_status: str)
Bases:
py_trees.behaviour.BehaviourSend a pause/resume/stop command to the coverage navigation server.
- Args:
name (str): Name of the behaviour. requested_status (str): One of
pause,resume, orstop.
- blackboards: typing.List[blackboard.Client]
- children: typing.List[Behaviour]
- initialise()
Execute user specified instructions prior to commencement of a new round of activity.
Users should override this method to perform any necessary initialising/clearing/resetting of variables prior to a new round of activity for the behaviour.
This method is automatically called via the
py_trees.behaviour.Behaviour.tick()method whenever the behaviour is notRUNNING.… note:: This method can be called more than once in the lifetime of a tree!
- name: str
- parent: typing.Optional[Behaviour]
- setup(**kwargs)
Set up and verify infrastructure (middleware connections, etc) is available.
Users should override this method for any configuration and/or validation that is necessary prior to ticking the tree. Such construction is best done here rather than in __init__ since there is no guarantee at __init__ that the infrastructure is ready or even available (e.g. you may be just rendering dot graphs of the trees, no robot around).
- Examples:
establishing a middleware connection to a sensor or driver
ensuring a sensor or driver is in a ‘ready’ state
This method will typically be called before a tree’s first tick as this gives the application time to check and verify that everything is in a ready state before executing. This is especially important given that a tree does not always tick every behaviour and if not checked up-front, it may be some time before discovering a behaviour was in a broken state.
Tip
When to use
__init__(),setup()and when to useinitialise()?Use
__init__()for configuration of non-runtime dependencies (e.g. no middleware).Use
setup()for one-offs or to get early signal that everything (e.g. middleware) is ready to go.Use
initialise()for just-in-time configurations and/or checks.There are times when it makes sense to do all three. For example, pythonic variable configuration in
__init__(), middleware service client creation / server existence checks insetup()and a just-in-time check to ensure the server is still available ininitialise().Tip
Faults are notified to the user of the behaviour via exceptions. Choice of exception to use is left to the user.
Warning
The kwargs argument is for distributing objects at runtime to behaviours before ticking. For example, a simulator instance with which behaviours can interact with the simulator’s python api, a ros2 node for setting up communications. Use sparingly, as this is not proof against keyword conflicts amongst disparate libraries of behaviours.
- Args:
- **kwargs: distribute arguments to this
behaviour and in turn, all of its children
- Raises:
Exception: if this behaviour has a fault in construction or configuration
See also
py_trees.behaviour.Behaviour.shutdown()
- status_commands = {'pause': 0, 'resume': 1, 'stop': 2}
- update()
Execute user specified instructions when the behaviour is ticked.
Users should override this method to perform any logic required to arrive at a decision on the behaviour’s new status. It is the primary worker function called by the
tick()mechanism.- Returns:
the behaviour’s new status
Status
Tip
This method should be almost instantaneous and non-blocking
See also
py_trees.behaviour.Behaviour.tick()