20 #include "server_handler.hpp"
21 #include "rclcpp/executors.hpp"
23 using namespace std::chrono_literals;
24 using namespace std::chrono;
26 namespace nav2_system_tests
30 ServerHandler::ServerHandler()
33 node_ = rclcpp::Node::make_shared(
"behavior_tree_tester");
35 clear_local_costmap_server = std::make_unique<DummyClearEntireCostmapService>(
36 node_,
"local_costmap/clear_entirely_local_costmap");
37 clear_global_costmap_server = std::make_unique<DummyClearEntireCostmapService>(
38 node_,
"global_costmap/clear_entirely_global_costmap");
39 clear_costmap_around_robot_server = std::make_unique<DummyClearCostmapAroundRobotService>(
40 node_,
"local_costmap/clear_around_local_costmap");
41 clear_costmap_except_region_server = std::make_unique<DummyClearCostmapExceptRegionService>(
42 node_,
"local_costmap/clear_except_local_costmap");
43 clear_costmap_around_pose_server = std::make_unique<DummyClearCostmapAroundPoseService>(
44 node_,
"local_costmap/clear_around_pose_local_costmap");
45 validate_path_server = std::make_unique<DummyService<nav2_msgs::srv::IsPathValid>>(
46 node_,
"is_path_valid");
47 compute_path_to_pose_server = std::make_unique<DummyComputePathToPoseActionServer>(node_);
48 follow_path_server = std::make_unique<DummyFollowPathActionServer>(node_);
49 spin_server = std::make_unique<DummyActionServer<nav2_msgs::action::Spin>>(
51 wait_server = std::make_unique<DummyActionServer<nav2_msgs::action::Wait>>(
53 backup_server = std::make_unique<DummyActionServer<nav2_msgs::action::BackUp>>(
55 compute_route_server = std::make_unique<DummyActionServer<nav2_msgs::action::ComputeRoute>>(
56 node_,
"compute_route");
57 smoother_server = std::make_unique<DummyActionServer<nav2_msgs::action::SmoothPath>>(
58 node_,
"smooth_path");
59 drive_on_heading_server = std::make_unique<DummyActionServer<nav2_msgs::action::DriveOnHeading>>(
60 node_,
"drive_on_heading");
61 ntp_server = std::make_unique<DummyActionServer<nav2_msgs::action::ComputePathThroughPoses>>(
62 node_,
"compute_path_through_poses");
65 ServerHandler::~ServerHandler()
72 void ServerHandler::activate()
75 throw std::runtime_error(
"Trying to activate while already activated");
80 std::make_shared<std::thread>(std::bind(&ServerHandler::spinThread,
this));
82 std::cout <<
"Server handler is active!" << std::endl;
85 void ServerHandler::deactivate()
88 throw std::runtime_error(
"Trying to deactivate while already inactive");
92 server_thread_->join();
94 std::cout <<
"Server handler has been deactivated!" << std::endl;
97 void ServerHandler::reset()
const
99 clear_global_costmap_server->reset();
100 clear_local_costmap_server->reset();
101 clear_costmap_around_robot_server->reset();
102 clear_costmap_except_region_server->reset();
103 clear_costmap_around_pose_server->reset();
104 compute_path_to_pose_server->reset();
105 follow_path_server->reset();
106 spin_server->reset();
107 wait_server->reset();
108 backup_server->reset();
109 drive_on_heading_server->reset();
112 void ServerHandler::spinThread()