logo Mr.Robota 具身智能学习手册 中文
Chapter 2: 02 Robot Basics Control And Hand Eye Coordination

1. Introduction: Why it is a “bridge”?

In the previous documents, we learned about position (kinematics) and force/moment (dynamics).

Jacobian Matrix (JJ) is called a “bridge” because it connects these two fields at the differential level:

  1. Connecting the joint space and the Cartesian space: It describes how the joint velocity q˙\dot{q} is mapped to the linear and angular velocities of the end effector v,ωv, \omega.

    v=J(q)q˙v = J(q) \dot{q}
  2. Linking motion and force (virtual work principle): This is the entry point to dynamics. It describes how the generalized force at the end point is converted into the torque required by the joint (τ\tau).

    For the 2R robotic arm, if a full pose velocity [x˙,y˙,ϕ˙]T[\dot{x}, \dot{y}, \dot{\phi}]^T is used, the end generalized force should be written as F=[fx,fy,mz]TF=[f_x, f_y, m_z]^T (two-dimensional force + end torque).

    τ=JT(q)F\tau = J^T(q) F

Without a Jacobian matrix, we cannot reverse-engineer the joint rotation speed based on the desired velocity at the end, nor can we calculate the required torque for the joint motor based on the load grasped by the end.

2. Core Definitions

For a robot with nn degrees of freedom, the joint variable is q=[q1,…,qn]Tq = [q_1, \dots, q_n]^T. The end pose (position and pose) can be written as x=f(q)x = f(q).

The Jacobian matrix is defined as a matrix of partial derivatives:

J(q)=∂f∂q=[∂x∂q1⋯∂x∂qn⋮⋱⋮]J(q) = \frac{\partial f}{\partial q} = \begin{bmatrix} \frac{\partial x}{\partial q_1} & \cdots & \frac{\partial x}{\partial q_n} \\ \vdots & \ddots & \vdots \\ \end{bmatrix}

3. Architecture Flow (Mermaid)

Mermaidgraph LR
    subgraph 关节空间 Joint Space
    q_dot["关节速度 (d_theta)"]
    Tau["关节力矩 (Torque)"]
    end

    subgraph 笛卡尔空间 Cartesian Space
    v["末端速度 (Linear/Angular Velocity)"]
    F["末端受力 (Force/Moment)"]
    end

    J_block["雅可比矩阵 J(q)"]
    JT_block["雅可比转置 J_T(q)"]

    q_dot -->|乘 J| J_block --> v
    F -->|乘 J_T| JT_block --> Tau

    style q_dot fill:#e1f5fe,stroke:#01579b
    style v fill:#e1f5fe,stroke:#01579b
    style Tau fill:#fff9c4,stroke:#fbc02d
    style F fill:#fff9c4,stroke:#fbc02d

We use the sympy derivation method to automatically generate the complete pose Jacobian of a planar 2R robotic arm 3×23 \times 2.

Pythonimport sympy as sp
import numpy as np

def calculate_jacobian_2link():
    # 1. 定义符号
    theta1, theta2 = sp.symbols('theta1 theta2')
    l1, l2 = sp.symbols('l1 l2')

    # 2. 正运动学方程 (末端 x, y 与姿态角 phi)
    # x = l1*c1 + l2*c12
    # y = l1*s1 + l2*s12
    x = l1 * sp.cos(theta1) + l2 * sp.cos(theta1 + theta2)
    y = l1 * sp.sin(theta1) + l2 * sp.sin(theta1 + theta2)
    phi = theta1 + theta2

    # 位姿向量: [x, y, phi]^T
    pose = sp.Matrix([x, y, phi])

    # 关节变量向量
    q = sp.Matrix([theta1, theta2])

    # 3. 计算雅可比矩阵 J = d(pose)/d(q), 维度为 3x2
    J = pose.jacobian(q)

    print("--- 完整符号形式的雅可比矩阵 J (3x2) ---")
    sp.pprint(J)

    # 4. 数值验证 (奇异点测试)
    # 完整 J 为 3x2 非方阵,不能直接取 det(J)。
    # 对平面 2R 位置任务,常用其线速度子矩阵 Jv(前两行)判断奇异性。
    # 当 theta2 = 0 时 (手臂完全伸直),Jv 行列式应为 0。
    J_func = sp.lambdify((theta1, theta2, l1, l2), J, 'numpy')

    # 测试: l1=1, l2=1, theta1=0, theta2=0 (伸直)
    J_val = J_func(0, 0, 1, 1)
    Jv_val = J_val[:2, :]
    det_Jv = np.linalg.det(Jv_val)
    rank_J = np.linalg.matrix_rank(J_val)

    print("\n--- 数值验证 (手臂伸直 theta2=0) ---")
    print(f"完整雅可比矩阵 J:\n{J_val}")
    print(f"线速度子矩阵 Jv:\n{Jv_val}")
    print(f"det(Jv) (接近0表示位置奇异): {det_Jv}")
    print(f"rank(J) = {rank_J} (用于判断完整雅可比列秩是否下降;小于2才表示列秩退化)")
    print("注: 位置任务的奇异性以 Jv 为准(例如 det(Jv) 是否接近 0)。")

    # 5. 力映射示例: tau = J^T * F
    # F = [fx, fy, mz]^T, 对应平面力与末端力矩
    F = np.array([10.0, 5.0, 1.0])
    tau = J_val.T @ F
    print("\n--- 力/力矩映射示例 ---")
    print(f"末端广义力 F = {F}")
    print(f"关节力矩 tau = J^T F = {tau}")

calculate_jacobian_2link()