跳转至

ImuSensor

robodyno.components.can_bus.imu_sensor

Imu sensor driver.

The imu sensor is a 6-axis inertial measurement unit (IMU) that provides accurate acceleration and angular rate (gyroscope) measurement data for space-constrained applications. This device also calculates and outputs quaternions that can be used to track the absolute orientation of the sensor.

Examples:

>>> from robodyno.components import ImuSensor
>>> from robodyno.interfaces import CanBus
>>> can = CanBus()
>>> imu = ImuSensor(can)
>>> imu.get_euler()
(-0.6930452576214104, -0.5058813752928343, 0.33744507654497824)
>>> can.disconnect()

ImuSensor

Bases: CanBusDevice

Imu sensor driver.

Attributes:

Name Type Description
id int

Device id.

type Model

Device type.

fw_ver float

Firmware version.

__init__(can, id_=49)

Initializes the imu sensor.

Parameters:

Name Type Description Default
can CanBus

Can bus instance.

required
id_ int

Device id. The default factory id is 0x31.

49

Raises:

Type Description
ValueError

If the device is not a imu sensor.

quaternion: tuple property

Quaternion of imu sensor.

Returns:

Type Description
tuple

Quaternion of imu sensor.

euler: tuple property

Euler angles of imu sensor.

Returns:

Type Description
tuple

Euler angles of imu sensor.

quat_to_euler(x, y, z, w) classmethod

Convert quaternion to euler angles.

Parameters:

Name Type Description Default
x float

x of quaternion.

required
y float

y of quaternion.

required
z float

z of quaternion.

required
w float

w of quaternion.

required

Returns:

Type Description
tuple

euler angles(roll, pitch, yaw).

config_can_bus(new_id, heartbeat=1000, bitrate=1000000)

Configures the CAN bus settings.

Parameters:

Name Type Description Default
new_id int

The new device id.

required
heartbeat int

The heartbeat period in milliseconds.

1000
bitrate int

The bitrate of the CAN bus. Choose from 250000, 500000, 1000000.

1000000

Raises:

Type Description
ValueError

If the new CAN id is not in the range of 0x01-0x3f.

set_ranges(gyro_range, accel_range)

Set gyro and accel range.

Parameters:

Name Type Description Default
gyro_range int

gyro range, 0: 250dps, 1: 500dps, 2: 1000dps, 3: 2000dps

required
accel_range int

accel range, 0: 2g, 1: 4g, 2: 8g, 3: 16g

required

Raises:

Type Description
ValueError

If gyro_range or accel_range is not in the range of 0-3.

get_quaternion(timeout=None)

Reads the quaternion of imu sensor.

Parameters:

Name Type Description Default
timeout float

Timeout in seconds.

None

Returns:

Type Description
tuple | None

Quaternion of imu sensor. (x, y, z, w)

get_euler(timeout=None)

Reads the euler angles of imu sensor.

Parameters:

Name Type Description Default
timeout float

Timeout in seconds.

None

Returns:

Type Description
tuple | None

Euler angles of imu sensor. (roll, pitch, yaw)

get_gyro(timeout=None)

Reads the gyro of imu sensor.

Parameters:

Name Type Description Default
timeout float

Timeout in seconds.

None

Returns:

Type Description
tuple | None

Gyroscope of imu sensor. (gyro_x, gyro_y, gyro_z)

get_accel(timeout=None)

Reads the accel of imu sensor.

Parameters:

Name Type Description Default
timeout float

Timeout in seconds.

None

Returns:

Type Description
tuple | None

Acceleration of imu sensor. (accel_x, accel_y, accel_z)