Skip to content

Commit c386689

Browse files
committed
CHG: activation logic moved to hardware_interface
1 parent 9e83533 commit c386689

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

robotiq_hande_driver/hardware/include/robotiq_hande_driver/application.hpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,12 @@ class GripperApplication {
130130
/**
131131
* @brief Activates the gripper, making it ready for use.
132132
*
133-
* @param blocking If true wait until the gripper is active.
134133
* @return None.
135134
* @note The status should be checked to verify successful execution. An exception is thrown if
136135
* communication issues occur.
137136
*/
138-
void activate(bool blocking = true) {
139-
int iter = 0;
140-
read();
141-
142-
if(status_.is_ready)
143-
printf("Gripper already active\n");
144-
else {
145-
printf("Activation in progress\n");
146-
protocol_logic_.activate();
147-
148-
while(!status_.is_ready && blocking) {
149-
printf("Waiting another 100ms, attempt: %d\n", iter);
150-
usleep(100 * 1000);
151-
read();
152-
if(iter++ > 100) break;
153-
}
154-
}
137+
void activate() {
138+
protocol_logic_.activate();
155139
};
156140

157141
/**

robotiq_hande_driver/hardware/src/hande_hardware_interface.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
namespace robotiq_hande_driver {
77

8+
constexpr auto ACTIVATION_MAX_ITER = 100;
9+
inline wait_100ms() {
10+
usleep(100 * 1000);
11+
}
12+
813
RobotiqHandeHardwareInterface::RobotiqHandeHardwareInterface() {}
914

1015
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_init(const HWI::HardwareInfo& info) {
@@ -115,7 +120,25 @@ std::vector<HWI::CommandInterface> RobotiqHandeHardwareInterface::export_command
115120

116121
HWI::CallbackReturn RobotiqHandeHardwareInterface::on_activate(
117122
const rlccp_lc::State& /*previous_state*/) {
118-
gripper_driver_.activate();
123+
int iter = 0;
124+
gripper_driver_.read();
125+
126+
if(gripper_driver_.get_status().is_ready)
127+
RCLCPP_INFO(get_logger(), "Hand-E already active");
128+
else {
129+
RCLCPP_INFO(get_logger(), "Hand-E activation in progress");
130+
gripper_driver_.activate();
131+
132+
while(!gripper_driver_.get_status().is_ready) {
133+
RCLCPP_INFO(get_logger(), "Waiting another 100ms, attempt: %d", iter);
134+
wait_100ms();
135+
gripper_driver_.read();
136+
if(iter++ > ACTIVATION_MAX_ITER) {
137+
RCLCPP_INFO(get_logger(), "Hand-E NOT activated, failure");
138+
return HWI::CallbackReturn::FAILURE;
139+
}
140+
}
141+
}
119142

120143
RCLCPP_INFO(get_logger(), "Hand-E successfully activated");
121144
return HWI::CallbackReturn::SUCCESS;

0 commit comments

Comments
 (0)