EasyManua.ls Logo

SunFounder PiCrawler Kit - Twist

Default Icon
141 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 PiCrawler Kit
Ready to explore and create with us? Click [] and join today!
3.14 Twist
We already know how to make PiCrawler assume a specific pose, the next step is to combine the poses to form a
continuous action.
Here, PiCrawler’s four feet are up and down in twos, jumping with the music.
Run the Code
cd ~/picrawler/examples
sudo python3 twist.py
Code
Note: You can Modify/Reset/Copy/Run/Stop the code below. But before that, you need to go to source code path
like picrawler\examples. After modifying the code, you can run it directly to see the effect.
from picrawler import Picrawler
from time import sleep
from robot_hat import Music
music = Music()
crawler = Picrawler()
def twist(speed):
new_step=[[50, 50, -80], [50, 50, -80],[50, 50, -80], [50, 50, -80]]
for i in range(4):
for inc in range(30, 50, 5):
rise = [50,50,(-80+inc*0.5)]
drop = [50,50,(-80-inc)]
new_step[i]=rise
new_step[(i+2)%4] = drop
new_step[(i+1)%4] = rise
new_step[(i-1)%4] = drop
crawler.do_step(new_step,speed)
def main():
music.music_play('./musics/sports-Ahjay_Stelino.mp3')
music.music_set_volume(20)
while True:
twist(speed=100)
(continues on next page)
78 Chapter 3. Play with Python

Other manuals for SunFounder PiCrawler Kit

Related product manuals