SunFounder PiDog Kit, Release 1.0
–
"single_bark_1"
–
"single_bark_2"
–
"snoring"
–
"woohoo"
Here is an example of usage:
from
pidog
import
Pidog
import
time
my_dog
=
Pidog()
try
:
my_dog
.
do_action(
"sit"
, speed
=
60
)
my_dog
.
wait_all_done()
time
.
sleep(
0.5
)
my_dog
.
do_action(
"wag_tail"
, step_count
=
100
,speed
=
20
)
my_dog
.
do_action(
"tilting_head"
, step_count
=
2
, speed
=
20
)
my_dog
.
speak(
'confused_3'
)
my_dog
.
wait_head_done()
my_dog
.
stop_and_lie()
except
KeyboardInterrupt
:
pass
except
Exception
as
e:
(f
"
\033
[31mERROR: {e}
\033
[m"
)
finally
:
(
"closing ..."
)
my_dog
.
close()
2.3.8 Read Distance
Through the Ultrasonic Module in its head, PiDog can detect obstacles ahead.
An ultrasonic module can detect objects between 2 and 400 cm away.
With the following function, you can read the distance as a floating point number.
Pidog
.
ultrasonic
.
read_distance()
Here is an example of usage:
from
pidog
import
Pidog
import
time
my_dog
=
Pidog()
while
True
:
distance
=
my_dog
.
ultrasonic
.
read_distance()
distance
=
round
(distance,
2
)
(f
"Distance: {distance} cm"
)
time
.
sleep(
0.5
)
2.3. Easy Coding
83
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 ...