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

Feature/adds attached body regression tests #3149

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

Conversation

TSNoble
Copy link
Contributor

@TSNoble TSNoble commented Dec 4, 2024

Description

I'm planning to implement the proposal made in #3060 (hierarchical collision objects). I figured it'd first be useful to add some tests for the existing functionality, check for regressions whilst making the changes, and as a basis to extend with tests checking the correctness of collision object -> collision object transformation calculations.

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • Extend the tutorials / documentation reference
  • Document API changes relevant to the user in the MIGRATION.md notes
  • Create tests, which fail without this PR reference
  • Include a screenshot if changing a GUI
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

@TSNoble
Copy link
Contributor Author

TSNoble commented Dec 4, 2024

The tests are currently segfaulting, with the following output from gtest:

root@2e16105760d5:~/ws_moveit# ./build/moveit_core/robot_state/test_attached_body 
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from SingleAttachedBody
[ RUN      ] SingleAttachedBody.RootBodyHasCorrecAttachedLink
SingleAttachedBody
Stack trace (most recent call last):
#12   Object "", at 0xffffffffffffffff, in 
#11   Object "/root/ws_moveit/build/moveit_core/robot_state/test_attached_body", at 0x55f370fd61e4, in _start
#10   Object "/usr/lib/x86_64-linux-gnu/libc.so.6", at 0x7f8d20cfc28a, in __libc_start_main
#9    Object "/usr/lib/x86_64-linux-gnu/libc.so.6", at 0x7f8d20cfc1c9, in 
#8    Object "/root/ws_moveit/build/moveit_core/robot_state/test_attached_body", at 0x55f370fd5a92, in main
#7    Object "/root/ws_moveit/build/moveit_core/robot_state/test_attached_body", at 0x55f370ffb41e, in testing::UnitTest::Run()
#6    Object "/root/ws_moveit/build/moveit_core/robot_state/test_attached_body", at 0x55f37100ad7b, in testing::internal::UnitTestImpl::RunAllTests()
#5    Object "/root/ws_moveit/build/moveit_core/robot_state/test_attached_body", at 0x55f370ffb236, in testing::TestSuite::Run()
#4    Object "/root/ws_moveit/build/moveit_core/robot_state/test_attached_body", at 0x55f370ffaff4, in testing::TestInfo::Run()
#3    Object "/root/ws_moveit/build/moveit_core/robot_state/test_attached_body", at 0x55f370ffadc0, in testing::Test::Run()
#2    Object "/root/ws_moveit/build/moveit_core/robot_state/test_attached_body", at 0x55f371014990, in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*)
#1    Object "/root/ws_moveit/build/moveit_core/robot_state/test_attached_body", at 0x55f370fda2bb, in SingleAttachedBody::SetUp()
#0    Object "/root/ws_moveit/build/moveit_core/robot_model/libmoveit_robot_model.so.2.12.0", at 0x7f8d21358cc0, in moveit::core::RobotModel::getLinkModel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool*)
Segmentation fault (Address not mapped to object [0x78])
Segmentation fault

It seems to me that the SingleLinkRobot fixture's setup isn't being called. This leads to a segfault when the SingleAttachedBody setup attempts to fetch a link, due to the robot model not yet being initialised.

My knowledge of gtest is a little rusty, but I believe inheriting from a fixture should call the parent's SetUp methods?

@TSNoble
Copy link
Contributor Author

TSNoble commented Dec 4, 2024

Also, I'm not a URDF expert, I'd appreciate any help simplifying it. After making the #3060 changes, I'm planning to mainly test attached body to attached body transforms, and the ability to look up child objects from parents, etc... so ideally the robot should just be the simplest possible example that a body can be attached to.

@TSNoble
Copy link
Contributor Author

TSNoble commented Dec 4, 2024

Adding an explicit call to the parent's SetUp(), and fixing some URDF issues seems to have fixed the issue, though I'm still unsure if this call is necessary

@TSNoble
Copy link
Contributor Author

TSNoble commented Dec 4, 2024

It seems this is just standard C++ behaviour. I wasn't sure if gtest had some magic under the hood for auto calling parent SetUp()s.

I've replaced SetUp() with constructors to get the desired effect.

@sea-bass sea-bass assigned sea-bass and unassigned sea-bass Dec 4, 2024
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.10%. Comparing base (f82cdcd) to head (ed8f0f9).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3149      +/-   ##
==========================================
+ Coverage   45.77%   46.10%   +0.34%     
==========================================
  Files         482      483       +1     
  Lines       40432    40632     +200     
==========================================
+ Hits        18502    18731     +229     
+ Misses      21930    21901      -29     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@sea-bass sea-bass left a comment

Choose a reason for hiding this comment

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

I'm not sure how far along this PR is on the draft vs. non-draft spectrum, but here are some initial suggestions.

Also... THANK YOU for contributing with tests 🤘🏻

Comment on lines +4 to +5
* Copyright (c) 2013, Willow Garage, Inc.
* All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

2024 / your name

Comment on lines +80 to +83
urdf::ModelInterfaceSharedPtr urdf_model = urdf::parseURDF(URDF_XML);
auto srdf_model = std::make_shared<srdf::Model>();
srdf_model->initString(*urdf_model, SRDF_XML);
robot_model_ = std::make_shared<moveit::core::RobotModel>(urdf_model, srdf_model);
Copy link
Contributor

Choose a reason for hiding this comment

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

optional, but you could also consider calling the testing helpers in e.g. moveit_core/utils/src/robot_model_test_utils.cpp

Comment on lines +95 to +115
const moveit::core::LinkModel* link = robot_model_->getLinkModel("link");
std::string name = "root_body";
Eigen::Isometry3d pose;
pose = Eigen::Translation3d(1, 2, 3);
auto box = std::make_shared<shapes::Box>(0.1, 0.2, 0.3);
std::vector<shapes::ShapeConstPtr> shapes = { box };
EigenSTL::vector_Isometry3d shape_poses;
Eigen::Isometry3d shape_pose;
shape_pose = Eigen::Translation3d(4, 5, 6);
shape_poses.push_back(shape_pose);
std::set<std::string> touch_links = { "link" };
trajectory_msgs::msg::JointTrajectory detach_posture;
detach_posture.joint_names.push_back("joint");
trajectory_msgs::msg::JointTrajectoryPoint p;
p.positions.push_back(0.1);
detach_posture.points.push_back(p);
Eigen::Isometry3d subframe_pose;
subframe_pose = Eigen::Translation3d(7, 8, 9);
moveit::core::FixedTransformsMap subframes{ { "subframe", subframe_pose } };
root_body_ = std::make_shared<moveit::core::AttachedBody>(link, name, pose, shapes, shape_poses, touch_links,
detach_posture, subframes);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a really compact block of code, consider splitting it up to make it a bit more readable

Comment on lines +90 to +93
class SingleAttachedBody : public SingleLinkRobot
{
public:
SingleAttachedBody()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want this to be a subclass of the above test fixture, or just have it be a single test?

like, I can imagine all this code could be part of the body of TEST_F(SingleAttachedBody, RootBodyHasCorrecAttachedLink), and any repetitive code as you add more tests can be a helper function / method of the original fixture.

This would

  • Save you the extra layer of inheritance
  • Make the test not just be a one liner

<inertial>
<mass value="2.81"/>
<origin rpy="0 0 0" xyz="0.0 0.0 .0"/>
<inertia ixx="0.1" ixy="-0.2" ixz="0.5" iyy="-.09" iyz="1" izz="0.101"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I will forever suggest leading zeros on all decimals. so -.09 -> -0.09


TEST_F(SingleAttachedBody, RootBodyHasCorrecAttachedLink)
{
ASSERT_EQ(root_body_->getName(), "root_body");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this test try to actually attach root_body_ to the robot model, and then do some lookups on the robot model to verify that the information propagated correctly?

Looking at the code base, seems like we want to

  • Get a robot state from the robot model
  • Call RobotState::attachBody
  • Call RobotState::getAttachedBodies and grab the info
  • Clear the bodies with RobotState::clearAttachedBody
  • Verify again the object is gone, etc.

@rr-tom-noble
Copy link
Contributor

Thanks @sea-bass for the comments. Will take a better look at them after work today. This PR is still very much in the early stages, just wanted to get a simple test passing and go from there. Raised as a regular PR to demonstrate the segfault I was getting in the workflow, but since that's fixed now (and I can run the tests pretty easy locally) I'm happy to move it to a draft.

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.

4 participants