DM-IMU-L1 Python 驱动
达妙 DM-IMU-L1 六轴惯性测量模块的 Python 驱动。用 USB 线把模块接到电脑后,几行 Python 就能读取姿态数据、调整模块参数、完成校准。
| 项目 | 说明 |
|---|---|
| 适用模块 | DM-IMU-L1 |
| 固件版本 | v2.1.0.0 及以上 |
| 操作系统 | Windows 10 / 11、Linux、macOS |
| Python | 3.8 及以上 |
功能
- 读取加速度、角速度、欧拉角、四元数
- 调整输出内容、上报周期、传感器量程、安装方向和输出滤波
- 陀螺零偏校准、加速度计六面校准
- 附带命令行工具 dmimu,不写代码也能看数据和改配置
安装
pip install dm-imu
或者从源码安装:
python -m pip install -e .
连接模块
- 用 USB 线连接模块的 USB 口(不是 485 / CAN 接口)。
- 确认模块的通信类型是 USB(可以用达妙上位机查看或切换)。
- Windows 在“设备管理器 → 端口”里确认串口号,例如 COM5;Linux 通常是 /dev/ttyACM0,需要把当前用户加入 dialout 组。
- 关闭正在占用该串口的其他程序,例如达妙上位机。
快速开始
from dm_imu import ImuUSB
with ImuUSB("COM5") as imu: # Linux 用 "/dev/ttyACM0"
print(imu.read_version())
data = imu.read(timeout=1.0)
print("加速度", data.accel) # m/s^2
print("角速度", data.gyro) # rad/s
print("欧拉角", data.euler) # 度
print("四元数", data.quat)
读取结果示例:
加速度 (2.10, -0.02, 9.73)
角速度 (0.03, 0.04, -0.04)
欧拉角 (-0.27, -12.57, -49.53)
连续读取:
with ImuUSB("COM5") as imu:
for data in imu.stream(hz=100, count=1000):
print(data.euler)
数据说明
| 数据 | 含义 | 单位 |
|---|---|---|
| accel | 加速度 X / Y / Z(含重力) | m/s² |
| gyro | 角速度 X / Y / Z | rad/s |
| euler | 横滚 / 俯仰 / 偏航 | 度 |
| quat | 四元数 W / X / Y / Z | 无 |
- 欧拉角范围:横滚 (-180, 180]、俯仰 [-90, 90]、偏航 (-180, 180];偏航角越过 ±180° 会跳变,属于正常现象。
- 温度:模块工作时不上报温度,需要时调用 imu.read_temperature() 读取一次。
- 温控:开启温控后,需要等温度进入目标值附近并稳定约 10 秒,才会输出正常测量数据。
修改配置
下面的代码会设置输出内容、上报周期和量程,并保存到模块:
from dm_imu import ImuUSB
with ImuUSB("COM5") as imu:
config = imu.configure(
outputs="accel,gyro,euler,quat", # 需要输出的数据
interval_ms=1, # 上报周期 1 ms
accel_range="24g", # 加速度量程
gyro_range="2000dps", # 角速度量程
save=True, # 保存到模块,断电不丢
)
print(config.interval_ms, config.outputs)
常用设置:
| 参数 | 说明 | 取值范围 |
|---|---|---|
| outputs | 需要输出的数据 | accel / gyro / euler / quat |
| interval_ms | 上报周期 | 1~1000 ms |
| accel_range | 加速度量程 | 3g / 6g / 12g / 24g |
| gyro_range | 角速度量程 | 125 / 250 / 500 / 1000 / 2000 dps |
| orientation | 安装方向 | 0~23,0 表示与模块坐标系一致 |
| temp_control / target_temperature | 温控开关与目标温度 | on/off、0~60 ℃ |
修改量程或安装方向后,建议重新做一次陀螺零偏校准。
查看当前配置:
config = imu.read_config()
print(config.outputs, config.interval_ms, config.accel_range_g, config.gyro_range_dps)
校准
陀螺零偏校准(模块保持静止,约 3 秒):
with ImuUSB("COM5") as imu:
result = imu.calibrate_gyro(on_progress=print)
print("零偏", result.bias_dps)
加速度计六面校准(依次把 +X -X +Y -Y +Z -Z 六个面朝上放稳,每个面约 1 秒):
with ImuUSB("COM5") as imu:
result = imu.calibrate_accel(on_progress=print)
print("零偏", result.bias_ms2, "比例", result.scale)
两种校准成功后都会自动保存,重启后仍然有效。
命令行工具
安装后可以直接使用 dmimu 命令:
| 命令 | 用途 |
|---|---|
| dmimu info -p COM5 | 查看版本、设备信息、当前配置和校准状态 |
| dmimu monitor -p COM5 | 实时显示姿态数据 |
| dmimu config -p COM5 ... | 修改配置 |
| dmimu calibrate gyro -p COM5 | 陀螺零偏校准 |
| dmimu calibrate accel -p COM5 | 加速度计六面校准 |
| dmimu action yaw-zero -p COM5 | 航向归零 |
| dmimu action reboot -p COM5 | 重启模块 |
常用示例:
dmimu info -p COM5
dmimu monitor -p COM5 --hz 10
dmimu config -p COM5 --outputs accel,gyro --interval 5
dmimu calibrate gyro -p COM5
常用接口
| 接口 | 用途 |
|---|---|
| ImuUSB("COM5") | 打开模块,支持 with 语句 |
| read() / stream() | 读取一次数据 / 连续读取 |
| read_version() | 读取固件版本 |
| read_temperature() | 读取温度 |
| read_config() | 查看当前配置 |
| configure() | 修改配置 |
| calibrate_gyro() / calibrate_accel() | 陀螺零偏校准 / 六面校准 |
| save() / reboot() / yaw_zero() | 保存参数 / 重启模块 / 航向归零 |
常见问题
| 现象 | 排查 |
|---|---|
| 打不开串口 | 达妙上位机或其他程序占用了串口,关闭后重试;也可以拔插一次 USB |
| 读不到数据 | 确认串口号是否正确、模块通信类型是否为 USB、输出开关是否打开 |
| 温度显示不出来 | 模块工作时不上报温度,请用 read_temperature() 读取 |
| 开启温控后一段时间没有数据 | 温度需要先稳定约 10 秒,属正常现象 |
| Linux 没有权限 | 把当前用户加入 dialout 组后重新登录 |
| 偏航角跳到 -180 | 欧拉角表示的固有现象,需要连续角度时请自行处理跳变 |
版本与支持
- 当前版本:1.0.0
- 适用固件:DM-IMU-L1 v2.1.0.0 及以上
Metadata
Release files for dm-imu 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dm_imu-1.0.0.tar.gz | 43.6 kB | Without provenance | Details for dm_imu-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dm_imu-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for dm_imu-1.0.0-py3-none-any.whl |
Total release size: 80.1 kB
Release files / dm_imu-1.0.0.tar.gz
| Download URL | dm_imu-1.0.0.tar.gz |
|---|---|
| Size | 43.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a9015d8cccc7db47e58513da328133c62991c0989f05ddc00d5b1735805f1733
|
|
BLAKE2b-256 checksum How to use checksums |
0560faa0f652dcd9965bd8004c168392ff939d44f4cfb0a2e7fbe00ddfb61193
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / dm_imu-1.0.0-py3-none-any.whl
| Download URL | dm_imu-1.0.0-py3-none-any.whl |
|---|---|
| Size | 36.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
325381da16d18f5f3041336e4d121a25741ae4858c5d2ae375416a7cbbedf512
|
|
BLAKE2b-256 checksum How to use checksums |
6fe6741d528d737427ee22b51f2796d90720e8fc7490f8e8334f71c8fc3be9fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for dm-imu 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.