In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "python DIY ultrasonic obstacle avoidance car method is what", in the daily operation, I believe many people in python DIY ultrasonic obstacle avoidance car method is what the problem is, Xiaobian consulted all kinds of information, sorted out simple and easy to use operation method, hope to answer "python DIY ultrasonic obstacle avoidance car method is what" doubts help! Next, please follow the small series to learn together!
I. Experimental equipment
1. TPYboard V102 board 1 piece
2. Motor drive module L298N 1
3. Motor 2
4. One trolley chassis
5, ultrasonic module 1
6, steering gear 1
7. SG90 steering gear bracket 1
8. Ultrasonic PTZ bracket 1
II. Ultrasonic module
What is an ultrasound module?
Ultrasonic sensors are sensors developed using the properties of ultrasonic waves. They work by transmitting an ultrasonic wave (well above the range of human hearing) and providing an output pulse corresponding to the time required for the burst echo to return to the sensor. Ultrasonic sensors are widely used in non-contact measurement, such as detecting liquid water level (especially corrosive liquids, such as sulfuric acid and nitric acid), automobile reversing anti-collision system, metal/non-metal flaw detection, etc., ultrasonic distance sensors can be used.
Principle of ultrasonic module distance measurement
TRIG trigger ranging with IO port, giving at least 10us high level signal.
The module automatically sends 8 square waves of 40kHz and automatically detects whether there is a signal return.
(3)There is a signal return, through the IO port ECHO output a high level, high level duration is the ultrasonic wave from emission to return time. Test distance =(high level time * sound speed (340M/S))/2.
Wiring as shown in the figure below, VCC for 5V power supply, GND for ground, TRIG trigger control signal input, X9 of the connector board, ECHO echo signal output, X10 of the connector board, four interface terminals.
III. Motor drive module
What is a motor drive module
Motor drive module is mainly able to control the operation of the motor: speed regulation, operation, stop, step, uniform speed and other operations.
How to use L298N
L298N module is 2-way H-bridge drive, so it can drive two motors at the same time. After ENA ENB is enabled as shown in the figure, PWM signals can be input from IN1 IN2 to drive the speed and direction of motor 1, and PWM signals can be input from IN3 IN4 to drive the speed and direction of motor 2. We connect OUT1 and OUT2 of motor 1 interface with the positive and negative poles of one motor of the trolley, and connect OUT3 and OUT2 of motor 2 interface with the positive and negative poles of another motor of the trolley. Then connect the terminals on both sides, i.e., the positive power supply terminal (the middle terminal is grounded) to VIN of TPYBoard, the middle terminal is grounded, connected to GND of TPYBoard, In1-In4 connected to X1, X2, Y1 and Y2 of TPYBoard, and control the rotation of the motor through the high and low levels of X1,X2 and Y1 and Y2, so as to make the trolley move forward, backward, left and right.
IV. Steering gear
overview
The steering gear is also called servo motor, which was first used to realize its steering function on ships. Because it can continuously control its rotation angle through programs, it is widely used in intelligent vehicles to realize steering and various joint movements of robots.
2. Composition of steering gear
Generally speaking, the steering gear is mainly composed of the following parts: steering wheel, reduction gear set, position feedback potentiometer, DC motor, control circuit, etc., as shown in the figure below.
There are three input lines of the steering gear, red in the middle, is the power line, gray on one side is the ground line, this root line provides the most basic energy guarantee for the steering gear, mainly the motor rotation consumption. Power supply has two specifications, one is 4.8V, the other is 6.0V, respectively corresponding to different torque standards, that is, the output torque is different, 6.0V corresponding to some larger, depending on the application conditions; another line is the control signal line, Futaba is generally white, JR is generally orange. Also note that some SANWA models have steering leads on the sides rather than in the middle, which needs to be identified. But remember that red is the power supply, gray is the ground, and the remaining one is the signal line. Generally, there will be no mistake. In this experiment, red servo is connected to VIN pin of TPYBoard v102+, gray is connected to GND pin of TPYBoard v102+, and the remaining orange is the signal line connected to X3 pin of TPYBoard V102+. X1, X2, X3, X4 of TPYBoard v102+ are signal pins.
3. Working principle of steering gear
The control circuit board receives the control signal from the signal line and controls the motor to rotate. The motor drives a series of gear sets, which are decelerated and transmitted to the output steering wheel. The output shaft of the steering gear is connected with the position feedback potentiometer. When the steering wheel rotates, it drives the position feedback potentiometer. The potentiometer will output a voltage signal to the control circuit board for feedback. Then the control circuit board determines the direction and speed of the motor rotation according to the position, so as to achieve the target stop. The working flow is as follows: control signal → control circuit board → motor rotation → gear set deceleration → steering wheel rotation → position feedback potentiometer → control circuit board feedback.
Fifth, the servo motor construction function and method
1. constructor
pyb.Servo(id)
In this id is 1-4, corresponding to X1-X4 of TPYBoard v102+.
2. method
Servo.angle([angle,time = 0 ])
If no arguments are given, the function returns the current angle.
Given parameters, this function sets the servo angle:
angle is the angle moved in degrees.
time is the number of milliseconds required to reach the specified angle. If omitted, the server moves to its new position as quickly as possible.
Servo.speed([speed, time=0])
If no arguments are given, the function returns the current speed.
If given parameters, this function sets the speed of the servo:
Speed is the speed that varies between-100 and 100.
time is the number of milliseconds required to reach the specified speed. If omitted, the server speeds up as fast as possible.
Servo.pulse_width([value ])
If no arguments are given, this function returns the current original pulse width value.
Given parameters, this function sets the original pulse width value.
Servo.calibration([pulse_min,pulse_max,pulse_centre [,pulse_angle_90,pulse_speed_100 ]])
If no arguments are given, the function returns the current calibration data as a 5-tuple.
If parameters are given, this function sets the timing calibration:
pulse_min is the minimum pulse width allowed.
pulse_max is the maximum pulse width allowed.
pulse_centre is the pulse width corresponding to the centre/null position.
pulse angle 90 is a pulse width corresponding to 90 degrees.
pulse speed 100 is the pulse width corresponding to speed 100.
VI. Hardware wiring diagram
TPYBoard v102
ultrasonic module
steering gear
L298N Driver Module
VIN
VCC
GND
GND
X9
Trig
X10
Echo
VIN
red
GND
ash
X3
orange
X1
In1
X2
In2
Y1
In3
Y2
In4
VIN
+12V
GND
GND
VIN
+5V
VII. Source Code
# main.py -- put your code here! import pybfrom pyb import Pinfrom pyb import Timerfrom pyb import servox1 = Pin('X1', Pin.OUT_PP)x2 = Pin('X2', Pin.OUT_PP)y1 = Pin('Y1', Pin.OUT_PP)y2 = Pin('Y2', Pin.OUT_PP)Trig = Pin('X9',Pin.OUT_PP)Echo = Pin('X10',Pin.IN)num=0flag=0run=1zuo=0qian=0you=0distance=0def start(t): global flag global num if(flag==0): num=0 else: num=num+1def stop(t): global run if(run==0): run=1start1=Timer(1,freq=10000,callback=start)stop1=Timer(4,freq=2,callback=stop)#Car left def left(): x1.high() x2.low() y1.high() y2.low()#car forward def go(): x1.high() x2.low() y1.low() y2.high()#car back def back(): x1.low() x2.high() y1.high() y2.low()#car turn right def right(): x1.low() x2.high() y1.low() y2.high()#car stop def stop(): x1.low() x2.low() y1.low() y2.low()#Control the steering gear to the right, left and forward def servo(): global distance global zuo global you global qian servo3=pyb.Servo(3) #75 to the right servo3.angle(-75,500) pyb.delay(1000) ceju() you=distance print('you',you) Turn left 75 degrees servo3.angle(75,500) pyb.delay(1000) ceju() zuo=distance print('zuo',distance) #Go to 0 degrees servo3.angle(0,500) pyb.delay(1000) ceju() qian=distance print('qian',distance) #Distance back to front, left, right return qian,zuo,you#Ranging method def ceju(): global flag global num global run global distance if(run==1): Trig.value(1) pyb.udelay(100) Trig.value(0) while(Echo.value()==0): Trig.value(1) pyb.udelay(100) Trig.value(0) flag=0 if(Echo.value()==1): flag=1 while(Echo.value()==1): flag=1 if(num!= 0): #Distance measurement distance=num/10000*34299/2 #print('Distance:') #print(distance,'cm') pyb.delay(500) flag=0 run=0 return distancedef main(): global distance global zuo global you global qian servo3=pyb.Servo(3) servo3.angle(0,500) pyb.delay(1000) ceju() while 1==1: ceju()、 #Forward distance greater than 40cm Forward if distance > 40: go() ceju() print('juli',distance) #Distance ahead less than 40cm if distance zuo: right() pyb.delay(400) ceju() #If the left front distance is greater than the right front distance if zuo>you: left() pyb.delay(400) ceju() #If the distance in all directions is less than 15cm if zuo
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.