SunFounder PiDog Kit, Release 1.0
After running this example, PiDog’s ultrasonic module will detect whether there is an obstacle ahead, If it detects your
hand, it makes the breathing light glow red, takes a step back, and barks.
At the same time, the touch sensor will also work. If the touch sensor is stroked (not just touched), PiDog will shake
its head, wag its tail, and show a comfortable look.
Code
Note:
You can
Modify/Reset/Copy/Run/Stop
the code below. But before that, you need to go to source code path
like
pidog\examples
. After modifying the code, you can run it directly to see the effect.
#!/usr/bin/env python3
from
pidog
import
Pidog
from
time
import
sleep
from
math
import
sin
from
preset_actions
import
bark_action
my_dog
=
Pidog()
sleep(
0.1
)
def
lean_forward
():
my_dog
.
speak(
'angry'
)
bark_action(my_dog)
sleep(
0.2
)
bark_action(my_dog)
sleep(
0.4
)
bark_action(my_dog)
def
head_nod
(step):
y
=
0
r
=
0
p
=
30
angs
=
[]
for
i
in
range
(
20
):
r
=
round
(
10
*
sin(i
*
0.314
),
2
)
p
=
round
(
20
*
sin(i
*
0.314
)
+
10
,
2
)
angs
.
append([y, r, p])
my_dog
.
head_move(angs
*
step, immediately
=
False
, speed
=
80
)
def
alert
():
my_dog
.
do_action(
'stand'
, step_count
=
1
, speed
=
90
)
my_dog
.
rgb_strip
.
set_mode(
'breath'
, front_color
=
'pink'
, brightness
=
0.8
, delay
=
0.08
)
while
True
:
(
f
'distance.value: {round(my_dog.distance.value, 2)} cm, touch {my_dog.
˓
→
dual_touch.is_slide()}'
)
# alert
if
my_dog
.
distance
.
value
<
15
and
my_dog
.
distance
.
value
>
1
:
my_dog
.
head_move([[
0
,
0
,
0
]], immediately
=
True
, speed
=
90
)
my_dog
.
tail_move([[
0
]], immediately
=
True
, speed
=
90
)
my_dog
.
rgb_strip
.
set_mode(
(continues on next page)
2.2. Funny Project
53
Содержание PiDog
Страница 1: ...SunFounder PiDog Kit Release 1 0 sunfounder Jan 09 2023 ...
Страница 2: ......
Страница 4: ...ii ...
Страница 6: ...SunFounder PiDog Kit Release 1 0 Content 2 CONTENTS ...
Страница 8: ...SunFounder PiDog Kit Release 1 0 4 Chapter 1 Component List and Assembly Instructions ...
Страница 15: ...SunFounder PiDog Kit Release 1 0 Step 7 Click the WRITE button 2 1 Quick Guide on Python 11 ...
Страница 92: ...SunFounder PiDog Kit Release 1 0 88 Chapter 2 Play with Python ...
Страница 108: ...SunFounder PiDog Kit Release 1 0 104 Chapter 4 Appendix ...