I am working on a 2 wheeled differential drive robot equipped with motors with encoders, IMU and a lidar.
I am using ros2_control with their diff drive controller (which works well) and I also use the madgwick imu filter package to produce an estimate of the orientation of the robot from the linear acceleration and angular velocities (no magnetometer used as the robot is indoor).
I am trying to fuse the odometry and imu data using the robot_localization package. In simulation using gazebo everything works well, however in the real robot I have a weird issue that I don't understand the origin of it.
When I start my nodes and start moving and rotating the robot, everything works fine for few seconds (I would say 10 seconds sometimes more like 40 seconds) but suddenly the robot jumps to a far position compared to where it was then again if I move like 5 or 10 seconds it works but this time relative to where the robot jumped and again the same happen it jumps to another far away position and it is completely random jumps. (RVIZ2)
I checked my raw odometry (before fusing with imu) and it seems correct and I also checked the imu and its value also seems correct, also robot_localization package is the only one publishing the odom basefootprint tf.
Do you have any idea of what might be the cause of these randoms jumps? Thank you.