raulmur / ORB_SLAM2

Real-Time SLAM for Monocular, Stereo and RGB-D Cameras, with Loop Detection and Relocalization Capabilities
Other
9.44k stars 4.69k forks source link

Problem setting an initial pose rotation in Tracking::StereoInitialization() #949

Open Gnome-Chomsky opened 4 years ago

Gnome-Chomsky commented 4 years ago

Hi,

I am running ORB SLAM 2 on a drone with a downward facing, RGBD camera. I am having an issue with the vision_pose being incorrect because the pose is initialised as if the camera is pointing towards the horizon by default instead of straight down.

To try and initialise the pose to suit my initial conditions, in the Tracking::StereoInitialization() function, I have replaced the line: mCurrentFrame.SetPose(cv::Mat::eye(4,4,CV_32F)); With: mCurrentFrame.SetPose(cv::Mat(4,4,CV_32F,quat_rot)); where quat_rot is a quaternion that represents a 90 degree pitch down on the Z axis.

I used an online calculator to find that the quaternion for the pitch down would be: (0.7071, 0, 0, -0.7071) or more simply, (0.7071 - 0.7071k).

I declared the quat_rot quaternion with those numbers: float quat_rot[16] = {0.7071, 0, 0, -0.7071, 0, 0.7071, -0.7071, 0, 0, -0.7071, 0.7071, 0, -0.7071, 0, 0, 0.7071};

But when using Rviz to check the pose, it is only rotated down at 45 degrees. I have tried swapping the position of the scalar number in the quaternion after reading about the differences in how Eigen processes quaternions but Eigen isn't used in the declaration. I have also tried with some different numbers but none give a rotation past 45 degrees without throwing errors.

I'm out of ideas and would greatly appreciate any input, perhaps the basis of the question is wrong and I should be doing this elsewhere in the code, I don't know, maybe someone can point me in the right direction.

Thanks!