Skip to content

Commit e204809

Browse files
author
Felix Exner
committed
Update to using quaternion
1 parent 7adf66e commit e204809

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@ enum StoppingInterface
8080
STOP_VELOCITY
8181
};
8282

83+
// We define our own quaternion to use it as a buffer, since we need to pass pointers to the state
84+
// interfaces.
85+
struct Quaternion
86+
{
87+
Quaternion() : x(0), y(0), z(0), w(0)
88+
{
89+
}
90+
91+
void set(const tf2::Quaternion& q)
92+
{
93+
x = q.x();
94+
y = q.y();
95+
z = q.z();
96+
w = q.w();
97+
}
98+
99+
double x;
100+
double y;
101+
double z;
102+
double w;
103+
};
104+
83105
/*!
84106
* \brief The HardwareInterface class handles the interface between the ROS system and the main
85107
* driver. It contains the read and write methods of the main control loop and registers various ROS
@@ -144,8 +166,8 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
144166
urcl::vector6d_t urcl_joint_efforts_;
145167
urcl::vector6d_t urcl_ft_sensor_measurements_;
146168
urcl::vector6d_t urcl_tcp_pose_;
147-
urcl::vector3d_t tcp_orientation_rpy_;
148169
tf2::Quaternion tcp_rotation_quat_;
170+
Quaternion tcp_rotation_buffer;
149171

150172
bool packet_read_;
151173

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,13 @@ std::vector<hardware_interface::StateInterface> URPositionHardwareInterface::exp
243243
state_interfaces.emplace_back(
244244
hardware_interface::StateInterface(tf_prefix + "tcp_pose", "position.z", &urcl_tcp_pose_[2]));
245245
state_interfaces.emplace_back(
246-
hardware_interface::StateInterface(tf_prefix + "tcp_pose", "orientation.r", &tcp_orientation_rpy_[0]));
246+
hardware_interface::StateInterface(tf_prefix + "tcp_pose", "orientation.x", &tcp_rotation_buffer.x));
247247
state_interfaces.emplace_back(
248-
hardware_interface::StateInterface(tf_prefix + "tcp_pose", "orientation.p", &tcp_orientation_rpy_[1]));
248+
hardware_interface::StateInterface(tf_prefix + "tcp_pose", "orientation.y", &tcp_rotation_buffer.y));
249249
state_interfaces.emplace_back(
250-
hardware_interface::StateInterface(tf_prefix + "tcp_pose", "orientation.y", &tcp_orientation_rpy_[2]));
250+
hardware_interface::StateInterface(tf_prefix + "tcp_pose", "orientation.z", &tcp_rotation_buffer.z));
251+
state_interfaces.emplace_back(
252+
hardware_interface::StateInterface(tf_prefix + "tcp_pose", "orientation.w", &tcp_rotation_buffer.w));
251253

252254
return state_interfaces;
253255
}
@@ -802,8 +804,7 @@ void URPositionHardwareInterface::extractToolPose()
802804
} else {
803805
tcp_rotation_quat_.setValue(0.0, 0.0, 0.0, 1.0); // default Quaternion is 0,0,0,0 which is invalid
804806
}
805-
auto rot_mat = tf2::Matrix3x3(tcp_rotation_quat_);
806-
rot_mat.getRPY(tcp_orientation_rpy_[0], tcp_orientation_rpy_[1], tcp_orientation_rpy_[2]);
807+
tcp_rotation_buffer.set(tcp_rotation_quat_);
807808
}
808809

809810
hardware_interface::return_type URPositionHardwareInterface::prepare_command_mode_switch(

0 commit comments

Comments
 (0)