SunFounder PiDog Kit, Release 1.0
(continued from previous page)
[
'shake_head'
,
0
,
90
],
[
'tilting_head'
,
0
,
60
],
[
'wag_tail'
,
0
,
100
],
]
sound_effects
=
[]
for
name
in
os
.
listdir(
'../sounds'
):
sound_effects
.
append(name
.
split(
'.'
)[
0
])
sound_effects
.
sort()
index
=
None
last_index
=
2
exit_flag
=
False
STANDUP_ACTIONS
=
[
'trot'
,
'forward'
,
'backward'
,
'turn_left'
,
'turn_right'
]
def
show_info
():
(
"
\033
[H
\033
[J"
, end
=
''
)
# clear terminal windows
(
"
\033
[104m
\033
[1m
Function Demonstration
\033
[0m"
)
(
"
\033
[90m
Input Function number to see how it goes.
\n
Actions will repeat
˓
→
10 times.
\033
[0m"
)
(
"
\033
[100m
\033
[1m
Actions:
Sound Effect:
\033
[0m"
)
first_line
=
5
last_line
=
0
for
i, action
in
enumerate
(actions):
(f
'
\033
[{i+first_line};4H{i+1}. {action[0]}'
)
last_line
=
i
+
first_line
for
i, sound_effect
in
enumerate
(sound_effects):
(f
'
\033
[{i+first_line};32H{i+len(a1}. {sound_effect}'
)
last_line
=
max
(i
+
first_line, last_line)
-
1
(
f
"
\033
[100m
\033
[1m
\033
[{las2};0H
Ctrl+C: Quit
˓
→
\033
[0m"
)
if
index
!=
None
:
(
'Current selection: '
, end
=
""
)
if
index
<
len
(actions):
(f
"{index+1}. {actions[index][0]}"
)
else
:
(f
"{index+1}. {sound_effects[index-len(actions)]}"
)
def
do_function
(index):
global
last_index
my_dog
.
body_stop()
if
index
<
len
(actions):
name, head_pitch_adjust, speed
=
actions[index]
# If last action is pushup, then lie down first
if
last_index
<
len
(actions)
and
actions[last_index][
0
]
in
(
'pushup'
):
my_dog
.
do_action(
'lie'
, wait
=
False
, speed
=
60
)
# If this action is trot, forward, turn left, turn right and backward, and,
˓
→
last action is not, then stand up
if
name
in
STANDUP_ACTIONS
and
last_index
<
len
(actions)
and
actions[last_
˓
→
index][
0
]
not in
STANDUP_ACTIONS:
(continues on next page)
50
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 ...