Get link absolute orientation - IMU position
Can anyone advise how to calculate the quaternion orientation of a link? I'm following a somewhat unconventional approach and using an IMU that outputs it's absolute quaternion to measure the position of my end effector link. I can see the absolute orientation of each link if I look at the TF tree in RVIZ.
I have encoders on my other joints which gives me an accurate pose up to the end effector. To remove the effects of these other joints on the IMU reading I have tried to multiply the IMU output by the inverse of the orientation quaternions to that point. I have pulled these quaternions from the rotation component of the TF broadcast. I then set my end effector position using the roll component of the transformed quaternion e.g.
tf2::convert(global_transforms_.transforms[0].transform.rotation, extension_pitch_component);
tf2::convert(global_transforms_.transforms[1].transform.rotation, slew_yaw_component);
tf2::convert(global_transforms_.transforms[7].transform.rotation, orbital_roll_component);
tf2::convert(global_transforms_.transforms[8].transform.rotation, tilt_pitch_component);
tf2::Quaternion output;
output = tilt_pitch_component * (orbital_roll_component * (extension_pitch_component * slew_yaw_component));
tf2::Quaternion publication;
publication = output.inverse() * imu_reading;
double roll, pitch, yaw;
tf2::Matrix3x3(publication).getEulerYPR(yaw, pitch, roll, 1);
setJointPosition(roll);
The problem is that the variable output
doesn't seem to match the TF absolute position of the link before the end effector. If I look at the TF output in RVIZ and publish a pose in the same position, there's a discrepancy between the two. I had a look at the source for the robot state publisher and it looks like it's multiplying the pose matrices of the joints from TF to get the absolute quaternion for each. Is that right?
My end effector can rotate 180 degrees and getting it's orientation right is fairly critical to my application. Unfortunately I can't change to an encoder at this point so I'm stuck with my IMU. Because the other joints can twist and roll I need to remove their effects on the IMU and measure only it's relative change in orientation. Any help appreciated!