Skip to content

Commit 81f71bc

Browse files
authored
Only append to start_modes in prepare_switch (#1344)
Before the main control mode (position/velocity) was always overwriting the complete list for the joint. That worked fine when that was the only control mode for a joint or if it was the first in the list. But that is not guaranteed. Since we create the list as an empty vector beforehand, anyway, we can simply append to that list in any case. The list will be checked for compatibility at a later point, anyway.
1 parent 072b5be commit 81f71bc

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,12 +1099,6 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
10991099
}
11001100
}
11011101

1102-
if (!std::all_of(start_modes_.begin() + 1, start_modes_.end(),
1103-
[&](const std::vector<std::string>& other) { return other == start_modes_[0]; })) {
1104-
RCLCPP_ERROR(get_logger(), "Start modes of all joints have to be the same.");
1105-
return hardware_interface::return_type::ERROR;
1106-
}
1107-
11081102
// Starting interfaces
11091103
// If a joint has been reserved already, raise an error.
11101104
// Modes that are not directly mapped to a single joint such as force_mode reserve all joints.
@@ -1119,7 +1113,7 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
11191113
"requested.");
11201114
return hardware_interface::return_type::ERROR;
11211115
}
1122-
start_modes_[i] = { hardware_interface::HW_IF_POSITION };
1116+
start_modes_[i].push_back(hardware_interface::HW_IF_POSITION);
11231117
} else if (key == info_.joints[i].name + "/" + hardware_interface::HW_IF_VELOCITY) {
11241118
if (std::any_of(start_modes_[i].begin(), start_modes_[i].end(), [&](const std::string& item) {
11251119
return item == hardware_interface::HW_IF_POSITION || item == PASSTHROUGH_GPIO ||
@@ -1129,7 +1123,7 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
11291123
"requested.");
11301124
return hardware_interface::return_type::ERROR;
11311125
}
1132-
start_modes_[i] = { hardware_interface::HW_IF_VELOCITY };
1126+
start_modes_[i].push_back(hardware_interface::HW_IF_VELOCITY);
11331127
} else if (key == tf_prefix + FORCE_MODE_GPIO + "/type") {
11341128
if (std::any_of(start_modes_[i].begin(), start_modes_[i].end(), [&](const std::string& item) {
11351129
return item == hardware_interface::HW_IF_POSITION || item == hardware_interface::HW_IF_VELOCITY;
@@ -1169,6 +1163,12 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
11691163
}
11701164
}
11711165

1166+
if (!std::all_of(start_modes_.begin() + 1, start_modes_.end(),
1167+
[&](const std::vector<std::string>& other) { return other == start_modes_[0]; })) {
1168+
RCLCPP_ERROR(get_logger(), "Start modes of all joints have to be the same.");
1169+
return hardware_interface::return_type::ERROR;
1170+
}
1171+
11721172
// Stopping interfaces
11731173
// add stop interface per joint in tmp var for later check
11741174
for (const auto& key : stop_interfaces) {

0 commit comments

Comments
 (0)