Nav2 Navigation Stack - rolling  main
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_, "%s", 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 (!getCurrentPoseChecked(initial_pose_)) {
37  std::string error_msg = "Initial robot pose is not available or not current.";
38  RCLCPP_ERROR(logger_, "%s", error_msg.c_str());
39  return ResultStatus{Status::FAILED, BackUpActionResult::TF_ERROR, error_msg};
40  }
41 
42  return ResultStatus{Status::SUCCEEDED, BackUpActionResult::NONE, ""};
43 }
44 
45 } // namespace nav2_behaviors
46 
47 #include "pluginlib/class_list_macros.hpp"
48 PLUGINLIB_EXPORT_CLASS(nav2_behaviors::BackUp, nav2_core::Behavior)
bool getCurrentPoseChecked(geometry_msgs::msg::PoseStamped &pose)
Get one checked robot pose in the local frame, preserving the TF timestamp.
Abstract interface for behaviors to adhere to with pluginlib.
Definition: behavior.hpp:42