gpt4 book ai didi

python-3.x - 求解 Atlas IK(无约束)失败?

转载 作者:行者123 更新时间:2023-12-04 07:52:29 40 4
gpt4 key购买 nike

我正在尝试解决 Atlas 的 IK 以实现类似 https://www.youtube.com/watch?v=LLGuGAs0cto .在几次尝试 AddPositionConstraint 失败后,我意识到即使没有任何约束,IK 问题也会失败(Strandbeest 也会失败)。

from pydrake.all import MultibodyPlant, FindResourceOrThrow, Parser, InverseKinematics, Solve
import numpy as np

plant = MultibodyPlant(0.001)
# filename = FindResourceOrThrow("drake/examples/multibody/strandbeest/Strandbeest.urdf")
filename = FindResourceOrThrow("drake/examples/atlas/urdf/atlas_minimal_contact.urdf")
Parser(plant).AddModelFromFile(filename)
plant.Finalize()
ik = InverseKinematics(plant=plant, with_joint_limits=False)
# epsilon = 1e-2
# r_foot_position = np.array([0.0, -0.08, 0.1])
# ik.AddPositionConstraint(
# frameB=plant.GetFrameByName("r_foot"),
# p_BQ=np.zeros(3),
# frameA=plant.world_frame(),
# p_AQ_upper=r_foot_position+epsilon,
# p_AQ_lower=r_foot_position-epsilon)
result = Solve(ik.prog())
print(f"Success? {result.is_success()}")

有什么我想念的吗?我认为无约束 IK 问题将是微不足道的

最佳答案

Atlas 机器人有一个 float 底座骨盆,其方向由一个四元数表示。四元数具有单位长度约束 zᵀz = 1。另一方面,Drake 中的优化问题默认使用零值向量作为初始猜测。这个零向量对于单位长度约束来说是一个糟糕的初始猜测,因为 zᵀz 的梯度在 z=0 时为零,因此基于梯度的非线性求解器不知道如何使用零梯度移动初始猜测。
一个快速的解决方案是使用更好的初始猜测

pelvis = plant.GetBodyByName("pelvis")
q0 = np.zeros((plant.num_positions(),))
# Set the initial guess of the pelvis quaternion as [1, 0, 0, 0]
q0[pelvis.floating_positions_start(): pelvis.floating_positions_start() + 4] = np.array([1, 0, 0, 0])
# Use q0 as the initial guess
result = Solve(ik.prog(), q0)
获得合理初始猜测的更好方法是通过 context .
context = plant.CreateDefaultContext()
q0 = plant.GetPositions(context)
result = Solve(ik.prog(), q0)
CreateDefaultContext()将初始化四元数,使其具有单位长度。
我们有一个关于 debugging MathematicalProgram 的教程,当 MathematicalProgram 没有给您想要的结果时,您可能会发现它很有用。如果您调用 result.GetInfeasibleConstraintNames(ik.prog()),请在此处它将打印单位长度约束。

关于python-3.x - 求解 Atlas IK(无约束)失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66882969/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com