66
fc
.
turn_right
(
Track_line_speed
)
if
__name__
==
'__main__'
:
while True
:
Track_line
()
follow.py
In the code, the ultrasonic module will take sample to form an array containing 11 elements; the module
detects once every 18° and puts the distance state (0,1,2) of every angle into the array. If there is
something obstructive at the right front, the detection value is [22222211122].
The array takes the 2 as a delimiter to divide the array anew. The examples above will be divided into
several null elements and a [111]- value element.
The corresponding angular range of the element with a value [111] is 108°~144° (0°+18°*6=108°, 0°+18°
*8=144°), and the car will turn its angle into a median 126°((144+108)/2)
Judge the distance, and keep the car away from the object about 10cm.
Note: Refer to 「scan_step()」and「get_status_at()」in 「_init_.py」to get more details about radar sampling
and the distance state judgement.
import
picar_4wd
as
fc
speed
=
30
def
main
():
while True
:
scan_list
=
fc
.
scan_step
(
23
)
if not
scan_list
:
Summary of Contents for PiCar-4WD
Page 6: ...1 Component List Structural Plates ...
Page 7: ...2 Mechanical Parts ...
Page 8: ...3 Electronic Parts ...
Page 9: ...4 Other Parts ...
Page 10: ...5 ...
Page 20: ...15 Step 9 Set country region language and time zone and then click next again ...
Page 21: ...16 Step 10 Input the new password of Raspberry Pi and click Next ...
Page 22: ...17 Step 11 Connect the Raspberry Pi to WIFI and click Next ...
Page 23: ...18 Step 12 Retrieve update ...
Page 47: ...42 Assembling Nylon Standoffs M2 5 6 Screw M2 5 8 6mm Nylon Standoff ...
Page 48: ...43 Assembling Top Plate and Bottom Plate M3 8 Screw M3 30mm Nylon Standoff M3 8 Screw ...
Page 49: ...44 Assembling Spoiler Spoiler ...
Page 50: ...45 Assembling Control Board 4WD Hat M2 5 11mm Nylon Standoff M2 5 6 Screw Raspberry Pi ...
Page 53: ...48 Assembling Ultrasonic Sensor Module M1 4 8 Screw M1 4 Nut Ultrasonic Module ...
Page 54: ...49 Assembling Wheels finished ...
Page 56: ...51 Interface Introduction ...
Page 63: ...58 ...
Page 67: ...62 Python Example Code Analysis Program Structure Framework ...