ikpy问题:typeError:__init __()缺少1所需的位置参数:' oneart_translation'
我正在尝试将ikpy库(v3.3.3)与python 3.8一起为我的Mujoco平台上的机器人组编程一些演示。但是,当我尝试进行运动学演示时,下面发生了一些错误。 在此处输入图像描述 这是下面我的项目代码:
utils.py
from mujoco_py import MjViewer
import glfw
import numpy as np
import ikpy
from ikpy.chain import Chain
from ikpy.link import OriginLink, URDFLink
open_viewers = [] # a static list to keep track of all viewers
class MjViewerExtended(MjViewer):
""" An extension of mujoco-py's MjViewer. MjViewerExtended does not
terminate all other viewers and the python interpreter when closeing.
"""
def __init__(self, sim):
glfw.init() # make sure glfw is initialized
super().__init__(sim)
open_viewers.append(self)
def close(self):
""" Closes the viewers glfw window. To open a new one, create a new
instance of MjViewerExtended
"""
# MjViewer only calls glfw.terminate() here killing glfw entierly.
if glfw.window_should_close(self.window):
return
try:
glfw.set_window_should_close(self.window, 1)
glfw.destroy_window(self.window)
except Exception:
pass
open_viewers.remove(self)
if len(open_viewers) == 0:
glfw.terminate()
def key_callback(self, window, key, scancode, action, mods):
if action == glfw.RELEASE and key == glfw.KEY_ESCAPE:
self.close()
else:
super().key_callback(window, key, scancode, action, mods)
class Wam4IK(Chain):
""" A basic kinamatic model of the MjWAM4 """
def __init__(self, tool_orientation=None,
tool_translation=None, # x, y, z
base_orientation=None, # x, y, z
base_translation=None):
if base_translation is None:
base_translation = [0, 0, 0.84]
if base_orientation is None:
base_orientation = [0, 0, np.pi / 2]
if tool_translation is None:
tool_translation = [0, 0, 0]
if tool_orientation is None:
tool_orientation = [0, 0, 0]
links = [OriginLink(),
URDFLink(name="wam/links/base",
translation=base_translation, # translation of frame
origin_orientation=base_orientation, # orientation of frame
rotation=[0, 0, 0]
), # joint axis [0, 0, 0] -> no joint
URDFLink(name="wam/links/shoulder_yaw",
translation=[0, 0, 0.16],
origin_orientation=[0, 0, 0],
rotation=[0, 0, 1]
),
URDFLink(name="wam/links/shoulder_pitch",
translation=[0, 0, 0.186],
origin_orientation=[0, 0, 0],
rotation=[1, 0, 0]
),
URDFLink(name="wam/links/shoulder_roll",
translation=[0, 0, 0],
origin_orientation=[0, 0, 0],
rotation=[0, 0, 1]
),
URDFLink(name="wam/links/upper_arm",
translation=[0, -0.045, 0.550],
origin_orientation=[0, 0, 0],
rotation=[1, 0, 0]
),
URDFLink(name="wam/links/tool_base_wo_plate",
translation=[0, 0.045, 0.350],
origin_orientation=[0, 0, 0],
rotation=[0, 0, 0]
),
URDFLink(name="wam/links/tool_base_w_plate",
translation=[0, 0, 0.008],
origin_orientation=[0, 0, 0],
rotation=[0, 0, 0]
),
URDFLink(name="wam/links/tool",
translation=tool_translation,
origin_orientation=tool_orientation,
rotation=[0, 0, 0]
)
]
self.all_joints = [False, False, True, True, True, True, False, False, False]
self.active_joints = list(map(lambda x: x == 1, active_joints))
self.active_links = [False, False, *self.active_joints, False, False, False]
Chain.__init__(self, name='wam4',
active_links_mask=self.active_links,
links=links)
def fk(self, joints, full_kinematics=False):
joints = np.array([0, 0, *joints, 0, 0, 0])
return Chain.forward_kinematics(self, joints, full_kinematics)
def ik(self, target_position=None, target_orientation=None, orientation_mode=None, **kwargs):
full = Chain.inverse_kinematics(self, target_position, target_orientation, orientation_mode, **kwargs)
active = self.joints_from_links(full)
return active
def joints_from_links(self, joints):
return np.compress(self.all_joints, joints, axis=0)
kinematics.py
import numpy as np
from mujoco_robots.utils import Wam4IK
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
# from juggling_wams.envs import SingleArmOneBall
from mujoco_robots.robots import MjWam4
def plot_joints(chain, qs):
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d', facecolor="1.0")
for pos in qs:
chain.plot([0, 0] + pos + [0, 0, 0], ax)
plt.xlabel('x')
plt.ylabel('y')
plt.show()
def main():
chain = Wam4IK(base_translation=[0, 0, 0.84],
base_orientation=[0, 0, np.pi / 2])
links = ['wam/links/base',
'wam/links/shoulder_yaw',
'wam/links/shoulder_pitch',
'wam/links/upper_arm',
'wam/links/forearm',
'wam/links/tool_base_wo_plate',
'wam/links/tool_base_w_plate']
x0 = np.array([0, 0, 0.84])
q_test = [[0, 0, 0, 0], [1, 1, 1, 1]]
robot = MjWam4(render=True, g_comp=True)
for q in q_test:
print(f'\n\ntesting for q={q}')
robot.reset(pos=q)
cart = chain.forward_kinematics([0, 0] + q + [0, 0, 0], full_kinematics=True)
for i in range(7):
print(f'\n{links[i][10:]}')
mj_pos = robot.get_body_full_mat(links[i])[:3, 3] - x0
ikpy_pos = cart[i + 1][:3, 3] - x0
print(f'mj: {mj_pos}')
print(f'ikpy: {ikpy_pos}')
print(f'diff: {mj_pos - ikpy_pos}')
plot_joints(chain, q_test)
# inverse kinematics
x_des = [0.15, 0.86, 1.45]
q = chain.active_from_full(chain.inverse_kinematics(x_des))
robot.set_mocap_pos('endeff_des', x_des)
robot.step(des_pos=q, n_steps=5000)
if __name__ == '__main__':
main()
我认为我的环境设置和其他Python文件没有问题。我认为应该在这两个文件中发生问题。如果您想查看其他文件,我会尽快上传它们。谢谢!
I am trying to use IKPy Library(v3.3.3) with Python 3.8 to program some demos for my robot arm on the Mujoco platform. However, When I try to do the Kinematic demo, there is something wrong that happened as below.
enter image description here
Here is my project code below:
utils.py
from mujoco_py import MjViewer
import glfw
import numpy as np
import ikpy
from ikpy.chain import Chain
from ikpy.link import OriginLink, URDFLink
open_viewers = [] # a static list to keep track of all viewers
class MjViewerExtended(MjViewer):
""" An extension of mujoco-py's MjViewer. MjViewerExtended does not
terminate all other viewers and the python interpreter when closeing.
"""
def __init__(self, sim):
glfw.init() # make sure glfw is initialized
super().__init__(sim)
open_viewers.append(self)
def close(self):
""" Closes the viewers glfw window. To open a new one, create a new
instance of MjViewerExtended
"""
# MjViewer only calls glfw.terminate() here killing glfw entierly.
if glfw.window_should_close(self.window):
return
try:
glfw.set_window_should_close(self.window, 1)
glfw.destroy_window(self.window)
except Exception:
pass
open_viewers.remove(self)
if len(open_viewers) == 0:
glfw.terminate()
def key_callback(self, window, key, scancode, action, mods):
if action == glfw.RELEASE and key == glfw.KEY_ESCAPE:
self.close()
else:
super().key_callback(window, key, scancode, action, mods)
class Wam4IK(Chain):
""" A basic kinamatic model of the MjWAM4 """
def __init__(self, tool_orientation=None,
tool_translation=None, # x, y, z
base_orientation=None, # x, y, z
base_translation=None):
if base_translation is None:
base_translation = [0, 0, 0.84]
if base_orientation is None:
base_orientation = [0, 0, np.pi / 2]
if tool_translation is None:
tool_translation = [0, 0, 0]
if tool_orientation is None:
tool_orientation = [0, 0, 0]
links = [OriginLink(),
URDFLink(name="wam/links/base",
translation=base_translation, # translation of frame
origin_orientation=base_orientation, # orientation of frame
rotation=[0, 0, 0]
), # joint axis [0, 0, 0] -> no joint
URDFLink(name="wam/links/shoulder_yaw",
translation=[0, 0, 0.16],
origin_orientation=[0, 0, 0],
rotation=[0, 0, 1]
),
URDFLink(name="wam/links/shoulder_pitch",
translation=[0, 0, 0.186],
origin_orientation=[0, 0, 0],
rotation=[1, 0, 0]
),
URDFLink(name="wam/links/shoulder_roll",
translation=[0, 0, 0],
origin_orientation=[0, 0, 0],
rotation=[0, 0, 1]
),
URDFLink(name="wam/links/upper_arm",
translation=[0, -0.045, 0.550],
origin_orientation=[0, 0, 0],
rotation=[1, 0, 0]
),
URDFLink(name="wam/links/tool_base_wo_plate",
translation=[0, 0.045, 0.350],
origin_orientation=[0, 0, 0],
rotation=[0, 0, 0]
),
URDFLink(name="wam/links/tool_base_w_plate",
translation=[0, 0, 0.008],
origin_orientation=[0, 0, 0],
rotation=[0, 0, 0]
),
URDFLink(name="wam/links/tool",
translation=tool_translation,
origin_orientation=tool_orientation,
rotation=[0, 0, 0]
)
]
self.all_joints = [False, False, True, True, True, True, False, False, False]
self.active_joints = list(map(lambda x: x == 1, active_joints))
self.active_links = [False, False, *self.active_joints, False, False, False]
Chain.__init__(self, name='wam4',
active_links_mask=self.active_links,
links=links)
def fk(self, joints, full_kinematics=False):
joints = np.array([0, 0, *joints, 0, 0, 0])
return Chain.forward_kinematics(self, joints, full_kinematics)
def ik(self, target_position=None, target_orientation=None, orientation_mode=None, **kwargs):
full = Chain.inverse_kinematics(self, target_position, target_orientation, orientation_mode, **kwargs)
active = self.joints_from_links(full)
return active
def joints_from_links(self, joints):
return np.compress(self.all_joints, joints, axis=0)
kinematics.py
import numpy as np
from mujoco_robots.utils import Wam4IK
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
# from juggling_wams.envs import SingleArmOneBall
from mujoco_robots.robots import MjWam4
def plot_joints(chain, qs):
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d', facecolor="1.0")
for pos in qs:
chain.plot([0, 0] + pos + [0, 0, 0], ax)
plt.xlabel('x')
plt.ylabel('y')
plt.show()
def main():
chain = Wam4IK(base_translation=[0, 0, 0.84],
base_orientation=[0, 0, np.pi / 2])
links = ['wam/links/base',
'wam/links/shoulder_yaw',
'wam/links/shoulder_pitch',
'wam/links/upper_arm',
'wam/links/forearm',
'wam/links/tool_base_wo_plate',
'wam/links/tool_base_w_plate']
x0 = np.array([0, 0, 0.84])
q_test = [[0, 0, 0, 0], [1, 1, 1, 1]]
robot = MjWam4(render=True, g_comp=True)
for q in q_test:
print(f'\n\ntesting for q={q}')
robot.reset(pos=q)
cart = chain.forward_kinematics([0, 0] + q + [0, 0, 0], full_kinematics=True)
for i in range(7):
print(f'\n{links[i][10:]}')
mj_pos = robot.get_body_full_mat(links[i])[:3, 3] - x0
ikpy_pos = cart[i + 1][:3, 3] - x0
print(f'mj: {mj_pos}')
print(f'ikpy: {ikpy_pos}')
print(f'diff: {mj_pos - ikpy_pos}')
plot_joints(chain, q_test)
# inverse kinematics
x_des = [0.15, 0.86, 1.45]
q = chain.active_from_full(chain.inverse_kinematics(x_des))
robot.set_mocap_pos('endeff_des', x_des)
robot.step(des_pos=q, n_steps=5000)
if __name__ == '__main__':
main()
I think there is no problem with my environment setting and other python files. The problem I think should be happened in these two files. If you would like to see other files, I would upload them soon. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您打了几个电话:
请确保指定强制性
onect> onect_translation
参数。You made several calls like this:
Please be sure to specify the mandatory
origin_translation
argument.