SunFounder PiCrawler Kit Instructions Manual

Hide thumbs Also See for PiCrawler Kit:

Advertisement

SunFounder PiCrawler Kit
www.sunfounder.com
Jan 06, 2023

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the PiCrawler Kit and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for SunFounder PiCrawler Kit

  • Page 1 SunFounder PiCrawler Kit www.sunfounder.com Jan 06, 2023...
  • Page 3: Table Of Contents

    CONTENTS 1 Component List and Assembly Instructions 2 About Robot HAT 3 Play with Python Quick Guide on Python ......... Calibrate the PiCrawler .
  • Page 4 Get the IP address ..........132 6 Copyright Notice...
  • Page 5 PiCrawler work the way you want. Ezblock Studio is a development platform developed by SunFounder for beginners, aiming to lower the barriers to entry for Raspberry Pi. It has two programming languages: Graphical and Python, which can be used on almost all different types of devices.
  • Page 6 SunFounder PiCrawler Kit CONTENTS...
  • Page 7: Component List And Assembly Instructions

    CHAPTER COMPONENT LIST AND ASSEMBLY INSTRUCTIONS You need to check whether there are missing or damaged components according to the list first. If there are any problems, please contact us and we will solve them as soon as possible. Please follow the steps on the PDF to assemble. If the servo has been powered on, please do not turn the Servo shaft to avoid damage.
  • Page 8 SunFounder PiCrawler Kit Chapter 1. Component List and Assembly Instructions...
  • Page 9: About Robot Hat

    CHAPTER ABOUT ROBOT HAT Robot HAT is a multifunctional expansion board that allows Raspberry Pi to be quickly turned into a robot. An MCU is on board to extend the PWM output and ADC input for the Raspberry Pi, as well as a motor driver chip, Bluetooth module, I2S audio module and mono speaker.
  • Page 10 SunFounder PiCrawler Kit Accepts 7-12V PH2.0 2pin power input with 2 power indicators. The board also has a user available LED and a button for you to quickly test some effects. Note: You can see more details in the Robot HAT Documentation.
  • Page 11: Play With Python

    CHAPTER THREE PLAY WITH PYTHON If you want to program in python, then you will need to learn some basic Python programming skills and basic knowledge of Raspberry Pi, please configure the Raspberry Pi first according to Quick Guide on Python.
  • Page 12 SunFounder PiCrawler Kit Power Adapter To connect to a power socket, the Raspberry Pi has a micro USB port (the same found on many mobile phones). You will need a power supply which provides at least 2.5 amps. Micro SD Card Your Raspberry Pi needs an Micro SD card to store all its files and the Raspberry Pi OS.
  • Page 13 SunFounder PiCrawler Kit 3.1.2 Installing the OS Required Components Any Raspberry Pi 1 * Personal Computer 1 * Micro SD card Step 1 Raspberry Pi have developed a graphical SD card writing tool that works on Mac OS, Ubuntu 18.04 and Windows, and is the easiest option for most users as it will download the image and install it automatically to the SD card.
  • Page 14 SunFounder PiCrawler Kit Scroll down to the end of the newly opened page and you will see Raspberry Pi OS(Legacy) and Raspberry Pi OS Lite(Legacy), these are security updates for Debian Buster, the difference between them is with or without the desktop.
  • Page 15 SunFounder PiCrawler Kit Step 5 Select the SD card you are using. Step 6 To open the advanced options page, click the setting button (appears after selecting operating system) or press Ctrl+Shift+X. Enable ssh and set the username and name. You can choose to always use this image customization options.
  • Page 16 SunFounder PiCrawler Kit Then scroll down to complete the wifi configuration and click SAVE. Note: wifi country should be set the two-letter ISO/IEC alpha2 code for the country in which you are using your Raspberry Pi, please refer to the following link: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_...
  • Page 17 SunFounder PiCrawler Kit Step 7 Click the WRITE button. 3.1. Quick Guide on Python...
  • Page 18 SunFounder PiCrawler Kit Step 8 If your SD card currently has any files on it, you may wish to back up these files first to prevent you from permanently losing them. If there is no file to be backed up, click Yes.
  • Page 19 SunFounder PiCrawler Kit Step 9 After waiting for a period of time, the following window will appear to represent the completion of writing. 3.1. Quick Guide on Python...
  • Page 20 SunFounder PiCrawler Kit 3.1.3 Set up Your Raspberry Pi If You Have a Screen If you have a screen, it will be easy for you to operate on the Raspberry Pi. Required Components • Any Raspberry Pi • 1 * Power Adapter •...
  • Page 21 SunFounder PiCrawler Kit Note: If you use a Raspberry Pi 4, you need to connect the screen to the HDMI0 (nearest the power in port). 4. Use the power adapter to power the Raspberry Pi. After a few seconds, the Raspberry Pi OS desktop will be displayed.
  • Page 22 SunFounder PiCrawler Kit • Don’t Have Temporarily Monitor (or TV)? Have Temporarily Monitor (or TV)? 1. Connect a monitor (or TV), mouse and keyboard to the Raspberry Pi and power it on. Select the menu according to the numbers in the figure.
  • Page 23 SunFounder PiCrawler Kit 3. A VNC icon appears on the upper right of the screen and the VNC server starts. 4. Open the VNC server window by clicking on the VNC icon, then click on the Menu button in the top right corner and select Options.
  • Page 24 SunFounder PiCrawler Kit 5. You will be presented with the following screen where you can change the options. Set Encryption to Prefer off and Authentication to VNC password. 6. When you click the OK button, the password input screen is displayed. You can use the same password as the Raspberry pi password or a different password, so enter it and click OK.
  • Page 25 SunFounder PiCrawler Kit You are now ready to connect from your Mac. It’s okay to disconnect the monitor. From here, it will be the operation on the Mac side. 1. Now, select Connect to Server from the Finder’s menu, which you can open by right-clicking.
  • Page 26 SunFounder PiCrawler Kit 3. You will be asked for a password, so please enter it. 4. The desktop of the Raspberry pi will be displayed, and you will be able to operate it from the Mac as it is. Chapter 3. Play with Python...
  • Page 27 SunFounder PiCrawler Kit Don’t Have Temporarily Monitor (or TV)? • You can apply the SSH command to open the Raspberry Pi’s Bash shell. • Bash is the standard default shell for Linux. • The shell itself is a command (instruction) when the user uses Unix/Linux.
  • Page 28 SunFounder PiCrawler Kit 2. The following message will be displayed only when you log in for the first time, so enter yes. The authenticity of host 'raspberrypi.local (2400:2410:2101:5800:635b:f0b6:2662:8cba)' can't be established. ED25519 key fingerprint is SHA256:oo7x3ZSgAo032wD1tE8eW0fFM/ kmewIvRwkBys6XRwg. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? 3.
  • Page 29 SunFounder PiCrawler Kit sudo raspi-config 6. The following screen will be displayed. Select 3 Interface Options with the arrow keys on the keyboard and press the Enter key. 7. Then select P3 VNC. 8. Use the arrow keys on the keyboard to select <Yes> -> <OK> -> <Finish> to complete the setup.
  • Page 30 SunFounder PiCrawler Kit 9. Now that the VNC server has started, let’s change the settings for connecting from a Mac. To specify parameters for all programs for all user accounts on the computer, create /etc/vnc/ config.d/common.custom. sudo nano /etc/vnc/config.d/common.custom After entering Authentication=VncAuthenter, press Ctrl+X -> Y -> Enter to save and exit.
  • Page 31 SunFounder PiCrawler Kit pi password or a different password. sudo vncpasswd -service 11. Once the setup is complete, restart the Raspberry Pi to apply the changes. sudo sudo reboot 12. Now, select Connect to Server from the Finder’s menu, which you can open by right-clicking.
  • Page 32 SunFounder PiCrawler Kit 14. You will be asked for a password, so please enter it. 15. The desktop of the Raspberry pi will be displayed, and you will be able to operate it from the Mac as it is. Chapter 3. Play with Python...
  • Page 33 SunFounder PiCrawler Kit Windows Users If you’re a Windows user, you can use Windows PowerShell to login Raspberry Pi remotely. 1. Press the windows + R shortcut key in your keyboard to open the Run program. Then type powershell in the input box.
  • Page 34 SunFounder PiCrawler Kit The authenticity of host 'raspberrypi.local (192.168.6.116)' can't be established. ECDSA key fingerprint is SHA256:7ggckKZ2EEgS76a557cddfxFNDOBBuzcJsgaqA/ igz4. Are you sure you want to continue connecting (yes/no/[fingerprint])? Input “yes”. 5. Input the password you set before. (Mine is raspberry.) Note: When you input the password, the characters do not display on window accordingly, which is normal.
  • Page 35 SunFounder PiCrawler Kit 2. Choose 3 Interfacing Options by press the down arrow key on your keyboard, then press the Enter key. 3. Then P3 VNC. 4. Use the arrow keys on the keyboard to select <Yes> -> <OK> -> <Finish> to complete the setup.
  • Page 36 SunFounder PiCrawler Kit Login to VNC 1. You need to download and install the VNC Viewer on personal computer. 2. Open it once the installation is complete. Then, enter the host name or IP address and press Enter. 3. After entering your Raspberry Pi name and password, click OK.
  • Page 37 SunFounder PiCrawler Kit 4. Now you can see the desktop of the Raspberry Pi. 3.1. Quick Guide on Python...
  • Page 38 SunFounder PiCrawler Kit Linux /Unix Users #. Go to Applications->Utilities, find the Terminal, and open it. 1. Check if your Raspberry Pi is on the same network by type in ping <hostname>.local. ping raspberrypi.local • If terminal prompts ping: cannot resolve <hostname>.local, it is possible that the Raspberry Pi failed to connect to the network.
  • Page 39 SunFounder PiCrawler Kit ssh pi@raspberrypi.local 3. The following message may appear. The authenticity of host 'raspberrypi.local (192.168.6.116)' can't be established. ECDSA key fingerprint is SHA256:7ggckKZ2EEgS76a557cddfxFNDOBBuzcJsgaqA/ igz4. Are you sure you want to continue connecting (yes/no/[fingerprint])? Input “yes”. 4. Input the password you set before. (Mine is raspberry.) 1.
  • Page 40 SunFounder PiCrawler Kit Note: Running setup.py will download some necessary components. You may fail to download due to network problems. You may need to download again at this time. In the following cases, enter Y and press Enter. Then download the code and install vilib module.
  • Page 41 SunFounder PiCrawler Kit Type y and press Enter to continue running the script. Type y and press Enter to run /dev/zero in the background. 3.1. Quick Guide on Python...
  • Page 42 SunFounder PiCrawler Kit Type y and press Enter to restart the machine. Note: If there is no sound after restarting, you may need to run the i2samp.sh script multiple times. 3.1.5 Enable I2C and Camera Interface Here we are using the Raspberry Pi’s I2C and Camera interfaces, but by default they are disabled, so we need to enable them first.
  • Page 43 SunFounder PiCrawler Kit 3. Then P5 I2C. 4. Use the arrow keys on the keyboard to select <Yes> -> <OK> to complete the setup of the I2C. 3.1. Quick Guide on Python...
  • Page 44 SunFounder PiCrawler Kit 5. Go to 3 Interfacing Options again and select P1 Camera. 6. Again select <Yes> -> <OK> to complete the setup. Chapter 3. Play with Python...
  • Page 45 SunFounder PiCrawler Kit 7. After you select <Finish>, a pop-up will remind you that you need to reboot for the settings to take effect, select <Yes>. 3.1. Quick Guide on Python...
  • Page 46 SunFounder PiCrawler Kit 3.1.6 Servo Adjust To ensure that the servo has been properly set to 0°, first insert the rocker arm into the servo shaft and then gently rotate the rocker arm to a different angle. Follow the instructions on the assembly foldout, insert the battery holder cable and turn the power switch to the ON.
  • Page 47 SunFounder PiCrawler Kit Note: If you get an error, try re-enabling the Raspberry Pi’s I2C port, see: i2c_config. Next, plug the servo cable into the P11 port as follows. At this point you will see the servo arm rotate to a specific position (0°). If the servo arm does not return to 0°, press the RST button to restart the Robot HAT.
  • Page 48: Calibrate The Picrawler

    SunFounder PiCrawler Kit 3.2 Calibrate the PiCrawler Due to possible deviations during PiCrawler installation or limitations of the servos themselves, some servo angles may be slightly tilted, so you can calibrate them. Of course you can skip this chapter if you think the assembly is perfect and doesn’t require calibration.
  • Page 49 SunFounder PiCrawler Kit 3. Press 2 and 3 keys respectively to choose left 2 legsthen press w, a, s, d, r, and f keys to move them to the calibration point. 4. Now, change the calibration paper to the right and press the 1 and 4 keys to choose right 2 legs, then press w, a, s, d, r, and f keys to move them to the calibration point.
  • Page 50: Move

    SunFounder PiCrawler Kit After the assembly is complete, you can try to run the projects below. 3.3 Move This is PiCrawler’s first project. Perform its most basic function - move. Chapter 3. Play with Python...
  • Page 51 SunFounder PiCrawler Kit Run the Code cd /home/pi/picrawler/examples sudo python3 move.py After the code is executed, PiCrawler will perform the following actions in sequence: move forward, move backward, turn left, turn right, stand. 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.
  • Page 52 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) __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.
  • Page 53: Keyboard Control

    SunFounder PiCrawler Kit 3.4 Keyboard Control In this project, we will learn how to use the keyboard to remotely control the PiCrawler. You can control the PiCrawler to move forward, backward, left, and right. Run the Code cd /home/pi/picrawler/examples sudo python3 keyboard_control.py...
  • Page 54: Sound Effect

    SunFounder PiCrawler Kit (continued from previous page) __name__ "__main__": main() How it works? PiCrawler should take appropriate action based on the keyboard characters read. The lower() function converts upper case characters into lower case characters, so that the letter remains valid regardless of case.
  • Page 55 SunFounder PiCrawler Kit Install i2samp Before using that functions, first activate the speaker so that it will be enabled and can make sounds. Run i2samp.sh in, and this script will install everything needed to use i2s amplifier. /home/pi/picrawler/ sudo bash i2samp.sh There will be several prompts asking to confirm the request.
  • Page 56 SunFounder PiCrawler Kit Code from time import sleep from robot_hat import Music,TTS import readchar music Music() TTS() manual Input key to call the function! q: Play background music 1: Play sound effect 2: Play sound effect with threads t: Text to speak...
  • Page 57: Obstacle Avoidance

    SunFounder PiCrawler Kit Functions related to background music include these: • music = Music() : Declare the object. • music.music_set_volume(20) : Set the volume, the range is 0~100. • music.background_music(./musics/sports-Ahjay_Stelino.mp3) : Play music files, here is the sports-Ahjay_Stelino.mp3 file under the ./musics path.
  • Page 58 SunFounder PiCrawler Kit Run the Code cd /home/pi/picrawler/examples sudo python3 avoid.py After the code runs, PiCrawler 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.
  • Page 59 SunFounder PiCrawler Kit (continued from previous page) 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]) sonar Ultrasonic(Pin("D2") ,Pin("D3")) alert_distance speed main(): distance sonar.read() print(distance) distance < pass elif distance <= alert_distance: try: music.sound_effect_threading('./sounds/sign.wav') except Exception as print(e) crawler.do_action('turn left angle',3,speed) time.sleep(0.2) else crawler.do_action('forward', 1,speed) time.sleep(0.2) __name__ "__main__":...
  • Page 60: Computer Vision

    SunFounder PiCrawler Kit (continued from previous page) print(e) crawler.do_action('turn left angle',3,speed) time.sleep(0.2) else crawler.do_action('forward', 1,speed) time.sleep(0.2) Note: You can add different sound effects or music to musics or sounds folder via Filezilla Software. 3.7 Computer Vision This project will officially enter the field of computer vision!
  • Page 61 SunFounder PiCrawler Kit • 0: Switch off Color detect • rScan the QR code • f: Switch ON/OFF face detect • s: Display detected object information Please follow the prompts to activate the corresponding functions. • Take Photo Type q in the terminal and press Enter. The picture currently seen by the camera will be saved (if the color detection function is turned on, the mark box will also appear in the saved picture).
  • Page 62 SunFounder PiCrawler Kit • QR Code Detect Enter r to open the QR code recognition. No other operations can be performed before the QR code is recognized. The decoding information of the QR code will be printed in the terminal.
  • Page 63 SunFounder PiCrawler Kit Entering s will print the information of the face detection (and color detection) target in the terminal. Including the center coordinates (X, Y) and size (Weight, height) of the measured object. Code from pydoc import text from...
  • Page 64 SunFounder PiCrawler Kit (continued from previous page) take_photo(): _time strftime('%Y-%m-%d-%H-%M-%S',localtime(time())) name 'photo_%s'%_time path "/home/pi/Pictures/PiCrawler/" Vilib.take_photo(name, path) print('photo save as %s%s.jpg'%(path,name)) object_show(): flag_color, flag_face global flag_color True: Vilib.detect_obj_parameter['color_n'] print('Color Detect: None') else: color_coodinate (Vilib.detect_obj_parameter['color_x'],Vilib.detect_obj_ parameter['color_y']) color_size (Vilib.detect_obj_parameter['color_w'],Vilib.detect_obj_ parameter['color_h']) print("[Color Detect] ","Coordinate:",color_coodinate,"Size",color_size)
  • Page 65 SunFounder PiCrawler Kit (continued from previous page) print('Color detect : %s'%color_list[index]) # face detection elif key =="f": flag_face flag_face face_detect(flag_face) # qrcode detection key =="r": elif qr_code_flag qr_code_flag qr_code_flag True: qrcode_thread None or not qrcode_thread.is_alive(): qrcode_thread threading.Thread(target=qrcode_detect) qrcode_thread.setDaemon(True) qrcode_thread.start() else:...
  • Page 66: Record Video

    SunFounder PiCrawler Kit The keys of the dictionary and their uses are shown in the following list: • color_x: the x value of the center coordinate of the detected color block, the range is 0~320 • color_y: the y value of the center coordinate of the detected color block, the range is 0~240 •...
  • Page 67 SunFounder PiCrawler Kit Recording can be stopped or started by pressing the keys on the keyboard. • Press q to begin recording or pause/continue, e to stop recording or save. • If you want to exit the program, press esc.
  • Page 68: Bull Fight

    SunFounder PiCrawler Kit (continued from previous page) rec_flag 'pause': elif rec_flag 'start' Vilib.rec_video_start() print_overwrite('continue') # stop elif rec_flag 'stop': None rec_flag 'stop' Vilib.rec_video_stop() print_overwrite("The video saved as %s%s.avi"%(Vilib.rec_video_set["path "],vname),end='\n') # quit elif readchar.key.CTRL_C readchar.key.ESCAPE_SEQUENCES: Vilib.camera_close() print('\nquit') break sleep(0.1) __name__ "__main__":...
  • Page 69 SunFounder PiCrawler Kit Run the Code cd /home/pi/picrawler/examples sudo python3 bull_fight.py View the Image After the code runs, the terminal will display the following prompt: No desktop ! * Serving Flask app "vilib.vilib" (lazy loading) * Environment: production WARNING: Do not use the development server in a production environment.
  • Page 70 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...
  • Page 71: Treasure Hunt

    SunFounder PiCrawler Kit 3.10 Treasure Hunt Arrange a maze in your room and place six different color cards in six corners. Then control PiCrawler to search for these color cards one by one! Note: You can download and print the PDF Color Cards for color detection.
  • Page 72 SunFounder PiCrawler Kit No desktop ! * Serving Flask app "vilib.vilib" (lazy loading) * Environment: production WARNING: Do not use the development server in a production environment. Use a production WSGI server instead. * Debug mode: off * Running on http://0.0.0.0:9000/ (Press CTRL+C to quit) Then you can enter http://<your IP>:9000/mjpg in the browser to view the video screen.
  • Page 73 SunFounder PiCrawler Kit (continued from previous page) lock threading.Lock() key_scan_thread(): global True: while key_temp readchar.readkey() print('\r',end='') lock: with key_temp.lower() readchar.key.SPACE: 'space' elif readchar.key.CTRL_C readchar.key.ESCAPE_ SEQUENCES: 'quit' break sleep(0.01) main(): global action None Vilib.camera_start(vflip=False,hflip=False) Vilib.display(local=False,web=True) sleep(0.8) speed print(manual) sleep(1) _key_t threading.Thread(target=key_scan_thread) _key_t.setDaemon(True)
  • Page 74 SunFounder PiCrawler Kit (continued from previous page) sleep(0.05) __name__ "__main__": main() How it works? In general, this project combines the knowledge points of Keyboard Control, Computer Vision Sound Effect. Its flow is shown in the figure below: Chapter 3. Play with Python...
  • Page 75: Pose

    SunFounder PiCrawler Kit 3.11 Pose PiCrawler can assume a specific posture by writing a coordinate array. Here it assumes a raised right rear foot posture. Run the Code cd /home/pi/picrawler/examples sudo python3 do_step.py Code from picrawler import Picrawler from time...
  • Page 76 SunFounder PiCrawler Kit (continued from previous page) crawler.do_step('stand',speed) print(crawler.step_list.get('stand')) sleep(3) crawler.do_step(new_step,speed) print(new_step) sleep(3) __name__ "__main__": main() How it works? In this code, the code you need to pay attention to is this crawler.do_step(). Similar to do_action(), do_step() can also manipulate PiCrawler’s behavior. The difference is that the former can perform the continuous behavior of move forward, while the latter can be used to make separate gestures of stand and sit.
  • Page 77 SunFounder PiCrawler Kit You need to measure the coordinates of each toe individually. As shown below: 3.11. Pose...
  • Page 78: Adjust Posture

    SunFounder PiCrawler Kit By the way: the step_list called in the first method also consists of an array containing 4 coordinate values. step_list "stand":[ [50, 50, -80], [50, 50, -80], [50, 50, -80], [50, 50, -80] "sit":[ [50, 50, -33],...
  • Page 79 SunFounder PiCrawler Kit Run the Code cd /home/pi/picrawler/examples sudo python3 do_single_leg.py After the code runs, please operate according to the prompt that pops up in the terminal. • Press 1234 to select the feet separately, 1: right front foot, 2: left front foot, 3: left rear foot, 4: right rear foot •...
  • Page 80 SunFounder PiCrawler Kit (continued from previous page) ....<=| | ------| |=> ``````` ``````` 1: Select right front leg 2: Select left front leg 3: Select left rear leg 4: Select right rear leg W: Y++ R: Z++ A: X--...
  • Page 81: Record New Step

    SunFounder PiCrawler Kit (continued from previous page) show_info() # quit elif readchar.key.CTRL_C readchar.key.ESCAPE_SEQUENCES: Quit") print("\n break sleep(0.05) __name__ "__main__": main() • current_step_all_leg_value() : Returns the coordinate values of all legs. • do_single_leg(leg,coordinate,speed) : Modify the coordinate value of a certain leg individually.
  • Page 82 SunFounder PiCrawler Kit (continued from previous page) termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return manual Press keys on keyboard to control PiSloth! w: Y++ a: X-- s: Y-- d: X++ r: Z++ f: Z-- 1: Select right front leg 2: Select left front leg...
  • Page 83 SunFounder PiCrawler Kit (continued from previous page) leg=0 coodinate=crawler.current_step_leg_value(leg) elif key: leg=1 coodinate=crawler.current_step_leg_value(leg) elif key: leg=2 coodinate=crawler.current_step_leg_value(leg) elif key: leg=3 coodinate=crawler.current_step_leg_value(leg) elif chr(32) key: print("[[right front],[left front],[left rear],[right rear]]") print("saved new step") print(crawler.current_step_all_leg_value()) save_new_step() elif key: play_all_new_step() elif chr(27) key:# 27 for ESC break sleep(0.05)
  • Page 84: Twist

    SunFounder PiCrawler Kit 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.
  • Page 85: Emotional Robot

    SunFounder PiCrawler Kit twist(speed): ## [right front],[left front],[left rear],[right rear] new_step=[[50, 50, -80], [50, 50, -80],[50, 50, -80], [50, 50, -80]] range(4): range(30,60,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) Simply put, it uses two layers of for loops to make the new_step array produce continuous and regular changes, and at the same time, crawler.do_step() executes the posture to form a continuous action.
  • Page 86 SunFounder PiCrawler Kit from picrawler import Picrawler sleep from time import 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]) handwork(speed): basic_step basic_step crawler.step_list.get("sit") left_hand crawler.mix_step(basic_step,0,[0,50,80]) right_hand crawler.mix_step(basic_step,1,[0,50,80]) two_hand crawler.mix_step(left_hand,1,[0,50,80]) crawler.do_step('sit',speed) sleep(0.6) crawler.do_step(left_hand,speed) sleep(0.6) crawler.do_step(two_hand,speed) sleep(0.6) crawler.do_step(right_hand,speed) sleep(0.6) crawler.do_step('sit',speed) sleep(0.6) twist(speed): new_step=[[50, 50, -80], [50, 50, -80],[50, 50, -80], [50, 50, -80]]...
  • Page 87 SunFounder PiCrawler Kit (continued from previous page) swimming(speed) pushup(speed) handwork(speed) twist(speed) sleep(0.05) __name__ "__main__": main() 3.15. Emotional Robot...
  • Page 88 SunFounder PiCrawler Kit Chapter 3. Play with Python...
  • Page 89: Play With Ezblock

    FOUR PLAY WITH EZBLOCK For beginners and novices, EzBlock is a software development platform offered by SunFounder for Raspberry Pi. Ezbock offers two programming environments: a graphical environment and a Python environment. It is available for almost all types of devices, including Mac, PC, and Android.
  • Page 90 SunFounder PiCrawler Kit 3. Follow the instructions on the assembly foldout, insert the battery holder cable and turn the power switch to the ON. Wait for 1-2 minutes, there will be a sound to indicate that the Raspberry Pi boots successfully.
  • Page 91 SunFounder PiCrawler Kit 5. At this point you will see the servo arm rotate to a specific position (0°). If the servo arm does not return to 0°, press the RST button to restart the Robot HAT. 6. Now you can continue the installation as instructed on the assembly foldout.
  • Page 92: Calibrate The Picrawler

    SunFounder PiCrawler Kit 4.2 Calibrate the PiCrawler After you connect the PiCrawler, there will be a calibration step. This is because of possible deviations in the instal- lation process or limitations of the servos themselves, making some servo angles slightly tilted, so you can calibrate them in this step.
  • Page 93 SunFounder PiCrawler Kit On this page, you can change the product name, product type, view the app version or calibrate the robot. Once you click on Calibrate you can go to the calibration page. 4.2. Calibrate the PiCrawler...
  • Page 94 SunFounder PiCrawler Kit The calibration steps are as follows: 1. Take out the assembly leaflet, turn it to the last page, and lay it flat on the table. Then place the PiCrawler as shown below, aligning its bottom with the outline on the calibration chart.
  • Page 95 SunFounder PiCrawler Kit 3. Align the other foot on the left in the same way. 4. After calibrating the left two feet, change the calibration paper to the right, and calibrate the right two feet according to the above method.
  • Page 96: Move

    SunFounder PiCrawler Kit Projects Here, we show you the projects of playing PiCrawler on Ezblock Studio. If you are new to these, you can refer to the code images inside each project to program, and can learn the use of blocks according to TIPS.
  • Page 97 SunFounder PiCrawler Kit Program Note: • You can write the program according to the following picture, please refer to the tutorial: How to Create a New Project?. • Or find the code with the same name on the Examples page of the EzBlock Studio and click Run or Edit directly.
  • Page 98 SunFounder PiCrawler Kit Click the Upload & Run button at the bottom right of the screen, and PiCrawler will execute “forward” and “backward” actions in sequence. How it works? First, you need to understand the program framework of Ezblock. as follows:...
  • Page 99 SunFounder PiCrawler Kit All Ezblock projects contain these two blocks. The Start block runs at the beginning of the program and is executed only once, and is often used to set variables; the Forever block runs after Start, and will be executed repeatedly, and is often used to implement main functions.
  • Page 100: Remote Control

    SunFounder PiCrawler Kit 4.4 Remote Control In this project, we will learn how to remote control the PiCrawler. You can control the PiCrawler to move forward, backward, left, and right. Note: You can refer to How to Use the Remote Control Function?.
  • Page 101 SunFounder PiCrawler Kit Switch to the Remote Control interface, and you will see the following widgets. 4.4. Remote Control...
  • Page 102 SunFounder PiCrawler Kit After the program is running, you can activate PiCrawler through D-Pad. How it works? After dragging out the widget on the Remote Control interface, a category named Remote will appear in the block categories column of the programming interface.
  • Page 103 SunFounder PiCrawler Kit We used an if block (you can find it in the Logic category on the left) to make the PiCrawler move forward once when the UP button of the D-pad is pressed. You can click the gear icon on the upper left of the block to modify the shape of the if block to realize multiple judgment branches.
  • Page 104: Sound Effect

    SunFounder PiCrawler Kit 4.5 Sound Effect In this example, we use PiCrawler’s (to be precise, Robot HAT’s) sound effects. It consists of three parts, namely Muisc, Sound, Text to Speech. Program Note: • You can write the program according to the following picture, please refer to the tutorial: How to Create a New Project?.
  • Page 105 SunFounder PiCrawler Kit Switch to the Remote Control interface, and you will see the following widgets. 4.5. Sound Effect...
  • Page 106 SunFounder PiCrawler Kit After the program is running, you can press different buttons to make PiCrawler sound. How it works? Functions related to background music include these: Functions related to sound effects include these: Functions related to Text to Speech include these:...
  • Page 107: Obstacle Avoidance

    SunFounder PiCrawler Kit 4.6 Obstacle Avoidance In this project, picrawler will use an ultrasonic module to detect obstacles in front. When PiCrawler detects an obstacle, it will send a signal and look for another direction to move forward. Program Note: •...
  • Page 108 SunFounder PiCrawler Kit • Or find the code with the same name on the Examples page of the EzBlock Studio and click Run or Edit directly. How it works? You can find the following blocks in the Module category to achieve distance detection:...
  • Page 109: Computer Vision

    SunFounder PiCrawler Kit It should be noted that the two pins of the block should correspond to the actual wiring, that is, trig-D2, echo-D3. Here is the main program. • Read the distance detected by ultrasonic module and filter out the values less than 0 (When the ultrasonic module is too far from the obstacle or cannot read the data correctly, distance<0 will appear).
  • Page 110 SunFounder PiCrawler Kit Switch to the Remote Control interface, and you will see the following widgets. Chapter 4. Play with Ezblock...
  • Page 111 SunFounder PiCrawler Kit After the program is running, you can switch the slider widget to turn on/off the face detection; click the D-Pad to select the color of the detection; click the button to print the detection result. How it works? This block is used to enable the camera module.
  • Page 112: Bull Fight

    SunFounder PiCrawler Kit These two blocks are used to output information. The detection result has five output values, namely coordinate x value, coordinate y value, width, height, and number. 4.8 Bull Fight Make PiCrawler an angry bull! Use its camera to track and rush the red cloth!
  • Page 113 SunFounder PiCrawler Kit Note: You can download and print the PDF Color Cards for color detection. Program Note: • You can write the program according to the following picture, please refer to the tutorial: How to Create a New Project?.
  • Page 114 SunFounder PiCrawler Kit Switch to the Remote Control interface, you will see the following screen. Chapter 4. Play with Ezblock...
  • Page 115 SunFounder PiCrawler Kit How it works? In general, this project combines the knowledge points of Move, Computer Vision Sound Effect. Its flow is shown in the figure below: 4.8. Bull Fight...
  • Page 116: Treasure Hunt

    SunFounder PiCrawler Kit 4.9 Treasure Hunt Arrange a maze in your room and place six different color cards in six corners. Then control PiCrawler to search for these color cards one by one! Note: You can download and print the PDF Color Cards for color detection.
  • Page 117 SunFounder PiCrawler Kit Switch to the Remote Control interface, and you will see the following widgets. How it works? 4.9. Treasure Hunt...
  • Page 118 SunFounder PiCrawler Kit In general, this project combines the knowledge points of Remote Control, Computer Vision Sound Effect. Its flow is shown in the figure below: Chapter 4. Play with Ezblock...
  • Page 119: Pose

    SunFounder PiCrawler Kit 4.10 Pose PiCrawler can assume a specific posture by writing a coordinate array. Here it assumes a raised right rear foot posture. Program Note: • You can write the program according to the following picture, please refer to the tutorial: How to Create a New Project?.
  • Page 120 SunFounder PiCrawler Kit How it works? In this code, the code you need to pay attention to is this do step. It has two uses: One: It can directly use stand or sit. Second: It can also write an array of 4 coordinate values.
  • Page 121 SunFounder PiCrawler Kit You need to measure the coordinates of each toe individually. As shown below: 4.10. Pose...
  • Page 122: Adjust Posture

    SunFounder PiCrawler Kit 4.11 Adjust Posture In this example, we use the remote function to control the PiCrawler foot by foot and assume the desired posture. You can tap the button to print out the current coordinate values. These coordinate values come in handy when you create unique actions for PiCrawler.
  • Page 123 SunFounder PiCrawler Kit Program Note: • You can write the program according to the following picture, please refer to the tutorial: How to Create a New Project?. • Or find the code with the same name on the Examples page of the EzBlock Studio and click Run or Edit directly.
  • Page 124 SunFounder PiCrawler Kit Switch to the Remote Control interface, and you will see the following widgets. Chapter 4. Play with Ezblock...
  • Page 125 SunFounder PiCrawler Kit How it works? What you need to pay attention to in this project are the following three blocks: Modify the coordinate value of a certain leg individually. Returns the coordinate value of the corresponding leg. You may want to simplify the program with Functions, especially when you perform the same operation multiple times.
  • Page 126: Record New Step

    SunFounder PiCrawler Kit 4.12 Record New Step We use the remote function to control PiCrawler to make several poses in turn, and record these poses. Replay them later. Program Note: • You can write the program according to the following picture, please refer to the tutorial: How to Create a New Project?.
  • Page 127 SunFounder PiCrawler Kit Switch to the Remote Control interface, and you will see the following widgets. 4.12. Record New Step...
  • Page 128 SunFounder PiCrawler Kit How it works? This project was born out of Adjust Posture. Added recording and replay functions. The recording function is implemented by the following code. The replay function is implemented by the following code. Chapter 4. Play with Ezblock...
  • Page 129: Twist

    SunFounder PiCrawler Kit 4.13 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.
  • Page 130 SunFounder PiCrawler Kit How it works? It uses two layers of for loops to make the new_step array produce continuous and regular changes, and at the same time, do step executes the posture to form a continuous action. You can intuitively get the coordinate value array corresponding to each pose from Adjust Posture.
  • Page 131: Emotional Robot

    SunFounder PiCrawler Kit It is essentially a two-dimensional array, which can be processed by blocks in the List category. Its structure is [[right front],[left front],[left rear],[right rear]]. In other words, in this example, new_step#1 corresponds to the right front; new_step#2 corresponds to the left front; new_step#3 corresponds to the left rear;...
  • Page 132 SunFounder PiCrawler Kit Chapter 4. Play with Ezblock...
  • Page 133: Appendix

    CHAPTER FIVE APPENDIX 5.1 Filezilla Software The File Transfer Protocol (FTP) is a standard communication protocol used for the transfer of computer files from a server to a client on a computer network. Filezilla is an open source software that not only supports FTP, but also FTP over TLS (FTPS) and SFTP. We can use Filezilla to upload local files (such as pictures and audio, etc.) to the Raspberry Pi, or download files from the Raspberry Pi to the local.
  • Page 134 SunFounder PiCrawler Kit Note: Quick Connect is a good way to test your login information. If you want to create a permanent entry, you can select File-> Copy Current Connection to Site Manager after a successful Quick Connect, enter the name and click OK.
  • Page 135: About The Battery

    SunFounder PiCrawler Kit 5.2 About the Battery Applicable Parameters • 3.7V • 18650 • Rechargeable • Li-ion Battery • Button Top • No Protective Board Note: • Robot HAT cannot charge the battery, so you need to buy a battery charger.
  • Page 136 SunFounder PiCrawler Kit Button Top Flat Top No protective board? You are recommend to use 18650 batteries without a protective board. Otherwise, the robot may be cut power and stop running because of the overcurrent protection of the protective board.
  • Page 137 CHAPTER COPYRIGHT NOTICE All contents including but not limited to texts, images, and code in this manual are owned by the SunFounder Company. You should only use it for personal study,investigation, enjoyment, or other non-commercial or nonprofit purposes, under therelated regulations and copyrights laws, without infringing the legal rights of the author and relevant right holders.

Table of Contents