Skip to content

Commit d12cbdf

Browse files
committed
Cleanup and more name convention
1 parent e269518 commit d12cbdf

File tree

4 files changed

+18
-104
lines changed

4 files changed

+18
-104
lines changed

ur_controllers/include/ur_controllers/freedrive_mode_controller.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
//----------------------------------------------------------------------
3030
/*!\file
3131
*
32-
* \author Felix Exner exner@fzi.de
33-
* \date 2023-06-29
32+
* \author Vincenzo Di Pentima dipentima@fzi.de
33+
* \date 2024-09-26
3434
*/
3535
//----------------------------------------------------------------------
3636
#ifndef UR_CONTROLLERS__FREEDRIVE_MODE_CONTROLLER_HPP_
@@ -60,12 +60,9 @@ namespace ur_controllers
6060
{
6161
enum CommandInterfaces
6262
{
63-
FREEDRIVE_MODE_ASYNC_SUCCESS = 25,
64-
FREEDRIVE_MODE_CMD = 26,
65-
};
66-
enum StateInterfaces
67-
{
68-
INITIALIZED_FLAG = 0u,
63+
FREEDRIVE_MODE_ASYNC_SUCCESS = 0u,
64+
FREEDRIVE_MODE_ENABLE = 1,
65+
FREEDRIVE_MODE_ABORT = 2,
6966
};
7067

7168
using namespace std::chrono_literals; // NOLINT

ur_controllers/src/freedrive_mode_controller.cpp

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ur_controllers::FreedriveModeController::on_configure(const rclcpp_lifecycle::St
8585
{
8686
// Subscriber definition
8787
enable_freedrive_mode_sub_ = get_node()->create_subscription<std_msgs::msg::Bool>(
88-
"~/freedrive_mode_active", 10,
88+
"~/enable_freedrive_mode", 10,
8989
std::bind(&FreedriveModeController::readFreedriveModeCmd, this, std::placeholders::_1));
9090

9191
timer_started_ = false;
@@ -267,89 +267,6 @@ void FreedriveModeController::timeout_callback()
267267
timer_started_ = false;
268268
}
269269

270-
// Timeout handling for the topic
271-
/*
272-
rclcpp_action::CancelResponse FreedriveModeController::goal_cancelled_callback(
273-
const std::shared_ptr<rclcpp_action::ServerGoalHandle<ur_msgs::action::EnableFreedriveMode>> goal_handle)
274-
{
275-
bool success;
276-
277-
// Check that cancel request refers to currently active goal (if any)
278-
const auto active_goal = *rt_active_goal_.readFromNonRT();
279-
if (active_goal && active_goal->gh_ == goal_handle) {
280-
RCLCPP_INFO(get_node()->get_logger(), "Disabling freedrive mode requested.");
281-
282-
freedrive_active_ = false;
283-
change_requested_ = true;
284-
285-
RCLCPP_INFO(get_node()->get_logger(), "Waiting for the freedrive mode to be disabled.");
286-
while (async_state_ == ASYNC_WAITING || change_requested_) {
287-
// Asynchronous wait until the hardware interface has set the force mode
288-
std::this_thread::sleep_for(std::chrono::milliseconds(10));
289-
}
290-
291-
success = async_state_ == 1.0;
292-
if (success) {
293-
RCLCPP_INFO(get_node()->get_logger(), "Freedrive mode has been disabled successfully.");
294-
} else {
295-
RCLCPP_ERROR(get_node()->get_logger(), "Could not disable freedrive mode.");
296-
}
297-
298-
// Mark the current goal as canceled
299-
auto result = std::make_shared<FreedriveModeAction::Result>();
300-
active_goal->setCanceled(result);
301-
rt_active_goal_.writeFromNonRT(RealtimeGoalHandlePtr());
302-
}
303-
return rclcpp_action::CancelResponse::ACCEPT;
304-
}
305-
*/
306-
307-
// Don't need this anymore, but logic must be reproduced in subscriber topic
308-
/*
309-
void FreedriveModeController::goal_accepted_callback(
310-
std::shared_ptr<rclcpp_action::ServerGoalHandle<ur_msgs::action::EnableFreedriveMode>> goal_handle)
311-
{
312-
RCLCPP_INFO_STREAM(get_node()->get_logger(), "Starting freedrive mode.");
313-
314-
bool success;
315-
316-
freedrive_active_ = true;
317-
change_requested_ = true;
318-
319-
RCLCPP_INFO(get_node()->get_logger(), "Waiting for freedrive mode to be set.");
320-
const auto maximum_retries = freedrive_params_.check_io_successful_retries;
321-
int retries = 0;
322-
while (async_state_ == ASYNC_WAITING || change_requested_) {
323-
std::this_thread::sleep_for(std::chrono::milliseconds(10));
324-
retries++;
325-
326-
if (retries > maximum_retries) {
327-
success = false;
328-
}
329-
}
330-
331-
// Check if the change was successful
332-
success = async_state_ == 1.0;
333-
334-
if (success) {
335-
RCLCPP_INFO_STREAM(get_node()->get_logger(), "Freedrive mode has been set successfully.");
336-
} else {
337-
RCLCPP_ERROR(get_node()->get_logger(), "Could not set the freedrive mode.");
338-
}
339-
340-
// Action handling will be done from the timer callback to avoid those things in the realtime
341-
// thread. First, we delete the existing (if any) timer by resetting the pointer and then create a new
342-
// one.
343-
RealtimeGoalHandlePtr rt_goal = std::make_shared<RealtimeGoalHandle>(goal_handle);
344-
rt_goal->execute();
345-
rt_active_goal_.writeFromNonRT(rt_goal);
346-
goal_handle_timer_.reset();
347-
goal_handle_timer_ = get_node()->create_wall_timer(action_monitor_period_.to_chrono<std::chrono::nanoseconds>(),
348-
std::bind(&RealtimeGoalHandle::runNonRealtime, rt_goal));
349-
return;
350-
}
351-
*/
352-
353270
bool FreedriveModeController::waitForAsyncCommand(std::function<double(void)> get_value)
354271
{
355272
const auto maximum_retries = freedrive_params_.check_io_successful_retries;

ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
287287
urcl::RobotReceiveTimeout receive_timeout_ = urcl::RobotReceiveTimeout::millisec(20);
288288

289289
// Check if name is correct here
290-
const std::string FREEDRIVE_MODE = "freedrive_mode";
290+
const std::string FREEDRIVE_MODE_GPIO = "freedrive_mode";
291291
const std::string PASSTHROUGH_GPIO = "trajectory_passthrough";
292292
};
293293
} // namespace ur_robot_driver

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,13 @@ std::vector<hardware_interface::CommandInterface> URPositionHardwareInterface::e
341341
tf_prefix + "zero_ftsensor", "zero_ftsensor_async_success", &zero_ftsensor_async_success_));
342342

343343
command_interfaces.emplace_back(hardware_interface::CommandInterface(
344-
tf_prefix + FREEDRIVE_MODE, "async_success", &freedrive_mode_async_success_));
344+
tf_prefix + FREEDRIVE_MODE_GPIO, "async_success", &freedrive_mode_async_success_));
345345

346346
command_interfaces.emplace_back(hardware_interface::CommandInterface(
347-
tf_prefix + FREEDRIVE_MODE, "enable", &freedrive_mode_enable_));
347+
tf_prefix + FREEDRIVE_MODE_GPIO, "enable", &freedrive_mode_enable_));
348348

349349
command_interfaces.emplace_back(hardware_interface::CommandInterface(
350-
tf_prefix + FREEDRIVE_MODE, "abort", &freedrive_mode_abort_));
350+
tf_prefix + FREEDRIVE_MODE_GPIO, "abort", &freedrive_mode_abort_));
351351

352352
command_interfaces.emplace_back(hardware_interface::CommandInterface(tf_prefix + PASSTHROUGH_GPIO, "transfer_state",
353353
&passthrough_trajectory_transfer_state_));
@@ -930,7 +930,7 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
930930
control_modes[i] = PASSTHROUGH_GPIO;
931931
}
932932
if (freedrive_mode_controller_running_) {
933-
control_modes[i] = FREEDRIVE_MODE;
933+
control_modes[i] = FREEDRIVE_MODE_GPIO;
934934
}
935935
}
936936

@@ -960,11 +960,11 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
960960
return hardware_interface::return_type::ERROR;
961961
}
962962
start_modes_[i] = PASSTHROUGH_GPIO;
963-
} else if (key == tf_prefix + FREEDRIVE_MODE + "/async_success") {
963+
} else if (key == tf_prefix + FREEDRIVE_MODE_GPIO + "/async_success") {
964964
if (start_modes_[i] != "UNDEFINED") {
965965
return hardware_interface::return_type::ERROR;
966966
}
967-
start_modes_[i] = FREEDRIVE_MODE;
967+
start_modes_[i] = FREEDRIVE_MODE_GPIO;
968968
}
969969
}
970970
}
@@ -991,9 +991,9 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
991991
control_modes[i] = "UNDEFINED";
992992
}
993993
}
994-
if (key == tf_prefix + FREEDRIVE_MODE + "/async_success") {
994+
if (key == tf_prefix + FREEDRIVE_MODE_GPIO + "/async_success") {
995995
stop_modes_.push_back(StoppingInterface::STOP_FREEDRIVE);
996-
if (control_modes[i] == FREEDRIVE_MODE) {
996+
if (control_modes[i] == FREEDRIVE_MODE_GPIO) {
997997
control_modes[i] = "UNDEFINED";
998998
}
999999
}
@@ -1013,15 +1013,15 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
10131013
}))) {
10141014
ret_val = hardware_interface::return_type::ERROR;
10151015
}
1016-
if (std::any_of(start_modes_.begin(), start_modes_.end(), [this](auto& item) { return (item == FREEDRIVE_MODE); }) &&
1016+
if (std::any_of(start_modes_.begin(), start_modes_.end(), [this](auto& item) { return (item == FREEDRIVE_MODE_GPIO); }) &&
10171017
(std::any_of(start_modes_.begin(), start_modes_.end(),
10181018
[this](auto& item) {
10191019
return (item == hardware_interface::HW_IF_VELOCITY || item == hardware_interface::HW_IF_POSITION ||
10201020
item == PASSTHROUGH_GPIO);
10211021
}) ||
10221022
std::any_of(control_modes.begin(), control_modes.end(), [this](auto& item) {
10231023
return (item == hardware_interface::HW_IF_VELOCITY || item == hardware_interface::HW_IF_POSITION ||
1024-
item == PASSTHROUGH_GPIO || item == FREEDRIVE_MODE);
1024+
item == PASSTHROUGH_GPIO || item == FREEDRIVE_MODE_GPIO);
10251025
}))) {
10261026
ret_val = hardware_interface::return_type::ERROR;
10271027
}
@@ -1090,7 +1090,7 @@ hardware_interface::return_type URPositionHardwareInterface::perform_command_mod
10901090
urcl_velocity_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
10911091
velocity_controller_running_ = true;
10921092
} else if (start_modes_.size() != 0 &&
1093-
std::find(start_modes_.begin(), start_modes_.end(), FREEDRIVE_MODE) != start_modes_.end()) {
1093+
std::find(start_modes_.begin(), start_modes_.end(), FREEDRIVE_MODE_GPIO) != start_modes_.end()) {
10941094
velocity_controller_running_ = false;
10951095
position_controller_running_ = false;
10961096
freedrive_mode_controller_running_ = true;

0 commit comments

Comments
 (0)