Open MatthijsBurgh opened 3 years ago
ping ;)
@tfoote ping ;)
For me it is unclear why all the to_msg
and from_msg
functions can just return the same message.
I would expect that if I have class A and I want to transform to class B, but there is no direct conversion from A to B, it will use the to_msg
and from_msg
way. So I have to go from A to a msg. Lets call it X. And then convert msg X to class B.
In my mind, msg X has to be ONE type of msg. As a random pair of to_msg
and from_msg
aren't compatible, unless the to_msg
functions outputs a type, which the from_msg
functions accepts. Otherwise AttributeError are doomed to happen IMO.
Maybe I am missing something, please explain.
The first example I sent isn't the best as those datatypes are already messages. So the convert to and from message is an identity transform which is why they return themselves.
For the KDL datatypes you can see a more complex version https://github.com/ros/geometry2/blob/noetic-devel/tf2_kdl/src/tf2_kdl/tf2_kdl.py
The logic is to chain the conversions if they exist via a star topology. Any datatype X trying to go to Y look to apply from_msg<Y>(to_msg(X)
. Thus if X is already a msg it can return itself.
What happens in the following situations?
to_msg
returns a PointStamped
, but the from_msg
can only handle PoseStamped
as input.to_msg
returns a PointStamped
, but Y is a PoseStamped and its from_msg
functions just returns the input msg. Just like https://github.com/ros/geometry2/blob/c73b5939723db078c9bbe18523230ad54f859682/tf2_geometry_msgs/src/tf2_geometry_msgs/tf2_geometry_msgs.py#L43-L471) The registrations are keyed on the datatype. A Vector3Stamped
converter and a PoseStamped
converter will never be chained.
2) Those theto_msg
and from_msg
will not be paired like you said because they have different datatype keys.
The noop returns are required because in python we can't detect what the datatype is so we don't know if the datatype matches the input datatype. So convert
always triggers to_msg
then from_msg
to make the conversion. If either end of that goal is already a message it will be the noop.
Is there any documentation on the convert/transform registration in Python?