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

Transform message in differential mode #216

Conversation

efernandez
Copy link
Collaborator

This is important because the relative transformation is not the same if the sensor and target frame are different.

Consider for example the case of an IMU sensor upside down:

  • The robot base frame is base_link
  • The IMU sensor frame is imu_link
  • The imu_link transformation wrt base_link is 180 degrees wrt the y or x axis
  • The angular velocity around the z axis has opposite sign in the sensor frame wrt the target frame

This only impacts the Imu2D, Pose2D and Odometry2D sensor models. The changes are similar for each, but with some differences. For this reason I've refrained from trying to factorize things out somehow. TBH it doesn't look trivial and probably not worth it, but at the same time I think there are too many if-else blocks and indentation levels. Any thoughts?

I'd be happy to make the implementation of this logic cleaner/simpler. 😃

For now I advise you to hide the whitespace changes when you inspect the changes.

This is important because the relative transformation is not the same if
the sensor and target frame are different.

Consider for example the case of an IMU sensor upside down:
* The robot base frame is base_link
* The IMU sensor frame is imu_link
* The imu_link transformation wrt base_link is 180 degrees wrt the y or
  x axis
* The angular velocity around the z axis has opposite sign in the
  sensor frame wrt the target frame
@efernandez efernandez requested review from ayrton04 and svwilliams and removed request for ayrton04 December 8, 2020 12:36
@efernandez efernandez self-assigned this Dec 8, 2020
@efernandez efernandez added the bug Something isn't working label Dec 8, 2020
@efernandez
Copy link
Collaborator Author

What's the error in the CI checks, please? I can't reproduce it offline.

@efernandez efernandez mentioned this pull request Dec 8, 2020
@efernandez
Copy link
Collaborator Author

Still don't know why the checks failed on this one. They passed on #217 , which is on top of this one. Maybe the CI test job should be re-kicked. 🤔

@svwilliams
Copy link
Contributor

The build error is:

C++ exception with description "Could not find required parameter pose_target_frame in namespace /Optimizer/wheel_odometry" thrown in the test body.

from here: https://github.com/locusrobotics/fuse/blob/devel/fuse_optimizers/test/test_optimizer.cpp#L49

This PR makes the "pose_target_frame" parameter required for the Odometry2D sensor. Previously it was not required when in differential mode. The configuration for the above test was not updated to include that required parameter:
https://github.com/locusrobotics/fuse/blob/devel/fuse_optimizers/test/config/struct/common_robot_config.yaml#L28-L33

@efernandez
Copy link
Collaborator Author

Thanks, that makes sense. Fixed.

Copy link
Contributor

@svwilliams svwilliams left a comment

Choose a reason for hiding this comment

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

I think there are too many if-else blocks and indentation levels

The only thing that's coming to mind is factoring out some of the if-else blocks into a separate function. For example, in imu_2d.cpp, if all of the differential logic was contained inside a function call, then you would end up with a pleasing:

  if (params_.differential)
  {
    some_new_function(probably, with, lots, of, parameters);
  }
  else
  {
    common::processAbsolutePoseWithCovariance(
      name(),
      device_id_,
      *pose,
      params_.pose_loss,
      params_.orientation_target_frame,
      {},
      params_.orientation_indices,
      tf_buffer_,
      validate,
      *transaction);
  }

Mostly that function call would just be moving/hiding the nesting levels. But it would allow you to exit early if needed.

void some_new_function(probably, with, lots, of, parameters)
{
  if (!common::transformMessage(tf_buffer_, *pose, *transformed_pose))
  {
    ROS_ERROR_STREAM("Cannot transform pose message with stamp "
      << pose->header.stamp << " to orientation target frame "
      <<  params_.orientation_target_frame);
    return;
  }
  if (!previous_pose_)
  {
    previous_pose_ = std::move(transformed_pose);
    return;
  }
  if (params_.use_twist_covariance)
  {
    // Do real work here
  }
  else
  {
    // Do other real work here
  }

To be very clear, I'm not requesting you do this as part of this PR. I'm happy enough as-is. But you did ask.

@efernandez
Copy link
Collaborator Author

efernandez commented Dec 11, 2020

Yes, I agree it'd look simpler and cleaner moving things a helper function.

Since both this and #217 are approved, I'll make that refactoring change on another PR. 😃

@svwilliams svwilliams merged commit 8c37388 into locusrobotics:devel Dec 11, 2020
@efernandez efernandez deleted the tansform-message-in-differential-mode branch December 15, 2020 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

None yet

3 participants