22 #include <gtest/gtest.h>
24 #include <trajopt/common.hpp>
39 #include <moveit_msgs/MotionPlanResponse.h>
55 ROS_ERROR_STREAM_NAMED(
"trajectory_test",
"robot model is not loaded correctly");
68 std::vector<double> vec_a = { 1, 2, 3, 4, 5 };
69 std::vector<double> vec_b = { 6, 7, 8, 9, 10 };
71 EXPECT_EQ(vec_c.size(), vec_a.size() + vec_b.size());
75 std::size_t length_ab = vec_a.size() + vec_b.size();
76 for (std::size_t index = 0; index < length_ab; ++index)
78 if (index < vec_a.size())
80 EXPECT_EQ(vec_c[index], vec_a[index]);
84 EXPECT_EQ(vec_c[index], vec_b[index - vec_a.size()]);
91 const std::string NODE_NAME =
"trajectory_test";
94 auto current_state = std::make_shared<moveit::core::RobotState>(robot_model_);
95 current_state->setToDefaultValues();
98 EXPECT_NE(joint_model_group,
nullptr);
100 EXPECT_EQ(joint_names.size(), 7);
102 auto planning_scene = std::make_shared<planning_scene::PlanningScene>(robot_model_);
110 std::vector<double> start_joint_values = { 0.4, 0.3, 0.5, -0.55, 0.88, 1.0, -0.075 };
111 auto start_state = std::make_shared<moveit::core::RobotState>(robot_model_);
112 start_state->setJointGroupPositions(joint_model_group, start_joint_values);
113 start_state->update();
115 req.start_state.joint_state.name = joint_names;
116 req.start_state.joint_state.position = start_joint_values;
117 req.goal_constraints.clear();
118 req.group_name = PLANNING_GROUP;
122 auto goal_state = std::make_shared<moveit::core::RobotState>(robot_model_);
123 std::vector<double> goal_joint_values = { 0.8, 0.7, 1, -1.3, 1.9, 2.2, -0.1 };
124 goal_state->setJointGroupPositions(joint_model_group, goal_joint_values);
125 goal_state->update();
127 req.goal_constraints.push_back(joint_goal);
128 req.goal_constraints[0].name =
"goal_pos";
130 std::vector<moveit_msgs::JointConstraint> goal_joint_constraint = req.goal_constraints[0].joint_constraints;
131 for (std::size_t
x = 0;
x < goal_joint_constraint.size(); ++
x)
133 req.goal_constraints[0].joint_constraints[
x].tolerance_above = 0.001;
134 req.goal_constraints[0].joint_constraints[
x].tolerance_below = 0.001;
141 std::unique_ptr<pluginlib::ClassLoader<planning_interface::PlannerManager>> planner_plugin_loader;
142 planning_interface::PlannerManagerPtr planner_instance;
144 std::string planner_plugin_name =
"trajopt_interface/TrajOptPlanner";
145 node_handle_.setParam(
"planning_plugin", planner_plugin_name);
148 EXPECT_TRUE(node_handle_.getParam(
"planning_plugin", planner_plugin_name));
151 planner_plugin_loader = std::make_shared<pluginlib::ClassLoader<planning_interface::PlannerManager>>(
152 "moveit_core",
"planning_interface::PlannerManager");
154 catch (pluginlib::PluginlibException& ex)
156 ROS_FATAL_STREAM_NAMED(NODE_NAME,
"Exception while creating planning plugin loader " << ex.what());
160 planner_instance.reset(planner_plugin_loader->createUnmanagedInstance(planner_plugin_name));
161 if (!planner_instance->initialize(robot_model_, node_handle_.getNamespace()))
162 ROS_FATAL_STREAM_NAMED(NODE_NAME,
"Could not initialize planner instance");
163 ROS_INFO_STREAM_NAMED(NODE_NAME,
"Using planning interface '" << planner_instance->getDescription() <<
"'");
165 catch (pluginlib::PluginlibException& ex)
167 const std::vector<std::string>& classes = planner_plugin_loader->getDeclaredClasses();
168 std::stringstream ss;
169 for (std::size_t i = 0; i < classes.size(); ++i)
170 ss << classes[i] <<
" ";
171 ROS_ERROR_STREAM_NAMED(NODE_NAME,
"Exception while loading planner '" << planner_plugin_name <<
"': " << ex.what()
173 <<
"Available plugins: " << ss.str());
178 planning_interface::PlanningContextPtr context =
184 moveit_msgs::MotionPlanResponse response;
189 std::vector<double> joints_values_last_step = response.trajectory.joint_trajectory.points.back().positions;
191 for (std::size_t joint_index = 0; joint_index < joints_values_last_step.size(); ++joint_index)
194 abs(joints_values_last_step[joint_index] - req.goal_constraints[0].joint_constraints[joint_index].position);
195 std::cerr <<
"goal_error: " << goal_error <<
'\n';
200 int main(
int argc,
char** argv)
202 testing::InitGoogleTest(&argc, argv);
203 ros::init(argc, argv,
"trajectory_test");
205 ros::AsyncSpinner spinner(1);
208 int result = RUN_ALL_TESTS();
const std::string PLANNING_GROUP
const double GOAL_TOLERANCE
ros::NodeHandle node_handle_
moveit::core::RobotModelPtr robot_model_
std::vector< std::string > group_joint_names_
const std::vector< std::string > & getActiveJointModelNames() const
Get the names of the active joints in this group. These are the names of the joints returned by getJo...
constexpr double GOAL_TOLERANCE
moveit_msgs::msg::Constraints constructGoalConstraints(const moveit::core::RobotState &state, const moveit::core::JointModelGroup *jmg, double tolerance_below, double tolerance_above)
Generates a constraint message intended to be used as a goal constraint for a joint group....
moveit::core::RobotModelPtr loadTestingRobotModel(const std::string &robot_name)
Loads a robot from moveit_resources.
moveit_msgs::msg::MotionPlanRequest MotionPlanRequest
This namespace includes the central class for representing planning contexts.
Eigen::VectorXd concatVector(const Eigen::VectorXd &vector_a, const Eigen::VectorXd &vector_b)
Appends b to a of type VectorXd.
void getMessage(moveit_msgs::msg::MotionPlanResponse &msg) const
moveit_msgs::msg::MoveItErrorCodes error_code_
int main(int argc, char **argv)
TEST_F(TrajectoryTest, concatVectorValidation)