问题描述
有没有办法找到一个框架的 Jacobian 矩阵关于给定模型的关节(而不是整个工厂),或者确定完整工厂 Jacobian 的哪些列对应于给定模型的关节?我找到了 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]]