Skip to content

Commit

Permalink
chore: Update timer implementation in simple_int_publisher and pollin…
Browse files Browse the repository at this point in the history
…g_int_subscriber

Signed-off-by: Autumn60 <[email protected]>
  • Loading branch information
Autumn60 committed Jul 7, 2024
1 parent dbc65e9 commit d06b2c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
17 changes: 10 additions & 7 deletions src/sample/simple_int_publisher/src/simple_int_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ SimpleIntPublisher::SimpleIntPublisher(const rclcpp::NodeOptions & options)

// Declare timer for update function
{
auto update_callback = [this]() { this->update(); };
auto period = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::duration<double>(1.0 / update_rate_hz));
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);
int update_dt_ms = static_cast<int>(1000.0 / update_rate_hz);
update_timer_ = this->create_wall_timer(
std::chrono::milliseconds(update_dt_ms), std::bind(&SimpleIntPublisher::update, this));
// auto update_callback = [this]() { this->update(); };
// auto period = std::chrono::duration_cast<std::chrono::nanoseconds>(
// std::chrono::duration<double>(1.0 / update_rate_hz));
// 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);
}

// Reset counter
Expand Down
17 changes: 10 additions & 7 deletions src/sample/simple_int_subscriber/src/polling_int_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ PollingIntSubscriber::PollingIntSubscriber(const rclcpp::NodeOptions & options)

// Declare timer for update function
{
auto update_callback = [this]() { this->update(); };
auto period = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::duration<double>(1.0 / update_rate_hz));
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);
int update_dt_ms = static_cast<int>(1000.0 / update_rate_hz);
update_timer_ = this->create_wall_timer(
std::chrono::milliseconds(update_dt_ms), std::bind(&PollingIntSubscriber::update, this));
// auto update_callback = [this]() { this->update(); };
// auto period = std::chrono::duration_cast<std::chrono::nanoseconds>(
// std::chrono::duration<double>(1.0 / update_rate_hz));
// 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);
}
}

Expand Down

0 comments on commit d06b2c8

Please sign in to comment.