Packages for common geometric calculations including the ROS transform library, "tf". Also includes ROS bindings for "bullet" physics engine and "kdl" kinematics/dynamics package.
175
stars
275
forks
source link
Using tf.transformations quaternion_from_euler with numpy array arguments can silently change the input arguments! #238
import numpy as np
from tf.transformations import quaternion_from_euler
angles = np.array([[0], [0], [1.0]])
print(angles[2], type(angles[2])) # prints [ 1. ], <type 'numpy.ndarray'>
q = quaternion_from_euler(0, 0, angles[2])
print(angles[2]) # prints [ 0.5 ], <type 'numpy.ndarray'>
The problem is that 1-element arrays behave like scalars, so the function works, however, different from scalars, they are passed to functions as reference as opposed to by value.
This code in
quaternion_from_euler
is actually dangerous when called with 1-D 1-element numpy arrays on input:https://github.com/ros/geometry/blob/63c3c7b404b8f390061bdadc5bc675e7ae5808be/tf/src/tf/transformations.py#L1100-L1128
E.g.
The problem is that 1-element arrays behave like scalars, so the function works, however, different from scalars, they are passed to functions as reference as opposed to by value.