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<DummyClearEntireCostmapService>(
35 node_,
"local_costmap/clear_entirely_local_costmap");
36 clear_global_costmap_server = std::make_unique<DummyClearEntireCostmapService>(
37 node_,
"global_costmap/clear_entirely_global_costmap");
38 clear_costmap_around_robot_server = std::make_unique<DummyClearCostmapAroundRobotService>(
39 node_,
"local_costmap/clear_around_local_costmap");
40 clear_costmap_except_region_server = std::make_unique<DummyClearCostmapExceptRegionService>(
41 node_,
"local_costmap/clear_except_local_costmap");
42 clear_costmap_around_pose_server = std::make_unique<DummyClearCostmapAroundPoseService>(
43 node_,
"local_costmap/clear_around_pose_local_costmap");
44 validate_path_server = std::make_unique<DummyService<nav2_msgs::srv::IsPathValid>>(
45 node_,
"is_path_valid");
46 compute_path_to_pose_server = std::make_unique<DummyComputePathToPoseActionServer>(node_);
47 follow_path_server = std::make_unique<DummyFollowPathActionServer>(node_);
48 spin_server = std::make_unique<DummyActionServer<nav2_msgs::action::Spin>>(
50 wait_server = std::make_unique<DummyActionServer<nav2_msgs::action::Wait>>(
52 backup_server = std::make_unique<DummyActionServer<nav2_msgs::action::BackUp>>(
54 compute_route_server = std::make_unique<DummyActionServer<nav2_msgs::action::ComputeRoute>>(
55 node_,
"compute_route");
56 smoother_server = std::make_unique<DummyActionServer<nav2_msgs::action::SmoothPath>>(
57 node_,
"smooth_path");
58 drive_on_heading_server = std::make_unique<DummyActionServer<nav2_msgs::action::DriveOnHeading>>(
59 node_,
"drive_on_heading");
60 ntp_server = std::make_unique<DummyActionServer<nav2_msgs::action::ComputePathThroughPoses>>(
61 node_,
"compute_path_through_poses");
64 ServerHandler::~ServerHandler()
71 void ServerHandler::activate()
74 throw std::runtime_error(
"Trying to activate while already activated");
79 std::make_shared<std::thread>(std::bind(&ServerHandler::spinThread,
this));
81 std::cout <<
"Server handler is active!" << std::endl;
84 void ServerHandler::deactivate()
87 throw std::runtime_error(
"Trying to deactivate while already inactive");
91 server_thread_->join();
93 std::cout <<
"Server handler has been deactivated!" << std::endl;
96 void ServerHandler::reset()
const
98 clear_global_costmap_server->reset();
99 clear_local_costmap_server->reset();
100 clear_costmap_around_robot_server->reset();
101 clear_costmap_except_region_server->reset();
102 clear_costmap_around_pose_server->reset();
103 compute_path_to_pose_server->reset();
104 follow_path_server->reset();
105 spin_server->reset();
106 wait_server->reset();
107 backup_server->reset();
108 drive_on_heading_server->reset();
111 void ServerHandler::spinThread()