42 #include <urdf_parser/urdf_parser.h>
43 #include <gtest/gtest.h>
50 class OneRobot :
public testing::Test
57 static const std::string MODEL2 =
58 "<?xml version=\"1.0\" ?>"
59 "<robot name=\"one_robot\">"
60 "<link name=\"base_link\">"
62 " <mass value=\"2.81\"/>"
63 " <origin rpy=\"0 0 0\" xyz=\"0.0 0.0 .0\"/>"
64 " <inertia ixx=\"0.1\" ixy=\"-0.2\" ixz=\"0.5\" iyy=\"-.09\" iyz=\"1\" izz=\"0.101\"/>"
66 " <collision name=\"my_collision\">"
67 " <origin rpy=\"0 0 0\" xyz=\"0 0 0\"/>"
69 " <box size=\"1 2 1\" />"
73 " <origin rpy=\"0 0 0\" xyz=\"0.0 0 0\"/>"
75 " <box size=\"1 2 1\" />"
79 "<joint name=\"panda_joint0\" type=\"continuous\">"
80 " <axis xyz=\"0 0 1\"/>"
81 " <parent link=\"base_link\"/>"
82 " <child link=\"link_a\"/>"
83 " <origin rpy=\" 0.0 0 0 \" xyz=\"0.0 0 0 \"/>"
85 "<link name=\"link_a\">"
87 " <mass value=\"1.0\"/>"
88 " <origin rpy=\"0 0 0\" xyz=\"0.0 0.0 .0\"/>"
89 " <inertia ixx=\"0.1\" ixy=\"-0.2\" ixz=\"0.5\" iyy=\"-.09\" iyz=\"1\" izz=\"0.101\"/>"
92 " <origin rpy=\"0 0 0\" xyz=\"0 0 0\"/>"
94 " <box size=\"1 2 1\" />"
98 " <origin rpy=\"0 0 0\" xyz=\"0.0 0 0\"/>"
100 " <box size=\"1 2 1\" />"
104 "<joint name=\"joint_b\" type=\"fixed\">"
105 " <parent link=\"link_a\"/>"
106 " <child link=\"link_b\"/>"
107 " <origin rpy=\" 0.0 -0.42 0 \" xyz=\"0.0 0.5 0 \"/>"
109 "<link name=\"link_b\">"
111 " <mass value=\"1.0\"/>"
112 " <origin rpy=\"0 0 0\" xyz=\"0.0 0.0 .0\"/>"
113 " <inertia ixx=\"0.1\" ixy=\"-0.2\" ixz=\"0.5\" iyy=\"-.09\" iyz=\"1\" izz=\"0.101\"/>"
116 " <origin rpy=\"0 0 0\" xyz=\"0 0 0\"/>"
118 " <box size=\"1 2 1\" />"
122 " <origin rpy=\"0 0 0\" xyz=\"0.0 0 0\"/>"
124 " <box size=\"1 2 1\" />"
128 " <joint name=\"panda_joint1\" type=\"prismatic\">"
129 " <axis xyz=\"1 0 0\"/>"
130 " <limit effort=\"100.0\" lower=\"0.0\" upper=\"0.09\" velocity=\"0.2\"/>"
131 " <safety_controller k_position=\"20.0\" k_velocity=\"500.0\" soft_lower_limit=\"0.0\" "
132 "soft_upper_limit=\"0.089\"/>"
133 " <parent link=\"link_b\"/>"
134 " <child link=\"link_c\"/>"
135 " <origin rpy=\" 0.0 0.42 0.0 \" xyz=\"0.0 -0.1 0 \"/>"
137 "<link name=\"link_c\">"
139 " <mass value=\"1.0\"/>"
140 " <origin rpy=\"0 0 0\" xyz=\"0.0 0 .0\"/>"
141 " <inertia ixx=\"0.1\" ixy=\"-0.2\" ixz=\"0.5\" iyy=\"-.09\" iyz=\"1\" izz=\"0.101\"/>"
144 " <origin rpy=\"0 0 0\" xyz=\"0 0 0\"/>"
146 " <box size=\"1 2 1\" />"
150 " <origin rpy=\"0 0 0\" xyz=\"0.0 0 0\"/>"
152 " <box size=\"1 2 1\" />"
156 " <joint name=\"mim_f\" type=\"prismatic\">"
157 " <axis xyz=\"1 0 0\"/>"
158 " <limit effort=\"100.0\" lower=\"0.0\" upper=\"0.19\" velocity=\"0.2\"/>"
159 " <parent link=\"link_c\"/>"
160 " <child link=\"link_d\"/>"
161 " <origin rpy=\" 0.0 0.0 0.0 \" xyz=\"0.1 0.1 0 \"/>"
162 " <mimic joint=\"joint_f\" multiplier=\"1.5\" offset=\"0.1\"/>"
164 " <joint name=\"joint_f\" type=\"prismatic\">"
165 " <axis xyz=\"1 0 0\"/>"
166 " <limit effort=\"100.0\" lower=\"0.0\" upper=\"0.19\" velocity=\"0.2\"/>"
167 " <parent link=\"link_d\"/>"
168 " <child link=\"link_e\"/>"
169 " <origin rpy=\" 0.0 0.0 0.0 \" xyz=\"0.1 0.1 0 \"/>"
171 "<link name=\"link_d\">"
173 " <origin rpy=\"0 0 0\" xyz=\"0 0 0\"/>"
175 " <box size=\"1 2 1\" />"
179 " <origin rpy=\"0 1 0\" xyz=\"0 0.1 0\"/>"
181 " <box size=\"1 2 1\" />"
185 "<link name=\"link_e\">"
187 " <origin rpy=\"0 0 0\" xyz=\"0 0 0\"/>"
189 " <box size=\"1 2 1\" />"
193 " <origin rpy=\"0 1 0\" xyz=\"0 0.1 0\"/>"
195 " <box size=\"1 2 1\" />"
201 static const std::string SMODEL2 =
202 "<?xml version=\"1.0\" ?>"
203 "<robot name=\"one_robot\">"
204 "<virtual_joint name=\"base_joint\" child_link=\"base_link\" parent_frame=\"odom_combined\" type=\"planar\"/>"
205 "<group name=\"base_from_joints\">"
206 "<joint name=\"base_joint\"/>"
207 "<joint name=\"panda_joint0\"/>"
208 "<joint name=\"panda_joint1\"/>"
210 "<group name=\"mim_joints\">"
211 "<joint name=\"joint_f\"/>"
212 "<joint name=\"mim_f\"/>"
214 "<group name=\"base_with_subgroups\">"
215 "<group name=\"base_from_base_to_tip\"/>"
216 "<joint name=\"panda_joint1\"/>"
218 "<group name=\"base_from_base_to_tip\">"
219 "<chain base_link=\"base_link\" tip_link=\"link_b\"/>"
220 "<joint name=\"base_joint\"/>"
222 "<group name=\"arm\">"
223 "<chain base_link=\"base_link\" tip_link=\"link_e\"/>"
224 "<joint name=\"base_joint\"/>"
226 "<group name=\"base_with_bad_subgroups\">"
227 "<group name=\"error\"/>"
231 urdf::ModelInterfaceSharedPtr urdf_model = urdf::parseURDF(MODEL2);
232 srdf::ModelSharedPtr srdf_model = std::make_shared<srdf::Model>();
233 srdf_model->initString(*urdf_model, SMODEL2);
234 robot_model_ = std::make_shared<moveit::core::RobotModel>(urdf_model, srdf_model);
246 const moveit::core::RobotModelConstPtr& robot_model_)
250 auto robot_state = std::make_shared<moveit::core::RobotState>(robot_model_);
251 robot_state->setToDefaultValues();
255 for (std::size_t traj_ix = 0; traj_ix < 3; ++traj_ix)
257 traj.push_back(std::make_shared<moveit::core::RobotState>(*robot_state));
260 ja = robot_state->getVariablePosition(
"panda_joint0");
261 jc = robot_state->getVariablePosition(
"panda_joint1");
265 robot_state->setVariablePosition(
"panda_joint0", ja);
267 robot_state->setVariablePosition(
"panda_joint1", jc);
268 traj.push_back(std::make_shared<moveit::core::RobotState>(*robot_state));
272 robot_state->setVariablePosition(
"panda_joint0", ja);
273 traj.push_back(std::make_shared<moveit::core::RobotState>(*robot_state));
277 robot_state->setVariablePosition(
"panda_joint1", jc);
278 traj.push_back(std::make_shared<moveit::core::RobotState>(*robot_state));
281 traj.push_back(std::make_shared<moveit::core::RobotState>(*robot_state));
288 std::vector<std::shared_ptr<moveit::core::RobotState>> traj;
291 const std::size_t expected_full_traj_len = 7;
297 EXPECT_EQ(full_traj_len, expected_full_traj_len);
303 std::vector<std::shared_ptr<moveit::core::RobotState>> traj;
306 const std::size_t expected_revolute_jump_traj_len = 4;
307 const std::size_t expected_prismatic_jump_traj_len = 5;
311 const double expected_revolute_jump_fraction = (double)expected_revolute_jump_traj_len / (
double)full_traj_len;
312 const double expected_prismatic_jump_fraction = (double)expected_prismatic_jump_traj_len / (
double)full_traj_len;
319 EXPECT_EQ(expected_revolute_jump_traj_len, traj.size());
320 EXPECT_NEAR(expected_revolute_jump_fraction,
fraction, 0.01);
326 EXPECT_EQ(expected_revolute_jump_traj_len, traj.size());
327 EXPECT_NEAR(expected_revolute_jump_fraction,
fraction, 0.01);
333 EXPECT_EQ(expected_revolute_jump_traj_len, traj.size());
334 EXPECT_NEAR(expected_revolute_jump_fraction,
fraction, 0.01);
340 EXPECT_EQ(expected_prismatic_jump_traj_len, traj.size());
341 EXPECT_NEAR(expected_prismatic_jump_fraction,
fraction, 0.01);
347 EXPECT_EQ(full_traj_len, traj.size());
354 std::vector<std::shared_ptr<moveit::core::RobotState>> traj;
357 const std::size_t expected_relative_jump_traj_len = 4;
361 const double expected_relative_jump_fraction = (double)expected_relative_jump_traj_len / (
double)full_traj_len;
368 EXPECT_EQ(expected_relative_jump_traj_len, traj.size());
369 EXPECT_NEAR(expected_relative_jump_fraction,
fraction, 0.01);
375 EXPECT_EQ(expected_relative_jump_traj_len, traj.size());
376 EXPECT_NEAR(expected_relative_jump_fraction,
fraction, 0.01);
382 EXPECT_EQ(full_traj_len, traj.size());
386 int main(
int argc,
char** argv)
388 testing::InitGoogleTest(&argc, argv);
389 return RUN_ALL_TESTS();
moveit::core::RobotModelConstPtr robot_model_
static Percentage checkAbsoluteJointSpaceJump(const JointModelGroup *group, std::vector< std::shared_ptr< RobotState >> &traj, double revolute_jump_threshold, double prismatic_jump_threshold)
Tests for absolute joint space jumps of the trajectory traj.
static Percentage checkRelativeJointSpaceJump(const JointModelGroup *group, std::vector< std::shared_ptr< RobotState >> &traj, double jump_threshold_factor)
Tests for relative joint space jumps of the trajectory traj.
static Percentage checkJointSpaceJump(const JointModelGroup *group, std::vector< std::shared_ptr< RobotState >> &traj, const JumpThreshold &jump_threshold)
Tests joint space jumps of a trajectory.
Struct for containing jump_threshold.
std::size_t generateTestTraj(std::vector< std::shared_ptr< moveit::core::RobotState >> &traj, const moveit::core::RobotModelConstPtr &robot_model_)
int main(int argc, char **argv)
TEST_F(OneRobot, testGenerateTrajectory)