SunFounder PiDog Kit, Release 1.0
2. Calculate the lean angle of PiDog’s body.
from
pidog
import
Pidog
import
time
import
math
my_dog
=
Pidog()
while
True
:
ax, ay, az
=
my_dog
.
accData
body_pitch
=
math
.
atan2(ay,ax)
/
math
.
pi
*
180
%
360
-
180
(f
"Body Degree: {body_pitch:.2f} °"
)
time
.
sleep(
0.2
)
my_dog
.
close()
3. While leaning, PiDog keeps its eyes level.
from
pidog
import
Pidog
import
time
import
math
my_dog
=
Pidog()
while
True
:
ax, ay, az
=
my_dog
.
accData
body_pitch
=
math
.
atan2(ay,ax)
/
math
.
pi
*
180
%
360
-
180
my_dog
.
head_move([[
0
,
0
,
0
]], pitch_comp
=-
body_pitch, speed
=
80
)
time
.
sleep(
0.2
)
my_dog
.
close()
2.3.11 Sound Direction Detect
The PiDog has a Sound Direction Sensor Module that detects where sound is coming from, and we can trigger it by
clapping near it.
Using this module is as simple as calling these functions.
Pidog
.
ears
.
isdetected()
Returns
True
if sound is detected,
False
otherwise.
Pidog
.
ears
.
read()
This function returns the direction of the sound source, with a range of 0 to 359; if the sound comes from the front, it
returns 0; if it comes from the right, it returns 90.
An example of how to use this module is as follows:
from
pidog
import
Pidog
my_dog
=
Pidog()
while
True
:
if
my_dog
.
ears
.
isdetected():
(continues on next page)
86
Chapter 2. Play with Python
Summary of Contents for PiDog
Page 1: ...SunFounder PiDog Kit Release 1 0 sunfounder Jan 09 2023 ...
Page 2: ......
Page 4: ...ii ...
Page 6: ...SunFounder PiDog Kit Release 1 0 Content 2 CONTENTS ...
Page 8: ...SunFounder PiDog Kit Release 1 0 4 Chapter 1 Component List and Assembly Instructions ...
Page 15: ...SunFounder PiDog Kit Release 1 0 Step 7 Click the WRITE button 2 1 Quick Guide on Python 11 ...
Page 92: ...SunFounder PiDog Kit Release 1 0 88 Chapter 2 Play with Python ...
Page 108: ...SunFounder PiDog Kit Release 1 0 104 Chapter 4 Appendix ...