You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to normalize a set of URDF files so that the joint axis always aligns with the z-axis. The conversion is done by changing the joint axis and than adding an addition rotation in the joint origin. When visualizing this in e.g. rviz this seems to be working correctly. However, when I now try to parse the changed URDF to KDL the joint axis is rotated back to the original axis. This is due to the rotation in line 54 of urdf.py: rotational = lambda j,F: kdl.Joint(j.name, F.p, F.M * kdl.Vector(*j.axis), kdl.Joint.RotAxis)
Also, when I compute the inverse dynamics for the normalized urdf I get a different result than with the original urdf. However, when I do the inverse dynamics computation in pyBullet (and use their urdf parser) I get the same result for the two urdfs.
Why is the joint axis rotated when parsing the URDF? Is there a way to get around this so that the joint axes in KDL match the joint axes in the URDF?
Cheers,
Johannes
Example Code
from kdl_parser_py import urdf
import PyKDL as kdl
import numpy as np
import pybullet
def to_kdl_array(a):
a_ = kdl.JntArray(len(a))
for i in range(len(a)):
a_[i] = a[i]
return a_
def from_kdl_array(a):
a_ = []
for i in range(a.rows()):
a_.append(a[i])
return a_
def inv_dyn(chain: kdl.Chain, q: list, qd: list, qdd: list) -> list:
rne_solver = kdl.ChainIdSolver_RNE(chain, kdl.Vector(0, 0, -9.81))
tau = to_kdl_array(len(q) * [0])
rne_solver.CartToJnt(to_kdl_array(q),
to_kdl_array(qd),
to_kdl_array(qdd),
[kdl.Wrench()] * chain.getNrOfSegments(),
tau)
return from_kdl_array(tau)
def rand_config():
q = [np.random.uniform(-2.356, 2.356)]
qd = [np.random.uniform(-5, 5)]
qdd = [np.random.uniform(-3, 3)]
return q, qd, qdd
def main():
urdf_joint_y = './exmpl_joint_y.urdf'
_, tree_joint_y = urdf.treeFromFile(urdf_joint_y)
chain_joint_y = tree_joint_y.getChain('world', 'pole')
urdf_joint_z = './exmpl_joint_z.urdf'
_, tree_joint_z = urdf.treeFromFile(urdf_joint_z)
chain_joint_z = tree_joint_z.getChain('world', 'pole')
print(urdf_joint_y)
for i in range(chain_joint_y.getNrOfSegments()):
s = chain_joint_y.getSegment(i)
j = s.getJoint()
print(s.getName(), '->', j.getName(), '->', j.JointAxis())
print('\n', urdf_joint_z)
for i in range(chain_joint_z.getNrOfSegments()):
s = chain_joint_z.getSegment(i)
j = s.getJoint()
print(s.getName(), '->', j.getName(), '->', j.JointAxis())
q, qd, qdd = rand_config()
print('\n', urdf_joint_y)
print('tau kdl ->', inv_dyn(chain_joint_y, q, qd, qdd))
connect_id = pybullet.connect(pybullet.DIRECT)
id_robot = pybullet.loadURDF(urdf_joint_y, 3*[0.], 3*[0.] + [1.], useFixedBase=True)
pybullet.setGravity(0, 0, -9.81)
print('tau bullet ->', pybullet.calculateInverseDynamics(id_robot, q, qd, qdd))
pybullet.disconnect(connect_id)
print('\n', urdf_joint_z)
print('tau ->', inv_dyn(chain_joint_z, q, qd, qdd))
_ = pybullet.connect(pybullet.DIRECT)
id_robot = pybullet.loadURDF(urdf_joint_z, 3 * [0.], 3 * [0.] + [1.], useFixedBase=True)
pybullet.setGravity(0, 0, -9.81)
print('tau bullet ->', pybullet.calculateInverseDynamics(id_robot, q, qd, qdd))
if __name__ == '__main__':
main()
Hi,
I'm trying to normalize a set of URDF files so that the joint axis always aligns with the z-axis. The conversion is done by changing the joint axis and than adding an addition rotation in the joint origin. When visualizing this in e.g. rviz this seems to be working correctly. However, when I now try to parse the changed URDF to KDL the joint axis is rotated back to the original axis. This is due to the rotation in line 54 of urdf.py:
rotational = lambda j,F: kdl.Joint(j.name, F.p, F.M * kdl.Vector(*j.axis), kdl.Joint.RotAxis)
Also, when I compute the inverse dynamics for the normalized urdf I get a different result than with the original urdf. However, when I do the inverse dynamics computation in pyBullet (and use their urdf parser) I get the same result for the two urdfs.
Why is the joint axis rotated when parsing the URDF? Is there a way to get around this so that the joint axes in KDL match the joint axes in the URDF?
Cheers,
Johannes
Example Code
Original URDF
"Normalized" URDF (joint axis is z)
The text was updated successfully, but these errors were encountered: