0
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心
发布
  • 发文章

  • 发资料

  • 发帖

  • 提问

  • 发视频

创作活动
CN0256D

CN0256D

  • 厂商:

    SUNFOUNDER

  • 封装:

  • 描述:

    Raspberry Pi Raspberry Pi 4B Python 项目套件

  • 数据手册
  • 价格&库存
CN0256D 数据手册
SunFounder PiCar-V www.sunfounder.com Dec 06, 2022 CONTENTS 1 2 About the PiCar-V 1.1 Components List . . . . . . . 1.2 Introduction . . . . . . . . . 1.3 Building the Car . . . . . . . 1.4 Circuits Building . . . . . . . 1.5 Get Started with Raspberry Pi 1.6 Servo Configuration . . . . . 1.7 Continue to Assemble . . . . 1.8 Getting on the Road! . . . . . 1.9 Appendix . . . . . . . . . . . 1.10 Thank You . . . . . . . . . . Copyright Notice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 10 11 23 27 36 38 44 58 64 65 i ii CHAPTER ONE ABOUT THE PICAR-V The car PiCar-V is equipped with a wide-angle USB webcam, three whole new circuit boards with less but more simple wiring, some acrylic plates with an adjusted structure, and new code suitable for almost all platforms to control the car. In this book, we will show you how to build the PiCar-V via description, illustrations of physical components, in both hardware and software respects. You will enjoy learning how all this work. You can view the latest PDF user manual or clone the code by click the link: https://github.com/sunfounder/SunFounder_PiCar-V/tree/V3.0. You are welcomed to post requests and issues on our page on Github. If you want to learn another projects which we don’t have, please feel free to send Email and we will update to our online tutorials as soon as possible, any suggestions are welcomed. Here is the Email: cs@sunfounder.com. 1 SunFounder PiCar-V 1.1 Components List 1.1.1 Plates 1. Upper Plate x 1 2. Front Half Plate x 1 3. Back Half Plate x 1 4. Pan-and-tilt Plate x 1 5. Pan-and-tilt Base Plate x 1 6. Camera Mount Plate x 1 7. Steering Connector Plate x 2 8. Bearing Shield x 8 9. Steering Linkage Plate x 1 10. Hex Front Wheel Fixing Plate x 8 2 Chapter 1. About the PiCar-V SunFounder PiCar-V 11. Gasket Plate x 2 Note: The Bearing Shield is similar to the Gasket Plate, but the aperture of Gasket Plate is large than the Bearing Shield. 1.1.2 Servo x 3 1. Servo 2. 1-arm Rocker Arm 3. arm Rocker Arm 4. 4-arm Rocker Arm 5. Rocker Arm Fixing Screw 6. Rocker Arm Screw 1.1. Components List 3 SunFounder PiCar-V 1.1.3 Mechanical Fasteners 4 Chapter 1. About the PiCar-V SunFounder PiCar-V 1.1. Components List 5 SunFounder PiCar-V 1.1.4 Wires 1.1.5 PCB 6 Chapter 1. About the PiCar-V SunFounder PiCar-V 1.1.6 Other Components 1.1. Components List 7 SunFounder PiCar-V 8 Chapter 1. About the PiCar-V SunFounder PiCar-V 1.1.7 Tools 1.1.8 Self-provided Components The following components are not included in this kit. Note: 1. You are recommend to use 18650 batteries without a protective board. Otherwise, the car may be cut power and stop running because of the overcurrent protection of the protective board. 2. For unprotected batteries, please purchase those with the anode bulged out (as shown below), so that it can ensure the well connection with the battery holder. 1.1. Components List 9 SunFounder PiCar-V 3. In order to keep the car working for a long time, use large-capacity batteries as much as possible 1.2 Introduction The PiCar-V is developed based on the previous Smart Video Car Kit. It’s equipped with the new PCA9685 PWM driver, smaller and better-performing DC motor driver module, a Robot Hat with power and interface integrated, a wider-angle camera with clearer vision, some better wheels and tires, and so on. Later we’ll check more details. The basic functions of this new version still stay the same, including controlling the PiCar-V remotely and streaming the video data it captures back. Then what’s new? Let’s unveil the mysteries! 10 Chapter 1. About the PiCar-V SunFounder PiCar-V 1.3 Building the Car Are you excited when you open the box and see so many components? Keep your patience and take it easy. Please note that some details in the following steps need careful observation. You should double-check your work based on the figures in the manual after finishing each step. let’s start! 1.3. Building the Car 11 SunFounder PiCar-V 1.3.1 Front Wheels Insert an M4x25 screw through a Steering Connector Plate, 3 Bearing Shields, 3 Hex Front Wheel Fixing Plates, and a front wheel, into an M4 Self-locking Nut as shown below: You can use the Cross Socket Wrench to secure the M4 Self-locking Nut, then use the screwdriver to tighten the M4x25 screw. Note: The Self-locking Nut should be screwed tight enough. It would be better to tighten the screw until the wheel and Steering Connector cannot move first, then loosen the screw a little, so that the Steering Plate can just move. Thus, the wheel can turn flexibly when the connection would not be too loose. Assemble the other front wheel in the same way, but bear in mind the Steering Connector plate on the wheel should be symmetric with the previous one. Now two front wheels have finished assembly. 12 Chapter 1. About the PiCar-V SunFounder PiCar-V 1.3.2 Pan-and-Tilt Take out the Cross rocker arm and mount it onto the Pan-and-tilt Base Plate with 2 M1.5x4 screws (into the hole like this). Pay attention to the holes on the round rocker arm to be fastened. Do the same operation to the Camera Mount Plate. Assemble the two servos to the Pan-and-tilt Plate with four M2x8 screws and the M2 nuts (The 2 servo shaft are close to the left side ): 1.3. Building the Car 13 SunFounder PiCar-V 1.3.3 Steering Part Connect the Steering Linkage and the 1-arm Rocker Arm with the M1.5x4 Self-tapping Screw. Note: Insert it into the FIRST hole of the arm (as indicated by the arrow below) which is the farthest from the gears. 14 Chapter 1. About the PiCar-V SunFounder PiCar-V And also fasten them as tightly as possible, and then loosen the screw a little so the Steering Linkage can move flexibly. 1.3.4 Upper Plate Mount the M2.5x8 copper standoffs and M2.5 nuts into the upper plate first. Pay attention that the side the protruding prop should face up. 1.3. Building the Car 15 SunFounder PiCar-V 1.3.5 Battery Holder Turn the Upper Plate upside down. Cut the ribbon into two halves. Thread them through the holes on the plate. Pay attention to the direction and leave one end longer out of the plate for each to remove the battery easily later. 16 Chapter 1. About the PiCar-V SunFounder PiCar-V Fasten the battery holder with two M3x8 countersunk screws and M3 nuts. Pay attention to the direction of battery holder’s wire. 1.3.6 Rear Wheels (Screws) Insert 4 M3x8 screws with four M3x25 copper standoffs: 1.3. Building the Car 17 SunFounder PiCar-V 1.3.7 PCB Assembly 1) Assemble the Raspberry Pi (TF Card inserted) with 8 M2.5x8 single pass copper standoffs, then plug the Robot HATS onto it. 2) Fix the Robot HATS with 4 M2.5x6 screws. 3) Fix The PCA9685 PWM Driver and the Motor Driver with 8 M2.5x12 screws and M2.5 nuts into the down plate 18 Chapter 1. About the PiCar-V SunFounder PiCar-V 1.3.8 Fixing Rear Wheels Assemble the two motors with four M3x25 screws and M3 nuts. Pay attention to place the motors with wires inward, providing convenience for connecting the circuit. 1.3. Building the Car 19 SunFounder PiCar-V Assemble the rear wheels with 4 M3 nuts. 20 Chapter 1. About the PiCar-V SunFounder PiCar-V Align the rear wheels with the motor shaft, and rotate to insert them gently. 1.3. Building the Car 21 SunFounder PiCar-V 22 Chapter 1. About the PiCar-V SunFounder PiCar-V 1.4 Circuits Building 1.4.1 Connect the Power 1.4. Circuits Building 23 SunFounder PiCar-V 1.4.2 Connect the Modules 24 Chapter 1. About the PiCar-V SunFounder PiCar-V 1.4.3 Connect the Servos 1.4. Circuits Building 25 SunFounder PiCar-V 1.4.4 Connect the Motor The complete connection is shown as follows. 26 Chapter 1. About the PiCar-V SunFounder PiCar-V 1.5 Get Started with Raspberry Pi In this chapter, we firstly learn to start up Raspberry Pi. The content includes installing the OS, Raspberry Pi network and how to open terminal. Note: 1. You can check the complete tutorial on the official website of the Raspberry Pi: https://projects.raspberrypi.org/ en/projects/raspberry-pi-setting-up 2. If your Raspberry Pi is set up, you can skip the part and go into the next chapter. 1.5. Get Started with Raspberry Pi 27 SunFounder PiCar-V 1.5.1 Installing the OS Required Components Any Raspberry Pi 1 * Micro SD card 1 * Personal Computer 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. Visit the download page: https://www.raspberrypi.org/software/. Click on the link for the Raspberry Pi Imager that matches your operating system, when the download finishes, click it to launch the installer. Step 2 When you launch the installer, your operating system may try to block you from running it. For example, on Windows I receive the following message: If this pops up, click on More info and then Run anyway, then follow the instructions to install the Raspberry Pi Imager. Step 3 Insert your SD card into the computer or laptop SD card slot. Step 4 In the Raspberry Pi Imager, select the OS that you want to install and the SD card you would like to install it on. 28 Chapter 1. About the PiCar-V SunFounder PiCar-V Note: 1) You will need to be connected to the internet the first time. 2) That OS will then be stored for future offline use(lastdownload.cache, C:/Users/yourname/AppData/Local/Raspberry Pi/Imager/cache, ). So the next time you open the software, it will have the display “Released: date, cached on your computer”. Step 5 Select the SD card you are using. Step 6 Press Ctrl+Shift+X to open the Advanced options page to enable SSH and configure wifi, these 2 items must be set, the others depend on your choice . You can choose to always use this image customization options. 1.5. Get Started with Raspberry Pi 29 SunFounder PiCar-V 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_assigned_code_elements 30 Chapter 1. About the PiCar-V SunFounder PiCar-V Step 7 Click the WRITE button. 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. 1.5. Get Started with Raspberry Pi 31 SunFounder PiCar-V Step 9 After waiting for a period of time, the following window will appear to represent the completion of writing. 32 Chapter 1. About the PiCar-V SunFounder PiCar-V Power on the Raspberry Pi Now, the Raspberry Pi OS is configured, you can plug out the USB card reader and then plug the Micro SD card into the Raspberry Pi. Put two 18650 fully charged batteries in the holder, plug the wires from the battery holder into the development board then toggle the switch from off to on. You are also recommended to use the power adapter of Raspberry Pi to power your car for that the first test will take a long time. Get the IP Address After the Raspberry Pi is powered on with a power adapter, we need to get the IP address of it. There are many ways to know the IP address, and two of them are listed as follows. 1. Checking via the router If you have permission to log in the router(such as a home network), you can check the addresses assigned to Raspberry Pi on the admin interface of router. The default hostname of the system, Raspberry Pi OS is raspberrypi, and you need to find it. (If you are using ArchLinuxARM system, please find alarmpi.) 2. Network Segment Scanning You can also use network scanning to look up the IP address of Raspberry Pi. You can apply the software, Advanced IP scanner(download from Google). Click Scan and the name of all connected devices will be displayed. Similarly, the default hostname of the Raspberry Pi OS is raspberrypi, now you need to find the hostname and its IP. Use the SSH Remote Control We can open the Bash Shell of Raspberry Pi by applying SSH. Bash is the standard default shell of Linux. The Shell itself is a program written in C that is the bridge linking the customers and Unix/Linux. Moreover, it can help to complete most of the work needed. • For Linux or/Mac OS X Users Step 1 Go to Applications->Utilities, find the Terminal, and open it. Step 2 1.5. Get Started with Raspberry Pi 33 SunFounder PiCar-V Type in ssh pi@ip_address . “pi” is your username and “ip_address” is your IP address. For example: ssh pi@192.168.18.197 Step 3 Input “yes”. Step 4 Input the password and the default password is raspberry. Step 5 We now get the Raspberry Pi connected and are ready to go to the next step. Note: When you input the password, the characters do not display on window accordingly, which is normal. What you need is to input the correct password. • For Windows Users 34 Chapter 1. About the PiCar-V SunFounder PiCar-V If you’re a Windows user, you can use SSH with the application of some software. Here, we recommend PuTTY(You can download from Google). Step 1 Download PuTTY. 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). Step 2 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 3 When the PuTTY window prompts “login as:”, type in pi (the user name of the RPi), and password: “raspberry” (the default one, if you haven’t changed it). 1.5. Get Started with Raspberry Pi 35 SunFounder PiCar-V Note: When you input the password, the characters do not display on window accordingly, which is normal. What you need is to input the correct password. Here, we get the Raspberry Pi connected and it is time to conduct the next steps. 1.6 Servo Configuration And since the servos used in this kit are adjusted by software and there’s no such physical sticking point as other servos, here we need to configure the servo via software. First you need to finish some software installation before the configuration. Note: Please do not forget to put in the battery and slide the power switch to ON in this chapter. 1.6.1 Get Source Code You can find the source code in our Github repositories. Download the source code by git clone: cd ~/ git clone https://github.com/sunfounder/SunFounder_PiCar-V -b V3.0 Note: Please pay attention to your typing – if you get the prompt of entering your user name and password, you may have typed wrong. If unluckily you did so, press Ctrl + C to exit and try again. Check by the ls command, then you can see the code directory SunFounder_PiCar-V: 36 Chapter 1. About the PiCar-V SunFounder PiCar-V 1.6.2 Go to the Code Directory cd ~/SunFounder_PiCar-V Enter the code directory and you can see the installation script: 1.6.3 Install the Environment via the Script You can get all the required software and configuration done with the install_dependencies script. If you want to do step by step instead, please follow the instructions in the Appendix 1: Function of the Server Installation Scripts. sudo ./install_dependencies Note: 1. The installation script will install the required components and configure for the running environment. Make sure your Raspberry is connected to the Internet during the installation, or it would fail. 2. The Raspberry Pi will prompt you to reboot after the installation. You’re recommended to type in yes to reboot. 1.6.4 Configure the Servo to 90 degrees After reboot, run the picar tool: cd ~/SunFounder_PiCar-V picar servo-install Note: If the “OSError: [Errno 121] Remote I/O error” error message appears, open raspi-config: sudo raspi-config Then choose 3 Interfacing Options → P5 I2C → →OK to enable I2C service. You can use the up, down, left, and right keys on the keyboard to select, and then press Enter to confirm. After the code is running, insert the rocker arm into the servo. You will see the rocker arm is rotate in clockwise and counterclockwise, then stop at a specific location. It means the servo is good. If the any of the conditions below happened to your servo, your servo is bad: 1) Noisy, hot. 2) If unplug the servo line and rotate the rocker arm, it sounds like “ka” “ka” “ka” or there has no sounds of gear driving. 3) Rotate slowly but continuously. 1.6. Servo Configuration 37 SunFounder PiCar-V If you find one of the conditions above, please send e-mail to service@sunfounder.com . We will change a new one to you. If it is broken in the process of using or assembling, you should go to the official website www.sunfounder.com to buy. 1.7 Continue to Assemble Warning: Please do forget to put in the battery and slide the power switch to ON, then keep servo-install running in the whole process of assembly. 1.7.1 Assemble the Steering Servo Mount the Steering Servo to the Upper Plate with two M2x8 Screws and M2 nuts (pay attention to the direction of the servo wires): 38 Chapter 1. About the PiCar-V SunFounder PiCar-V 1.7.2 Front Half Chassis The Rocker Arm is facing straight ahead, and then inserted into the Servo shaft, and then fixed with Rocker Arm Fixing Screw (the shortest). Mount the wheels onto the Upper Plate carefully. Assemble the Front Half Chassis with four M3x25 copper standoffs and M3 nuts. 1.7. Continue to Assemble 39 SunFounder PiCar-V Then put the assembled Front Half Chassis onto the Upper Plate with standoffs aligned with the holes. Hold them carefully, turn upside down, and fasten the standoffs and Upper Plate with four M3x8 screws. 40 Chapter 1. About the PiCar-V SunFounder PiCar-V Assemble the assembled Pan-and-tilt Plate, Gasket Plate and Camera Mount Plate with the Rocker Arm Fixing Screw in a fixed angle as shown below: Note: Do not rotate the servo by hands in case of breaking the servodown. 1.7. Continue to Assemble 41 SunFounder PiCar-V Similarly check that the servo shaft has spun to 90 degrees. Then assemble the Pan-and-tilt Base Plate with the Rocker Arm Fixing Screw and the Gasket Plate in the angle as shown below. Assemble the Pan-and-tilt Plate to the car with two M3x10 screws and the M3 nuts. 42 Chapter 1. About the PiCar-V SunFounder PiCar-V 1.7.3 Assemble the Camera Take out the camera and nip it to the Camera Mount. Connect its USB cable to the USB port on the Raspberry Pi. So now, the whole assembly is DONE! Congratulations! You can power off the car now! Don’t forget to charge your batteries. 1.7. Continue to Assemble 43 SunFounder PiCar-V 1.8 Getting on the Road! Make sure all the procedures have been finished, and check there is no problem about the mechanical assembly and software installation. 1.8.1 Remote Control Here is what we’re going to do: Use the Raspberry Pi as the server. Run a web server with an API for controlling the car and transmitting images captured by the camera. Then take a PC, cell phone, or tablet as the client, and acquire the images from the camera and control the car by calling the API of the web server. Now, you can power on the car again. You are also recommended to use the power adapter of Raspberry Pi to power your car for that the first test will take a long time. Run the Server(Operation on Raspberry Pi) Remotely log into the Raspberry Pi. Run the startup script start under the remote_control directory to start the web service. cd ~/SunFounder_PiCar-V/remote_control python3 manage.py migrate sudo ./start The script will enable the service and the corresponding data will appear. The hardware is initialized at the same time, so the servos connected to the front wheels and the pan-and-tilt will turn, indicating the hardware initialization is done. If you get the result similar as shown above, the server is ready. Now move on to start the client. Warning: Keep the server being running all the time until you stop to run the Client. 44 Chapter 1. About the PiCar-V SunFounder PiCar-V Run the Client(Operation on PC) Visit the server of the car at http://:8000/. You will see a welcome page: Click LET’S ROCK to go to the operation interface: On this page, you can press the keys W, A, S, and D on the keyboard to control the car to move forward, backward, turn left, and turn right, press the arrow keys to control the camera’s movement, and number 1~5 to change the speed level. Calibration 1.8. Getting on the Road! 45 SunFounder PiCar-V Click FULLSCREEN again to bring back the title bar. And then, tap the setting button at the top-right corner of the page to go to the calibration page: There are three calibration parts: Camera Calibration, Front Wheels Calibration and Rear Wheels Calibration. When you enter this page, the car will go forward; if not, click Left and Right in Rear Wheels Calibration to adjust the angle of the wheel. Note: Every time you press a button, the angle will be changed slightly. For your larger change per time, you need to long press the button. Click OK to save the result after all the calibration is done. For Mobile Phones Also for mobile phones, tap the FULLSCREEN button to have a better view and performance. Then, tap the buttons of 5 speed levels on the page to control the speed, and the arrow buttons to control the direction of the car and the pan-and-tilt. But you can only tab one touch point at one time. 46 Chapter 1. About the PiCar-V SunFounder PiCar-V Take this screenshot from an Android phone: Though the appearance may not be as good as on the PC. Later updates may be released irregularly on Github. You are welcome to fork our repository and submit a Pull request with your changes. If there is no problem after testing, we are more than pleased to merge your request. 1.8. Getting on the Road! 47 SunFounder PiCar-V 1.8.2 ball_tracker In addition to using the keyboard to control the status of the car, we also wrote a ball tracking code. Install OpenCV Before installing OpenCV, you need to install the dependencies first. Different operating systems require different dependent libraries. (If you don’t know your operating system version, you can try to install both.) • If your operating system is RASPBERRY PI BUSTER, you need to install the following dependencies. sudo apt-get install libatlas-base-dev libjasper-dev libqt4-test libwebp6 libtiff5 ˓→libopenexr23 libgstreamer1.0-0 libavcodec-dev libavformat-dev libswscale-dev ˓→libqtgui4 -y • If your operating system is RASPBERRY PI BULLSEYE, you need to install the following dependencies. sudo apt-get install libatlas-base-dev libjasper-dev libwebp6 libtiff5 libopenexr25 ˓→libgstreamer1.0-0 libavcodec-dev libavformat-dev libswscale-dev -y Next is to install OpenCV. sudo pip3 install opencv-python==3.4.6.27 Run the Code cd ~/SunFounder_PiCar-V/ball_track python3 ball_tracker.py After the code runs, find a red ball (at least larger than the diameter of the camera) and put it within 10-50cm range in front of the camera to get the car to follow your ball. If you want to know whether the car has catched your ball, you can do as follows: Step 1: Enable the VNC on the Raspberry Pi. sudo raspi-config Choose 3 Interfacing Options by press the down arrow key on your keyboard, then press the Enter key.. 48 Chapter 1. About the PiCar-V SunFounder PiCar-V P3 VNC Press the left arrow key on your keyboard to choose Yes. 1.8. Getting on the Road! 49 SunFounder PiCar-V Finally select OK->Finish to exit the config. Step 2: Download the VNC Viewer for your computer and install it. https://www.realvnc.com/en/connect/download/viewer/ Note: During your installation on your Windows, if you encounter the following prompt, please click Continue to continue your installation. Step 3: Open VNC Viewer you have installed, type in your Raspberry Pi IP address, and press the Enter button. 50 Chapter 1. About the PiCar-V SunFounder PiCar-V Step 4: Enter the username and password of your Raspberry Pi on this page, by default, they are pi and raspberry; then click OK. When you log in with VNC Viewer, the screen may be black.If your screen is working, skip to Step 5. Changing the resolution to the highest on the Raspberry Pi. 1.8. Getting on the Road! 51 SunFounder PiCar-V sudo raspi-config Choose 2 Display Options. Choose D1 Resolution. Change the default to a higher resolution like Mode 16, then click OK. Reboot the Raspberry Pi, log in again, and it will work. sudo reboot Step 5: Now, we enter the Raspberry Pi desktop, click Terminal and type the following commands to open the code ball_tracker.py. 52 Chapter 1. About the PiCar-V SunFounder PiCar-V cd ~/SunFounder_PiCar-V/ball_track sudo nano ball_tracker.py Then modify the code as follows: Show_image_enable = True Draw_circle_enble = True Press Ctrl+X and Y to save the change. Note: After you finish doing this step, you must log in the Raspberry Pi via VNC, or you can use a monitor; if not, the warning is as follows: Step 6: Run the ball_tracker.py. python3 ball_tracker.py 1.8. Getting on the Road! 53 SunFounder PiCar-V Step 7: After running the code ball_tracker.py, these four images will appear. If you place a red ball in front of the camera, you can see a green circle which represents that the car has catched your red ball. 54 Chapter 1. About the PiCar-V SunFounder PiCar-V 1.8.3 File Analysis There are two folders under /home/pi: SunFounder_PiCar for controlling motors and steering and SunFounder_PiCar-V for pan/tilt and wireless control. Here look into the code of PiCar-V. Since too many contents and instructions are involved in the code, we will not cover every detail. For more knowledge about Python 2, Python 3, Django, HTML, and CSS in the programs, you can visit related websites or buy books to learn by yourself. In the following part, we will go through the overall structure and the process in brief. First, let’s check the files in the code folder: • .git is a hidden directory to store all the information of a Git repository; it’s generated automatically after you create the repository. • Ball_track is used to let the car follow the red ball. • datasheet stores the manual of some chips used in the hardware modules. • mjpg-streamer is an open source streaming media library, through which the data of the camera is transferred. • Remote_control is to store the code of the web server; it controls the motor and servo of the car based on the API request. • .gitignore records the requests of file types to be ignored when the Github repository is synchronized. • _init_.py is automatically generated when you create a project which is a standard necessary document of python package, just leave it there. • i2cHelper.py is a Python script written by Python 2 to configure and detect the I2C connection. • install_dependencies, an executable bash script for simple installation and environment configuration. • LICENSE, as the name suggests, is a text file of GNU V2 license. • README.md and show record some information normally for statement and prompts. 1.8. Getting on the Road! 55 SunFounder PiCar-V Server Code The server code is based on Django 1.10 (adapt to the latest release if needed). If you are interested in this, you can visit the Django website https://www.djangoproject.com/. Here we will just learn how the web server works. Note: The code may be updated irregularly on Github to fix bugs and release some functions update. So the code here is the initial version. You can view the updates in the Github repository at: https://github.com/sunfounder/SunFounder_PiCar-V/tree/V3.0 Open the code directory and check the file by ls: pi@raspberry:~ $ cd SunFounder_PiCar-V/ pi@raspberry:~/SunFounder_PiCar-V $ ls datasheet install_dependencies mjpg-streamer client i2cHelper.py LICENSE remote_control README.md show remote_control is the main code directory of the web server. Open the code directory by cd remote_control, and check the file by ls: pi@raspberry:~/SunFounder_PiCar-V $ cd remote_control pi@raspberry:~/SunFounder_PiCar-V/remote_control $ ls db.sqlite3 manage.py remote_control start static • db.sqlite3 is generated when you create a Django project. • manage.py is the main program of the Django project and is generated when the project is created. It normally does not need to be modified. • remote_control includes the main code files. • start is a small script written to run sudo python manage.py runserver 0.0.0.0:8000, and servo installation with attribute install just for convenience. • static is to store some static pictures on the web. The Django web server normally runs sudo python manage.py runserver to start. The address 0.0.0.0:8000 means the listening address covers all the addresses on the LAN, and the port number is 8000. Here we will just focus on the code in remote_control folder. Go to the directory via cd remote_control: pi@raspberry:~/SunFounder_PiCar-V/remote_control $ cd remote_control pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control $ ls driver \__init__.py settings.py templates urls.py views.py wsgi.py • driver stores the drivers of the car. • __init__.py is automatically generated when you create a Django project which is a standard necessary document of python package, just leave it there. • settings.py is automatically generated and stores the related settings. • templates is a Django app for storing the webs in the html format. • urls.py is generated automatically to configure the URL to associate with the code. • views.py is the code for page control which is associated by the URL. It calls the templates to show the page and the driver to control the car. • wsgi.py is generated automatically and does not need changes. For more, please visit the official website of Django. 56 Chapter 1. About the PiCar-V SunFounder PiCar-V So here is how the code works: Run the main program manage.py which will be associated with urls. py automatically, to respond to the URL. When you run the web browser like the Chrome to visit http:// : or visit the configured API via the client, the manage.py will turn to views.py due to the association of the urls.py. Then the views.py processes this and returns the templates to the browser. In addition, it will call the driver package on the basis of the parameters set in the browser to control the car. Now open the folder driver and check: pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control $ cd driver/ pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control/driver $ ls camera.py config \__init__.py stream.py The driver folder mainly includes the driver modules for controlling the pan and tilt and camera streamer. camera.py for controlling the pan-and-tilt. config stores the calibration data. __init__.py is the essential file of the package and you can just leave it alone. stream.py is a video streaming service based on the MJPG-streamer. Exit and open the folder templates to view: pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control/driver $ cd ../ pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control $ cd templates/ admin.py \__init__.py models.py tests.py apps.py migrations templates views.py This folder is created by the manage.py startapp just for calling the templates conveniently. Therefore, the files have not been changed except for the templates. Open the templates again: pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control/templates $ cd ˓→templates pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control/templates/templates $ ˓→ls base.html cali.html run.html There are three HTML files that also consist of layers. The low level base.html stores contents contained on each page such as the of HTML, the overall layout, and contents of the home page by default. The surface layer: cali.html for calibration and run.html to control the car. 1.8.4 Advanced Now the car is running! You may try control it or view the image captured in Windows, Linux, or Mac OS X. So what to do next? Yes, sensors! There are 8 digital and 4 analog channels on the Robot HATS, as well as two I2C ports. Plus the 3mm slot on the acrylic plate in the car head, it enables the connection of various sensors, making the car smarter and more intriguing as you want! And, coding! If you know programming and are capable of compiling code, you may change the code provided for the kit to make the car more fabulous. For instance, you can find the code that controls the front and back wheels in the folder SunFounder_PiCar, downloaded to the directory /home/pi if you’ve installed the program by installdependences. You may check what’s in the file: 1.8. Getting on the Road! 57 SunFounder PiCar-V cd ~/SunFounder_PiCar ls After you’ve changed the code, you can go to the page of the Github repository for the car, and fork it to help improve it! Also you’re quite welcome to post issues and request a pull on our Github page: PiCar-V: https://github.com/sunfounder/SunFounder_PiCar-V/tree/V3.0 PiCar driver: https://github.com/sunfounder/SunFounder_PiCar And of course, if you have any questions or ideas, please feel free to email us at service@sunfounder.com. 1.9 Appendix 1.9.1 Appendix 1: Function of the Server Installation Scripts You may have a question: What do the installation scripts do when we install the server on the Raspberry Pi by them? So here let’s check the detailed steps. 1. Install pip. sudo apt-get install python-pip 2. Use pip to install django. sudo pip install django 3. Install i2c-tools and python-smbus. sudo pip3 install smbus2 4. Install PiCar drivers. cd ~/ git clone --recursive https://github.com/sunfounder/SunFounder_PiCar.git cd SunFounder_PiCar sudo python setup.py install 5. Download source code. cd ~/ git clone https://github.com/sunfounder/SunFounder_PiCar-V -b V3.0 6. Copy the MJPG-Streamer file to system directory. cd ~/SunFounder_PiCar-V sudo cp mjpg-streamer/mjpg_streamer /usr/local/bin sudo cp mjpg-streamer/output_http.so /usr/local/lib/ sudo cp mjpg-streamer/input_file.so /usr/local/lib/ sudo cp mjpg-streamer/input_uvc.so /usr/local/lib/ sudo cp -R mjpg-streamer/www /usr/local/www 7. Export paths. 58 Chapter 1. About the PiCar-V SunFounder PiCar-V export LD_LIBRARY_PATH=/usr/local/lib/ >> ~/.bashrc export LD_LIBRARY_PATH=/usr/local/lib/ >> ~/.profile source ~/.bashrc 8. Enable I2C1. Edit the file /boot/config.txt: sudo nano /boot/config.txt Add the line in the end: dtparam=i2c_arm=ons 9. Reboot. sudo reboot 1.9.2 Appendix 2: Components Robot HATS Robot HATS is a specially-designed HAT for a 40-pin Raspberry Pi and can work with Raspberry Pi model B+, 2 model B, 3 model B, 3 model B+, and 4 model B. It supplies power to the Raspberry Pi from the GPIO ports. Thanks to the design of the ideal diode based on the rules of HATS, it can supply the Raspberry Pi via both the USB cable and the DC port thus protecting it from damaging the TF card caused by batteries running out of power. The PCF8591 is used as the ADC chip, with I2C communication, and the address 0x48. 1.9. Appendix 59 SunFounder PiCar-V 1. Digital ports: 3-wire digital sensor ports, signal voltage: 3.3V, VCC voltage: 3.3V. 2. Analog ports: 3-wire 4-channel 8-bit ADC sensor port, reference voltage: 3.3V, VCC voltage: 3.3V. 3. I2C ports: 3.3V I2C bus ports 4. 5V power output: 5V power output to PWM driver. 5. UART port: 4-wire UART port, 5V VCC, perfectly working with SunFounder FTDI Serial to USB. 6. Motor control ports: 5V for motors, direction control of motors MA and MB and a floating pin NC ; working with SunFounder motor driver module. 7. Switch: power switch 8. Power indicators: indicating the voltage – 2 indicators on: >7.9V; 1 indicator on: 7.9V~7.4V; no indicator on:
CN0256D 价格&库存

很抱歉,暂时无法提供与“CN0256D”相匹配的价格&库存,您可以联系我们找货

免费人工找货