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(1);
64 traj1.joint_trajectory.points[0].positions.push_back(0.0);
65
66 traj2 = traj1;
67 traj2.joint_trajectory.joint_names.push_back("panda_joint2");
68 traj2.joint_trajectory.points[0].positions.push_back(1.0);
69 traj2.multi_dof_joint_trajectory.joint_names.push_back("panda_joint3");
70 traj2.multi_dof_joint_trajectory.points.resize(1);
71 traj2.multi_dof_joint_trajectory.points[0].transforms.resize(1);
72 }
73
74protected:
75 ros::NodeHandle nh_;
76 MoveItCppPtr moveit_cpp_ptr;
77 PlanningComponentPtr planning_component_ptr;
78 trajectory_execution_manager::TrajectoryExecutionManagerPtr trajectory_execution_manager_ptr;
79 moveit_msgs::RobotTrajectory traj1;
80 moveit_msgs::RobotTrajectory traj2;
81};
82
83TEST_F(MoveItCppTest, EnsureActiveControllersForJointsTest)
84{
85 ASSERT_TRUE(trajectory_execution_manager_ptr->ensureActiveControllersForJoints({ "panda_joint1" }));
86}
87
88TEST_F(MoveItCppTest, ensureActiveControllerTest)
89{
90 ASSERT_TRUE(trajectory_execution_manager_ptr->ensureActiveController("fake_panda_arm_controller"));
91}
92
93TEST_F(MoveItCppTest, ExecuteEmptySetOfTrajectoriesTest)
94{
95 // execute with empty set of trajectories
96 trajectory_execution_manager_ptr->execute();
97 auto last_execution_status = trajectory_execution_manager_ptr->waitForExecution();
98 ASSERT_EQ(last_execution_status, moveit_controller_manager::ExecutionStatus::SUCCEEDED);
99}
100
101TEST_F(MoveItCppTest, PushExecuteAndWaitTest)
102{
103 ASSERT_TRUE(trajectory_execution_manager_ptr->push(traj1));
104 ASSERT_TRUE(trajectory_execution_manager_ptr->push(traj2));
105 traj1.multi_dof_joint_trajectory = traj2.multi_dof_joint_trajectory;
106 ASSERT_TRUE(trajectory_execution_manager_ptr->push(traj1));
107 auto last_execution_status = trajectory_execution_manager_ptr->executeAndWait();
108 ASSERT_EQ(last_execution_status, moveit_controller_manager::ExecutionStatus::SUCCEEDED);
109}
110
111} // namespace moveit_cpp
112
113int main(int argc, char** argv)
114{
115 testing::InitGoogleTest(&argc, argv);
116 ros::init(argc, argv, "test_execution_manager");
117
118 int result = RUN_ALL_TESTS();
119
120 return result;
121}
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)