有什么方法可以找到与给定模型(而不是整个工厂)的关节相关的框架的雅可比行列式,或者确定完整工厂雅可比列的哪些列对应于给定模型的关节?我找到了 MultibodyPlant.CalcJacobian*
,但我不确定这些是否是正确的方法。
我也尝试映射 JointIndex
将模型中的每个关节添加到 MultibodyPlant.CalcJacobian*
的列中,但结果没有意义——联合索引是连续的(所有一个模型后跟所有其他模型),但雅可比列看起来交错(一列对应一个模型,然后一个对应另一个模型) .
最佳答案
假设您正在计算速度,您将需要使用 Joint.velocity_start()
和 Joint.num_velocities()
创建一个掩码或一组索引。如果您使用的是 Python,那么您可以使用 NumPy 的数组切片来选择您想要的雅可比列。
(如果您计算 w.r.t. 位置,请确保使用 Joint.position_start()
和 Joint.num_positions()
。)
示例笔记本:
https://nbviewer.jupyter.org/github/EricCousineau-TRI/repro/blob/eb7f11d/drake_stuff/notebooks/multibody_plant_jacobian_subset.ipynb
(TODO:指向更官方的来源。)
主要需要注意的代码:
def get_velocity_mask(plant, joints):
"""
Generates a mask according to supplied set of ``joints``.
The binary mask is unable to preserve ordering for joint indices, thus
`joints` required to be a ``set`` (for simplicity).
"""
assert isinstance(joints, set)
mask = np.zeros(plant.num_velocities(), dtype=np.bool)
for joint in joints:
start = joint.velocity_start()
end = start + joint.num_velocities()
mask[start:end] = True
return mask
def get_velocity_indices(plant, joints):
"""
Generates a list of indices according to supplies list of ``joints``.
The indices are generated according to the order of ``joints``, thus
``joints`` is required to be a list (for simplicity).
"""
indices = []
for joint in joints:
start = joint.velocity_start()
end = start + joint.num_velocities()
for i in range(start, end):
indices.append(i)
return indices
...
# print(Jv1_WG1) # Prints 7 dof from a 14 dof plant
[[0.000 -0.707 0.354 0.707 0.612 -0.750 0.256]
[0.000 0.707 0.354 -0.707 0.612 0.250 0.963]
[1.000 -0.000 0.866 -0.000 0.500 0.612 -0.079]
[-0.471 0.394 -0.211 -0.137 -0.043 -0.049 0.000]
[0.414 0.394 0.162 -0.137 0.014 0.008 0.000]
[0.000 -0.626 0.020 0.416 0.035 -0.064 0.000]]
关于drake - 在 Pydrake 中找到与给定模型的关节相关的框架的雅可比行列式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68578567/