跳转至

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.

属性:

名称 类型 描述
id int

Device id.

type Model

Device type.

fw_ver float

Firmware version.

__init__(can, id_=49)

Initializes the imu sensor.

参数:

名称 类型 描述 默认
can CanBus

Can bus instance.

必需
id_ int

Device id. The default factory id is 0x31.

49

引发:

类型 描述
ValueError

If the device is not a imu sensor.

quaternion property

Quaternion of imu sensor.

返回:

类型 描述
tuple

Quaternion of imu sensor.

euler property

Euler angles of imu sensor.

返回:

类型 描述
tuple

Euler angles of imu sensor.

quat_to_euler(x, y, z, w) classmethod

Convert quaternion to euler angles.

参数:

名称 类型 描述 默认
x float

x of quaternion.

必需
y float

y of quaternion.

必需
z float

z of quaternion.

必需
w float

w of quaternion.

必需

返回:

类型 描述
tuple

euler angles(roll, pitch, yaw).

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

Configures the CAN bus settings.

参数:

名称 类型 描述 默认
new_id int

The new device id.

必需
heartbeat int

The heartbeat period in milliseconds.

1000
bitrate int

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

1000000

引发:

类型 描述
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.

参数:

名称 类型 描述 默认
gyro_range int

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

必需
accel_range int

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

必需

引发:

类型 描述
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.

参数:

名称 类型 描述 默认
timeout float

Timeout in seconds.

None

返回:

类型 描述
tuple | None

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

get_euler(timeout=None)

Reads the euler angles of imu sensor.

参数:

名称 类型 描述 默认
timeout float

Timeout in seconds.

None

返回:

类型 描述
tuple | None

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

get_gyro(timeout=None)

Reads the gyro of imu sensor.

参数:

名称 类型 描述 默认
timeout float

Timeout in seconds.

None

返回:

类型 描述
tuple | None

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

get_accel(timeout=None)

Reads the accel of imu sensor.

参数:

名称 类型 描述 默认
timeout float

Timeout in seconds.

None

返回:

类型 描述
tuple | None

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