You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Franka Panda机械臂绕panda_rightfinger轴旋转的四元数计算咨询

你现在的问题核心是四元数乘法顺序和旋转坐标系的对应关系错了:左乘四元数对应绕基座panda_link0的固定轴旋转,右乘对应绕当前末端局部坐标系的轴旋转,你之前的实现都是左乘逻辑,所以只能绕基轴旋转。

修改思路

  1. 删掉全局累计欧拉角的逻辑,累计全局欧拉角不仅会引入万向锁风险,也不符合绕局部轴旋转的计算逻辑,改为每次按键触发时生成一个小角度的局部增量旋转四元数。
  2. 调整四元数乘法顺序,将增量旋转四元数右乘到当前基系下的末端四元数上,得到的新四元数就是绕局部轴旋转后的基系下的位姿。
  3. 如果panda_rightfinger坐标系和你从O_T_EE拿到的末端执行器坐标系轴定义不一致,可以直接用轴角方式生成对应轴的增量旋转,避免欧拉角顺序搞错。

代码修改示例

首先删掉原有全局axis字典和累计逻辑,改为生成增量四元数:

def get_delta_quaternion(self, rotate_axis, step=0.01):
    # rotate_axis对应你要绕的手指局部轴,根据实际轴定义调整参数即可
    delta_r = step if rotate_axis == 'roll' else 0
    delta_p = step if rotate_axis == 'pitch' else 0
    delta_y = step if rotate_axis == 'yaw' else 0
    # 生成局部坐标系下的增量旋转四元数
    return tf.transformations.quaternion_from_euler(delta_r, delta_p, delta_y)

然后修改旋转计算逻辑:

# 保持位置不变
eq_pose.pose.position = current_goal_pose.pose.position
# 提取当前基系下的末端四元数
q_current = [
    current_goal_pose.pose.orientation.x,
    current_goal_pose.pose.orientation.y,
    current_goal_pose.pose.orientation.z,
    current_goal_pose.pose.orientation.w
]
# 生成本次的局部增量旋转
q_delta = orientation_producer.get_delta_quaternion(goal_pose.gesture)
# 右乘增量四元数,实现绕局部轴旋转
q_new = tf.transformations.quaternion_multiply(q_current, q_delta)
# 归一化避免浮点误差累积
q_new = q_new / np.linalg.norm(q_new)
# 赋值给发布的位姿
eq_pose.pose.orientation.x = q_new[0]
eq_pose.pose.orientation.y = q_new[1]
eq_pose.pose.orientation.z = q_new[2]
eq_pose.pose.orientation.w = q_new[3]
# 发布位姿
eq_publisher.publish(eq_pose)
# 更新当前目标位姿
current_goal_pose = eq_pose

注意事项

如果要更精准对应panda_rightfinger的某根轴,可直接用轴角生成四元数,比如绕局部Z轴转0.01rad的写法为tf.transformations.quaternion_about_axis(0.01, [0,0,1]),比欧拉角更直观,不会搞错顺序。

内容的提问来源于stack exchange,提问作者snice

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 05:45:00