IMU

What is an IMU?

IMU stands for Inertial Measurement Unit. It is a device that measures the orientation and motion of a robot. Specifically, typical IMUs have three sensors:

  • Accelerometer: This measures linear acceleration by measuring forces exerted on the device. On Earth this usually means the force of gravity, but other forces are measured as well.
  • Gyroscope: This measures angular velocity, or the rate of rotation around an axis. This is done by measuring the Coriolis force, which is proportional to the object’s rotation.
  • Magnetometer: This measures the orientation of the device relative to the Earth’s magnetic field. This is used to determine the device’s heading.

Reading from the IMU

K-Scale maintains Python and Rust packages for interacting with IMUs.

pip install kscale-imu  # Install the Python package
cargo install imu  # Install the Rust crate

Getting Started

Hexmove IMU

To see the original documentation, see this page and here. A more detailed datasheet will be released soon.

To use the Hexmove IMU, you’ll first need to set up the CAN interface with a baud rate of 500000. On Linux, you can do this with:

sudo ip link set can0 up type can bitrate 500000

It’s important to note that Hexmove IMUs have model IDs as well as CAN IDs

Example usage

from imu import HexmoveImuReader
 
# Initialize the IMU reader for the 'can0' interface and imu with CAN ID 1 and model 1
imu_reader = HexmoveImuReader("can0", 1, 1)
 
while True:
    # Get the current IMU data
    data = imu_reader.get_data()
    print(
        f"Angular Position: X={data.x_angle}°, Y={data.y_angle}°, Z={data.z_angle}° | "
        f"Angular Velocity: X={data.x_velocity}°/s, Y={data.y_velocity}°/s, Z={data.z_velocity}°/s"
    )
 
    # Sleep for a short duration to avoid spamming the console
    time.sleep(0.1)