Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize DIY by Python A thinking Barrier car

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

The main content of this article is to explain "how to achieve DIY in Python, a thinking barrier car". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to achieve Python DIY a thinking barrier car" it!

1. Required equipment:

1. 1 TurnipBit development board (available on TB)

2. Download 1 data line

3. 1 set of intelligent car kit (chassis, wheels, motor, etc.)

4. 1 ultrasonic module (HC-SR04) (used as the "eye" of the car)

5. 1 L298N motor drive module

6. 1 computer connected to the Internet (Google Chome or Firefox browser is recommended)

Second, the assembly of barrier cars

The first step is to tear off the yellow protective paper of the car floor, fasteners and code plate, and then insert the fasteners into the car floor.

The second step is to install the code plate and fix the motor on the base plate. One side of the axis of the code disk is big and the other is small, and the big side is inserted into the motor shaft (note: the copper piece of the motor lead is facing the inside, that is, one end of the code disk).

The third step is to insert the screw, fix the motor to the bottom plate of the car, and screw on the nut.

The fourth step is to insert the screw and fix the battery box. This step can be omitted in this experiment, we use portable battery for power supply.

The fifth step is to put in the copper column, tighten 8 screws to fix the universal wheel, hold the motor (protective fastener) by hand, and insert the wheel into it to complete the assembly.

Finally, let's take a look at the effect of the assembly.

Third, motor drive and ultrasonic installation

The connection of hardware is mainly the connection between the pins. The details are (see the table below): there are 4 pins in the ultrasonic module, namely VCC, GND, Trig and Echo. The VCC is connected to the + 5V pin of the TurnipBit expansion board, the GND is connected to the GND pin of the TurnipBit expansion board, and the Trig trigger pin is connected to the P5e echo return pin to the P8. The OUT3 and OUT4 terminals on the left side of the L298N motor drive module correspond to the copper sheets on the lower and upper sides of the revolver motor, as well as on the right side. The input terminals IN1, IN2, IN3 and IN4 of L298N are respectively connected to P19, P13, P12 and P11 of the expansion board. Finally, this experiment uses portable battery for power supply, as long as the charging board is connected to the microusb port of the TurnipBit development board through the USB line.

IV. Plug-in programming

Step 1: because P11 and P12 control a wheel, P13 and P19 control a wheel, only need to give the corresponding wheel P12 and P19 high level, the other two pins low and high level, the two wheels of the obstacle avoidance vehicle will rotate, if the rotation direction of the two wheels are different or backward, it means that you do not pay attention to the connected L298N pins, just need to change, the obstacle avoidance vehicle will go forward, as shown in the following figure.

Step 2: add an endless loop to keep the program running.

Step 3: next, we need to complete the function of detecting obstacles, which needs ultrasonic module to achieve. We need to add the content of obstacle detection in the dead cycle, so that the obstacle avoidance vehicle can constantly detect the distance from the obstacle in front of it.

Step 4: in order to realize the function more simply, conveniently and quickly, we use the way of counting, measure an approximate distance, and then determine whether to avoid obstacles. Careful students may find that we define a variable of num at the beginning of the program, and we count it with num. When pin 8 is high, indicating that the echo of the ultrasonic module enters the receiving mode, we keep letting num add 1 until the ultrasonic module receives the return signal, that is, pin 8 is low, stop counting. The num here can reflect the distance between the current car and the obstacle. Here, the safe distance of 25 cm is tested, and it is found that the value of num is 8. Therefore, if the distance between the car and the obstacle is less than 25 cm, the num is less than 8. Therefore, it is judged in the program that if the value of num is less than or equal to 8, it will be turned to avoid obstacles.

Step 5: at this point, the thinking car has been completed. In order to make the obstacle avoidance vehicle more cool, we can use the LED screen to dynamically display the current direction of the obstacle avoidance vehicle. The method is to show the direction of the turn with arrows before the car makes a steering action, and then do the action.

Step 6: change the name of the program to turnipbit-car, and click the [download hex] button to save the program to your computer. Drag the saved turnipbit- car.hex file to the TurnipBit disk and we will see the light on the TurnipBit board flashing, indicating that it is being downloaded to the control board. After the download is successful, insert the TurnipBit correctly into the slot of the gold finger card of the TurnipBit expansion board and start the obstacle avoidance vehicle.

At this point, I believe you have a deeper understanding of "how to achieve DIY in Python, a thinking barrier car". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report