EasyManua.ls Logo

SunFounder PiDog - Page 54

Default Icon
109 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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():
print("\033[H\033[J", end='') # clear terminal windows
print(
"\033[104m\033[1m Function Demonstration \033[0m")
print("\033[90m Input Function number to see how it goes.\n Actions will repeat
˓10 times.\033[0m")
print(
"\033[100m\033[1m Actions: Sound Effect: \033[0m")
first_line = 5
last_line = 0
for i, action in enumerate(actions):
print(f'\033[{i+first_line};4H{i+1}. {action[0]}')
last_line = i+first_line
for i, sound_effect in enumerate(sound_effects):
print(f'\033[{i+first_line};32H{i+len(actions)+1}. {sound_effect}')
last_line = max(i+first_line, last_line) - 1
print(
f"\033[100m\033[1m\033[{last_line +2};0H Ctrl+C: Quit
˓ \033[0m")
if index != None:
print('Current selection: ', end="")
if index < len(actions):
print(f"{index+1}. {actions[index][0]}")
else:
print(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

Related product manuals