Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
time_marker.cpp
1 // Copyright (c) 2025, Open Navigation LLC
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 
16 #include <memory>
17 #include <string>
18 
19 #include "nav2_route/plugins/route_operations/time_marker.hpp"
20 
21 namespace nav2_route
22 {
23 
25  const rclcpp_lifecycle::LifecycleNode::SharedPtr node,
26  std::shared_ptr<nav2_costmap_2d::CostmapSubscriber>/* costmap_subscriber */,
27  const std::string & name)
28 {
29  RCLCPP_INFO(node->get_logger(), "Configuring Adjust speed limit operation.");
30  name_ = name;
31  nav2_util::declare_parameter_if_not_declared(
32  node, getName() + ".time_tag", rclcpp::ParameterValue("abs_time_taken"));
33  time_tag_ = node->get_parameter(getName() + ".time_tag").as_string();
34  clock_ = node->get_clock();
35  edge_start_time_ = rclcpp::Time(0.0);
36 }
37 
39  NodePtr /*node_achieved*/,
40  EdgePtr edge_entered,
41  EdgePtr edge_exited,
42  const Route & /*route*/,
43  const geometry_msgs::msg::PoseStamped & /*curr_pose*/,
44  const Metadata * /*mdata*/)
45 {
46  OperationResult result;
47  rclcpp::Time now = clock_->now();
48  if (!edge_exited || edge_exited->edgeid != curr_edge_) {
49  edge_start_time_ = now;
50  curr_edge_ = edge_entered ? edge_entered->edgeid : 0;
51  return result;
52  }
53 
54  float dur = static_cast<float>((now - edge_start_time_).seconds());
55  if (edge_start_time_.seconds() > 1e-3) {
56  edge_exited->metadata.setValue<float>(time_tag_, dur);
57  }
58 
59  edge_start_time_ = now;
60  curr_edge_ = edge_entered ? edge_entered->edgeid : 0;
61  return result;
62 }
63 
64 } // namespace nav2_route
65 
66 #include "pluginlib/class_list_macros.hpp"
A plugin interface to perform an operation while tracking the route such as triggered from the graph ...
A route operation to add accurate times to the graph's edges after navigation to use in later iterati...
Definition: time_marker.hpp:36
void configure(const rclcpp_lifecycle::LifecycleNode::SharedPtr node, std::shared_ptr< nav2_costmap_2d::CostmapSubscriber > costmap_subscriber, const std::string &name) override
Configure.
Definition: time_marker.cpp:24
OperationResult perform(NodePtr node_achieved, EdgePtr edge_entered, EdgePtr edge_exited, const Route &route, const geometry_msgs::msg::PoseStamped &curr_pose, const Metadata *mdata=nullptr) override
The main speed limit operation to adjust the maximum speed of the vehicle.
Definition: time_marker.cpp:38
std::string getName() override
Get name of the plugin for parameter scope mapping.
Definition: time_marker.hpp:60
An object representing edges between nodes.
Definition: types.hpp:134
An object to store arbitrary metadata regarding nodes from the graph file.
Definition: types.hpp:35
An object to store the nodes in the graph file.
Definition: types.hpp:183
a struct to hold return from an operation
An ordered set of nodes and edges corresponding to the planned route.
Definition: types.hpp:211