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 
51 namespace moveit_cpp
52 {
53 class MoveItCppTest : public ::testing::Test
54 {
55 public:
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 
74 protected:
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 
83 TEST_F(MoveItCppTest, EnsureActiveControllersForJointsTest)
84 {
85  ASSERT_TRUE(trajectory_execution_manager_ptr->ensureActiveControllersForJoints({ "panda_joint1" }));
86 }
87 
88 TEST_F(MoveItCppTest, ensureActiveControllerTest)
89 {
90  ASSERT_TRUE(trajectory_execution_manager_ptr->ensureActiveController("fake_panda_arm_controller"));
91 }
92 
93 TEST_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 
101 TEST_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 
113 int 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 }
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
moveit_cpp::MoveItCppTest::traj1
moveit_msgs::RobotTrajectory traj1
Definition: test_execution_manager.cpp:143
ros.h
main
int main(int argc, char **argv)
Definition: test_execution_manager.cpp:113
moveit_cpp::MoveItCppTest::nh_
ros::NodeHandle nh_
Definition: moveit_cpp_test.cpp:146
moveit_cpp::MoveItCppTest::moveit_cpp_ptr
MoveItCppPtr moveit_cpp_ptr
Definition: moveit_cpp_test.cpp:147
moveit_cpp
Definition: moveit_cpp.h:50
moveit_cpp::MoveItCppTest::planning_component_ptr
PlanningComponentPtr planning_component_ptr
Definition: moveit_cpp_test.cpp:148
moveit_controller_manager::ExecutionStatus::SUCCEEDED
SUCCEEDED
moveit_cpp::MoveItCppTest::traj2
moveit_msgs::RobotTrajectory traj2
Definition: test_execution_manager.cpp:144
planning_component.h
moveit_cpp.h
moveit_cpp::MoveItCppTest::SetUp
void SetUp() override
Definition: moveit_cpp_test.cpp:120
moveit_cpp::MoveItCppTest::trajectory_execution_manager_ptr
trajectory_execution_manager::TrajectoryExecutionManagerPtr trajectory_execution_manager_ptr
Definition: test_execution_manager.cpp:142
ros::NodeHandle
moveit_cpp::TEST_F
TEST_F(MoveItCppTest, GetCurrentStateTest)
Definition: moveit_cpp_test.cpp:126


planning
Author(s): Ioan Sucan , Sachin Chitta
autogenerated on Wed Feb 21 2024 03:25:45