35#include <gtest/gtest.h>
45#include <rclcpp/rclcpp.hpp>
47static const rclcpp::Logger LOGGER = rclcpp::get_logger(
"unittest_pilz_industrial_motion_planner");
54 rclcpp::NodeOptions node_options;
55 node_options.automatically_declare_parameters_from_overrides(
true);
56 node_ = rclcpp::Node::make_shared(
"unittest_pilz_industrial_motion_planner", node_options);
72 rm_loader_ = std::make_unique<robot_model_loader::RobotModelLoader>(
node_);
74 ASSERT_TRUE(
bool(
robot_model_)) <<
"Failed to load robot model";
77 ASSERT_TRUE(
node_->has_parameter(
"planning_plugins")) <<
"Could not find parameter 'planning_plugins'";
84 "moveit_core",
"planning_interface::PlannerManager");
86 catch (pluginlib::PluginlibException& ex)
88 RCLCPP_FATAL_STREAM(LOGGER,
"Exception while creating planning plugin loader " << ex.what());
97 <<
"Initializing the planner instance failed.";
99 catch (pluginlib::PluginlibException& ex)
101 FAIL() <<
"Could not create planner " << ex.what() <<
'\n';
115 std::unique_ptr<robot_model_loader::RobotModelLoader>
rm_loader_;
129 std::vector<std::string> algs;
130 planner_instance_->getPlanningAlgorithms(algs);
131 ASSERT_EQ(4u, algs.size()) <<
"Found more or less planning algorithms as expected! Found:"
132 << ::testing::PrintToString(algs);
135 std::set<std::string> algs_set;
136 for (
const auto& alg : algs)
138 algs_set.insert(alg);
140 ASSERT_EQ(algs.size(), algs_set.size()) <<
"There are two or more algorithms with the same name!";
141 ASSERT_TRUE(algs_set.find(
"LIN") != algs_set.end());
142 ASSERT_TRUE(algs_set.find(
"PTP") != algs_set.end());
143 ASSERT_TRUE(algs_set.find(
"CIRC") != algs_set.end());
144 ASSERT_TRUE(algs_set.find(
"POLYLINE") != algs_set.end());
154 std::vector<std::string> algs;
155 planner_instance_->getPlanningAlgorithms(algs);
157 for (
const auto& alg : algs)
160 req.planner_id = alg;
161 req.group_name =
"manipulator";
163 EXPECT_TRUE(planner_instance_->canServiceRequest(req));
170 std::vector<std::string> algs;
171 planner_instance_->getPlanningAlgorithms(algs);
173 for (
const auto& alg : algs)
176 req.planner_id = alg;
178 EXPECT_FALSE(planner_instance_->canServiceRequest(req));
185 std::vector<std::string> algs;
186 planner_instance_->getPlanningAlgorithms(algs);
188 for (
const auto& alg : algs)
191 req.planner_id = alg;
192 req.group_name =
"1234manipulator";
194 EXPECT_FALSE(planner_instance_->canServiceRequest(req));
205 req.planner_id =
"NON_EXISTEND_ALGORITHM_HASH_da39a3ee5e6b4b0d3255bfef95601890afd80709";
206 req.group_name =
"manipulator";
208 EXPECT_FALSE(planner_instance_->canServiceRequest(req));
218 req.group_name =
"manipulator";
220 EXPECT_FALSE(planner_instance_->canServiceRequest(req));
228 moveit_msgs::msg::MotionPlanRequest req;
229 moveit_msgs::msg::MoveItErrorCodes error_code;
230 EXPECT_EQ(
nullptr, planner_instance_->getPlanningContext(
nullptr, req, error_code));
239 moveit_msgs::msg::MotionPlanRequest req;
240 moveit_msgs::msg::MoveItErrorCodes error_code;
242 req.group_name =
"manipulator";
244 std::vector<std::string> algs;
245 planner_instance_->getPlanningAlgorithms(algs);
247 for (
const auto& alg : algs)
249 req.planner_id = alg;
251 EXPECT_NE(
nullptr, planner_instance_->getPlanningContext(
nullptr, req, error_code));
260 std::string desc = planner_instance_->getDescription();
261 EXPECT_GT(desc.length(), 0u);
279 return "Test_Algorithm";
282 bool loadContext(planning_interface::PlanningContextPtr& ,
const std::string& ,
283 const std::string& )
const override
292 std::make_shared<TestPlanningContextLoader>();
295 moveit_msgs::msg::MotionPlanRequest req;
296 req.planner_id =
"Test_Algorithm";
297 req.group_name =
"manipulator";
299 moveit_msgs::msg::MoveItErrorCodes error_code;
301 EXPECT_EQ(moveit_msgs::msg::MoveItErrorCodes::PLANNING_FAILED, error_code.val);
306 rclcpp::init(argc, argv);
307 testing::InitGoogleTest(&argc, argv);
308 return RUN_ALL_TESTS();
planning_interface::PlannerManagerPtr planner_instance_
std::unique_ptr< pluginlib::ClassLoader< planning_interface::PlannerManager > > planner_plugin_loader_
std::vector< std::string > planner_plugin_names_
rclcpp::Node::SharedPtr node_
moveit::core::RobotModelConstPtr robot_model_
std::unique_ptr< robot_model_loader::RobotModelLoader > rm_loader_
void createPlannerInstance()
initialize the planner plugin The planner is loaded using the pluginlib. Checks that the planner was ...
MoveIt Plugin for Planning with Standard Robot Commands This planner is dedicated to return a instanc...
planning_interface::PlanningContextPtr getPlanningContext(const planning_scene::PlanningSceneConstPtr &planning_scene, const planning_interface::MotionPlanRequest &req, moveit_msgs::msg::MoveItErrorCodes &error_code) const override
Returns a PlanningContext that can be used to solve(calculate) the trajectory that corresponds to com...
bool initialize(const moveit::core::RobotModelConstPtr &model, const rclcpp::Node::SharedPtr &node, const std::string &ns) override
Initializes the planner Upon initialization this planner will look for plugins implementing pilz_indu...
void registerContextLoader(const pilz_industrial_motion_planner::PlanningContextLoaderPtr &planning_context_loader)
Register a PlanningContextLoader to be used by the CommandPlanner.
Base class for all PlanningContextLoaders. Since planning_interface::PlanningContext has a non empty ...
virtual std::string getAlgorithm() const
Return the algorithm the loader uses.
virtual bool loadContext(planning_interface::PlanningContextPtr &planning_context, const std::string &name, const std::string &group) const =0
Return the planning context.
std::shared_ptr< PlanningContextLoader > PlanningContextLoaderPtr
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
int main(int argc, char **argv)
TEST_F(CommandPlannerTest, ObtainLoadedPlanningAlgorithms)
Test that PTP can be loaded This needs to be extended with every new planning Algorithm.