43#include <gtest/gtest.h>
51#include <ompl/geometric/SimpleSetup.h>
52#include <ompl/base/Constraint.h>
53#include <ompl/base/ConstrainedSpaceInformation.h>
54#include <ompl/base/spaces/constraint/ProjectedStateSpace.h>
61 return moveit::getLogger(
"moveit.planners.ompl.test_constrained_state_validity_checker");
65std::ostream&
operator<<(std::ostream& os,
const std::vector<double>& v)
78 DummyConstraint(
const unsigned int num_dofs) : ompl::base::Constraint(num_dofs, 1)
81 void function(
const Eigen::Ref<const Eigen::VectorXd>& , Eigen::Ref<Eigen::VectorXd> out)
const override
100 SCOPED_TRACE(
"testEqualityPositionConstraints");
106 SCOPED_TRACE(
"testJointLimits");
109 auto checker = std::make_shared<ompl_interface::ConstrainedPlanningStateValidityChecker>(
planning_context_.get());
118 auto state = ompl_state->as<ompl::base::ConstrainedStateSpace::StateType>()
127 bool result = checker->isValid(ompl_state.get());
131 double distance = 0.0;
132 result = checker->isValid(ompl_state.get(), distance);
134 RCLCPP_DEBUG(
getLogger(),
"Distance from the isValid function '%f': ", distance);
136 EXPECT_GT(distance, 0.0);
139 state->values[0] = std::numeric_limits<double>::max();
140 state->clearKnownInformation();
145 bool result_2 = checker->isValid(ompl_state.get());
146 EXPECT_FALSE(result_2);
149 double distance_2 = 0.0;
150 result_2 = checker->isValid(ompl_state.get(), distance_2);
151 EXPECT_FALSE(result_2);
153 EXPECT_EQ(distance_2, 0.0);
158 SCOPED_TRACE(
"testSelfCollision");
161 auto checker = std::make_shared<ompl_interface::ConstrainedPlanningStateValidityChecker>(
planning_context_.get());
172 auto state = ompl_state->as<ompl::base::ConstrainedStateSpace::StateType>()
182 bool result = checker->isValid(ompl_state.get());
183 EXPECT_FALSE(result);
186 double distance = 0.0;
187 result = checker->isValid(ompl_state.get(), distance);
188 EXPECT_FALSE(result);
192 EXPECT_TRUE(result_2);
215 state_space_ = std::make_shared<ompl_interface::ConstrainedPlanningStateSpace>(space_spec);
218 auto dummy_constraint = std::make_shared<DummyConstraint>(
num_dofs_);
224 ASSERT_NE(
state_space_,
nullptr) <<
"Initialize state space before creating the planning context.";
234 auto si_constrained =
dynamic_cast<ompl::base::ConstrainedSpaceInformation*
>(si.get());
235 ASSERT_NE(si_constrained,
nullptr);
244 RCLCPP_DEBUG(
getLogger(),
"Planning context with name '%s' is ready (but not configured).",
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 });
307 testJointLimits({ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 });
314 testSelfCollision({ -2.95993, -0.682185, -2.43873, -0.939784, 3.0544, 0.882294 });
324 testing::InitGoogleTest(&argc, argv);
325 return RUN_ALL_TESTS();
Dummy constraint for testing, always satisfied. We need this to create and OMPL ConstrainedStateSpace...
DummyConstraint(const unsigned int num_dofs)
void function(const Eigen::Ref< const Eigen::VectorXd > &, Eigen::Ref< Eigen::VectorXd > out) const override
FanucTestStateValidityChecker()
PandaValidityCheckerTests()
Generic implementation of the tests that can be executed on different robots.
moveit::core::RobotStatePtr initial_robot_state_
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_
ompl::base::ConstrainedStateSpacePtr constrained_state_space_
ompl_interface::ModelBasedPlanningContextSpecification planning_context_spec_
ompl_interface::ModelBasedPlanningContextPtr planning_context_
TestStateValidityChecker(const std::string &robot_name, const std::string &group_name)
unsigned int getVariableCount() const
Get the number of variables that describe this joint group. This includes variables necessary for mim...
Robot independent test class setup.
moveit::core::RobotStatePtr robot_state_
moveit::core::RobotModelPtr robot_model_
LoadTestRobot(const std::string &robot_name, const std::string &group_name)
const moveit::core::JointModelGroup * joint_model_group_
rclcpp::Logger getLogger(const std::string &name)
Creates a namespaced logger.
ModelBasedStateSpacePtr state_space_
og::SimpleSetupPtr ompl_simple_setup_
int main(int argc, char **argv)
rclcpp::Logger getLogger()
constexpr bool VERBOSE
This flag sets the verbosity level for the state validity checker.
TEST_F(PandaValidityCheckerTests, testConstructor)
std::ostream & operator<<(std::ostream &os, const std::vector< double > &v)
Pretty print std:vectors.
rclcpp::Logger getLogger()
constexpr bool VERBOSE
This flag sets the verbosity level for the state validity checker.
bool getState(const std::shared_ptr< moveit_msgs::srv::GetRobotStateFromWarehouse::Request > &request, const std::shared_ptr< moveit_msgs::srv::GetRobotStateFromWarehouse::Response > &response, moveit_warehouse::RobotStateStorage &rs)