Nav2 Navigation Stack - jazzy  jazzy
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  RCLCPP_INFO(
24  logger_,
25  "Backing up in Y and Z not supported, will only move in X.");
26  return ResultStatus{Status::FAILED, BackUpActionResult::INVALID_INPUT};
27  }
28 
29  // Silently ensure that both the speed and direction are negative.
30  command_x_ = -std::fabs(command->target.x);
31  command_speed_ = -std::fabs(command->speed);
32  command_time_allowance_ = command->time_allowance;
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  RCLCPP_ERROR(logger_, "Initial robot pose is not available.");
41  return ResultStatus{Status::FAILED, BackUpActionResult::TF_ERROR};
42  }
43 
44  return ResultStatus{Status::SUCCEEDED, BackUpActionResult::NONE};
45 }
46 
47 } // namespace nav2_behaviors
48 
49 #include "pluginlib/class_list_macros.hpp"
50 PLUGINLIB_EXPORT_CLASS(nav2_behaviors::BackUp, nav2_core::Behavior)
Abstract interface for behaviors to adhere to with pluginlib.
Definition: behavior.hpp:42