EasyManua.ls Logo

SunFounder PiCrawler Kit - Page 70

Default Icon
137 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
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
from vilib import Vilib
crawler = Picrawler([10,11,12,4,5,6,1,2,3,7,8,9])
#crawler.set_offset([0,0,0,0,0,0,0,0,0,0,0,0])
music = Music()
def main():
Vilib.camera_start()
Vilib.display()
Vilib.color_detect("red")
speed = 100
while True:
if Vilib.detect_obj_parameter['color_n']!=0:
coordinate_x = Vilib.detect_obj_parameter['color_x']
music.sound_effect_threading('./sounds/talk1.wav')
if coordinate_x < 100:
crawler.do_action('turn left',1,speed)
sleep(0.05)
elif coordinate_x > 220:
crawler.do_action('turn right',1,speed)
sleep(0.05)
else :
crawler.do_action('forward',2,speed)
sleep(0.05)
else :
crawler.do_step('stand',speed)
sleep(0.05)
if __name__ == "__main__":
main()
How it works?
In general, this project combines the knowledge points of Move, Computer Vision and Sound Effect.
Its flow is shown in the figure below:
66 Chapter 3. Play with Python

Other manuals for SunFounder PiCrawler Kit

Related product manuals