Skip to content

Commit

Permalink
replace update timer to FunctionTimer (#104)
Browse files Browse the repository at this point in the history
Signed-off-by: Autumn60 <[email protected]>
  • Loading branch information
Autumn60 committed Jul 28, 2024
1 parent d1b9657 commit 0bd622b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/planning/dwa_planner/include/dwa_planner/dwa_planner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define DWA_PLANNER__DWA_PLANNER_HPP_

#include <rclcpp/rclcpp.hpp>
#include <wheel_stuck_common_utils/ros/function_timer.hpp>
#include <wheel_stuck_common_utils/ros/no_callback_subscription.hpp>

#include <geometry_msgs/msg/pose_stamped.hpp>
Expand All @@ -27,6 +28,7 @@

namespace dwa_planner
{
using FunctionTimer = wheel_stuck_common_utils::ros::FunctionTimer;

using OccupancyGrid = nav_msgs::msg::OccupancyGrid;
using Odometry = nav_msgs::msg::Odometry;
Expand Down Expand Up @@ -87,7 +89,7 @@ class DWAPlanner : public rclcpp::Node
double calculate_stage_cost(const State & state);
double calculate_terminal_cost(const State & state);

rclcpp::TimerBase::SharedPtr update_timer_;
FunctionTimer::SharedPtr update_timer_;

OccupancyGridSubscription::SharedPtr map_sub_;
OdometrySubscription::SharedPtr odom_sub_;
Expand Down
9 changes: 2 additions & 7 deletions src/planning/dwa_planner/src/dwa_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,8 @@ DWAPlanner::DWAPlanner(const rclcpp::NodeOptions & options) : Node("dwa_planner"

// Declare timer for update function
{
auto update_callback = [this]() { this->update(); };
auto period =
std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::duration<double>(dt_));
update_timer_ = std::make_shared<rclcpp::GenericTimer<decltype(update_callback)>>(
this->get_clock(), period, std::move(update_callback),
this->get_node_base_interface()->get_context());
this->get_node_timers_interface()->add_timer(update_timer_, nullptr);
update_timer_ =
FunctionTimer::create_function_timer(this, update_rate_hz, [this]() { this->update(); });
}
}

Expand Down

0 comments on commit 0bd622b

Please sign in to comment.