@@ -88,6 +88,8 @@ ur_controllers::FreedriveModeController::on_configure(const rclcpp_lifecycle::St
8888 " ~/freedrive_mode_active" , 10 ,
8989 std::bind (&FreedriveModeController::readFreedriveModeCmd, this , std::placeholders::_1));
9090
91+ timer_started_ = false ;
92+
9193 const auto logger = get_node ()->get_logger ();
9294
9395 if (!freedrive_param_listener_) {
@@ -218,6 +220,17 @@ controller_interface::return_type ur_controllers::FreedriveModeController::updat
218220
219221void FreedriveModeController::readFreedriveModeCmd (const std_msgs::msg::Bool::SharedPtr msg)
220222{
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+ }
233+
221234 // Process the freedrive_mode command.
222235 if (msg->data )
223236 {
@@ -231,6 +244,24 @@ void FreedriveModeController::readFreedriveModeCmd(const std_msgs::msg::Bool::Sh
231244 change_requested_ = true ;
232245 }
233246 }
247+
248+ if (freedrive_sub_timer_)
249+ {
250+ freedrive_sub_timer_->reset ();
251+ }
252+ }
253+
254+ void FreedriveModeController::timeout_callback ()
255+ {
256+
257+ if (timer_started_){
258+ RCLCPP_INFO (get_node ()->get_logger (), " Freedrive mode will be deactivated since client is not reachable." );
259+
260+ freedrive_active_ = false ;
261+ change_requested_ = true ;
262+ }
263+
264+ timer_started_ = false ;
234265}
235266
236267// Timeout handling for the topic
0 commit comments