SunFounder PiCar-S
Functions Explanation
ua = Ultra_Sonic.UltraSonic_Avoidance(17)
Create an object
ua
of a
UltraSonic_Avoidance
class in the Ultra_Sonic module. The number in the round bracket is
the initial parameter, which represents the pin number the SIG of the module is connected to. Since the BCM naming
method is applied, the corresponding pin on the Raspberry Pi is #17.
back_distance
and
turn_distance
, two constants are to set the thresholds of the ranging distance.
while()
loop
When the detected distance is less than the
back_distance
, the car will move backwards; when it is between
back_distance
and
turn_distance
, the car will turn a direction (you can set the turning angle in the aforementioned
parameter
turning_angle
and the angle can be a positive or negative number, for turning left or turning right respec-
tively;
NOTE
that the number of the turning angle should be
-90 to 90
considering the servo’s max rotation degrees,
or the servo may be burnt.); when the detected distance is greater than the
turn_distance
, the car will keep moving
forward.
bw.backward()
, making the rear wheels rotate backwards;
bw.forward()
, making the rear wheels spin forward. These
two functions in the rear wheel driving module back_wheels are to set the wheel’s rotating direction.
bw.set_speed(speed)
, function in the back_wheels, to set the wheel’s rotating speed. The larger the number (within
the range 0-100) is, the faster the wheel rotates.
fw.turn(angle)
, function in the back_wheels, to set the turning angle. The angle is 90 when the car moves straight
forwards; reduce the number to turn left, and increase it to turn right.
52
Chapter 1. About the PiCar-S
Summary of Contents for PiCar-S
Page 1: ...SunFounder PiCar S www sunfounder com Nov 10 2021 ...
Page 2: ......
Page 4: ...ii ...
Page 8: ...SunFounder PiCar S 4 Chapter 1 About the PiCar S ...
Page 9: ...SunFounder PiCar S 1 1 3 Mechanical Fasteners 1 1 Components List 5 ...
Page 10: ...SunFounder PiCar S 1 1 4 Wires 6 Chapter 1 About the PiCar S ...
Page 11: ...SunFounder PiCar S 1 1 5 PCB 1 1 Components List 7 ...
Page 12: ...SunFounder PiCar S 1 1 6 Other Components 8 Chapter 1 About the PiCar S ...
Page 22: ...SunFounder PiCar S 18 Chapter 1 About the PiCar S ...
Page 26: ...SunFounder PiCar S 22 Chapter 1 About the PiCar S ...
Page 27: ...SunFounder PiCar S 1 4 Circuits Building 1 4 1 Connect the Power 1 4 Circuits Building 23 ...
Page 28: ...SunFounder PiCar S 1 4 2 Connect the Modules 24 Chapter 1 About the PiCar S ...
Page 29: ...SunFounder PiCar S 1 4 3 Connect the Servo 1 4 Circuits Building 25 ...
Page 69: ...SunFounder PiCar S Subflow of Line Following Function 1 8 Arming the Car 65 ...
Page 74: ...SunFounder PiCar S 70 Chapter 1 About the PiCar S ...