跳转至

Tools ViewModel

controller.presentation.view_models.tools_view_model

工具ViewModel

ToolsViewModel

ToolsViewModel(app_service: ToolsApplicationService)

Bases: QObject

工具 ViewModel。

职责: 1. 转发 UI 的计算请求到 Application Service 2. 转发 Application Service 的结果信号到 UI 3. 处理获取当前位置和逆运动学计算请求

属性:

名称 类型 描述
calculation_result pyqtSignal

正运动学结果信号,携带结果字典。

current_angles_received pyqtSignal

当前关节角度信号,携带角度列表。

inverse_result pyqtSignal

逆运动学结果信号,携带结果字典。

app_service ToolsApplicationService

工具应用服务。

初始化工具 ViewModel。

参数:

名称 类型 描述 默认
app_service ToolsApplicationService

工具应用服务。

必需
源代码位于: src/controller/controller/presentation/view_models/tools_view_model.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def __init__(self, app_service: ToolsApplicationService):
    """初始化工具 ViewModel。

    Args:
        app_service (ToolsApplicationService): 工具应用服务。
    """
    super().__init__()
    self.app_service = app_service

    # 连接Application Service的信号
    self.app_service.calculation_result_signal.connect(
        self.calculation_result.emit
    )
    self.app_service.current_angles_signal.connect(
        self.current_angles_received.emit
    )
    self.app_service.inverse_result_signal.connect(
        self.inverse_result.emit
    )

calculate_kinematics

calculate_kinematics(joint_angles: List[float])

请求计算正运动学(转发给 Application Service)。

参数:

名称 类型 描述 默认
joint_angles List[float]

6个关节角度(弧度)。

必需
源代码位于: src/controller/controller/presentation/view_models/tools_view_model.py
49
50
51
52
53
54
55
def calculate_kinematics(self, joint_angles: List[float]):
    """请求计算正运动学(转发给 Application Service)。

    Args:
        joint_angles (List[float]): 6个关节角度(弧度)。
    """
    self.app_service.calculate_forward_kinematics(joint_angles)

get_current_position

get_current_position()

请求获取当前机械臂关节角度。

源代码位于: src/controller/controller/presentation/view_models/tools_view_model.py
57
58
59
def get_current_position(self):
    """请求获取当前机械臂关节角度。"""
    self.app_service.get_current_joint_angles()

calculate_inverse_kinematics

calculate_inverse_kinematics(rotation_matrix: List[List[float]], position: List[float], initial_theta: List[float] = None)

请求计算逆运动学。

参数:

名称 类型 描述 默认
rotation_matrix List[List[float]]

3x3 旋转矩阵。

必需
position List[float]

[x, y, z] 位置(米)。

必需
initial_theta List[float]

初始关节角度. Defaults to None.

None
源代码位于: src/controller/controller/presentation/view_models/tools_view_model.py
61
62
63
64
65
66
67
68
69
def calculate_inverse_kinematics(self, rotation_matrix: List[List[float]], position: List[float], initial_theta: List[float] = None):
    """请求计算逆运动学。

    Args:
        rotation_matrix (List[List[float]]): 3x3 旋转矩阵。
        position (List[float]): [x, y, z] 位置(米)。
        initial_theta (List[float], optional): 初始关节角度. Defaults to None.
    """
    self.app_service.calculate_inverse_kinematics(rotation_matrix, position, initial_theta)