Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
assisted_teleop_behavior_tester.hpp
1 // Copyright (c) 2020 Samsung Research
2 // Copyright (c) 2018 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License. Reserved.
15 
16 #ifndef BEHAVIORS__ASSISTED_TELEOP__ASSISTED_TELEOP_BEHAVIOR_TESTER_HPP_
17 #define BEHAVIORS__ASSISTED_TELEOP__ASSISTED_TELEOP_BEHAVIOR_TESTER_HPP_
18 
19 #include <gtest/gtest.h>
20 #include <memory>
21 #include <string>
22 #include <thread>
23 #include <algorithm>
24 
25 #include "geometry_msgs/msg/pose_stamped.hpp"
26 #include "geometry_msgs/msg/pose_with_covariance_stamped.hpp"
27 #include "geometry_msgs/msg/twist_stamped.hpp"
28 #include "geometry_msgs/msg/pose.hpp"
29 #include "nav2_costmap_2d/costmap_topic_collision_checker.hpp"
30 #include "nav2_msgs/action/assisted_teleop.hpp"
31 #include "nav2_ros_common/node_thread.hpp"
32 #include "nav2_util/robot_utils.hpp"
33 #include "rclcpp_action/rclcpp_action.hpp"
34 #include "rclcpp/executors/single_threaded_executor.hpp"
35 #include "rclcpp/node.hpp"
36 #include "rclcpp/publisher.hpp"
37 #include "rclcpp/time.hpp"
38 #include "std_msgs/msg/empty.hpp"
39 
40 #include "tf2/utils.hpp"
41 #include "nav2_ros_common/tf2_factories.hpp"
42 
43 namespace nav2_system_tests
44 {
45 
47 {
48 public:
49  using AssistedTeleop = nav2_msgs::action::AssistedTeleop;
50 
53 
54  // Runs a single test with given target yaw
55  bool defaultAssistedTeleopTest(
56  const float lin_vel,
57  const float ang_vel);
58 
59  void activate();
60 
61  void deactivate();
62 
63  bool isActive() const
64  {
65  return is_active_;
66  }
67 
68 private:
69  void sendInitialPose();
70 
71  void amclPoseCallback(geometry_msgs::msg::PoseWithCovarianceStamped::ConstSharedPtr);
72 
73  void filteredVelCallback(geometry_msgs::msg::TwistStamped::ConstSharedPtr msg);
74 
75  unsigned int counter_;
76  bool is_active_;
77  bool initial_pose_received_;
78  rclcpp::Time stamp_;
79 
80  nav2::TransformBuffer::SharedPtr tf_buffer_;
81  nav2::TransformListener::SharedPtr tf_listener_;
82 
83  rclcpp::Node::SharedPtr node_;
84  rclcpp::executors::SingleThreadedExecutor executor_;
85 
86  // Publishers
87  rclcpp::Publisher<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr initial_pose_pub_;
88  rclcpp::Publisher<std_msgs::msg::Empty>::SharedPtr preempt_pub_;
89  rclcpp::Publisher<geometry_msgs::msg::TwistStamped>::SharedPtr cmd_vel_pub_;
90 
91  // Subscribers
92  nav2::Subscription<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr subscription_;
93  nav2::Subscription<geometry_msgs::msg::TwistStamped>::SharedPtr filtered_vel_sub_;
94 
95  // Action client to call AssistedTeleop action
96  nav2::ActionClient<AssistedTeleop>::SharedPtr client_ptr_;
97 
98  // collision checking
99  std::shared_ptr<nav2_costmap_2d::CostmapSubscriber> costmap_sub_;
100  std::shared_ptr<nav2_costmap_2d::FootprintSubscriber> footprint_sub_;
101  std::unique_ptr<nav2_costmap_2d::CostmapTopicCollisionChecker> collision_checker_;
102 };
103 
104 } // namespace nav2_system_tests
105 
106 #endif // BEHAVIORS__ASSISTED_TELEOP__ASSISTED_TELEOP_BEHAVIOR_TESTER_HPP_