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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions moveit_core/robot_state/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ if(BUILD_TESTING)
"${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_BINARY_DIR}/../utils")
endif()

ament_add_gtest(test_attached_body test/attached_body_test.cpp
APPEND_LIBRARY_DIRS ${APPEND_LIBRARY_DIRS})
target_link_libraries(test_attached_body moveit_test_utils moveit_utils
moveit_exceptions moveit_robot_state)

ament_add_gtest(test_robot_state test/robot_state_test.cpp
APPEND_LIBRARY_DIRS "${APPEND_LIBRARY_DIRS}")

Expand Down
133 changes: 133 additions & 0 deletions moveit_core/robot_state/test/attached_body_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*********************************************************************
* Software License Agreement (BSD License)
*
* Copyright (c) 2013, Willow Garage, Inc.
* All rights reserved.
Comment on lines +4 to +5
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

*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Willow Garage nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/

/* Author: Tom Noble */

#include <geometric_shapes/shapes.h>
#include <moveit/robot_state/attached_body.hpp>
#include <moveit/robot_model/robot_model.hpp>
#include <moveit/robot_state/robot_state.hpp>
#include <urdf_parser/urdf_parser.h>
#include <gtest/gtest.h>

class SingleLinkRobot : public ::testing::Test
{
public:
SingleLinkRobot()
{
static const std::string URDF_XML = R"(
<?xml version="1.0" ?>
<robot name="single_link_robot">
<link name="link">
<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

</inertial>
<collision name="my_collision">
<origin rpy="0 0 0" xyz="0 0 0"/>
<geometry>
<box size="1 2 1" />
</geometry>
</collision>
<visual>
<origin rpy="0 0 0" xyz="0.0 0 0"/>
<geometry>
<box size="1 2 1" />
</geometry>
</visual>
</link>
</robot>
)";

static const std::string SRDF_XML = R"xml(
<?xml version="1.0" ?>
<robot name="single_link_robot">
</robot>
)xml";

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);
Comment on lines +80 to +83
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

}

protected:
moveit::core::RobotModelConstPtr robot_model_;
};

class SingleAttachedBody : public SingleLinkRobot
{
public:
SingleAttachedBody()
Comment on lines +90 to +93
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

{
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);
Comment on lines +95 to +115
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

}

protected:
std::shared_ptr<moveit::core::AttachedBody> root_body_;
};

// Verifies that a single body attached to a link works as intended

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.

}

int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Loading