mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-11 17:14:41 +00:00
examples/pup: acceleration and angular velocity
This commit is contained in:
@@ -191,8 +191,20 @@ Reading the tilt value
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_primehub/imu_tilt.py
|
||||
|
||||
Reading the tilt value with custom hub orientation
|
||||
Using a custom hub orientation
|
||||
**************************************************
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_primehub/imu_tilt_blast.py
|
||||
|
||||
Reading acceleration and angular velocity vectors
|
||||
**************************************************
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_primehub/imu_read_vector.py
|
||||
|
||||
Reading acceleration and angular velocity on one axis
|
||||
*****************************************************
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_primehub/imu_read_scalar.py
|
||||
|
||||
@@ -19,17 +19,17 @@ Technic Hub
|
||||
|
||||
.. rubric:: Using the IMU
|
||||
|
||||
.. automethod:: pybricks.hubs::PrimeHub.imu.up
|
||||
.. automethod:: pybricks.hubs::TechnicHub.imu.up
|
||||
|
||||
.. automethod:: pybricks.hubs::PrimeHub.imu.tilt
|
||||
.. automethod:: pybricks.hubs::TechnicHub.imu.tilt
|
||||
|
||||
.. automethod:: pybricks.hubs::PrimeHub.imu.acceleration
|
||||
.. automethod:: pybricks.hubs::TechnicHub.imu.acceleration
|
||||
|
||||
.. automethod:: pybricks.hubs::PrimeHub.imu.angular_velocity
|
||||
.. automethod:: pybricks.hubs::TechnicHub.imu.angular_velocity
|
||||
|
||||
.. automethod:: pybricks.hubs::PrimeHub.imu.heading
|
||||
.. automethod:: pybricks.hubs::TechnicHub.imu.heading
|
||||
|
||||
.. automethod:: pybricks.hubs::PrimeHub.imu.reset_heading
|
||||
.. automethod:: pybricks.hubs::TechnicHub.imu.reset_heading
|
||||
|
||||
.. rubric:: Using the battery
|
||||
|
||||
@@ -80,8 +80,20 @@ Reading the tilt value
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_technichub/imu_tilt.py
|
||||
|
||||
Reading the tilt value with custom hub orientation
|
||||
Using a custom hub orientation
|
||||
**************************************************
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_technichub/imu_tilt_blast.py
|
||||
|
||||
Reading acceleration and angular velocity vectors
|
||||
**************************************************
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_technichub/imu_read_vector.py
|
||||
|
||||
Reading acceleration and angular velocity on one axis
|
||||
*****************************************************
|
||||
|
||||
.. literalinclude::
|
||||
../../../examples/pup/hub_technichub/imu_read_scalar.py
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
from pybricks.hubs import PrimeHub
|
||||
from pybricks.tools import wait
|
||||
from pybricks.geometry import Axis
|
||||
|
||||
# Initialize the hub.
|
||||
hub = PrimeHub()
|
||||
|
||||
# Get the acceleration or angular_velocity along a single axis.
|
||||
# If you need only one value, this is more memory efficient.
|
||||
while True:
|
||||
|
||||
# Read the forward acceleration.
|
||||
forward_acceleration = hub.imu.acceleration(Axis.X)
|
||||
|
||||
# Read the yaw rate.
|
||||
yaw_rate = hub.imu.angular_velocity(Axis.Z)
|
||||
|
||||
# Print the yaw rate.
|
||||
print(yaw_rate)
|
||||
wait(100)
|
||||
@@ -0,0 +1,14 @@
|
||||
from pybricks.hubs import PrimeHub
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the hub.
|
||||
hub = PrimeHub()
|
||||
|
||||
# Get the acceleration vector.
|
||||
print(hub.imu.acceleration())
|
||||
|
||||
# Get the angular velocity vector.
|
||||
print(hub.imu.angular_velocity())
|
||||
|
||||
# Wait so we can see what we printed
|
||||
wait(5000)
|
||||
@@ -0,0 +1,21 @@
|
||||
# ExampleHub = TechnicHub PrimeHub
|
||||
from pybricks.hubs import ExampleHub
|
||||
from pybricks.tools import wait
|
||||
from pybricks.geometry import Axis
|
||||
|
||||
# Initialize the hub.
|
||||
hub = ExampleHub()
|
||||
|
||||
# Get the acceleration or angular_velocity along a single axis.
|
||||
# If you need only one value, this is more memory efficient.
|
||||
while True:
|
||||
|
||||
# Read the forward acceleration.
|
||||
forward_acceleration = hub.imu.acceleration(Axis.X)
|
||||
|
||||
# Read the yaw rate.
|
||||
yaw_rate = hub.imu.angular_velocity(Axis.Z)
|
||||
|
||||
# Print the yaw rate.
|
||||
print(yaw_rate)
|
||||
wait(100)
|
||||
@@ -0,0 +1,15 @@
|
||||
# ExampleHub = TechnicHub PrimeHub
|
||||
from pybricks.hubs import ExampleHub
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the hub.
|
||||
hub = ExampleHub()
|
||||
|
||||
# Get the acceleration vector.
|
||||
print(hub.imu.acceleration())
|
||||
|
||||
# Get the angular velocity vector.
|
||||
print(hub.imu.angular_velocity())
|
||||
|
||||
# Wait so we can see what we printed
|
||||
wait(5000)
|
||||
@@ -0,0 +1,20 @@
|
||||
from pybricks.hubs import TechnicHub
|
||||
from pybricks.tools import wait
|
||||
from pybricks.geometry import Axis
|
||||
|
||||
# Initialize the hub.
|
||||
hub = TechnicHub()
|
||||
|
||||
# Get the acceleration or angular_velocity along a single axis.
|
||||
# If you need only one value, this is more memory efficient.
|
||||
while True:
|
||||
|
||||
# Read the forward acceleration.
|
||||
forward_acceleration = hub.imu.acceleration(Axis.X)
|
||||
|
||||
# Read the yaw rate.
|
||||
yaw_rate = hub.imu.angular_velocity(Axis.Z)
|
||||
|
||||
# Print the yaw rate.
|
||||
print(yaw_rate)
|
||||
wait(100)
|
||||
@@ -0,0 +1,14 @@
|
||||
from pybricks.hubs import TechnicHub
|
||||
from pybricks.tools import wait
|
||||
|
||||
# Initialize the hub.
|
||||
hub = TechnicHub()
|
||||
|
||||
# Get the acceleration vector.
|
||||
print(hub.imu.acceleration())
|
||||
|
||||
# Get the angular velocity vector.
|
||||
print(hub.imu.angular_velocity())
|
||||
|
||||
# Wait so we can see what we printed
|
||||
wait(5000)
|
||||
Reference in New Issue
Block a user