SunFounder picar-x Manual
Hide thumbs Also See for picar-x:

Advertisement

SunFounder picar-x
www.sunfounder.com
Feb 21, 2023

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the picar-x and is the answer not in the manual?

Questions and answers

Summary of Contents for SunFounder picar-x

  • Page 1 SunFounder picar-x www.sunfounder.com Feb 21, 2023...
  • Page 3: Table Of Contents

    ......... . Calibrating the PiCar-X .
  • Page 4 5.10 Background Music ..........107 5.11 Say Hello .
  • Page 5 Thanks for choosing our PiCar-X. The PiCar-X is an AI-driven self-driving robot car for the Raspberry Pi platform, upon which the Raspberry Pi acts as the control center. The PiCar-X’s 2-axis camera module, ultrasonic module, and line tracking modules can provide the functions of color/face/traffic-signs detection, automatic obstacle avoidance, automatic line tracking, etc.
  • Page 6 SunFounder picar-x • In this course page, right-click and select Translate to xx. If the current language is not what you want, you can change it later. • There will be a language popup in the upper right corner. Click on the menu button to choose another language.
  • Page 7 SunFounder picar-x Content CONTENTS...
  • Page 8 SunFounder picar-x CONTENTS...
  • Page 9: Introduction

    CHAPTER INTRODUCTION 1.1 The History of Self-driving Cars Experiments have been conducted on self-driving cars since at least the 1920’s. Promising trials took place in the 1950’s, and work has proceeded forward ever since. The first self-sufficient and truly autonomous cars appeared in the 1980’s, with Carnegie Mellon University’s Navlab and ALV projects in 1984, and Mercedes-Benz and Bundeswehr University Munich’s Eureka Prometheus Project in 1987.
  • Page 10 The proven way to allow an emerging technology to quickly mature is to make it easily accessible to everyone by minimizing the market-entry requirements. This is SunFounders motivation for launching PiCar-X. SunFounders goal is to help beginners, novices, and those who simply just want to learn about autonomous driving, to understand the development process, the technology, and the latest innovations in self-driving vehicles.
  • Page 11: About Picar-X

    SunFounder picar-x 1.2 About PiCar-X The PiCar-X is an AI-controlled self-driving robot car for the Raspberry Pi platform, upon which the Raspberry Pi acts as the control center. The PiCar-X’s 2-axis camera module, ultrasonic module, and line tracking modules can provide the functions of color/face/traffic signs detection, automatic obstacle avoidance, automatic line tracking, etc.
  • Page 12: Deep Learning And Neural Networks

    SunFounder picar-x 1.3 Deep Learning and Neural Networks To learn more about deep learning and Neural Networks, SunFounder recommends the following resources: Machine Learning - Andrew Ng : This course provides a broad introduction to machine learning, datamining, and statistical pattern recognition.
  • Page 13: Component List And Assembly Instructions

    CHAPTER COMPONENT LIST AND ASSEMBLY INSTRUCTIONS Before assembling the PiCar-X, please first verify that all parts and components have been included. If there are any missing or damaged components, please contact SunFounder immediately at cs@sunfounder.com to resolve the issue as soon as possible.
  • Page 14 SunFounder picar-x Chapter 2. Component List and Assembly Instructions...
  • Page 15: About Robot Hat

    CHAPTER THREE ABOUT ROBOT HAT Left/Right Motor Port • 2-channel XH2.54 motor ports. • The left port is connected to GPIO 4 and the right port is connected to GPIO 5. I2C Pin...
  • Page 16 SunFounder picar-x • 2-channel I2C pins from Raspberry Pi. PWM Pin • 12-channel PWM pins, P0-P12. ADC Pin • 4-channel ADC pins, A0-A3. Digital Pin • 4-channel digital pins, D0-D3. Battery Indicator • Two LEDs light up when the voltage is higher than 7.8V.
  • Page 17: Play With Python

    CHAPTER FOUR PLAY WITH PYTHON For novices and beginners wishing to program in Python, some basic Python programming skills and knowledge of the Raspberry Pi OS are needed. To start configuring the Raspberry Pi, please reference Quick Guide on Python: 4.1 Quick Guide on Python This section is to teach you how to install Raspberry Pi OS, configure wifi...
  • Page 18 SunFounder picar-x 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 19: Installing The Os

    SunFounder picar-x 4.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 20 SunFounder picar-x 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 21 SunFounder picar-x 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 22 SunFounder picar-x 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 23 SunFounder picar-x Step 7 Click the WRITE button. 4.1. Quick Guide on Python...
  • Page 24 SunFounder picar-x 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 25 SunFounder picar-x Step 9 After waiting for a period of time, the following window will appear to represent the completion of writing. 4.1. Quick Guide on Python...
  • Page 26: Set Up Your Raspberry Pi

    SunFounder picar-x 4.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 27 SunFounder picar-x 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 28 SunFounder picar-x • 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 29 SunFounder picar-x 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 30 SunFounder picar-x 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 31 SunFounder picar-x 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 32 SunFounder picar-x 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 4. Play with Python...
  • Page 33 SunFounder picar-x 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 34 SunFounder picar-x 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 35 SunFounder picar-x 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 36 SunFounder picar-x 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 37 SunFounder picar-x 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 38 SunFounder picar-x 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 4. Play with Python...
  • Page 39 SunFounder picar-x Windows Users Login Raspberry Pi Remotely If you are using win10, you can use follow way to login Raspberry Pi remotely. 1. Type powershell in the search box of your Windows desktop, right click on the Windows PowerShell, and select Run as administrator from the menu that appears.
  • Page 40 SunFounder picar-x Warning: If a prompt appears The term 'ssh' is not recognized as the name of a cmdlet..It means your system is too old and does not have ssh tools pre-installed, you need to manually Install OpenSSH via Powershell.
  • Page 41 SunFounder picar-x 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 42 SunFounder picar-x 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 43 SunFounder picar-x 4. Now you can see the desktop of the Raspberry Pi. 4.1. Quick Guide on Python...
  • Page 44 SunFounder picar-x 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 As shown above, you can see the Raspberry Pi’s IP address after it has been connected to the network.
  • Page 45: Install All The Modules

    SunFounder picar-x ssh pi@raspberrypi.local Note: If a prompt appears The term 'ssh' is not recognized as the name of a cmdlet..It means your system is too old and does not have ssh tools pre-installed, you need to manually Install OpenSSH via Powershell.
  • Page 46 You may need to download again at this point. See the following interface, type Y and press Enter. Then download and install the vilib module. /home/pi/ git clone https://github.com/sunfounder/vilib.git cd vilib sudo python3 install.py Download and install the picar-x module. /home/pi/ git clone -b v2.0 https://github.com/sunfounder/picar-x.git cd picar-x sudo python3 setup.py install...
  • Page 47 SunFounder picar-x Type y and press enter to continue running the script. Type y and press enter to run /dev/zero in the background. 4.1. Quick Guide on Python...
  • Page 48: Enable I2C And Camera Interface

    SunFounder picar-x Type y and press enter to restart the Picar-X. Note: If there is no sound after restarting, you may need to run the i2samp.sh script several times. 4.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 49 SunFounder picar-x 3. Then P5 I2C. 4. Use the arrow keys on the keyboard to select <Yes> -> <OK> to complete the setup of the I2C. 4.1. Quick Guide on Python...
  • Page 50 SunFounder picar-x 5. Go to 3 Interfacing Options again and select P1 Camera. 6. Again select <Yes> -> <OK> to complete the setup. Chapter 4. Play with Python...
  • Page 51 SunFounder picar-x 7. After you select <Finish>, a pop-up will remind you that you need to reboot for the settings to take effect, select <Yes>. 4.1. Quick Guide on Python...
  • Page 52: Servo Adjust

    It is recommended that you Calibrating the PiCar-X after assembling it. The servo angle will be tilted due to possible deviations during assembly or limitations of the servo itself, so you can get the servo to a perfect state by calibrating it, usually the calibration angle is -5~5°.
  • Page 53 SunFounder picar-x 3. Now, run servo_zeroing.py in the example/ folder. cd /home/pi/picar-x/example sudo python3 servo_zeroing.py 4. Next, plug the servo cable into the P11 port as follows. 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.
  • Page 54: Calibrating The Picar-X

    After the PiCar-X assembly is completed, try running the projects below: 4.2 Calibrating the PiCar-X Some servo angles may be slightly tilted due to possible deviations during PiCar-X installation or limitations of the servos themselves, so you can calibrate them.
  • Page 55 6. Press the number key 3 to select the tilt servo, then press the W/S key to make the pan/tilt platform look straight ahead and not tilt up and down. 4.2. Calibrating the PiCar-X...
  • Page 56 SunFounder picar-x 7. Since the wiring of the motors may be reversed during installation, you can press E to test whether the car can move forward normally. If not, use the number keys 4 and 5 to select the left and right motors, then press the Q key to calibrate the rotation direction.
  • Page 57: Let Picar-X Move

    /home/pi/picar-x/example sudo python3 move.py After running the code, PiCar-X will move forward, turn in an S-shape, stop and shake its head. Code Note: You can Modify/Reset/Copy/Run/Stop the code below. But before that, you need to go to source code path like picar-x/example.
  • Page 58 The basic functionality of Parker is in the picarx module, Can be used to control steering gear and wheels, and will make the PiCar-X move forward, turn in an S-shape, or shake its head. Now, the libraries to support the basic functionality of PiCar-X are imported. These lines will appear in all the examples that involve PiCar-X movement.
  • Page 59: Obstacle Avoidance

    SunFounder picar-x 4.4 Obstacle Avoidance In this project, PiCar-X will detect obstacles in front of it while moving forward, and when the obstacles are too close, it will change the direction of moving forward. Run the Code cd /home/pi/picar-x/example sudo python3 avoiding_obstacles.py After running the code, PiCar-X will walk forward.
  • Page 60 If there is no obstacle in the direction after turning left or the obstacle distance is greater than 25cm, 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 picar-x/example. After modifying the code, you can run it directly to see the effect. from picarx import...
  • Page 61: Line Tracking

    This project will use the Grayscale module to make the PiCar-X move forward along a line. Use dark-colored tape to make a line as straight as possible, and not too curved. Some experimenting might be needed if the PiCar-X is derailed.
  • Page 62: Text To Speech

    Before using the Text-to-Speech (TTS) functions, first activate the speaker so that it will be enabled and can make sounds. Run i2samp.sh in the picar-x folder, and this script will install everything needed to use i2s amplifier. cd /home/pi/picar-x sudo bash i2samp.sh...
  • Page 63 Run the Code cd /home/pi/picar-x/example sudo python3 tts_example.py After running the code, PiCar-X will say “Hello”, “Hi”, “Good bye”, “Nice to meet you”. Code Note: You can Modify/Reset/Copy/Run/Stop the code below. But before that, you need to go to source code path like picar-x/example.
  • Page 64: Computer Vision

    • This project requires access to the Raspberry Pi desktop to view the footage taken by the camera module. • You can connect a screen to the PiCar-X or refer to the tutorial remote_desktop to access it with VNC or XRDP.
  • Page 65 SunFounder picar-x (continued from previous page) frame.array cv2.imshow("video", img) # OpenCV image show rawCapture.truncate(0) # Release cache cv2.waitKey(1) & 0xFF break print('quit ...') cv2.destroyAllWindows() camera.close() How it works? Photos are obtained with PiCamera. This package provides a pure Python interface to the Raspberry Pi camera.
  • Page 66 SunFounder picar-x (continued from previous page) import numpy # Create the in-memory stream stream io.BytesIO() with picamera.PiCamera() camera: camera.start_preview() time.sleep(2) camera.capture(stream, format='jpeg') # Construct a numpy array from the stream data np.fromstring(stream.getvalue(), dtype=np.uint8) # "Decode" the image from the array, preserving colour image cv2.imdecode(data, 1)
  • Page 67: Color Detection

    • This project requires access to the Raspberry Pi desktop to view the footage taken by the camera module. • You can connect a screen to the PiCar-X or refer to the tutorial remote_desktop to access it with VNC or XRDP.
  • Page 68 Python editor. cd /home/pi/picar-x/example sudo python3 color_detect.py When the code is run, if PiCar-X captures a red object, it will frame it out. You can also change the 'red' in the code to another color for detection. Code...
  • Page 69 SunFounder picar-x (continued from previous page) cv2.cvtColor(resize_img, cv2.COLOR_BGR2HSV) # Convert from BGR to HSV color_type color_name mask cv2.inRange(hsv,np.array([min(color_dict[color_type]), 60, 60]), array([max(color_dict[color_type]), 255, 255]) ) # inRange()Make the ones between lower/upper white, and the rest black color_type 'red': mask_2 cv2.inRange(hsv, (color_dict['red_2'][0],0,0),...
  • Page 70 SunFounder picar-x (continued from previous page) frame.array img,img_2,img_3 color_detect(img,'red') # Color detection function cv2.imshow("video", img) # OpenCV image show cv2.imshow("mask", img_2) # OpenCV image show cv2.imshow("morphologyEx_img", img_3) # OpenCV image show rawCapture.truncate(0) # Release cache cv2.waitKey(1) & 0xFF # 27 is the ESC key, which means that if you press the ESC key to exit...
  • Page 71 SunFounder picar-x (continued from previous page) # Find the contour in morphologyEx_img, and the contours are arranged according to the area from small to large. _tuple cv2.findContours(morphologyEx_img,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_ SIMPLE) # compatible with opencv3.x and openc4.x len(_tuple) _, contours, hierarchy _tuple else:...
  • Page 72: Face Detection

    • This project requires access to the Raspberry Pi desktop to view the footage taken by the camera module. • You can connect a screen to the PiCar-X or refer to the tutorial remote_desktop to access it with VNC or XRDP.
  • Page 73 How it works? In the same path as this project (picar-x/example/) , put a file haarcascade_frontalhuman face_default.xml. This file is a face detection model file trained in OpenCV. This file is called by Cascade Classifier of OpenCV. 4.9. Face Detection...
  • Page 74 SunFounder picar-x face_cascade cv2.CascadeClassifier('haarcascade_frontalface_default.xml') Object Detection using Haar feature-based cascade classifiers is an effective object detection method proposed by Paul Viola and Michael Jones in their paper, “Rapid Object Detection using a Boosted Cascade of Simple Features” in 2001. This is a machine learning based approach, where a cascade function is trained from a large quantity of positive and negative images, and then used to detect objects in other images.
  • Page 75: Video Car

    • This project requires access to the Raspberry Pi desktop to view the footage taken by the camera module. • You can connect a screen to the PiCar-X or refer to the tutorial remote_desktop to access it with VNC or XRDP.
  • Page 76 SunFounder picar-x # #!/usr/bin/env python3 print('Please run under desktop environment (eg: vnc) to display the image window') reset_mcu from utils import reset_mcu() from picarx import Picarx Vilib from vilib import from time import sleep, time, strftime, localtime import readchar manual...
  • Page 77 SunFounder picar-x (continued from previous page) status 'stop' Vilib.camera_start(vflip=False,hflip=False) Vilib.display(local=True,web=True) sleep(2) # wait for startup print(manual) while True: print("\rstatus: , speed: "%(status, speed), end='', flush=True) # readkey readchar.readkey().lower() # operation ('wsadfop'): # throttle 'o': speed <=90: speed elif 'p': speed >=10:...
  • Page 78: Controlled By The App

    In addition, this application provides a live video streaming service. Let’s customize a PiCar-X controller using this app. How to do? 1. Install the sunfounder-controller module. The robot-hat, vilib, and picar-x modules need to be installed first, for details see: Install All the Modules.
  • Page 79 SunFounder picar-x Give it a name and select the Controller type. There are preset controllers for some products in the Preset section, which you can use as needed. You can also customize your own controller by following the steps below.
  • Page 80 SunFounder picar-x 5. Add different widgets to this controller. You can add different types and shapes of widgets to the A-Q 17 small areas inside this controller. Chapter 4. Play with Python...
  • Page 81 SunFounder picar-x In the A area, add an Speedometer widget to display the car’s speed. Note: You can delete the widget you have selected by clicking on it, swiping left to find the Delete button, and clicking on it. Set the name, maximum and minimum values and units by clicking the Settings icon in the upper right corner.
  • Page 82 SunFounder picar-x Set your current environment’s Line_Ref and Cliff_Ref for the Grayscale Detection widget in the D area. Lastly, add the remaining widgets and click the top right button to save. Chapter 4. Play with Python...
  • Page 83 SunFounder picar-x 6. Connect to PiCar-x. When you click the Connect button, it will automatically search for robots nearby. Its name is defined in picarx_control.py and it must be running at all times. 4.11. Controlled by the APP...
  • Page 84 SunFounder picar-x Once you click on the product name, the message “Connected Successfully” will appear and the product name will appear in the upper right corner. Chapter 4. Play with Python...
  • Page 85 SunFounder picar-x Note: • You need to make sure that your mobile device is connected to the same LAN as PiCar-X. • If it doesn’t search automatically, you can also manually enter the IP to connect. 7. Run this controller.
  • Page 86 SunFounder picar-x • I: turn on the line following function. • J: voice recognition, press and hold this widget to start speaking, and it will show the recognized voice when you release it. We have set forward, backard, left and right 4 commands in the code to control the car.
  • Page 87: Play With Ezblock

    It is recommended that you follow the intructions on the APP to calibrate the picar-x after assembling it. The servo angle will be tilted due to possible deviations during assembly or limitations of the servo itself, so you can get the servo to a perfect state by calibrating it, usually the calibration angle is -5~5°.
  • Page 88 SunFounder picar-x 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 89: Install And Configure Ezblock Studio

    Examples: View or run the related example directly. Note: After you connect the Picar-x, there will be a calibration step. This is because of possible deviations in the installation process or limitations of the servos themselves, making some servo angles slightly tilted, so you can...
  • Page 90: Calibrate The Car

    5.2 Calibrate the Car After you connect the PiCar-X, there will be a calibration step. This is because of possible deviations in the installation process or limitations of the servos themselves, making some servo angles slightly tilted, so you can calibrate them in this step.
  • Page 91 SunFounder picar-x 3. 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. The calibration steps are as follows:...
  • Page 92 2. Click on the left prompt point to calibrate the PiCar-X’s Pan-Tilt(the camera part). By using the two sets of buttons on the right, you can slowly adjust the Pan-Tilt’s orientation, as well as view their angles. When the adjustment is complete, click on Confirm.
  • Page 93 SunFounder picar-x 3. To calibrate the front wheel orientation, click on the right prompt point. Use the two buttons on the right to get the front wheel facing straight ahead. When the adjustment is done, click on Confirm. Projects 5.2. Calibrate the Car...
  • Page 94: Move

    Basic 5.3 Move This first project teaches how to program movement actions for the PiCar-X. In this project, the program will tell the PiCar-X to execute five actions in order: “forward”, “backward”, “turn left”, “turn right”, and “stop”. To learn the basic usage of Ezblock Studio, please read through the following two sections: •...
  • Page 95 SunFounder picar-x TIPS This block will make the PiCar-X move forward at a speed based on a percentage of available power. In the example below “50” is 50% of power, or half-speed. This block will make the PiCar-X move backward at a speed based on a percentage of available power.
  • Page 96 SunFounder picar-x This block will cause a timed break between commands, based on milliseconds. In the example below, the PiCar-X will wait for 1 second (1000 milliseconds) before executing the next command. This block will bring the PiCar-X to a complete stop.
  • Page 97 SunFounder picar-x 5.3. Move...
  • Page 98: Remote Control

    SunFounder picar-x 5.4 Remote Control This project will teach how to remotely control the PiCar-X with the Joystick widget. Note: After dragging and dropping the Joystick widget from the Remote Control page, use the “Map” function to calibrate the Joysticks X-axis and Y-axis readings.
  • Page 99 SunFounder picar-x to “100”. Toggling the white point and dragging it directly to the far left of the Joystick will result in an X value of “-100” and a Y value of “0”. After dragging and dropping a widget on the remote control page, a new category-Remote with the above block will appear.
  • Page 100: Test Ultrasonic Module

    5.5 Test Ultrasonic Module PiCar-X has a built-in Ultrasonic Sensor module that can be used for obstacle avoidance and automatic object- following experiments. In this lesson the module will read a distance in centimeters (24 cm = 1 inch), and Print the results in a Debug window.
  • Page 101 SunFounder picar-x This program is simplified with a Variable. For example, when there are multiple functions in a program that each need to use the distance to an obstacle, a Variable can be used to report the same distance value to each function, instead of each function reading the same value separately.
  • Page 102: Test Grayscale Module

    Use the Grayscale module block to read the value of one of the sensors. In the example above, the “A0” sensor is the sensor on the far left of the PiCar-X. Use the drop-down arrow to change the sensor to “A1” (center sensor), or “A2”...
  • Page 103: Color Detection

    SunFounder picar-x 5.7 Color Detection PiCar-X is a self-driving car with a built-in camera, which allows Ezblock programs to utilize object detection and color recognition code. In this section, Ezblock will be used to create a program for color detection.
  • Page 104 SunFounder picar-x Note: The printed colors may have a slightly different hue from the Ezblock color models due to printer toner differences, or the printed medium, such as a tan-colored paper. This can cause a less accurate color recognition. Chapter 5. Play with Ezblock...
  • Page 105 SunFounder picar-x TIPS Drag the Video widget from the remote Control page, and it will generate a video monitor. For more information on how to use the Video widget, please reference the tutorial on Ezblock video here: How to Use the Video Function?.
  • Page 106: Face Detection

    5.8 Face Detection In addition to color detection, PiCar-X also includes a face detection function. In the following example the Joystick widget is used to adjust the direction of the camera, and the number of faces will be displayed in the debug monitor.
  • Page 107 SunFounder picar-x TIPS Set the face detection widget to on to enable facial detection. These two blocks are used to adjust the orientation of the pan-tilt camera, similar to driving the PiCar-X in the Remote Control tutorial. As the value increases, the camera will rotate to the right, or upwards, a decreasing value will rotate the camera right, or downwards.
  • Page 108 SunFounder picar-x The image detection results are given through the of detected face block. Use the drop-down menu options to choose between reading the coordinates, size, or number of results from the image detection function. Use the create text with block to print the combination of text and of detected face data.
  • Page 109: Sound Effect

    PiCar-X has a built-in speaker that can be used for audio experiments. Ezblock allows users to enter text to make the PiCar-X speak, or make specific sound effects. In this tutorial, the PiCar-X will make the sound of a gun firing after a 3-second countdown, using a do/while function.
  • Page 110 SunFounder picar-x Use the say block with a text block to write a sentence for the PiCar-X to say. The say block can be used with text or numbers. The number block. Using the repeat block will repeatedly execute the same statement, which reduces the size of the code.
  • Page 111: Background Music

    SunFounder picar-x 5.10 Background Music In addition to programming the PiCar-X to play sound effects or text-to-speech (TTS), the PiCar-X will also play background music. This project will also use a Slider widget for adjusting the music volume. • How to Use the Remote Control Function?
  • Page 112: Say Hello

    5.11 Say Hello This project will combine several functions from the preceding projects. The PiCar-X movement will be remotely con- trolled, and the PiCar’s camera will be remotely controlled by using two joystick controllers. When PiCar recognizes someone’s face, it will nod politely and then say “Hello!”.
  • Page 113 SunFounder picar-x TIPS The if do block is used to nod politely once the conditional judgment of “if” is true. The conditional statements block is used in conjunction with the if do block. The conditions can be “=”, “>”, “<”, ”...
  • Page 114 SunFounder picar-x Chapter 5. Play with Ezblock...
  • Page 115: Music Car

    SunFounder picar-x 5.12 Music Car This project will turn the PiCar-X into a music car that will travel around your home, playing cheerful music. This project will also show how the PiCar-X avoids hitting walls with the built-in ultrasonic sensor.
  • Page 116: Cliff Detection

    SunFounder picar-x 5.13 Cliff Detection This project will use the grayscale module to prevent the PiCar-X from falling off a cliff while it is moving freely around your home. This is an essential project for houses with staircases. TIPS The grayscale module will be performing the same operation multiple times. To simplify the program, this project introduces a function that will return a list variable to the do forever block.
  • Page 117 SunFounder picar-x 5.13. Cliff Detection...
  • Page 118: Minecart

    If the minecart reaches the end of the track or derails, the Grayscale module will no longer detect the dark-colored tape track, and the PiCar-X will come to a stop.
  • Page 119 SunFounder picar-x black surfaces, and fill in their middle values in this block. EXAMPLE 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 120 SunFounder picar-x Chapter 5. Play with Ezblock...
  • Page 121: Minecart Plus

    SunFounder picar-x 5.15 Minecart Plus In this project, derailment recovery has been added to the Minecart project to let the PiCar-X adapt and recover from a more severe curve. 5.15. Minecart Plus...
  • Page 122 TIPS 1. Use another to do something block to allow the PiCar-X to back up and recover from a sharp curve. Note that the new to do something function does not return any values, but is used just for reorienting the PiCar-X.
  • Page 123 SunFounder picar-x 5.15. Minecart Plus...
  • Page 124 SunFounder picar-x Chapter 5. Play with Ezblock...
  • Page 125 SunFounder picar-x 5.15. Minecart Plus...
  • Page 126: Bullfight

    SunFounder picar-x 5.16 Bullfight Turn PiCar-X into an angry bull! Prepare a red cloth, such as a handkerchief, and become a Bullfighter. When the PiCar-X chases after the red cloth, be careful not to get hit! Note: This project is more advanced than the preceding projects. The PiCar-X will need to use the color detection function to keep the camera facing towards the red cloth, then the body orientation will need to automatically adjust in response to the direction that the camera is facing.
  • Page 127 SunFounder picar-x The “object detection” will output the detected coordinates in (x, y) values, based on the center point of the camera image. The screen is divided into a 3x3 grid, as shown below, so if the red cloth is kept in the top left of the cameras’...
  • Page 128: Beware Of Pedestrians

    X will come to a complete stop if a pedestrian is detected in its path. Once the program is running, hold a photo of a person in front of the PiCar-X. The Video Monitor will detect the person’s face, and the PiCar-X will automatically come to a stop.
  • Page 129 SunFounder picar-x EXAMPLE 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 130: Traffic Sign Detection

    In addition to color, face detection, PiCar-X can also do traffic sign detection. Now let’s combine this traffic sign detection with the line following function. Let PiCar-X track the line, and when you put the Stop sign in front of it, it will stop. When you place a Forward sign in front of it, it will continue to move forward.
  • Page 131 SunFounder picar-x • [PDF]Traffic Sign Cards 2. Set ref to () block is used to set the grayscale threshold, you need to modify it according to the actual situation. You can go ahead and run to see the values of the grayscale module on the white and Test Grayscale Module black surfaces, and fill in their middle values in this block.
  • Page 132 SunFounder picar-x Chapter 5. Play with Ezblock...
  • Page 133 SunFounder picar-x 5.18. Traffic Sign Detection...
  • Page 134: Orienteering

    This project uses the remote control function to guide the PiCar-X through a competitive scavenger hunt! First, set up either an obstacle course, or a maze, or even an empty room that the PiCar-X can drive through. Then, randomly place six markers along the route, and put a color-card at each of the six markers for the PiCar-X to find.
  • Page 135 This can cause a less accurate color recognition. The PiCar-X will be programmed to find three of the six colors in a random order, and will be using the TTS function to announce which color to look for next.
  • Page 136 SunFounder picar-x Take turns playing this game with friends to see who can help PiCar-X complete the objective the fastest! EXAMPLE Note: • You can write the program according to the following picture, please refer to the tutorial: How to Create a New Project?.
  • Page 137 SunFounder picar-x 5.19. Orienteering...
  • Page 138 SunFounder picar-x Chapter 5. Play with Ezblock...
  • Page 139 SunFounder picar-x 5.19. Orienteering...
  • Page 140 SunFounder picar-x Chapter 5. Play with Ezblock...
  • Page 141: Appendix

    CHAPTER APPENDIX 6.1 PuTTY If you are a Windows user, you can use some applications of SSH. Here, we recommend PuTTY. Step 1 Download PuTTY. Step 2 Open PuTTY and click Session on the left tree-alike structure. Enter the IP address of the RPi in the text box under Host Name (or IP address) and 22 under Port (by default it is 22).
  • Page 142 SunFounder picar-x Step 3 Click Open. Note that when you first log in to the Raspberry Pi with the IP address, there prompts a security reminder. Just click Yes. Step 4 When the PuTTY window prompts “login as:”, type in “pi” (the user name of the RPi), and password: “raspberry”...
  • Page 143: Install Openssh Via Powershell

    SunFounder picar-x Step 5 Here, we get the Raspberry Pi connected and it is time to conduct the next steps. 6.2 Install OpenSSH via Powershell When you use ssh <username>@<hostname>.local (or ssh <username>@<IP address>) to connect to your Raspberry Pi, but the following error message appears.
  • Page 144: About The Battery

    SunFounder picar-x Get-WindowsCapability -Online Where-Object Name -like 'OpenSSH * ' 5. It now tells you that OpenSSH.Client has been successfully installed. Name OpenSSH.Client~~~~0.0.1.0 State : Installed Name OpenSSH.Server~~~~0.0.1.0 State : NotPresent Warning: If the above prompt does not appear, it means that your Windows system is still too old, and you are advised to install a third-party SSH tool, like PuTTY.
  • Page 145 SunFounder picar-x • When the two power indicators on the Robot HAT are off, it means the power is too low and the batteries need to be charged. Button Top vs Flat Top? Please choose battery with button top to ensure a good connection between the battery and the battery holder.
  • Page 146 SunFounder picar-x Chapter 6. Appendix...
  • Page 147: Faq

    CHAPTER SEVEN Q1: After installing Ezblock OS, the servo can’t turn to 0°? 1) Check if the servo cable is properly connected and if the Robot HAT power is on. 2) Press Reset button. 3) If you have already run the program in Ezblock Studio, the custom program for P11 is no longer available. You can refer to the picture below to manually write a program in Ezblock Studio to set the servo angle to 0.
  • Page 148 SunFounder picar-x Chapter 7. FAQ...
  • Page 149: Thank You

    CHAPTER EIGHT THANK YOU Thanks to the evaluators who evaluated our products, the veterans who provided suggestions for the tutorial, and the users who have been following and supporting us. Your valuable suggestions to us are our motivation to provide better products! Particular Thanks •...
  • Page 150 SunFounder picar-x Chapter 8. Thank You...
  • Page 151: Japanese On-Line Tutorials

    CHAPTER NINE JAPANESE ON-LINE TUTORIALS •...
  • Page 152 SunFounder picar-x Chapter 9. Japanese On-line Tutorials...
  • Page 153: Copyright Notice

    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

Save PDF