20 #include "server_handler.hpp"
22 using namespace std::chrono_literals;
23 using namespace std::chrono;
25 namespace nav2_system_tests
29 ServerHandler::ServerHandler()
32 node_ = rclcpp::Node::make_shared(
"behavior_tree_tester");
34 clear_local_costmap_server = std::make_unique<DummyService<nav2_msgs::srv::ClearEntireCostmap>>(
35 node_,
"local_costmap/clear_entirely_local_costmap");
36 clear_global_costmap_server = std::make_unique<DummyService<nav2_msgs::srv::ClearEntireCostmap>>(
37 node_,
"global_costmap/clear_entirely_global_costmap");
38 compute_path_to_pose_server = std::make_unique<DummyComputePathToPoseActionServer>(node_);
39 follow_path_server = std::make_unique<DummyFollowPathActionServer>(node_);
40 spin_server = std::make_unique<DummyActionServer<nav2_msgs::action::Spin>>(
42 wait_server = std::make_unique<DummyActionServer<nav2_msgs::action::Wait>>(
44 backup_server = std::make_unique<DummyActionServer<nav2_msgs::action::BackUp>>(
46 compute_route_server = std::make_unique<DummyActionServer<nav2_msgs::action::ComputeRoute>>(
47 node_,
"compute_route");
48 smoother_server = std::make_unique<DummyActionServer<nav2_msgs::action::SmoothPath>>(
49 node_,
"smooth_path");
50 drive_on_heading_server = std::make_unique<DummyActionServer<nav2_msgs::action::DriveOnHeading>>(
51 node_,
"drive_on_heading");
52 ntp_server = std::make_unique<DummyActionServer<nav2_msgs::action::ComputePathThroughPoses>>(
53 node_,
"compute_path_through_poses");
56 ServerHandler::~ServerHandler()
63 void ServerHandler::activate()
66 throw std::runtime_error(
"Trying to activate while already activated");
71 std::make_shared<std::thread>(std::bind(&ServerHandler::spinThread,
this));
73 std::cout <<
"Server handler is active!" << std::endl;
76 void ServerHandler::deactivate()
79 throw std::runtime_error(
"Trying to deactivate while already inactive");
83 server_thread_->join();
85 std::cout <<
"Server handler has been deactivated!" << std::endl;
88 void ServerHandler::reset()
const
90 clear_global_costmap_server->reset();
91 clear_local_costmap_server->reset();
92 compute_path_to_pose_server->reset();
93 follow_path_server->reset();
96 backup_server->reset();
97 drive_on_heading_server->reset();
100 void ServerHandler::spinThread()