36 #include <condition_variable>
37 #include <gmock/gmock.h>
38 #include <gtest/gtest.h>
45 #include <actionlib/client/simple_action_client.h>
50 #include <moveit_msgs/Constraints.h>
51 #include <moveit_msgs/GetMotionPlan.h>
52 #include <moveit_msgs/JointConstraint.h>
54 #include <sensor_msgs/JointState.h>
62 #include <moveit_msgs/MoveGroupSequenceAction.h>
64 static constexpr
double WAIT_FOR_RESULT_TIME_OUT{ 5. };
65 static constexpr
double TIME_BEFORE_CANCEL_GOAL{ 1.0 };
66 static constexpr
double WAIT_FOR_ACTION_SERVER_TIME_OUT{ 10. };
89 MOCK_METHOD1(feedback_callback,
void(
const moveit_msgs::msg::MoveGroupSequenceFeedbackConstPtr& feedback));
90 MOCK_METHOD2(done_callback,
void(
const actionlib::SimpleClientGoalState& state,
91 const moveit_msgs::msg::MoveGroupSequenceResultConstPtr& result));
94 ros::NodeHandle ph_{
"~" };
95 actionlib::SimpleActionClient<moveit_msgs::msg::MoveGroupSequenceAction> ac_{ ph_,
SEQUENCE_ACTION_NAME,
true };
96 std::shared_ptr<moveit::planning_interface::MoveGroupInterface> move_group_;
99 robot_model::RobotModelPtr robot_model_;
100 double joint_position_tolerance_;
102 std::string test_data_file_name_;
103 std::string group_name_;
115 ph_.param<std::string>(
GROUP_NAME, group_name_,
"manipulator");
117 robot_model_ = model_loader_.getModel();
119 data_loader_ = std::make_unique<XmlTestdataLoader>(test_data_file_name_, robot_model_);
120 ASSERT_NE(
nullptr, data_loader_) <<
"Failed to load test data by provider.";
123 ASSERT_TRUE(ac_.waitForServer(ros::Duration(WAIT_FOR_ACTION_SERVER_TIME_OUT))) <<
"Action server is not active.";
126 start_config = data_loader_->getJoints(
"ZeroPose", group_name_);
127 robot_state::RobotState robot_state{ start_config.toRobotState() };
129 move_group_ = std::make_shared<moveit::planning_interface::MoveGroupInterface>(start_config.getGroupName());
130 move_group_->setPlannerId(
"PTP");
131 move_group_->setGoalTolerance(joint_position_tolerance_);
132 move_group_->setJointValueTarget(robot_state);
133 move_group_->setMaxVelocityScalingFactor(1.0);
134 move_group_->setMaxAccelerationScalingFactor(1.0);
137 ASSERT_TRUE(
isAtExpectedPosition(robot_state, *(move_group_->getCurrentState()), joint_position_tolerance_));
153 Sequence seq{ data_loader_->getSequence(
"ComplexSequence") };
155 moveit_msgs::msg::MoveGroupSequenceGoal seq_goal;
158 ac_.sendGoal(seq_goal);
160 ros::Duration(TIME_BEFORE_CANCEL_GOAL).sleep();
163 ac_.waitForResult(ros::Duration(WAIT_FOR_RESULT_TIME_OUT));
165 moveit_msgs::msg::MoveGroupSequenceResultConstPtr res = ac_.getResult();
166 EXPECT_EQ(res->response.error_code.val, moveit_msgs::msg::MoveItErrorCodes::PREEMPTED)
167 <<
"Error code should be preempted.";
170 int main(
int argc,
char** argv)
172 ros::init(argc, argv,
"integrationtest_sequence_action_preemption");
175 ros::AsyncSpinner spinner{ 1 };
178 testing::InitGoogleTest(&argc, argv);
179 return RUN_ALL_TESTS();
MOCK_METHOD1(feedback_callback, void(const moveit_msgs::msg::MoveGroupSequenceFeedbackConstPtr &feedback))
MOCK_METHOD0(active_callback, void())
MOCK_METHOD2(done_callback, void(const actionlib::SimpleClientGoalState &state, const moveit_msgs::msg::MoveGroupSequenceResultConstPtr &result))
Class to define a robot configuration in space with the help of joint values.
Data class storing all information regarding a Sequence command.
moveit_msgs::msg::MotionSequenceRequest toRequest() const
Test class that allows the handling of asynchronous test objects.
const std::string JOINT_POSITION_TOLERANCE("joint_position_tolerance")
int main(int argc, char **argv)
const std::string GROUP_NAME("group_name")
const std::string SERVER_IDLE_EVENT
const std::string GOAL_SUCCEEDED_EVENT
const std::string TEST_DATA_FILE_NAME("testdata_file_name")
TEST_F(IntegrationTestSequenceAction, TestCancellingOfGoal)
Tests that goal can be cancelled.
const std::string SEQUENCE_ACTION_NAME("/sequence_move_group")
::testing::AssertionResult isAtExpectedPosition(const moveit::core::RobotState &expected, const moveit::core::RobotState &actual, const double epsilon, const std::string &group_name="")
std::unique_ptr< TestdataLoader > TestdataLoaderUPtr