SunFounder PiDog Kit, Release 1.0
#!/usr/bin/env python3
import
time
from
pidog
import
Pidog
from
time
import
sleep
from
preset_actions
import
bark
t
=
time
.
time()
my_dog
=
Pidog()
my_dog
.
do_action(
'stand'
, speed
=
80
)
my_dog
.
wait_all_done()
sleep(
0.1
)
stand
=
my_dog
.
legs_angle_calculation([[
0
,
80
], [
0
,
80
], [
30
,
75
], [
30
,
75
]])
def
patrol
():
my_dog
.
rgb_strip
.
set_mode(
'breath'
,
'white'
, delay
=
0.1
)
my_dog
.
do_action(
'forward'
, step_count
=
2
, wait
=
False
, speed
=
98
)
my_dog
.
do_action(
'shake_head'
, step_count
=
1
, wait
=
False
, speed
=
80
)
my_dog
.
do_action(
'wag_tail'
, step_count
=
5
, wait
=
False
, speed
=
99
)
(f
"distance: {round(my_dog.distance.value, 2)} cm"
)
if
my_dog
.
distance
.
value
<
15
:
(f
"distance: {round(my_dog.distance.value, 2)} cm. DANGER!"
)
my_dog
.
body_stop()
head_yaw
=
my_dog
.
head_current_angles[
0
]
my_dog
.
rgb_strip
.
set_mode(
'boom'
,
'red'
, delay
=
0.01
)
my_dog
.
tail_move([[
0
]], speed
=
80
)
my_dog
.
legs_move([stand], speed
=
70
)
my_dog
.
wait_all_done()
sleep(
0.1
)
bark(my_dog, [head_yaw,
0
,
0
])
my_dog
.
rgb_strip
.
set_mode(
'breath'
,
'white'
, delay
=
0.1
)
if
__name__
==
"__main__"
:
try
:
while
True
:
patrol()
finally
:
my_dog
.
close()
2.2.5 Response
In this project, PiDog will interact with you in an interesting way.
If you reach out and grab PiDog’s head from the front, it will bark vigilantly.
But if you reach out from behind it and pet its head, it will enjoy it very much.
Run the Code
cd
/
home
/
pi
/
pidog
/
examples
sudo python3
4
_response
.
py
52
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 ...