EasyManua.ls Logo

SunFounder PiCrawler Kit - Page 52

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
(continued from previous page)
sleep(0.05)
crawler.do_action('backward',2,speed)
sleep(0.05)
crawler.do_action('turn left',2,speed)
sleep(0.05)
crawler.do_action('turn right',2,speed)
sleep(0.05)
crawler.do_action('turn left angle',2,speed)
sleep(0.05)
crawler.do_action('turn right angle',2,speed)
sleep(0.05)
crawler.do_step('stand',speed)
sleep(1)
if __name__ == "__main__":
main()
How it works?
First, import the Picrawler class from the picrawler library you have installed, which contains all of PiCrawler’s
actions and the functions that implement them.
from picrawler import Picrawler
Then instantiate the crawler class.
crawler = Picrawler([10,11,12,4,5,6,1,2,3,7,8,9])
Finally use the crawler.do_action() function to make Pisloth move.
crawler.do_action('forward',2,speed)
crawler.do_action('backward',2,speed)
crawler.do_action('turn left',2,speed)
crawler.do_action('turn right',2,speed)
crawler.do_action('turn left angle',2,speed)
crawler.do_action('turn right angle',2,speed)
In general, all movement of PiCrawler can be implemented with the do_action() function. It has 3 parameters:
motion_name is the name of specific actions, including: forward, turn right, turn left,
backward, turn left angle, turn right angle.
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.
In addition, crawler.do_step('stand',speed) is also used here to make PiCrawler stand. The usage of this
function will be explained in the following example.
48 Chapter 3. Play with Python

Other manuals for SunFounder PiCrawler Kit

Related product manuals