SunFounder PiDog Kit, Release 1.0
(continued from previous page)
# style:"boom", color="cyan", brightness=0.1, delay=0.1
my_dog.rgb_strip.set_mode(style="boom", color="cyan", brightness=0.5, delay=0.05)
time.sleep(3)
# close
my_dog.rgb_strip.close()
time.sleep(2)
2.3.10 IMU Read
Through the 6-DOF IMU Module, PiDog can determine if it’s standing on a slope, or if it’s being picked up.
The 6-DOF IMU Module is equipped with a 3-axis accelerometer and a 3-axis gyroscope, allowing acceleration and
angular velocity to be measured in three directions.
Note: Before using the module, make sure that it is correctly assembled. The label on the module will let you know
if it is reversed.
You can read their acceleration with:
ax, ay, az = Pidog.accData
With the PiDog placed horizontally, the acceleration on the x-axis (ie ax) should be close to the acceleration of gravity
(1g), with a value of -16384. The values of the y-axis and x-axis are close to 0.
Use the following way to read their angular velocity:
gx, gy, gz = my_dog.gyroData
In the case where PiDog is placed horizontally, all three values are close to 0.
Here are some examples of how 6-DOF Module is used:
1. Read real-time acceleration, angular velocity
from pidog import Pidog
import time
my_dog = Pidog()
my_dog.do_action("pushup", step_count=10, speed=20)
while True:
ax, ay, az = my_dog.accData
gx, gy, gz = my_dog.gyroData
print(f"accData: {ax/16384:.2f} g ,{ay/16384:.2f} g, {az/16384:.2f} g
˓→gyroData: {gx} °/s, {gy} °/s, {gz} °/s")
time.sleep(0.2)
if my_dog.is_legs_done():
break
my_dog.stop_and_lie()
my_dog.close()
2.3. Easy Coding 85