Analytical Single-step IK for EE control of SO101

<aside> 🤗

觉得有用的话,欢迎给我的XLeRobot Github Repo一个star!

XLeRobot/simulation/Maniskill/codes at main · Vector-Wangel/XLeRobot

</aside>

<aside> 💭

English Version

The controller decouples traditional IK into different components that can be either directly controlled or solved via simple analytical solutions (law of cosines).

IMG_0856.jpeg

Horizontal Plane Direction/Angle

Vertical Plane 2D Position

Tip Orientation

<aside> 💭

Chinese Blog:

控制器将传统逆运动学解耦为不同的组件,这些组件可以直接控制或通过简单的解析解决方案(余弦定理)求解。

IMG_0856.jpeg

水平面方向/角度

垂直平面2D位置

末端朝向

代码实现 Show Me the Code

def inverse_kinematics(x, y, l1=0.1159, l2=0.1350):
    """
    这里展示最主要的垂直2D平面的2-link的IK,余弦定理计算,其他角度都是一对一独立控制
    """
    # 基于urdf算角度offset
    theta1_offset = -math.atan2(0.028, 0.11257)  
    theta2_offset = -math.atan2(0.0052, 0.1349) + theta1_offset  

    # 目标点到原点距离,如果超过范围则缩放到最近点
    r = math.sqrt(x**2 + y**2)
		r_max, r_min = l1 + l2, abs(l1 - l2)
		scale = (l1 + l2)/r if r > (l1 + l2) else ((l2 - l1)/r if 0 < r < (l2 - l1) else 1)
		x, y, r = x*scale, y*scale, r*scale
    
    # 余弦定理与角度计算
    cos_theta2 = -(r**2 - l1**2 - l2**2) / (2 * l1 * l2)
    theta2 = math.pi - math.acos(cos_theta2)
    theta1 = math.atan2(y, x) + math.atan2(l2 * math.sin(theta2), l1 + l2 * math.cos(theta2))
    
    # 加上offsets并保证在角度限制
    joint2 = max(-0.1, min(3.45, theta1 - theta1_offset))
    joint3 = max(-0.2, min(math.pi, theta2 - theta2_offset))
    
    return joint2, joint3

代码完整版(以及键盘尖端控制与VR尖端控制代码)见 Complete codes:

https://github.com/Vector-Wangel/XLeRobot/blob/main/simulation/Maniskill/codes/demo_ctrl_action_ee.py

仿真验证与实验

EE Control of SO101 based on this IK function

理论验证/Validation

1747141373069.mov

VR control

hand tracking with Quest3

1747376552464.mov

基于键盘EE控制实现的一系列家庭任务

A series of household tasks implemented using keyboard-based end-effector control

32474.mov