ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How can I visualize magnetometer data in Rviz?

asked 2018-08-21 06:04:35 -0500

hbaqueiro gravatar image

Hi, I am using a magnetometer plugin ( from UUV Simulator in Gazebo and it delivers sensor_msgs/MagneticField messages. In order to see if it is working (well, I've already echoed the topic and it is indeed working), but I would like to have a way to visualize it in Rviz so that the data is easily understandable.

A general view of what I wanted to do is to provide a way for the robot to know the North direction and I am assuming using the magnetometer is the best way to do that. Opinions are welcome.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-08-21 09:11:25 -0500

The magnetic field information is fundamentally a 3D vector, with the direction and strength of the field. You could use an Arrow Marker message to represent this information. If you set the start of the arrow to your robot body and scale the length suitably so it's visible this should work.

Unless you're near the equator this vector will be pointing up or down a fair bit since the Earth's magnetic field isn't parallel to the surface of the earth. So if you're just interested in the direction of magnetic north you could zero out the z element of the magnetic field vector and normalize the length of the vector to 1.

You'd need to make a small node to subscribe to sensor_msgs/MagneticField messages and publish an equivalent visualization_msgs/Marker to do this.

Hope this helps.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-08-21 06:04:35 -0500

Seen: 817 times

Last updated: Aug 21 '18