Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7860894

Browse files
committed
libs/unit/imu.py: IMU Unit is a 6-axis attitude sensor.
Signed-off-by: Pandian Nano <pandian.nano@gmail.com>
1 parent52581eb commit7860894

File tree

10 files changed

+563
-0
lines changed

10 files changed

+563
-0
lines changed

‎docs/en/refs/unit.imu.ref‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.. |IMUUnit| image:: https://static-cdn.m5stack.com/resource/docs/products/unit/imu/imu_01.webp
2+
:target: https://docs.m5stack.com/en/unit/imu
3+
:height: 200px
4+
:width: 200 px
5+
6+
.. |init.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/imu/init.png
7+
.. |example.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/imu/example.png
8+
.. |get_accelerometer.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/imu/get_accelerometer.png
9+
.. |get_gyroscope.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/imu/get_gyroscope.png
10+
.. |get_attitude.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/imu/get_attitude.png
11+
.. |set_accel_range.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/imu/set_accel_range.png
12+
.. |set_gyro_range.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/imu/set_gyro_range.png
13+
.. |set_accel_unit.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/imu/set_accel_unit.png
14+
.. |set_gyro_unit.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/imu/set_gyro_unit.png
15+
.. |set_gyro_calibrate.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/imu/set_gyro_calibrate.png
16+
.. |set_gyro_offsets.png| image:: https://static-cdn.m5stack.com/mpy_docs/unit/imu/set_gyro_offsets.png
17+
18+
19+
.. |unit-imu-demo.m5f2| raw:: html
20+
21+
<a
22+
href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/unit/imu/unit-imu-demo.m5f2"
23+
target="_blank"
24+
>
25+
unit-imu-demo.m5f2
26+
</a>
27+

‎docs/en/units/imu.rst‎

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
IMU Unit
2+
=========
3+
4+
..include::../refs/unit.imu.ref
5+
6+
6-Axis IMU Unit is a 6-axis attitude sensor with 3-axis gravity accelerometer and 3-axis gyroscope, which can calculate tilt angle and acceleration in real time. The chip adopts mpu6886
7+
8+
Support the following products:
9+
10+
|IMUUnit|
11+
12+
Micropython Example::
13+
14+
import os, sys, io
15+
import M5
16+
from M5 import *
17+
from hardware import *
18+
from unit import IMUUnit
19+
import time
20+
21+
i2c0 = I2C(0, scl=Pin(1), sda=Pin(2), freq=100000)
22+
imu_0 = IMUUnit(i2c0)
23+
imu_0.set_accel_unit(1)
24+
imu_0.set_gyro_unit(1)
25+
26+
while True:
27+
print((str('Acc:') + str((imu_0.get_accelerometer()))))
28+
print((str('Gryo:') + str((imu_0.get_gyroscope()))))
29+
print((str('Attitude') + str((imu_0.get_attitude()))))
30+
time.sleep_ms(100)
31+
32+
UIFLOW2 Example:
33+
34+
|example.png|
35+
36+
..only::builder_html
37+
38+
|unit-imu-demo.m5f2|
39+
40+
41+
class IMUUnit
42+
-------------
43+
44+
Constructors
45+
------------
46+
47+
..class::IMUUnit(i2c)
48+
49+
Create a IMUUnit object
50+
51+
:param i2c: the I2C object.
52+
53+
UIFLOW2:
54+
55+
|init.png|
56+
57+
58+
Methods
59+
-------
60+
61+
..method::IMUUnit.get_accelerometer()
62+
63+
Get the tuple of x, y, and z values of the accelerometer and acceleration vector in gravity units (9.81m/s^2).
64+
65+
- Return: ``tuple``: (float, float, float)
66+
67+
UIFLOW2:
68+
69+
|get_accelerometer.png|
70+
71+
72+
..method::IMUUnit.get_gyroscope()
73+
74+
Get the tuple of x, y, and z values of the gyroscope and gyroscope vector in rad/sec.
75+
76+
- Return: ``tuple``: (float, float, float)
77+
78+
UIFLOW2:
79+
80+
|get_gyroscope.png|
81+
82+
83+
..method::IMUUnit.get_attitude()
84+
85+
Get the attitude angles as yaw, pitch, and roll in degrees..
86+
87+
- Return: ``tuple``: (float, float, float)
88+
89+
UIFLOW2:
90+
91+
|get_attitude.png|
92+
93+
94+
..method::IMUUnit.set_accel_range(accel_scale)
95+
96+
Set the accelerometer scale range.
97+
98+
:param accel_scale: scale range of ±2g, ±4g, ±8g and ±16g.
99+
:type unit: int
100+
101+
UIFLOW2:
102+
103+
|set_accel_range.png|
104+
105+
106+
..method::IMUUnit.set_gyro_range(gyro_scale)
107+
108+
Set the gyroscope scale range.
109+
110+
:param gyro_scale: scale range of ±250 dps, ±500 dps, ±1000 dps, and ±2000 dps.
111+
:type unit: int
112+
113+
UIFLOW2:
114+
115+
|set_gyro_range.png|
116+
117+
118+
..method::IMUUnit.set_accel_unit(unit)
119+
120+
Set the accelerometer unit g or m/s^2.
121+
122+
:param unit: 0: g, 1: m/s^2.
123+
:type unit: int
124+
125+
UIFLOW2:
126+
127+
|set_accel_unit.png|
128+
129+
130+
..method::IMUUnit.set_gyro_unit(unit)
131+
132+
Set the gyroscope unit rad/sec or degrees/sec.
133+
134+
:param unit: 0: degrees/sec, 1: rad/sec.
135+
:type unit: int
136+
137+
UIFLOW2:
138+
139+
|set_gyro_unit.png|
140+
141+
142+
..method::IMUUnit.set_gyro_calibrate(samples, delay)
143+
144+
Set the gyro calibrations with the number of samples and delay of each samples
145+
146+
:param samples: number of samples.
147+
:type samples: int.
148+
:param delay: delay in milliseconds for each samples.
149+
:type delay: int
150+
151+
UIFLOW2:
152+
153+
|set_gyro_calibrate.png|
154+
155+
156+
..method::IMUUnit.set_gyro_offsets(x, y, z)
157+
158+
Set the manual gyro calibrations offsets value
159+
160+
:param x: 0.0
161+
:type unit: float
162+
:param y: 0.0
163+
:type unit: float
164+
:param z: 0.0
165+
:type unit: float
166+
167+
UIFLOW2:
168+
169+
|set_gyro_offsets.png|
170+

‎docs/en/units/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Unit
2828
glass2.rst
2929
grove2grove.rst
3030
hall_effect.rst
31+
imu.rst
3132
ir.rst
3233
joystick.rst
3334
key.rst
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"V2.0","versionNumber":"V2.0.9","type":"cores3","components":[{"name":"screen","type":"screen","layer":0,"screenId":"builtin","screenName":"","id":"__cores3_screen","createTime":1720066029701,"x":0,"y":0,"width":320,"height":240,"backgroundColor":"#222222","size":0,"isSelected":true}],"resources":[{"hardware":["hardware_button","hardware_pin_button","imu","speaker","touch","als","mic","i2c"]},{"unit":["unit_imu"]}],"units":[{"type":"unit_imu","name":"imu_0","portList":["A","PAHUB","Custom"],"portType":"A","userPort":[22,21],"id":"mCkFn6ccEyeF7m-^","createTime":1720066037134,"bus":"i2c0","pahubPortList":[0,1,2,3,4,5],"pahubPort":0,"initBlockId":"FlHBS5zFk+7Pm0_zq~@!"}],"hats":[],"bases":[],"i2cs":[{"id":"i2c0","portType":"A","userPort":[22,21],"freq":"100000","blockId":"Q=e_Yyd?s#SA@{axfAN8"}],"blockly":"<block type=\"basic_on_setup\" id=\"setup_block\" deletable=\"false\" x=\"-330\" y=\"-270\"><mutation isBegin=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_begin\" id=\"system_m5_begin\"><next><block type=\"i2c_init\" id=\"Q=e_Yyd?s#SA@{axfAN8\"><field name=\"NAME\">0</field><field name=\"FREQ\">100000</field><value name=\"SCL\"><shadow type=\"math_number\" id=\"B5Mwy%UUg{%-hK6_=q,A\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1</field></shadow></value><value name=\"SDA\"><shadow type=\"math_number\" id=\"lFps;anc{vB6h:8^.t$H\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">2</field></shadow></value><next><block type=\"unit_imu_init\" id=\"FlHBS5zFk+7Pm0_zq~@!\"><field name=\"NAME\">imu_0</field><next><block type=\"unit_imu_set_accel_unit\" id=\"^]1[ln43Hg+:CRSs-]R*\"><field name=\"NAME\">imu_0</field><field name=\"UNIT\">1</field><next><block type=\"unit_imu_set_gyro_unit\" id=\"+JPJWT-YC6$YhD`jn|*b\"><field name=\"NAME\">imu_0</field><field name=\"UNIT\">1</field></block></next></block></next></block></next></block></next></block></statement></block><block type=\"basic_on_loop\" id=\"loop_block\" deletable=\"false\" x=\"-330\" y=\"-10\"><mutation isUpdate=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_update\" id=\"system_m5_update\"><next><block type=\"text_print\" id=\"5YippNcnJ+h]fzK#4e_X\"><value name=\"TEXT\"><shadow type=\"text\" id=\"]q32hfN*--Be-Xw@cV43\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"text_add_str\" id=\"q=S^+FwrzG~m5.cl!pv5\"><value name=\"VALUE1\"><shadow type=\"text\" id=\"O226vsVX|_U$`zobWFID\"><field name=\"TEXT\">Acc:</field></shadow></value><value name=\"VALUE2\"><block type=\"unit_imu_get_accelerometer\" id=\"6(8pP;s7i2.^.0%Q~DNb\"><field name=\"NAME\">imu_0</field></block></value></block></value><next><block type=\"text_print\" id=\"%mLpf[BbefWV/K-nH*cW\"><value name=\"TEXT\"><shadow type=\"text\" id=\"]q32hfN*--Be-Xw@cV43\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"text_add_str\" id=\"`aI]?/b?n1t(`DR[~5.Q\"><value name=\"VALUE1\"><shadow type=\"text\" id=\"?hV+OH?sX545eF99AU^{\"><field name=\"TEXT\">Gryo:</field></shadow></value><value name=\"VALUE2\"><block type=\"unit_imu_get_gyroscope\" id=\"%J4T:B-qvEynLnoQi_fF\"><field name=\"NAME\">imu_0</field></block></value></block></value><next><block type=\"text_print\" id=\"R_R-#Sx,s*|H_;4#HvYw\"><value name=\"TEXT\"><shadow type=\"text\" id=\"]q32hfN*--Be-Xw@cV43\"><field name=\"TEXT\">hello M5</field></shadow><block type=\"text_add_str\" id=\"O#Cc`0qDnV1uFxOTfDEH\"><value name=\"VALUE1\"><shadow type=\"text\" id=\"82%#0sCmG71g+!hx}~!B\"><field name=\"TEXT\">Attitude</field></shadow></value><value name=\"VALUE2\"><block type=\"unit_imu_get_attitude\" id=\"}6XLaL+Znfau29=]){+z\"><field name=\"NAME\">imu_0</field></block></value></block></value><next><block type=\"time_sleep_millisecond\" id=\"~tT[2q#xlfbY?Sh15*Jc\"><value name=\"MS\"><shadow type=\"math_number\" id=\"R4*Y6d=mj1Afkg7zmwUc\"><mutation max=\"Infinity\" min=\"0\" precision=\"0\"></mutation><field name=\"NUM\">100</field></shadow></value></block></next></block></next></block></next></block></next></block></statement></block>","screen":[{"simulationName":"Built-in","type":"builtin","width":320,"height":240,"scale":0.78,"screenName":"","blockId":"","screenColorType":0,"id":"builtin","createTime":1720066029691}],"logicWhenNum":0,"customList":[]}

‎examples/unit/imu/unit-imu-demo.py‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
importos,sys,io
2+
importM5
3+
fromM5import*
4+
fromhardwareimport*
5+
fromunitimportIMUUnit
6+
importtime
7+
8+
9+
i2c0=None
10+
imu_0=None
11+
12+
13+
defsetup():
14+
globali2c0,imu_0
15+
16+
M5.begin()
17+
Widgets.fillScreen(0x222222)
18+
19+
i2c0=I2C(0,scl=Pin(1),sda=Pin(2),freq=100000)
20+
imu_0=IMUUnit(i2c0)
21+
imu_0.set_accel_unit(1)
22+
imu_0.set_gyro_unit(1)
23+
24+
25+
defloop():
26+
globali2c0,imu_0
27+
M5.update()
28+
print((str("Acc:")+str((imu_0.get_accelerometer()))))
29+
print((str("Gryo:")+str((imu_0.get_gyroscope()))))
30+
print((str("Attitude")+str((imu_0.get_attitude()))))
31+
time.sleep_ms(100)
32+
33+
34+
if__name__=="__main__":
35+
try:
36+
setup()
37+
whileTrue:
38+
loop()
39+
except (Exception,KeyboardInterrupt)ase:
40+
try:
41+
fromutilityimportprint_error_msg
42+
43+
print_error_msg(e)
44+
exceptImportError:
45+
print("please update to latest firmware")

‎m5stack/libs/driver/manifest.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"modbus/master/uSerial.py",
6060
"paj7620.py",
6161
"mlx90640.py",
62+
"mpu6886.py",
6263
"timezone.py",
6364
"vl53l1x.py",
6465
),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp