mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-11 17:14:41 +00:00
examples/pup: add imu tilt examples
This commit is contained in:
@@ -174,3 +174,25 @@ Detecting button presses
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_primehub/button_main.py
|
||||
|
||||
IMU examples
|
||||
---------------
|
||||
|
||||
Testing which way is up
|
||||
********************************
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_primehub/imu_up.py
|
||||
|
||||
|
||||
Reading the tilt value
|
||||
********************************
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_primehub/imu_tilt.py
|
||||
|
||||
Reading the tilt value with custom hub orientation
|
||||
**************************************************
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_primehub/imu_tilt_blast.py
|
||||
|
||||
@@ -63,3 +63,25 @@ Creating light animations
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_technichub/light_animate.py
|
||||
|
||||
IMU examples
|
||||
---------------
|
||||
|
||||
Testing which way is up
|
||||
********************************
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_technichub/imu_up.py
|
||||
|
||||
|
||||
Reading the tilt value
|
||||
********************************
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_technichub/imu_tilt.py
|
||||
|
||||
Reading the tilt value with custom hub orientation
|
||||
**************************************************
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_technichub/imu_tilt_blast.py
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
from pybricks.hubs import PrimeHub
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the hub.
|
||||
hub = PrimeHub()
|
||||
|
||||
while True:
|
||||
# Read the tilt values.
|
||||
pitch, roll = hub.imu.tilt()
|
||||
|
||||
# Print the result.
|
||||
print(pitch, roll)
|
||||
wait(200)
|
||||
@@ -0,0 +1,17 @@
|
||||
from pybricks.hubs import PrimeHub
|
||||
from pybricks.tools import wait
|
||||
from pybricks.geometry import Axis
|
||||
|
||||
# Initialize the hub. In this case, specify that the hub is mounted with the
|
||||
# top side facing forward and the front side facing to the right.
|
||||
# For example, this is how the hub is mounted in BLAST in the 51515 set.
|
||||
hub = PrimeHub(top_side=Axis.X, front_side=-Axis.Y)
|
||||
|
||||
while True:
|
||||
# Read the tilt values. Now, the values are 0 when BLAST stands upright.
|
||||
# Leaning forward gives positive pitch. Leaning right gives positive roll.
|
||||
pitch, roll = hub.imu.tilt()
|
||||
|
||||
# Print the result.
|
||||
print(pitch, roll)
|
||||
wait(200)
|
||||
@@ -0,0 +1,14 @@
|
||||
# ExampleHub = TechnicHub PrimeHub
|
||||
from pybricks.hubs import ExampleHub
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the hub.
|
||||
hub = ExampleHub()
|
||||
|
||||
while True:
|
||||
# Read the tilt values.
|
||||
pitch, roll = hub.imu.tilt()
|
||||
|
||||
# Print the result.
|
||||
print(pitch, roll)
|
||||
wait(200)
|
||||
@@ -0,0 +1,18 @@
|
||||
# ExampleHub = TechnicHub PrimeHub
|
||||
from pybricks.hubs import ExampleHub
|
||||
from pybricks.tools import wait
|
||||
from pybricks.geometry import Axis
|
||||
|
||||
# Initialize the hub. In this case, specify that the hub is mounted with the
|
||||
# top side facing forward and the front side facing to the right.
|
||||
# For example, this is how the hub is mounted in BLAST in the 51515 set.
|
||||
hub = ExampleHub(top_side=Axis.X, front_side=-Axis.Y)
|
||||
|
||||
while True:
|
||||
# Read the tilt values. Now, the values are 0 when BLAST stands upright.
|
||||
# Leaning forward gives positive pitch. Leaning right gives positive roll.
|
||||
pitch, roll = hub.imu.tilt()
|
||||
|
||||
# Print the result.
|
||||
print(pitch, roll)
|
||||
wait(200)
|
||||
@@ -0,0 +1,13 @@
|
||||
from pybricks.hubs import TechnicHub
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the hub.
|
||||
hub = TechnicHub()
|
||||
|
||||
while True:
|
||||
# Read the tilt values.
|
||||
pitch, roll = hub.imu.tilt()
|
||||
|
||||
# Print the result.
|
||||
print(pitch, roll)
|
||||
wait(200)
|
||||
@@ -0,0 +1,17 @@
|
||||
from pybricks.hubs import TechnicHub
|
||||
from pybricks.tools import wait
|
||||
from pybricks.geometry import Axis
|
||||
|
||||
# Initialize the hub. In this case, specify that the hub is mounted with the
|
||||
# top side facing forward and the front side facing to the right.
|
||||
# For example, this is how the hub is mounted in BLAST in the 51515 set.
|
||||
hub = TechnicHub(top_side=Axis.X, front_side=-Axis.Y)
|
||||
|
||||
while True:
|
||||
# Read the tilt values. Now, the values are 0 when BLAST stands upright.
|
||||
# Leaning forward gives positive pitch. Leaning right gives positive roll.
|
||||
pitch, roll = hub.imu.tilt()
|
||||
|
||||
# Print the result.
|
||||
print(pitch, roll)
|
||||
wait(200)
|
||||
Reference in New Issue
Block a user