imu_filter_madgwick not changing orientation in odometry

asked 2020-07-18 13:52:09 -0500

updated 2020-07-18 19:48:34 -0500

Orhan gravatar image

I'm trying to use imu_filter_madgwick to incorporate the /imu/mag channel data into the odometry to get an absolute orientation for input into an ekf for robot_navigation. I am using a Xsens imu so I had to write a small script to translate the output of /imu/mag to the message type imu_filter_madgwick expects.

#!/usr/bin/env python
import rospy

from geometry_msgs.msg import Vector3Stamped
from sensor_msgs.msg import MagneticField

def vector3Callback(msg):
    global mag_pub

    mag_msg = MagneticField()
    mag_msg.header = msg.header
    mag_msg.magnetic_field = msg.vector

    mag_pub.publish(mag_msg)

def main():
    global mag_pub

    rospy.init_node('mag_convert')
    rospy.Subscriber('/imu/magnetic_field', Vector3Stamped, vector3Callback)
    mag_pub = rospy.Publisher('/imu/mag', MagneticField, queue_size=10)
    rospy.spin()

if __name__ == "__main__":
    try:
        main()
    except rospy.ROSInterruptException:
        pass

I posted my issue on github here with the launch file and script along with a short bag file: https://github.com/ccny-ros-pkg/imu_t...

I'm asking here because I thought someone here might have encountered the same issue or has found a better way to incorporate the mag data into the localization.

edit retag flag offensive close merge delete

Comments

I included the code you wrote. I'm thinking, since you directly set the header from the message that is coming from the driver, maybe its frame is wrong. Did you check the frame? Also the header's seq is overwritten while publishing, so you could just set the frame with your expected frame and time to rospy.Time.now()

Orhan gravatar image Orhan  ( 2020-07-18 19:53:29 -0500 )edit

I did check the frame. The thing that fixed this (and eliminated my need for imu_filter_madgwick) was calibrating my IMU. The Xsens IMU has a ton of features and it wasn't obvious to me that we'd need to calibrate it to get useful data of it. I had thought that by configuring it I would just have some offsets in the heading. It turns out that if it isn't calibrated some of the internal settings will saturate the inputs for the sensors and you'll get the identity for orientation at the output.

tyler-picknik gravatar image tyler-picknik  ( 2020-07-24 06:24:38 -0500 )edit