Skip to content

Commit f6596c2

Browse files
committed
Reduce bitset tests for in_error state
1 parent a3df292 commit f6596c2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

ur_robot_driver/src/ros/hardware_interface.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,18 @@
3333

3434
using industrial_robot_status_interface::RobotMode;
3535
using industrial_robot_status_interface::TriState;
36+
using namespace ur_driver::rtde_interface;
3637

3738
namespace ur_driver
3839
{
40+
// bitset mask is applied to robot safety status bits in order to determine 'in_error' state
41+
static const std::bitset<11> in_error_bitset_(1 << toUnderlying(UrRtdeSafetyStatusBits::IS_PROTECTIVE_STOPPED) |
42+
1 << toUnderlying(UrRtdeSafetyStatusBits::IS_ROBOT_EMERGENCY_STOPPED) |
43+
1 << toUnderlying(UrRtdeSafetyStatusBits::IS_EMERGENCY_STOPPED) |
44+
1 << toUnderlying(UrRtdeSafetyStatusBits::IS_VIOLATION) |
45+
1 << toUnderlying(UrRtdeSafetyStatusBits::IS_FAULT) |
46+
1 << toUnderlying(UrRtdeSafetyStatusBits::IS_STOPPED_DUE_TO_SAFETY));
47+
3948
HardwareInterface::HardwareInterface()
4049
: joint_position_command_({ 0, 0, 0, 0, 0, 0 })
4150
, joint_velocity_command_({ 0, 0, 0, 0, 0, 0 })
@@ -673,12 +682,7 @@ void HardwareInterface::extractRobotStatus()
673682
// I found no way to reliably get information if the robot is moving
674683
robot_status_resource_.in_motion = TriState::UNKNOWN;
675684

676-
if (safety_status_bits_[toUnderlying(UrRtdeSafetyStatusBits::IS_PROTECTIVE_STOPPED)] ||
677-
safety_status_bits_[toUnderlying(UrRtdeSafetyStatusBits::IS_ROBOT_EMERGENCY_STOPPED)] ||
678-
safety_status_bits_[toUnderlying(UrRtdeSafetyStatusBits::IS_EMERGENCY_STOPPED)] ||
679-
safety_status_bits_[toUnderlying(UrRtdeSafetyStatusBits::IS_VIOLATION)] ||
680-
safety_status_bits_[toUnderlying(UrRtdeSafetyStatusBits::IS_FAULT)] ||
681-
safety_status_bits_[toUnderlying(UrRtdeSafetyStatusBits::IS_STOPPED_DUE_TO_SAFETY)])
685+
if ((safety_status_bits_ | in_error_bitset_).any())
682686
{
683687
robot_status_resource_.in_error = TriState::TRUE;
684688
}

0 commit comments

Comments
 (0)