Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
back_up.cpp
1 // Copyright (c) 2022 Joshua Wallace
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "nav2_behaviors/plugins/back_up.hpp"
16 
17 namespace nav2_behaviors
18 {
19 
20 ResultStatus BackUp::onRun(const std::shared_ptr<const BackUpAction::Goal> command)
21 {
22  if (command->target.y != 0.0 || command->target.z != 0.0) {
23  std::string error_msg = "Backing up in Y and Z not supported, will only move in X.";
24  RCLCPP_INFO(logger_, error_msg.c_str());
25  return ResultStatus{Status::FAILED, BackUpActionResult::INVALID_INPUT, error_msg};
26  }
27 
28  // Silently ensure that both the speed and direction are negative.
29  command_x_ = -std::fabs(command->target.x);
30  command_speed_ = -std::fabs(command->speed);
31  command_time_allowance_ = command->time_allowance;
32  command_disable_collision_checks_ = command->disable_collision_checks;
33 
34  end_time_ = this->clock_->now() + command_time_allowance_;
35 
36  if (!nav2_util::getCurrentPose(
37  initial_pose_, *tf_, local_frame_, robot_base_frame_,
38  transform_tolerance_))
39  {
40  std::string error_msg = "Initial robot pose is not available.";
41  RCLCPP_ERROR(logger_, error_msg.c_str());
42  return ResultStatus{Status::FAILED, BackUpActionResult::TF_ERROR, error_msg};
43  }
44 
45  return ResultStatus{Status::SUCCEEDED, BackUpActionResult::NONE, ""};
46 }
47 
48 } // namespace nav2_behaviors
49 
50 #include "pluginlib/class_list_macros.hpp"
51 PLUGINLIB_EXPORT_CLASS(nav2_behaviors::BackUp, nav2_core::Behavior)
Abstract interface for behaviors to adhere to with pluginlib.
Definition: behavior.hpp:42