43 #include <rclcpp/node.hpp>
53 builder.
addChain(
"a->b",
"continuous");
54 builder.
addChain(
"b->c",
"prismatic");
56 robot_model_ = builder.
build();
66 static std::size_t generateTestTraj(std::vector<std::shared_ptr<RobotState>>& traj,
67 const RobotModelConstPtr& robot_model_);
71 const RobotModelConstPtr& robot_model_)
75 auto robot_state = std::make_shared<RobotState>(robot_model_);
76 robot_state->setToDefaultValues();
80 for (std::size_t traj_ix = 0; traj_ix < 3; ++traj_ix)
82 traj.push_back(std::make_shared<RobotState>(*robot_state));
85 ja = robot_state->getVariablePosition(
"a-b-joint");
86 jc = robot_state->getVariablePosition(
"b-c-joint");
90 robot_state->setVariablePosition(
"a-b-joint", ja);
92 robot_state->setVariablePosition(
"b-c-joint", jc);
93 traj.push_back(std::make_shared<RobotState>(*robot_state));
97 robot_state->setVariablePosition(
"a-b-joint", ja);
98 traj.push_back(std::make_shared<RobotState>(*robot_state));
102 robot_state->setVariablePosition(
"b-c-joint", jc);
103 traj.push_back(std::make_shared<RobotState>(*robot_state));
106 traj.push_back(std::make_shared<RobotState>(*robot_state));
113 std::vector<std::shared_ptr<RobotState>> traj;
116 const std::size_t expected_full_traj_len = 7;
119 std::size_t full_traj_len = generateTestTraj(traj, robot_model_);
122 EXPECT_EQ(full_traj_len, expected_full_traj_len);
127 const JointModelGroup* joint_model_group = robot_model_->getJointModelGroup(
"group");
128 std::vector<std::shared_ptr<RobotState>> traj;
131 const std::size_t expected_revolute_jump_traj_len = 4;
132 const std::size_t expected_prismatic_jump_traj_len = 5;
135 std::size_t full_traj_len = generateTestTraj(traj, robot_model_);
136 const double expected_revolute_jump_fraction =
137 static_cast<double>(expected_revolute_jump_traj_len) /
static_cast<double>(full_traj_len);
138 const double expected_prismatic_jump_fraction =
139 static_cast<double>(expected_prismatic_jump_traj_len) /
static_cast<double>(full_traj_len);
145 generateTestTraj(traj, robot_model_);
147 EXPECT_EQ(expected_revolute_jump_traj_len, traj.size());
148 EXPECT_NEAR(expected_revolute_jump_fraction, fraction, 0.01);
151 generateTestTraj(traj, robot_model_);
153 EXPECT_EQ(expected_revolute_jump_traj_len, traj.size());
154 EXPECT_NEAR(expected_revolute_jump_fraction, fraction, 0.01);
157 generateTestTraj(traj, robot_model_);
159 EXPECT_EQ(expected_prismatic_jump_traj_len, traj.size());
160 EXPECT_NEAR(expected_prismatic_jump_fraction, fraction, 0.01);
171 const JointModelGroup* joint_model_group = robot_model_->getJointModelGroup(
"group");
172 std::vector<std::shared_ptr<RobotState>> traj;
175 const std::size_t expected_relative_jump_traj_len = 4;
178 std::size_t full_traj_len = generateTestTraj(traj, robot_model_);
179 const double expected_relative_jump_fraction =
180 static_cast<double>(expected_relative_jump_traj_len) /
static_cast<double>(full_traj_len);
183 double fraction = 0.0;
186 generateTestTraj(traj, robot_model_);
188 EXPECT_EQ(expected_relative_jump_traj_len, traj.size());
189 EXPECT_NEAR(expected_relative_jump_fraction, fraction, 0.01);
192 generateTestTraj(traj, robot_model_);
194 EXPECT_EQ(full_traj_len, traj.size());
195 EXPECT_NEAR(1.0, fraction, 0.01);
351 int main(
int argc,
char** argv)
353 testing::InitGoogleTest(&argc, argv);
354 rclcpp::init(argc, argv);
355 return RUN_ALL_TESTS();
static std::size_t generateTestTraj(std::vector< std::shared_ptr< RobotState >> &traj, const RobotModelConstPtr &robot_model_)
RobotModelConstPtr robot_model_
static Percentage checkJointSpaceJump(const JointModelGroup *group, std::vector< std::shared_ptr< RobotState >> &path, const JumpThreshold &jump_threshold)
Checks if a path has a joint-space jump, and truncates the path at the jump.
Easily build different robot models for testing. Essentially a programmer-friendly light wrapper arou...
void addChain(const std::string §ion, const std::string &type, const std::vector< geometry_msgs::msg::Pose > &joint_origins={}, urdf::Vector3 joint_axis=urdf::Vector3(1.0, 0.0, 0.0))
Adds a chain of links and joints to the builder. The joint names are generated automatically as "<par...
moveit::core::RobotModelPtr build()
Builds and returns the robot model added to the builder.
void addGroupChain(const std::string &base_link, const std::string &tip_link, const std::string &name="")
Adds a new group using a chain of links. The group is the parent joint of each link in the chain.
Core components of MoveIt.
static JumpThreshold relative(double relative_factor)
Detect joint-space jumps relative to the average joint-space displacement along the path.
static JumpThreshold absolute(double revolute, double prismatic)
Detect joint-space jumps greater than the given absolute thresholds.
int main(int argc, char **argv)
TEST_F(SimpleRobot, testGenerateTrajectory)