Skip to content

Commit 372c28f

Browse files
committed
Fix tbcf / tcf test
1 parent fb20bf8 commit 372c28f

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

src/compas_fab/robots/robot_cell.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,7 @@ def get_attached_rigid_bodies(self, robot_cell_state, group):
906906
# Transformation functions
907907
# ----------------------------------------
908908

909-
def t_pcf_tcf(self, robot_cell_state, tool_id):
910-
# type: (RobotCellState, str) -> Transformation
909+
def t_pcf_tcf(self, robot_cell_state : RobotCellState, tool_id: str) -> Transformation:
911910
"""Returns the transformation from the PCF (Planner Coordinate Frame) to the TCF (Tool Coordinate Frame).
912911
913912
Parameters
@@ -922,9 +921,33 @@ def t_pcf_tcf(self, robot_cell_state, tool_id):
922921
Transformation from the tool's TCF to TBCF.
923922
"""
924923

924+
t_pcf_tbcf = self.t_pcf_tbcf(robot_cell_state, tool_id)
925+
926+
# t_tbcf_tcf is Tool Frame, a property of the tool model, describing Tool Coordinate Frame (TCF) relative to Tool Base Frame (TBCF)
927+
tool_model = self.tool_models[tool_id]
928+
t_tbcf_tcf = Transformation.from_frame(tool_model.frame)
929+
930+
t_pcf_tcf = t_pcf_tbcf * t_tbcf_tcf
931+
return t_pcf_tcf
932+
933+
def t_pcf_tbcf(self, robot_cell_state : RobotCellState, tool_id: str) -> Transformation:
934+
"""Returns the transformation from the PCF (Planner Coordinate Frame) to the TBCF (Tool Base Coordinate Frame).
935+
936+
Parameters
937+
----------
938+
tool_id : str
939+
The id of a tool found in `self.robot_cell.tool_models`.
940+
The tool must be attached to the robot.
941+
942+
Returns
943+
-------
944+
:class:`~compas.geometry.Transformation`
945+
Transformation from the tool's TCF to TBCF.
946+
"""
947+
925948
if tool_id not in self.tool_models:
926949
raise ValueError("Tool with id '{}' not found in robot cell.".format(tool_id))
927-
tool_model = self.tool_models[tool_id]
950+
928951
tool_state = robot_cell_state.tool_states[tool_id]
929952
if not tool_state.attached_to_group:
930953
raise ValueError("Tool with id '{}' is not attached to the robot.".format(tool_id))
@@ -933,14 +956,10 @@ def t_pcf_tcf(self, robot_cell_state, tool_id):
933956
# t_pcf_tbcf is Tool Attachment Frame, describing Tool Base Coordinate Frame (TBCF) relative to PCF Frame on the Robot (PCF)
934957
attachment_frame = tool_state.attachment_frame or Frame.worldXY()
935958
t_pcf_tbcf = Transformation.from_frame(attachment_frame)
936-
# t_tbcf_tcf is Tool Frame, a property of the tool model, describing Tool Coordinate Frame (TCF) relative to Tool Base Frame (TBCF)
937-
t_tbcf_tcf = Transformation.from_frame(tool_model.frame)
938959

939-
t_pcf_tcf = t_pcf_tbcf * t_tbcf_tcf
940-
return t_pcf_tcf
960+
return t_pcf_tbcf
941961

942-
def t_pcf_ocf(self, robot_cell_state, workpiece_id):
943-
# type: (RobotCellState, str) -> Transformation
962+
def t_pcf_ocf(self, robot_cell_state : RobotCellState, workpiece_id : str) -> Transformation:
944963
"""Returns the transformation from the PCF (Planner Coordinate Frame) to the OCF (Object Coordinate Frame).
945964
946965
Parameters

tests/robots/test_robot_cell.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,17 @@ def test_compute_attach_objects_frames(ur10e_gripper_one_beam):
413413
rcs.rigid_body_states[workpiece_id].attachment_frame = work_attachment_frame
414414

415415
# Use the transformation functions for the test
416-
t_pcf_tcf = rc.t_pcf_tcf(rcs, tool_id)
416+
t_pcf_tbcf = rc.t_pcf_tbcf(rcs, tool_id)
417417
t_pcf_ocf = rc.t_pcf_ocf(rcs, workpiece_id)
418418

419419
# Define the expected frames
420420
t_wcf_rcf = Transformation.from_frame(rcs.robot_base_frame)
421421
ee_link_name = rc.get_end_effector_link_name(group=rc.main_group_name)
422422
t_rcf_pcf = Transformation.from_frame(rc.robot_model.forward_kinematics(rcs.robot_configuration, ee_link_name))
423-
t_wcf_tcf = t_wcf_rcf * t_rcf_pcf * t_pcf_tcf
423+
t_wcf_tbcf = t_wcf_rcf * t_rcf_pcf * t_pcf_tbcf
424424
t_wcf_ocf = t_wcf_rcf * t_rcf_pcf * t_pcf_ocf
425425

426-
expected_tool_frame = Frame.from_transformation(t_wcf_tcf)
426+
expected_tool_frame = Frame.from_transformation(t_wcf_tbcf)
427427
expected_workpiece_frame = Frame.from_transformation(t_wcf_ocf)
428428

429429
# Test the function

0 commit comments

Comments
 (0)