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 <ros/ros.h>
32 #include <move_base_msgs/MoveBaseAction.h>
33 #include <planner_cspace_msgs/PlannerStatus.h>
34 
35 #include <gtest/gtest.h>
36 
37 class PreemptTest : public ::testing::Test
38 {
39 public:
41  : node_()
42  {
43  move_base_ = std::make_shared<ActionClient>("/move_base");
44  status_sub_ = node_.subscribe("/planner_3d/status",
45  10,
47  this);
48  if (!move_base_->waitForServer(ros::Duration(30.0)))
49  {
50  ROS_ERROR("Failed to connect move_base action");
51  exit(EXIT_FAILURE);
52  }
53  }
55  {
56  }
57 
58 protected:
60  using ActionClientPtr = std::shared_ptr<ActionClient>;
61 
62  void StatusCallback(const planner_cspace_msgs::PlannerStatus& msg)
63  {
64  status_ = msg;
65  }
66  move_base_msgs::MoveBaseGoal CreateGoalInFree()
67  {
68  move_base_msgs::MoveBaseGoal goal;
69  goal.target_pose.header.stamp = ros::Time::now();
70  goal.target_pose.header.frame_id = "map";
71  goal.target_pose.pose.position.x = 1.24;
72  goal.target_pose.pose.position.y = 0.65;
73  goal.target_pose.pose.position.z = 0.0;
74  goal.target_pose.pose.orientation.x = 0.0;
75  goal.target_pose.pose.orientation.y = 0.0;
76  goal.target_pose.pose.orientation.z = 0.0;
77  goal.target_pose.pose.orientation.w = 1.0;
78  return goal;
79  }
80 
84  planner_cspace_msgs::PlannerStatus status_;
85 };
86 
88 {
89  move_base_->sendGoal(CreateGoalInFree());
90  while (move_base_->getState().state_ !=
92  {
93  ros::Duration(1.0).sleep();
94  }
95  while (move_base_->getState().state_ ==
97  {
98  move_base_->cancelAllGoals();
99  ros::Duration(1.0).sleep();
100  }
101 
103  move_base_->getState().state_);
104  ASSERT_EQ(planner_cspace_msgs::PlannerStatus::GOING_WELL,
105  status_.error);
106  ASSERT_EQ(planner_cspace_msgs::PlannerStatus::DONE,
107  status_.status);
108 }
109 
110 int main(int argc, char** argv)
111 {
112  testing::InitGoogleTest(&argc, argv);
113  ros::init(argc, argv, "test_preempt");
114 
116  spinner.start();
117  int ret = RUN_ALL_TESTS();
118  spinner.stop();
119  ros::shutdown();
120  return ret;
121 }
std::shared_ptr< ActionClient > ActionClientPtr
TEST_F(PreemptTest, Preempt)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
bool sleep() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void spinner()
planner_cspace_msgs::PlannerStatus status_
move_base_msgs::MoveBaseGoal CreateGoalInFree()
ros::NodeHandle node_
ros::Subscriber status_sub_
void StatusCallback(const planner_cspace_msgs::PlannerStatus &msg)
static Time now()
ROSCPP_DECL void shutdown()
int main(int argc, char **argv)
ActionClientPtr move_base_
#define ROS_ERROR(...)


planner_cspace
Author(s): Atsushi Watanabe
autogenerated on Tue Jul 9 2019 05:00:13