ROS2 IMU Tilt Compensation

Medium Perception 0% pass rate

Practice the ROS2 IMU Tilt Compensation coding problem in Perception. Browser-based execution with automated grading — no local ROS install required. 0% of engineers pass this challenge.

Problem Statement

Implement a ROS2 node that reads sensor_msgs/Imu data and computes roll and pitch from the IMU's orientation quaternion, then publishes them as a geometry_msgs/Vector3Stamped (roll=x, pitch=y, yaw=z).

Requirements

Your node must:

  • Subscribe to /imu/data (sensor_msgs/Imu)
  • In the callback, extract the quaternion from msg.orientation (x, y, z, w)
  • Implement quaternion_to_euler(x, y, z, w) -> (roll, pitch, yaw) using:
    roll  = atan2(2*(w*x + y*z), 1 - 2*(x*x + y*y))
    pitch = asin(clamp(2*(w*y - z*x), -1, 1))
    yaw   = atan2(2*(w*z + x*y), 1 - 2*(y*y + z*z))
    
  • Publish geometry_msgs/Vector3Stamped on /imu/euler_angles where:
    • vector.x = roll (radians)
    • vector.y = pitch (radians)
    • vector.z = yaw (radians)
  • Log roll and pitch in degrees every callback
  • Log "IMU Processor Ready" on startup

Input / Output

Input: sensor_msgs/Imu on /imu/data Output: geometry_msgs/Vector3Stamped on /imu/euler_angles

🤖 Why This Matters in Real Robots

Every ground robot needs tilt estimation for stability monitoring — if a robot tips past 30°, it should emergency stop. Drones use this to level their airframe. The RPY decomposition of the orientation quaternion is one of the most commonly needed calculations in any ROS2 project, yet it's not built into the standard message types.

Input/Output Format

Input: /imu (sensor_msgs/Imu) | Output: /tilt (std_msgs/Float32)

⚠️ Common Pitfalls

  • Ignoring gravity vector
  • Confusing degrees and radians

📚 Helpful Resources

Frequently asked questions

What is the ROS2 IMU Tilt Compensation practice problem?

It is a hands-on Perception challenge on SimuCode where you implement and run ROS2 code in the browser with runtime-verified tests.

How do I practice ROS2 IMU Tilt Compensation online?

Open this page, sign in, and solve the problem in the built-in IDE. Your solution is graded against real ROS2 execution checks.

What skills does ROS2 IMU Tilt Compensation test?

This Medium problem focuses on Perception skills used in robotics interviews and production systems.