From a6cda743b39e1fb16d28eae33c3677891fd1b78c Mon Sep 17 00:00:00 2001 From: Victor LEUNG Date: Thu, 20 Jun 2024 11:12:35 +0800 Subject: [PATCH 1/4] Updated Backends Documentation --- docs/developer/backends.rst | 46 +++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/docs/developer/backends.rst b/docs/developer/backends.rst index 991bd40fdb..a2154e51c8 100644 --- a/docs/developer/backends.rst +++ b/docs/developer/backends.rst @@ -19,18 +19,18 @@ but for now, such methods and attributes will be left with the client. The ``PlannerInterface`` serves as a template for any client-specific -planner, providing default behavior for each of the -methods listed within. When a developer wishes to override any -of these defaults, they should make use of the appropriate backend -feature interface from ``backends/interfaces.py``. The file -``interfaces.py`` consists of a collection of classes, any -implementation of which is callable through its ``__call__`` magic -method. For example: +planner and contains all unified planning function signatures. +Developers wishing to develop new planner features should inherit from the +appropriate backend feature interface from ``backends/interfaces/backend_features.py``. +These features are then composed into a single class that inherits from +``PlannerInterface``. +For example: .. code-block:: python from compas.geometry import Frame from compas_fab.backends.interfaces import InverseKinematics + from compas_fab.backends.interfaces.client import PlannerInterface class ExampleInverseKinematics(InverseKinematics): def inverse_kinematics(self, robot, @@ -38,18 +38,27 @@ method. For example: start_configuration=None, group=None, options=None): + # Access to the Client Interface is available: + client = self.client # insert fancy code here pass -can be instantiated and called in the following manner: + class ExamplePlanner( + ExampleInverseKinematics, + PlannerInterface, + ): + pass + +The planner can be instantiated and called in the following manner: .. code-block:: python - calculate_example_ik = ExampleInverseKinematics() + # Instantiate the client and change its planner to the ExamplePlanner + client = MyExamplePlanner(robot) + client.planner = ExamplePlanner(client) + # Call the inverse kinematics method as usual frame = Frame([0, 0, 0], [1, 0, 0], [0, 1, 0]) - ik_result = calculate_example_ik(robot, frame) - # or equivalently: - ik_result = calculate_example_ik.inverse_kinematics(robot, frame) + ik_result = robot.inverse_kinematics(robot, frame) These backend feature interfaces exist in part to enforce a common @@ -67,9 +76,16 @@ backend of ``ClientB`` is slow to compute inverse kinematics but can plan motion .. code-block:: python - with ClientA() as client_a, ClientB() as client_b: - inverse_kinematics = ClientAInverseKinematics(client_a) - plan_motion = ClientBPlanMotion(client_b) + with ClientA(robot) as client_a, ClientB(robot) as client_b: + inverse_kinematics = client_a.planner.inverse_kinematics + plan_motion = client_b.planner.plan_motion + + frame = Frame([0, 0, 0], [1, 0, 0], [0, 1, 0]) + ik_result = inverse_kinematics(frame) + + start_configuration = robot.zero_configuration() + goal_configuration = robot.random_configuration() + motion_plan = plan_motion(start_configuration, goal_configuration) Here we can assign the inverse kinematics to be calculated by the backend of ``ClientA``, while the motion planning is calculated by the backend of From e0d64fbbd971394f411b14f2f682e21c54a2669f Mon Sep 17 00:00:00 2001 From: Victor LEUNG Date: Fri, 21 Jun 2024 07:02:20 +0200 Subject: [PATCH 2/4] Update docs/developer/backends.rst Co-authored-by: Gonzalo Casas --- docs/developer/backends.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/developer/backends.rst b/docs/developer/backends.rst index a2154e51c8..78ac43df72 100644 --- a/docs/developer/backends.rst +++ b/docs/developer/backends.rst @@ -30,7 +30,7 @@ For example: from compas.geometry import Frame from compas_fab.backends.interfaces import InverseKinematics - from compas_fab.backends.interfaces.client import PlannerInterface + from compas_fab.backends.interfaces import PlannerInterface class ExampleInverseKinematics(InverseKinematics): def inverse_kinematics(self, robot, From ec2a8ade564430cb31406af0f2620dd21cf6a4c3 Mon Sep 17 00:00:00 2001 From: Victor LEUNG Date: Fri, 21 Jun 2024 07:03:06 +0200 Subject: [PATCH 3/4] Update docs/developer/backends.rst Co-authored-by: Gonzalo Casas --- docs/developer/backends.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/developer/backends.rst b/docs/developer/backends.rst index 78ac43df72..c42d756acb 100644 --- a/docs/developer/backends.rst +++ b/docs/developer/backends.rst @@ -38,8 +38,8 @@ For example: start_configuration=None, group=None, options=None): - # Access to the Client Interface is available: - client = self.client + # The backend features have access to the instance of the client + print(type(self.client)) # insert fancy code here pass From aa0415b48c7223a5f6be27cc632af562a5cc1a37 Mon Sep 17 00:00:00 2001 From: Victor LEUNG Date: Fri, 21 Jun 2024 07:07:19 +0200 Subject: [PATCH 4/4] Update docs/developer/backends.rst Co-authored-by: Gonzalo Casas --- docs/developer/backends.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/developer/backends.rst b/docs/developer/backends.rst index c42d756acb..61f9bebbfe 100644 --- a/docs/developer/backends.rst +++ b/docs/developer/backends.rst @@ -43,10 +43,9 @@ For example: # insert fancy code here pass - class ExamplePlanner( - ExampleInverseKinematics, - PlannerInterface, - ): + + # Now we can create a custom planner using our newly implemented backend feature + class ExamplePlanner(ExampleInverseKinematics, PlannerInterface): pass The planner can be instantiated and called in the following manner: