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

Pose with covariance display #76

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

Thodoris1999
Copy link
Contributor

@Thodoris1999 Thodoris1999 commented Apr 18, 2022

🎉 New feature

PoseWithCovariance display, largely inspired by the original implementation in RViz

More info in this post https://community.gazebosim.org/t/gsoc-2022-potential-project-ideas/1339/4

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

@osrf-triage
Copy link

This pull request has been mentioned on Gazebo Community. There might be relevant details there:

https://community.gazebosim.org/t/gsoc-2022-potential-project-ideas/1339/4

@Thodoris1999 Thodoris1999 force-pushed the pose_with_covariance_display branch from fe14391 to d03e221 Compare April 18, 2022 17:19
Copy link
Collaborator

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

There is some commits from this other PR #75 can you clean the history ?

@Thodoris1999
Copy link
Contributor Author

Can you help me with how to remove those changes from history? I haven't done this before and don't want to accidentally mess anything up.

@Thodoris1999 Thodoris1999 force-pushed the pose_with_covariance_display branch from d03e221 to e7b5a07 Compare April 21, 2022 14:12
@Thodoris1999
Copy link
Contributor Author

@ahcorde I dropped the "Add fortress support" commit with rebase

@Thodoris1999 Thodoris1999 requested a review from ahcorde April 21, 2022 14:15
Copy link
Collaborator

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

Thank you, for this contribution! Some notes:

  • Use 100 characters per line
    • Run linters colcon test you might find a lot of linters errors
  • Use the same style in the variable names. Camelcase and _camelCase in arguments
  • Use ign-math instead of Eigen
  • Use PIMPL
  • Implement methods in the cpp

Comment on lines 18 to 19
#include <ignition/rendering.hh>
#include <ignition/math.hh>
Copy link
Collaborator

Choose a reason for hiding this comment

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

alphabetize

/**
* @brief Visualizes the covariance of a pose (orientation+position) using 2D and 3D ellipses
*
* One 3D ellipsoid indicates position covariance and 3 2D ellipsoids indicate the uncertainty of orientation along rotation at each axis.
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should use lines of 100 characters

*/
void updateVisual()
{
for (int i = 0; i < 3; ++i) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why 3 here? Use a constant

Comment on lines 56 to 59
float shaftLength = 1.0;
float shaftRadius = 0.05;
float headLength = 0.25;
float headRadius = 0.1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
float shaftLength = 1.0;
float shaftRadius = 0.05;
float headLength = 0.25;
float headRadius = 0.1;
float shaftLength = 1.0f;
float shaftRadius = 0.05f;
float headLength = 0.25f;
float headRadius = 0.1f;

Comment on lines 79 to 80
float length = 1.0;
float radius = 0.1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
float length = 1.0;
float radius = 0.1;
float length = 1.0f;
float radius = 0.1f;

void update() override;

private:
ignition::rendering::RenderEngine * engine;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use PIMPL. Use IGN_UTILS_IMPL_PTR from #include <ignition/utils/ImplPtr.hh>

@@ -42,11 +42,15 @@
<qresource prefix="PoseDisplay/">
<file alias="PoseDisplay.qml">qml/PoseDisplay.qml</file>
</qresource>

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

@@ -0,0 +1,713 @@
/*
* Copyright (C) 2020 Open Source Robotics Foundation
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Copyright (C) 2020 Open Source Robotics Foundation
* Copyright (C) 2022 Open Source Robotics Foundation

Comment on lines 20 to 23
double deg2rad(double degrees)
{
return degrees * 3.14159265358979 / 180.0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove this and use IGN_RTOD and IGN_DTOR from ign-math. Angle class defines them

}

// Local function to force the axis to be right handed for 3D. Taken from ecl_statistics
void makeRightHanded(Eigen::Matrix3d & eigenvectors, Eigen::Vector3d & eigenvalues)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you do this math with ign-math ? I would perfer not to add Eigen as a dependency

If there is something not in the API we might consider to add it there

@Thodoris1999
Copy link
Contributor Author

Thodoris1999 commented Apr 22, 2022

Thank you for the review! I will get to the changes soon.

As for the math, I used Eigen to be on a safe side with performance. I use diagonalization, which is very optimized in Eigen with a LAPACK implementation that takes advantage of the symmetric covariance https://eigen.tuxfamily.org/dox-devel/classEigen_1_1SelfAdjointEigenSolver.html#a110f7f5ff19fcabe6a10c6d48d5c419c. MassMatrix uses a diagonalization implementation https://github.com/ignitionrobotics/ign-math/blob/c08c659229777e32d684841aea8fdcc1bdc57c4f/include/ignition/math/MassMatrix3.hh#L646 for calculating the principal axes with ign-math but uses two separate functions for eigenvalues and eigenvectors. Maybe those two implementation could be merged into one and extracted to an outside function that takes a Matrix3 and returns the right-handed diagonalization.

@Thodoris1999
Copy link
Contributor Author

Thodoris1999 commented Apr 22, 2022

@ahcorde Sorry to bother, but I am having some issues using PIMPL with utils::MakeImpl<Implementation>() in the last commit I pushed, apparently somewhere there is an unwanted copy construction. Do these compiler errors maybe ring a bell to you?

--- stderr: ign_rviz_plugins
In file included from /home/thodoris/src/ignition/install/include/ignition/utils1/ignition/utils/ImplPtr.hh:24,
                 from /home/thodoris/src/ignition/install/include/ignition/common4/ignition/common/Pbr.hh:22,
                 from /home/thodoris/src/ignition/install/include/ignition/common4/ignition/common/Material.hh:27,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering/Scene.hh:24,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering/base/BaseArrowVisual.hh:21,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering.hh:23,
                 from /home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/include/ignition/rviz/plugins/PoseWithCovarianceDisplay.hpp:18,
                 from /home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/src/rviz/plugins/PoseWithCovarianceDisplay.cpp:15:
/home/thodoris/src/ignition/install/include/ignition/utils1/ignition/utils/detail/DefaultOps.hh: In instantiation of ‘T* ignition::utils::detail::DefaultCopyConstruct(const T&) [with T = ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation]’:
/home/thodoris/src/ignition/install/include/ignition/utils1/ignition/utils/detail/ImplPtr.hh:135:21:   required from ‘ignition::utils::ImplPtr<T> ignition::utils::MakeImpl(Args&& ...) [with T = ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation; Args = {}]’
/home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/src/rviz/plugins/PoseWithCovarianceDisplay.cpp:68:61:   required from here
/home/thodoris/src/ignition/install/include/ignition/utils1/ignition/utils/detail/DefaultOps.hh:56:16: error: use of deleted function ‘ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation::Implementation(const ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation&)’
   56 |         return new T(_source);
      |                ^~~~~~~~~~~~~~
/home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/src/rviz/plugins/PoseWithCovarianceDisplay.cpp:50:34: note: ‘ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation::Implementation(const ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation&)’ is implicitly deleted because the default definition would be ill-formed:
   50 | class PoseWithCovarianceDisplay::Implementation
      |                                  ^~~~~~~~~~~~~~
/home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/src/rviz/plugins/PoseWithCovarianceDisplay.cpp:50:34: error: use of deleted function ‘std::mutex::mutex(const std::mutex&)’
In file included from /usr/include/c++/9/condition_variable:39,
                 from /usr/include/c++/9/shared_mutex:37,
                 from /usr/include/c++/9/memory_resource:41,
                 from /usr/include/c++/9/regex:66,
                 from /home/thodoris/src/ignition/install/include/ignition/math6/ignition/math/Helpers.hh:27,
                 from /home/thodoris/src/ignition/install/include/ignition/math6/ignition/math/AxisAlignedBox.hh:23,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering/Visual.hh:22,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering/CompositeVisual.hh:21,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering/ArrowVisual.hh:21,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering/base/BaseArrowVisual.hh:20,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering.hh:23,
                 from /home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/include/ignition/rviz/plugins/PoseWithCovarianceDisplay.hpp:18,
                 from /home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/src/rviz/plugins/PoseWithCovarianceDisplay.cpp:15:
/usr/include/c++/9/bits/std_mutex.h:94:5: note: declared here
   94 |     mutex(const mutex&) = delete;
      |     ^~~~~
In file included from /home/thodoris/src/ignition/install/include/ignition/utils1/ignition/utils/ImplPtr.hh:24,
                 from /home/thodoris/src/ignition/install/include/ignition/common4/ignition/common/Pbr.hh:22,
                 from /home/thodoris/src/ignition/install/include/ignition/common4/ignition/common/Material.hh:27,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering/Scene.hh:24,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering/base/BaseArrowVisual.hh:21,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering.hh:23,
                 from /home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/include/ignition/rviz/plugins/PoseWithCovarianceDisplay.hpp:18,
                 from /home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/src/rviz/plugins/PoseWithCovarianceDisplay.cpp:15:
/home/thodoris/src/ignition/install/include/ignition/utils1/ignition/utils/detail/DefaultOps.hh: In instantiation of ‘void ignition::utils::detail::DefaultCopyAssign(T&, const T&) [with T = ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation]’:
/home/thodoris/src/ignition/install/include/ignition/utils1/ignition/utils/detail/ImplPtr.hh:135:21:   required from ‘ignition::utils::ImplPtr<T> ignition::utils::MakeImpl(Args&& ...) [with T = ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation; Args = {}]’
/home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/src/rviz/plugins/PoseWithCovarianceDisplay.cpp:68:61:   required from here
/home/thodoris/src/ignition/install/include/ignition/utils1/ignition/utils/detail/DefaultOps.hh:64:15: error: use of deleted function ‘ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation& ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation::operator=(const ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation&)’
   64 |         _dest = _source;
      |         ~~~~~~^~~~~~~~~
/home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/src/rviz/plugins/PoseWithCovarianceDisplay.cpp:50:34: note: ‘ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation& ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation::operator=(const ignition::rviz::plugins::PoseWithCovarianceDisplay::Implementation&)’ is implicitly deleted because the default definition would be ill-formed:
   50 | class PoseWithCovarianceDisplay::Implementation
      |                                  ^~~~~~~~~~~~~~
/home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/src/rviz/plugins/PoseWithCovarianceDisplay.cpp:50:34: error: use of deleted function ‘std::mutex& std::mutex::operator=(const std::mutex&)’
In file included from /usr/include/c++/9/condition_variable:39,
                 from /usr/include/c++/9/shared_mutex:37,
                 from /usr/include/c++/9/memory_resource:41,
                 from /usr/include/c++/9/regex:66,
                 from /home/thodoris/src/ignition/install/include/ignition/math6/ignition/math/Helpers.hh:27,
                 from /home/thodoris/src/ignition/install/include/ignition/math6/ignition/math/AxisAlignedBox.hh:23,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering/Visual.hh:22,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering/CompositeVisual.hh:21,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering/ArrowVisual.hh:21,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering/base/BaseArrowVisual.hh:20,
                 from /home/thodoris/src/ignition/install/include/ignition/rendering5/ignition/rendering.hh:23,
                 from /home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/include/ignition/rviz/plugins/PoseWithCovarianceDisplay.hpp:18,
                 from /home/thodoris/src/ignition/src/ign-rviz/ign_rviz_plugins/src/rviz/plugins/PoseWithCovarianceDisplay.cpp:15:
/usr/include/c++/9/bits/std_mutex.h:95:12: note: declared here
   95 |     mutex& operator=(const mutex&) = delete;
      |            ^~~~~~~~
make[2]: *** [CMakeFiles/PoseWithCovarianceDisplay.dir/build.make:97: CMakeFiles/PoseWithCovarianceDisplay.dir/src/rviz/plugins/PoseWithCovarianceDisplay.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:178: CMakeFiles/PoseWithCovarianceDisplay.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
---
Failed   <<< ign_rviz_plugins [11.3s, exited with code 2]

Copy link
Collaborator

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

Merge with main and review the conflicts

Thodoris1999 and others added 3 commits April 25, 2022 20:46
Signed-off-by: Theodoros Tyrovouzis <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Co-authored-by: Theodoros Tyrovouzis <[email protected]>
@Thodoris1999 Thodoris1999 force-pushed the pose_with_covariance_display branch from 68eddd2 to e829ee7 Compare April 25, 2022 17:55
@Thodoris1999
Copy link
Contributor Author

@ahcorde Did the merge

By the way, the error I sent above was due to std::mutex not being copy-assignable. We can wrap it with std::shared_ptr and that fixes it, but I am not sure if it's the cleanest solution. Shouldn't the PoseWithCovariance::Implementation not be copy-assigned in the first place?

Signed-off-by: Theodoros Tyrovouzis <[email protected]>
Signed-off-by: Theodoros Tyrovouzis <[email protected]>
…doris1999/ign-rviz into pose_with_covariance_display

Signed-off-by: Theodoros Tyrovouzis <[email protected]>
@Thodoris1999 Thodoris1999 force-pushed the pose_with_covariance_display branch from 79f97eb to 65e4d6a Compare May 9, 2022 16:14
@Thodoris1999
Copy link
Contributor Author

Hi, I came back after catching up to school work.
I ended up using a shared pointer for the mutex.

I tried to address the linter warnings:

  • cpplint erroneously considers ROS distribution includes (messages, TF etc) as C system dependencies and complains that they should be included before C++ system includes. I guess these warnings were ignored since they exist for the entire source code.
  • cpplint and uncrustify seem to conflict in the following piece of code:
if (user_data_.position_frame == Frame::Local &&
    fixed_orientation_visual_->HasChild(position_root_visual_)) {
    this->root_visual_->AddChild(fixed_orientation_visual_->RemoveChild(position_root_visual_));
} else if (user_data_.position_frame == Frame::Fixed &&
    root_visual_->HasChild(position_root_visual_)) {
    fixed_orientation_visual_->AddChild(this->root_visual_->RemoveChild(position_root_visual_));
}
if (user_data_.orientation_frame == Frame::Local &&
    fixed_orientation_visual_->HasChild(orientation_root_visual_)) {
    this->root_visual_->AddChild(fixed_orientation_visual_->RemoveChild(orientation_root_visual_));
} else if (user_data_.orientation_frame == Frame::Fixed &&
    root_visual_->HasChild(orientation_root_visual_)) {
    fixed_orientation_visual_->AddChild(this->root_visual_->RemoveChild(orientation_root_visual_));
}

uncrustify wants the else if's opening brackets to be placed on the next line, while cpplint wants "else statements have one bracket on the same line they should have both". Is there a way to fix this?

  • The rest of the errors where fixed.

Finally, there seems to be a DCO error:

Summary

Commit sha: [b7f3ef7](https://github.com/gazebosim/gz-rviz/pull/76/commits/b7f3ef7a1d71d4d8883709946d5e8f1e80da9e6b), Author: Alejandro Hernández Cordero, Committer: Theodoros Tyrovouzis; Expected "Alejandro Hernández Cordero [[email protected]](mailto:[email protected])", but got "ahcorde [[email protected]](mailto:[email protected])".

@Thodoris1999 Thodoris1999 requested a review from ahcorde May 9, 2022 16:35
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.

3 participants