Skip to content

Commit 5082992

Browse files
Janosch MachowinskiJanosch Machowinski
authored andcommitted
fix: Removed hack for getting clock from timer
Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com>
1 parent 1e526d2 commit 5082992

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

rclcpp/src/rclcpp/executors/events_cbg_executor/timer_manager.hpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,6 @@ class TimerQueue
128128
std::function<void(const std::function<void()> & executed_cb)> timer_ready_callback;
129129
};
130130

131-
class GetClockHelper : public rclcpp::TimerBase
132-
{
133-
public:
134-
static rclcpp::Clock::SharedPtr get_clock(const rclcpp::TimerBase & timer)
135-
{
136-
// SUPER ugly hack, but we need the correct clock
137-
return static_cast<const GetClockHelper *>(&timer)->clock_;
138-
}
139-
};
140-
141131
public:
142132
TimerQueue(rcl_clock_type_t timer_type, const rclcpp::Context::SharedPtr & context)
143133
: timer_type(timer_type), clock_waiter(context)
@@ -262,7 +252,7 @@ class TimerQueue
262252

263253
std::unique_ptr<TimerData> data = std::make_unique<TimerData>(TimerData{std::move(handle),
264254
timer,
265-
GetClockHelper::get_clock(*timer), false, timer_ready_callback});
255+
timer->get_clock(), false, timer_ready_callback});
266256

267257
timer->set_on_reset_callback(
268258
[data_ptr = data.get(), this](size_t) {

rclcpp/src/rclcpp/timer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ TimerBase::clear_on_reset_callback()
208208
on_reset_callback_ = nullptr;
209209
}
210210
}
211-
212211
void
213212
TimerBase::set_on_reset_callback(rcl_event_callback_t callback, const void * user_data)
214213
{
@@ -218,3 +217,8 @@ TimerBase::set_on_reset_callback(rcl_event_callback_t callback, const void * use
218217
rclcpp::exceptions::throw_from_rcl_error(ret, "Failed to set timer on reset callback");
219218
}
220219
}
220+
221+
const rclcpp::Clock::SharedPtr & TimerBase::get_clock() const
222+
{
223+
return clock_;
224+
}

0 commit comments

Comments
 (0)