SunFounder pisloth
music
.
background_music(
'./musics/india-Arulo.mp3'
)
music
.
music_set_volume(
20
)
In general, all actions of PiSloth can be implemented with the
sloth.do_action()
function. It has four parame-
ters:
•
motion_name
is the name of specific actions, including:
forward
,
turn right
,
turn left
,
backward
,
stand
,
moon walk left
,
moon walk right
,
hook
,
big swing
,
swing
,
walk
boldly
,
walk backward boldly
,
walk shyly
,
walk backward shyly
,
stomp rihgt
,
stomp left
,
close
,
open
,
tiptoe left
,
tiptoe right
,
fall left
,
fall right
.
•
step
represents the number of each action is done, the default is 1.
•
speed
indicates the speed of the action, the default is 50 and the range is 0~100.
•
bpm
means rhythm, the bpm parameter here affects the interval time of PiSloth movement. The higher the
value, the shorter the interval time. When we know the beat of a song through the
bpm calculator
, we can
make PiSloth dance to the music.
For music bmp, if you want to know more, you can refer to:
https://en.wikipedia.org/wiki/Tempo
Note:
You can add different sound effects or music to
musics
or
sounds
folder via
4.4 Obstacle Avoidance
In this project, PiSloth will use an ultrasonic module to detect obstacles in front. When PiSloth detects an obstacle, it
will send a signal and look for another direction to move forward.
Run the Code
cd
/
home
/
pi
/
pisloth
/
examples
sudo python3 avoid
.
py
After the code runs, PiSloth will walk forward. If it detects that the distance of the obstacle ahead is less than 10cm, it
will stop and sound a warning, then turn left and stop. If there is no obstacle in the direction after turning left or the
obstacle distance is greater than 10, it will continue to move forward.
Code
Note:
You can
Modify/Reset/Copy/Run/Stop
the code below. But before that, you need to go to source code path
like
pisloth\examples
. After modifying the code, you can run it directly to see the effect.
from
pisloth
import
Sloth
from
robot_hat
import
TTS, Music
from
robot_hat
import
Ultrasonic
from
robot_hat
import
Pin
import
time
import
os
tts
=
TTS()
music
=
Music()
sloth
=
Sloth([
1
,
2
,
3
,
4
])
(continues on next page)
4.4. Obstacle Avoidance
65
Содержание PiSloth
Страница 1: ...SunFounder pisloth www sunfounder com Oct 19 2021 ...
Страница 2: ......
Страница 4: ...ii ...
Страница 6: ...SunFounder pisloth 2 CONTENTS ...
Страница 8: ...SunFounder pisloth 4 Chapter 1 Component List and Assembly Instructions ...
Страница 18: ...SunFounder pisloth EXAMPLE 14 Chapter 3 Play with Ezblock ...
Страница 20: ...SunFounder pisloth 16 Chapter 3 Play with Ezblock ...
Страница 22: ...SunFounder pisloth Confuse Happy 18 Chapter 3 Play with Ezblock ...
Страница 23: ...SunFounder pisloth Fear Sad 3 5 Emotional PiSloth 19 ...
Страница 24: ...SunFounder pisloth Fall Call all custom functions in the Forever block 20 Chapter 3 Play with Ezblock ...
Страница 25: ...SunFounder pisloth 3 6 Dance Now PiSltoh will show you his newly learned dance 3 6 Dance 21 ...
Страница 28: ...SunFounder pisloth 24 Chapter 3 Play with Ezblock ...
Страница 32: ...SunFounder pisloth 28 Chapter 3 Play with Ezblock ...
Страница 35: ...SunFounder pisloth 3 8 Remote Control 31 ...
Страница 39: ...SunFounder pisloth 3 9 Custom Step 35 ...
Страница 41: ...SunFounder pisloth The complete code is as follows 3 9 Custom Step 37 ...
Страница 50: ...SunFounder pisloth Step 7 Click the WRITE button 46 Chapter 4 Play with Python ...
Страница 86: ...SunFounder pisloth 82 Chapter 4 Play with Python ...
Страница 90: ...SunFounder pisloth Yes then Ok Finish 86 Chapter 5 Appendix ...
Страница 94: ...SunFounder pisloth Step 4 Double click the connection just created 90 Chapter 5 Appendix ...
Страница 95: ...SunFounder pisloth Step 5 Enter Username pi and Password raspberry by default 5 3 Remote Desktop 91 ...
Страница 96: ...SunFounder pisloth Step 6 Now you can see the desktop of the Raspberry Pi 92 Chapter 5 Appendix ...
Страница 102: ...SunFounder pisloth 98 Chapter 5 Appendix ...
Страница 104: ...SunFounder pisloth 100 Chapter 6 Thank You ...