Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix odometry msgs with child frame other than baseLink #728

Merged
merged 5 commits into from
Apr 25, 2022

Conversation

frygge
Copy link

@frygge frygge commented Feb 17, 2022

This PR addresses #726

It fixes the bug that ignores the child frame of odometry messages. This is relevant for processing odometry messages in differential mode (since there, it computes the differential in the child frame, hence it needs to know its name) and odometry poses in relative mode.

Copy link
Collaborator

@SteveMacenski SteveMacenski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ayrton04
Copy link
Collaborator

Moving the conversation from #726 over here.

First, thank you for the PR and the conversation in the original ticket.

I get what you're attempting to do here (and it's clever), but I can't help feeling that we're abusing the frame IDs in messages a bit. It also changes the filter behaviour: if you enable differential mode on a nav_msgs/Odometry input but your child_frame_id is filled out, it will always use that. I'm trying to determine if that will be a problem.

Moreover, anyone who has their transform tree set up such that the frame_id of the nav_msgs/Odometry input is set to the sensor's frame could see a change in behaviour.

Having said that, I like having this as a solution to pose data being measured from a sensor that is onboard the vehicle and reported in a frame that does not align with the robot's world frame.

I wonder if it makes sense to gate the behaviour behind a parameter that is only relevant for nav_msgs/Odometry inputs? Something like differential_use_child_frame or something?

Just for my own curiosity, what happens if you don't use your code change, but change the frame_id of your message to be alb_sensor_frame? Technically, the data from your sensor is not reported in the odom frame, but if we're not using it directly, it doesn't matter.

@SteveMacenski
Copy link
Collaborator

I think adding a parameter would be a reasonable move given what you describe above on differential mode.

@frygge
Copy link
Author

frygge commented Feb 23, 2022

Sorry for the delay. I agree with you both, There might be use cases that break with this patch; thus, a gating parameter is a good approach.

Since the PR solves a similar problem with relative enabled, I'd rather propose a parameter name such as pose_from_child_frame, pose_use_child_frame, diff_rel_use_child_frame, or something alike. What do you think?

@ayrton04 I changed the header.frame_id to alb_sensor_frame in the bag file with a short python script. The differential use case did not show any changes (it's still going sideways). The relative use case now does not work at all since it can't find the transformation between alb_sensor_frame and odom.

@ayrton04
Copy link
Collaborator

Never apologise to me for taking a long time to respond! I am notorious for it here.

I am really happy about this PR, as it enables the package to support a use case that it didn't support previously. I like diff_rel_use_child_frame the most. Naming parameters with very specific purposes is hard.

In any case, thank you for the PR!

@ayrton04
Copy link
Collaborator

ayrton04 commented Mar 2, 2022

Zero rush, just checking in on this. Will you be willing/able to add the parameter in question?

@frygge
Copy link
Author

frygge commented Mar 3, 2022

Yes, sure. I'm happy to finish it as we agreed. I just have an urgent paper deadline ahead for next week monday :)

@frygge
Copy link
Author

frygge commented Mar 8, 2022

Aiming at writing easy-to-read code for better maintainability, I could set the child_frame parameter in the pose-callback functions, i. e.

  • on geometry_msgs::PoseWithCovarianceStamped, the callback passes the child frame baseLinkFrameId_ (as it was before)
  • on sensor_msgs::Imu, the callback passes the child frame baseLinkFrameId_ (as it was before; only relevant if differential is enabled since there is a imuData flag also passed through, which changes the logic)
  • on nav_msgs::Odometry, the callback either passes the child frame baseLinkFrameId_ or header.child_frame_id depending on a parameter.

The last point yields that the newly introduced parameter also changes the child frame without enabling differential or relative. It seems to me that this is a) the easier implementation and b) a more consistent implementation. In that case, I would suggest a parameter odomN_pose_uses_child_frame, which also is easier to read while precisely describing what it does.

Implementing the new behavior only for differential and relative odometry messages includes a lot of if-else conditions, which makes the code much harder to read and maintain.

What do you think about this?

@frygge
Copy link
Author

frygge commented Mar 9, 2022

I implemented the proposal and compared the behavior with the parameter enabled and disabled.

  • with odom0_diff_rel_use_child_frame=False, everything looks as without the patch
  • with odom0_diff_rel_use_child_frame=True, the new feature looks just fine

I found a bug in my previous implementation: it always interpreted the pose from child_frame_id to header.frame when differential and relative was disabled, which could break certain use cases. With the way of gating the behavior as described in the previous post, this bug is fixed.

Now, the parameter odomN_pose_uses_child_frame (or something alike) makes even more sense than diff_rel_use_child_frame. I'd change that if you'd agree.

@frygge
Copy link
Author

frygge commented Mar 21, 2022

FYI: I posted a related question on stackoverflow regarding the interpretation of the child_frame. No one seems to know the answer. So I took the freedom to link this pull request there since it basically creates the answer "You're free to choose." :)

Copy link
Collaborator

@ayrton04 ayrton04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Just a couple things I want to iron out.

src/ros_filter.cpp Show resolved Hide resolved
include/robot_localization/ros_filter.h Outdated Show resolved Hide resolved
src/ros_filter.cpp Outdated Show resolved Hide resolved
@frygge
Copy link
Author

frygge commented Apr 12, 2022

The debian based pipeline failed with the following error message:

08:27:52 time="2022-04-12T06:30:47Z" level=error msg="error waiting for container: unexpected EOF"

This seems to be no bug related to this PR. Can you look into it or maybe just restart this particular pipeline?

@ayrton04
Copy link
Collaborator

We don't have the ability to restart jobs on the ROS build farm. It would likely just get kicked off again in a bit, but we can force its hand by just closing and re-opening your PR.

@ayrton04 ayrton04 closed this Apr 12, 2022
@ayrton04 ayrton04 reopened this Apr 12, 2022
@ayrton04
Copy link
Collaborator

OK, merging this. I don't suppose you have a ROS 2 workspace? It would be good to get this change in there. I can also manually pull the change over.

@ayrton04 ayrton04 merged commit 87b8d6b into cra-ros-pkg:noetic-devel Apr 25, 2022
@ayrton04
Copy link
Collaborator

Thank you for the PR!

@frygge
Copy link
Author

frygge commented Apr 26, 2022

Unfortunately, I don't yet.

Thanks a lot to you as well. We're happy to use the software in our cars :)

@HaoguangYang
Copy link
Contributor

OK, merging this. I don't suppose you have a ROS 2 workspace? It would be good to get this change in there. I can also manually pull the change over.

I would be happy to port this over to ros2 branches as well.

@roncapat
Copy link

Any news on a ros2 port?

@HaoguangYang
Copy link
Contributor

Any news on a ros2 port?

Actually, I do have a compiling version but I got side-tracked by other projects recently. I will test my modifications when I have time and keep you posted.

HaoguangYang added a commit to HaoguangYang/robot_localization that referenced this pull request Jun 19, 2022
@Timple Timple mentioned this pull request Jul 26, 2022
ayrton04 pushed a commit that referenced this pull request Aug 3, 2022
* compiling version of commit #753 and #728 ported to ros2 rolling

* format fixes

* fix time source disagreement by converting to seconds beforehand, append parameter usage, fix linting

* fix linting and uncrustify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants