Skip to content

Commit b7efaa4

Browse files
committed
Fix to start timer only for relevant msgs
1 parent 3d906dd commit b7efaa4

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

ur_controllers/include/ur_controllers/freedrive_mode_controller.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class FreedriveModeController : public controller_interface::ControllerInterface
109109
std::atomic<double> first_log_;
110110
std::atomic<double> timer_started_;
111111

112+
void start_timer();
112113
void timeout_callback();
113114

114115
static constexpr double ASYNC_WAITING = 2.0;

ur_controllers/src/freedrive_mode_controller.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,28 +220,20 @@ controller_interface::return_type ur_controllers::FreedriveModeController::updat
220220

221221
void FreedriveModeController::readFreedriveModeCmd(const std_msgs::msg::Bool::SharedPtr msg)
222222
{
223-
if (!timer_started_)
224-
{
225-
// Start the timer only after the first message is received
226-
freedrive_sub_timer_ = get_node()->create_wall_timer(
227-
timeout_interval_,
228-
std::bind(&FreedriveModeController::timeout_callback, this));
229-
timer_started_ = true;
230-
231-
RCLCPP_INFO(get_node()->get_logger(), "Timer started after receiving first command.");
232-
}
233223

234224
// Process the freedrive_mode command.
235225
if(msg->data)
236226
{
237227
if((!freedrive_active_) && (!change_requested_)){
238228
freedrive_active_ = true;
239229
change_requested_ = true;
230+
start_timer();
240231
}
241232
} else{
242233
if((freedrive_active_) && (!change_requested_)){
243234
freedrive_active_ = false;
244235
change_requested_ = true;
236+
start_timer();
245237
}
246238
}
247239

@@ -251,6 +243,20 @@ void FreedriveModeController::readFreedriveModeCmd(const std_msgs::msg::Bool::Sh
251243
}
252244
}
253245

246+
void FreedriveModeController::start_timer()
247+
{
248+
if (!timer_started_)
249+
{
250+
// Start the timer only after the first message is received
251+
freedrive_sub_timer_ = get_node()->create_wall_timer(
252+
timeout_interval_,
253+
std::bind(&FreedriveModeController::timeout_callback, this));
254+
timer_started_ = true;
255+
256+
RCLCPP_INFO(get_node()->get_logger(), "Timer started after receiving first command.");
257+
}
258+
}
259+
254260
void FreedriveModeController::timeout_callback()
255261
{
256262

0 commit comments

Comments
 (0)