test_preempt.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, the neonavigation authors
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <memory>
31 #include <string>
32 
33 #include <gtest/gtest.h>
34 
36 #include <move_base_msgs/MoveBaseAction.h>
37 #include <planner_cspace_msgs/PlannerStatus.h>
38 #include <ros/ros.h>
39 
41 
43  : public ActionTestBase<move_base_msgs::MoveBaseAction, ACTION_TOPIC_MOVE_BASE>
44 {
45 protected:
46  move_base_msgs::MoveBaseGoal CreateGoalInFree()
47  {
48  move_base_msgs::MoveBaseGoal goal;
49  goal.target_pose.header.stamp = ros::Time::now();
50  goal.target_pose.header.frame_id = "map";
51  goal.target_pose.pose.position.x = 1.24;
52  goal.target_pose.pose.position.y = 0.65;
53  goal.target_pose.pose.position.z = 0.0;
54  goal.target_pose.pose.orientation.x = 0.0;
55  goal.target_pose.pose.orientation.y = 0.0;
56  goal.target_pose.pose.orientation.z = 0.0;
57  goal.target_pose.pose.orientation.w = 1.0;
58  return goal;
59  }
60 };
61 
63 {
64  const ros::Time deadline = ros::Time::now() + ros::Duration(5);
65  const ros::Duration wait(1.0);
66 
67  move_base_->sendGoal(CreateGoalInFree());
68  while (move_base_->getState().state_ !=
70  {
71  wait.sleep();
72  ASSERT_LT(ros::Time::now(), deadline)
73  << "Action didn't get active: " << move_base_->getState().toString()
74  << statusString();
75  }
76  while (move_base_->getState().state_ ==
78  {
79  move_base_->cancelAllGoals();
80  wait.sleep();
81  ASSERT_LT(ros::Time::now(), deadline)
82  << "Action didn't get inactive: " << move_base_->getState().toString()
83  << statusString();
84  }
85 
86  ASSERT_TRUE(planner_status_);
87 
89  move_base_->getState().state_);
90  ASSERT_EQ(planner_cspace_msgs::PlannerStatus::GOING_WELL,
91  planner_status_->error);
92  ASSERT_EQ(planner_cspace_msgs::PlannerStatus::DONE,
93  planner_status_->status);
94 }
95 
96 int main(int argc, char** argv)
97 {
98  testing::InitGoogleTest(&argc, argv);
99  ros::init(argc, argv, "test_preempt");
100 
102  spinner.start();
103  int ret = RUN_ALL_TESTS();
104  spinner.stop();
105  ros::shutdown();
106  return ret;
107 }
TEST_F(PreemptTest, Preempt)
void wait(int seconds)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void spinner()
move_base_msgs::MoveBaseGoal CreateGoalInFree()
static Time now()
ROSCPP_DECL void shutdown()
int main(int argc, char **argv)
bool sleep() const


planner_cspace
Author(s): Atsushi Watanabe
autogenerated on Mon Jul 3 2023 02:39:06