moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
test_execution_manager.cpp
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2012, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34
35/* Author: Ioan Sucan, Cristian C. Beltran
36 Desc: Test the TrajectoryExecutionManager with MoveitCpp
37*/
38
39// ROS
40#include <ros/ros.h>
41
42// Testing
43#include <gtest/gtest.h>
44
45// Main class
48// Msgs
49#include <geometry_msgs/PointStamped.h>
50
51namespace moveit_cpp
52{
53class MoveItCppTest : public ::testing::Test
54{
55public:
56 void SetUp() override
57 {
58 nh_ = ros::NodeHandle();
59 moveit_cpp_ptr = std::make_shared<MoveItCpp>(nh_);
60 trajectory_execution_manager_ptr = moveit_cpp_ptr->getTrajectoryExecutionManagerNonConst();
61
62 traj1.joint_trajectory.joint_names.push_back("panda_joint1");
63 traj1.joint_trajectory.points.resize(2);
64 traj1.joint_trajectory.points[0].positions.push_back(0.0);
65 traj1.joint_trajectory.points[1].positions.push_back(0.5);
66 traj1.joint_trajectory.points[1].time_from_start.fromSec(0.5);
67
68 traj2 = traj1;
69 traj2.joint_trajectory.joint_names.push_back("panda_joint2");
70 traj2.joint_trajectory.points[0].positions.push_back(1.0);
71 traj2.joint_trajectory.points[1].positions.push_back(1.5);
72 traj2.multi_dof_joint_trajectory.joint_names.push_back("panda_joint3");
73 traj2.multi_dof_joint_trajectory.points.resize(2);
74 traj2.multi_dof_joint_trajectory.points[0].transforms.resize(1);
75 traj2.multi_dof_joint_trajectory.points[1].transforms.resize(1);
76
77 ros::param::del("~/trajectory_execution/allowed_start_tolerance_joints");
78 }
79
80protected:
81 ros::NodeHandle nh_;
82 MoveItCppPtr moveit_cpp_ptr;
83 PlanningComponentPtr planning_component_ptr;
84 trajectory_execution_manager::TrajectoryExecutionManagerPtr trajectory_execution_manager_ptr;
85 moveit_msgs::RobotTrajectory traj1;
86 moveit_msgs::RobotTrajectory traj2;
87};
88
89TEST_F(MoveItCppTest, EnsureActiveControllersForJointsTest)
90{
91 ASSERT_TRUE(trajectory_execution_manager_ptr->ensureActiveControllersForJoints({ "panda_joint1" }));
92}
93
94TEST_F(MoveItCppTest, ensureActiveControllerTest)
95{
96 ASSERT_TRUE(trajectory_execution_manager_ptr->ensureActiveController("fake_panda_arm_controller"));
97}
98
99TEST_F(MoveItCppTest, ExecuteEmptySetOfTrajectoriesTest)
100{
101 // execute with empty set of trajectories
102 trajectory_execution_manager_ptr->execute();
103 auto last_execution_status = trajectory_execution_manager_ptr->waitForExecution();
104 ASSERT_EQ(last_execution_status, moveit_controller_manager::ExecutionStatus::SUCCEEDED);
105}
106
107TEST_F(MoveItCppTest, PushExecuteAndWaitTest)
108{
109 ASSERT_TRUE(trajectory_execution_manager_ptr->push(traj1));
110 ASSERT_TRUE(trajectory_execution_manager_ptr->push(traj2));
111 traj1.multi_dof_joint_trajectory = traj2.multi_dof_joint_trajectory;
112 ASSERT_TRUE(trajectory_execution_manager_ptr->push(traj1));
113 auto last_execution_status = trajectory_execution_manager_ptr->executeAndWait();
114 ASSERT_EQ(last_execution_status, moveit_controller_manager::ExecutionStatus::SUCCEEDED);
115}
116
117TEST_F(MoveItCppTest, RejectTooFarFromStart)
118{
119 moveit_msgs::RobotTrajectory traj = traj1;
120 traj.joint_trajectory.points[0].positions[0] = 0.3;
121
122 trajectory_execution_manager_ptr->setAllowedStartTolerance(0.01);
123 ASSERT_TRUE(trajectory_execution_manager_ptr->push(traj));
124 auto last_execution_status = trajectory_execution_manager_ptr->executeAndWait();
125 ASSERT_EQ(last_execution_status, moveit_controller_manager::ExecutionStatus::ABORTED);
126}
127
128TEST_F(MoveItCppTest, AcceptAllowedJointStartTolerance)
129{
130 moveit_msgs::RobotTrajectory traj = traj1;
131 traj.joint_trajectory.points[0].positions[0] = 0.3;
132
133 trajectory_execution_manager_ptr->setAllowedStartTolerance(0.01);
134 ros::param::set("~/trajectory_execution/allowed_start_tolerance_joints/panda_joint1", 0.5);
135 ASSERT_TRUE(trajectory_execution_manager_ptr->push(traj));
136 auto last_execution_status = trajectory_execution_manager_ptr->executeAndWait();
137 ASSERT_EQ(last_execution_status, moveit_controller_manager::ExecutionStatus::SUCCEEDED);
138}
139
140TEST_F(MoveItCppTest, DoNotValidateJointStartToleranceZero)
141{
142 moveit_msgs::RobotTrajectory traj = traj1;
143 traj.joint_trajectory.points[0].positions[0] = 0.3;
144
145 trajectory_execution_manager_ptr->setAllowedStartTolerance(0);
146 ASSERT_TRUE(trajectory_execution_manager_ptr->push(traj));
147 auto last_execution_status = trajectory_execution_manager_ptr->executeAndWait();
148 ASSERT_EQ(last_execution_status, moveit_controller_manager::ExecutionStatus::SUCCEEDED);
149
150 trajectory_execution_manager_ptr->setAllowedStartTolerance(0.1);
151 ASSERT_TRUE(trajectory_execution_manager_ptr->push(traj));
152 last_execution_status = trajectory_execution_manager_ptr->executeAndWait();
153 ASSERT_EQ(last_execution_status, moveit_controller_manager::ExecutionStatus::ABORTED);
154
155 ros::param::set("~/trajectory_execution/allowed_start_tolerance_joints/panda_joint1", 0);
156 ASSERT_TRUE(trajectory_execution_manager_ptr->push(traj));
157 last_execution_status = trajectory_execution_manager_ptr->executeAndWait();
158 ASSERT_EQ(last_execution_status, moveit_controller_manager::ExecutionStatus::SUCCEEDED);
159}
160
161} // namespace moveit_cpp
162
163int main(int argc, char** argv)
164{
165 testing::InitGoogleTest(&argc, argv);
166 ros::init(argc, argv, "test_execution_manager");
167
168 int result = RUN_ALL_TESTS();
169
170 return result;
171}
PlanningComponentPtr planning_component_ptr
moveit_msgs::RobotTrajectory traj2
moveit_msgs::RobotTrajectory traj1
trajectory_execution_manager::TrajectoryExecutionManagerPtr trajectory_execution_manager_ptr
TEST_F(MoveItCppTest, GetCurrentStateTest)
int main(int argc, char **argv)