56 #include <gtest/gtest.h>
63 #include <ompl/geometric/SimpleSetup.h>
68 static const rclcpp::Logger LOGGER = rclcpp::get_logger(
"moveit.ompl_planning.test.test_state_validity_checker");
71 std::ostream&
operator<<(std::ostream& os,
const std::vector<double>& v)
91 SCOPED_TRACE(
"testConstructor");
98 SCOPED_TRACE(
"testJointLimits");
101 auto checker = std::make_shared<ompl_interface::StateValidityChecker>(
planning_context_.get());
111 RCLCPP_DEBUG_STREAM(LOGGER, ompl_state.reals());
115 EXPECT_TRUE(checker->isValid(ompl_state.get()));
121 RCLCPP_DEBUG_STREAM(LOGGER, ompl_state.reals());
123 EXPECT_FALSE(checker->isValid(ompl_state.get()));
129 SCOPED_TRACE(
"testSelfCollision");
132 auto checker = std::make_shared<ompl_interface::StateValidityChecker>(
planning_context_.get());
142 RCLCPP_DEBUG_STREAM(LOGGER, ompl_state.reals());
145 EXPECT_FALSE(checker->isValid(ompl_state.get()));
153 SCOPED_TRACE(
"testPathConstraints");
155 ASSERT_NE(
planning_context_,
nullptr) <<
"Initialize planning context before adding path constraints.";
165 { ee_pose.translation().
x(), ee_pose.translation().y(), ee_pose.translation().z() }, { 0.1, 0.1, 0.1 }));
167 moveit_msgs::msg::MoveItErrorCodes error_code_not_used;
170 auto checker = std::make_shared<ompl_interface::StateValidityChecker>(
planning_context_.get());
178 RCLCPP_DEBUG_STREAM(LOGGER, ompl_state.reals());
180 EXPECT_TRUE(checker->isValid(ompl_state.get()));
184 path_constraints_2.position_constraints.at(0).constraint_region.primitive_poses.at(0).position.z += 0.2;
186 ASSERT_TRUE(
planning_context_->setPathConstraints(path_constraints_2, &error_code_not_used));
192 EXPECT_FALSE(checker->isValid(ompl_state.get()));
206 state_space_ = std::make_shared<ompl_interface::JointModelStateSpace>(space_spec);
212 ASSERT_NE(
state_space_,
nullptr) <<
"Initialize state space before creating the planning context.";
228 std::array<double, 3> dimensions)
230 shape_msgs::msg::SolidPrimitive box;
231 box.type = shape_msgs::msg::SolidPrimitive::BOX;
232 box.dimensions.resize(3);
233 box.dimensions[shape_msgs::msg::SolidPrimitive::BOX_X] = dimensions[0];
234 box.dimensions[shape_msgs::msg::SolidPrimitive::BOX_Y] = dimensions[1];
235 box.dimensions[shape_msgs::msg::SolidPrimitive::BOX_Z] = dimensions[2];
237 geometry_msgs::msg::Pose box_pose;
238 box_pose.position.x = position[0];
239 box_pose.position.y = position[1];
240 box_pose.position.z = position[2];
241 box_pose.orientation.w = 1.0;
243 moveit_msgs::msg::PositionConstraint pc;
246 pc.constraint_region.primitives.push_back(box);
247 pc.constraint_region.primitive_poses.push_back(box_pose);
278 testJointLimits({ 0., -0.785, 0., -2.356, 0., 1.571, 0.785 });
285 testSelfCollision({ 2.31827, -0.169668, 2.5225, -2.98568, -0.36355, 0.808339, 0.0843406 });
292 testPathConstraints({ 0., -0.785, 0., -2.356, 0., 1.571, 0.785 });
314 testJointLimits({ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 });
321 testSelfCollision({ -2.95993, -0.682185, -2.43873, -0.939784, 3.0544, 0.882294 });
327 testPathConstraints({ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 });
333 int main(
int argc,
char** argv)
335 testing::InitGoogleTest(&argc, argv);
336 return RUN_ALL_TESTS();
Generic implementation of the tests that can be executed on different robots.
void setupPlanningContext()
ompl_interface::ModelBasedStateSpacePtr state_space_
void testJointLimits(const std::vector< double > &position_in_limits)
void testSelfCollision(const std::vector< double > &position_in_self_collision)
planning_scene::PlanningScenePtr planning_scene_
moveit_msgs::msg::PositionConstraint createPositionConstraint(std::array< double, 3 > position, std::array< double, 3 > dimensions)
Helper function to create a position constraint.
void testPathConstraints(const std::vector< double > &position_in_joint_limits)
ompl_interface::ModelBasedPlanningContextSpecification planning_context_spec_
ompl_interface::ModelBasedPlanningContextPtr planning_context_
TestStateValidityChecker(const std::string &robot_name, const std::string &group_name)
Representation of a robot's state. This includes position, velocity, acceleration and effort.
void setToDefaultValues()
Set all joints to their default positions. The default position is 0, or if that is not within bounds...
Robot independent test class setup.
moveit::core::RobotStatePtr robot_state_
moveit::core::RobotModelPtr robot_model_
std::string ee_link_name_
LoadTestRobot(const std::string &robot_name, const std::string &group_name)
const moveit::core::JointModelGroup * joint_model_group_
std::string base_link_name_
ModelBasedStateSpacePtr state_space_
og::SimpleSetupPtr ompl_simple_setup_
int main(int argc, char **argv)
std::ostream & operator<<(std::ostream &os, const std::vector< double > &v)
Pretty print std:vectors.
TEST_F(PandaValidity, testConstructor)
constexpr bool VERBOSE
This flag sets the verbosity level for the state validity checker.