what is the right way to inverse a transform in python
I am wondering if you know a better way (less boiler code) that will allow me to inverse a transform msg, in Python. For now I use the following code:
from geometry_msgs.msg import PoseStamped, TransformStamped
from tf import TransformerROS
res = TransformStamped() # creating new transform msg
res.header.stamp = input_transform.header.stamp # same timestamp
res.header.frame_id = input_transform.child_frame_id # inverting frame_id and child_frame_id manualy
res.child_frame_id = input_transform.header.frame_id
transformer = TransformerROS() # using a transformer in order to compute inverse transform
transformer.setTransform(input_transform) # using the input_transform
translation, rotation = transformer.lookupTransform(res.header.frame_id, res.child_frame_id, rospy.Time(0)) # using lookup in order to get the inverse of input transform (here I use input_transform.child_frame_id to input_transform_frame_id
for attr_name, val in zip(['x', 'y', 'z'], translation):
res.transform.translation.__setattr__(attr_name, val)
for attr_name, val in zip(['x', 'y', 'z', 'w'], rotation):
res.transform.rotation.__setattr__(attr_name, val)
what do you think ?
setattr(x, y)
should always be preferred overx.__setattr__(y)