Skip to content

Commit 5bd4221

Browse files
committed
timeout feature updated
updated the param for yaml
1 parent 58a335b commit 5bd4221

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

io_gripper_controller/include/io_gripper_controller/io_gripper_controller.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ class IOGripperController : public controller_interface::ControllerInterface
236236
std::atomic<bool> openFlag_{false};
237237
std::atomic<bool> closeFlag_{false};
238238

239-
bool check_state_ios{false};
239+
std::atomic<bool> check_gripper_state_ios_{false};
240+
std::atomic<bool> transition_time_updated_{false};
240241

241242
private:
242243
/**

io_gripper_controller/src/io_gripper_controller.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,26 @@ void IOGripperController::handle_gripper_state_transition(
277277
break;
278278

279279
case IOGripperState::HALTED:
280-
// do nothing
280+
gripper_state_buffer_.writeFromNonRT(IOGripperState::IDLE);
281281
RCLCPP_ERROR(
282282
get_node()->get_logger(), "%s - HALTED: Gripper is in HALTED state",
283283
transition_name.c_str());
284+
transition_time_updated_.store(false);
284285
break;
285286

286287
case IOGripperState::SET_BEFORE_COMMAND:
287288

288-
last_transition_time_ = current_time;
289+
if (!transition_time_updated_.load())
290+
{
291+
last_transition_time_ = current_time;
292+
transition_time_updated_.store(true);
293+
}
289294
if (set_commands(ios.set_before_command_ios, transition_name + " - SET_BEFORE_COMMAND"))
290295
{
291296
// TODO(destogl): check to use other Realtime sync object to have write from RT
292297
gripper_state_buffer_.writeFromNonRT(IOGripperState::CHECK_BEFORE_COMMAND);
293298
}
294-
if ((current_time - last_transition_time_).seconds() > params_.timeout)
299+
else if ((current_time - last_transition_time_).seconds() > params_.timeout)
295300
{
296301
RCLCPP_ERROR(
297302
get_node()->get_logger(),
@@ -314,7 +319,6 @@ void IOGripperController::handle_gripper_state_transition(
314319
transition_name.c_str(), params_.timeout);
315320
gripper_state_buffer_.writeFromNonRT(IOGripperState::HALTED);
316321
}
317-
last_transition_time_ = current_time;
318322
break;
319323
case IOGripperState::SET_COMMAND:
320324
RCLCPP_INFO(
@@ -326,11 +330,7 @@ void IOGripperController::handle_gripper_state_transition(
326330
// TODO(destogl): check to use other Realtime sync object to have write from RT
327331
gripper_state_buffer_.writeFromNonRT(IOGripperState::CHECK_COMMAND);
328332
}
329-
else
330-
{
331-
RCLCPP_ERROR(get_node()->get_logger(), "failed");
332-
}
333-
if ((current_time - last_transition_time_).seconds() > params_.timeout)
333+
else if ((current_time - last_transition_time_).seconds() > params_.timeout)
334334
{
335335
RCLCPP_ERROR(
336336
get_node()->get_logger(),
@@ -341,7 +341,7 @@ void IOGripperController::handle_gripper_state_transition(
341341
break;
342342
case IOGripperState::CHECK_COMMAND:
343343
// check the state of the gripper
344-
check_state_ios = true;
344+
check_gripper_state_ios_.store(true);
345345
if (ios.has_multiple_end_states)
346346
{
347347
for (const auto & possible_end_state : ios.possible_states)
@@ -350,25 +350,26 @@ void IOGripperController::handle_gripper_state_transition(
350350
ios.multiple_states_ios.at(possible_end_state),
351351
transition_name + " - CHECK_COMMAND"))
352352
{
353-
check_state_ios = true;
353+
check_gripper_state_ios_.store(true);
354354
after_joint_states_ =
355355
params_.close.state.possible_closed_states_map.at(possible_end_state).joint_states;
356356
// TODO(Sachin): store possible_end_state in a variable to publish on status topic
357357
break;
358358
}
359359
else
360360
{
361-
check_state_ios = false;
361+
check_gripper_state_ios_.store(false);
362362
}
363363
}
364364
}
365365
else // only single end state
366366
{
367367
after_joint_states_ = params_.open.joint_states;
368-
check_state_ios = check_states(ios.state_ios, transition_name + " - CHECK_COMMAND");
368+
check_gripper_state_ios_.store(
369+
check_states(ios.state_ios, transition_name + " - CHECK_COMMAND"));
369370
}
370371

371-
if (check_state_ios)
372+
if (check_gripper_state_ios_.load())
372373
{
373374
gripper_state_buffer_.writeFromNonRT(IOGripperState::SET_AFTER_COMMAND);
374375
}
@@ -411,6 +412,7 @@ void IOGripperController::handle_gripper_state_transition(
411412
RCLCPP_INFO(
412413
get_node()->get_logger(), "%s - CHECK_AFTER_COMMAND: Gripper reached target state",
413414
transition_name.c_str());
415+
transition_time_updated_.store(false); // resetting the flag
414416
}
415417
else if ((current_time - last_transition_time_).seconds() > params_.timeout)
416418
{

io_gripper_controller/test/test_io_gripper_controller.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
// [RosTeamWorkspace](https://github.com/StoglRobotics/ros_team_workspace) repository.
1818
//
1919

20-
#ifndef TEMPLATES__ROS2_CONTROL__CONTROLLER__TEST_GRIPPER_IO_CONTROLLER_HPP_
21-
#define TEMPLATES__ROS2_CONTROL__CONTROLLER__TEST_GRIPPER_IO_CONTROLLER_HPP_
20+
#ifndef TEST_IO_GRIPPER_CONTROLLER_HPP_
21+
#define TEST_IO_GRIPPER_CONTROLLER_HPP_
2222

2323
#include <chrono>
2424
#include <limits>
@@ -140,7 +140,7 @@ class IOGripperControllerFixture : public ::testing::Test
140140

141141
// setting the command state interfaces manually
142142
std::vector<hardware_interface::LoanedCommandInterface> command_itfs;
143-
command_itfs.reserve(3); // TODO (Sachin) : change this some variable later
143+
command_itfs.reserve(3); // TODO(Sachin) : change this some variable later
144144

145145
command_itfs.emplace_back(greif_oeffen_wqg1_cmd_);
146146
command_itfs.emplace_back(greif_schliess_wqg2_cmd_);
@@ -220,6 +220,7 @@ class IOGripperControllerFixture : public ::testing::Test
220220
void setup_parameters()
221221
{
222222
controller_->get_node()->set_parameter({"use_action", false});
223+
controller_->get_node()->set_parameter({"timeout", 5.0});
223224
controller_->get_node()->set_parameter({"open_close_joints", open_close_joints});
224225
controller_->get_node()->set_parameter({"open.joint_states", open_joint_states});
225226
controller_->get_node()->set_parameter(
@@ -433,4 +434,4 @@ class IOGripperControllerFixture : public ::testing::Test
433434
class IOGripperControllerTest : public IOGripperControllerFixture<TestableIOGripperController>
434435
{
435436
};
436-
#endif // TEMPLATES__ROS2_CONTROL__CONTROLLER__TEST_GRIPPER_IO_CONTROLLER_HPP_
437+
#endif // TEST_IO_GRIPPER_CONTROLLER_HPP_

0 commit comments

Comments
 (0)