chapter 2
2.1 Start the car
go (左轮功率,右轮功率,持续时长)
Use the go function to steer the car forward with 50% power for 2 seconds
go(50, 50, 2)
Action Module -> Forward -> 50 -> 50 -> 2
and so on
2.2 Control the direction of the car
2.2.1 Car's left turn
Left wheel horsepower 20% , right wheel horsepower 90% , running time 1s
go(20, 90, 1)
2.2.2 Car's right turn
The horsepower of the left wheel is 90% , the horsepower of the right wheel is 20 %**, and the running time is 1s
go(90, 20, 1)
2.2.3 Rotate in situ
Left wheel horsepower -20% , right wheel horsepower 20%, running time 2s
go(-20, 20, 2)
2.2.4 Learn to control your car
Left wheel horsepower -100% / -80% / -60% / -40% /-20% , right wheel horsepower 100% / 80% / 60% / 40% / 20% , running time 1s
go(-100, 100, 1)
go(-80, 80, 1)
go(-60, 60, 1)
go(-40, 40, 1)
go(-20, 20, 1)
2.3 Control the car through the U-shaped track
Let's not talk about the trial part
go(100, 100, 2)
go(100, 30, 1.9)
go(100, 100, 1)
go(100, 20, 1.7)
go(100, 100, 2.2)
2.4 Control the car to complete the designated road
2.4.1 Advance an edge
go(100, 100, 2.45)
2.4.2 Turn right 90°
def turn_right():
go(100, (-100), 0.65)
go(10, (-10), 0.3)
turn_right()
2.4.3 Square route
def turn_right():
go(100, (-100), 0.65)
go(10, (-10), 0.3)
for count in range(4):
go(100, 100, 2.45)
turn_right()
2.5 Understanding and Application of Vehicle Sensors
2.5.1 Understanding Sensors
1 -> 左前传感器
2 -> 右前传感器
3 -> 前传感器
4 -> 后传感器
2.5.2 Ultrasonic sensors
Car stops automatically (1)
setTarget(3)
time = 0.1
while get_ultrasound()[2] > 100:
go(100, 100, time)
Car stops automatically (2)
setTarget(4)
time = 0.1
while get_ultrasound()[2] < 800:
go((-100), (-100), time)
2.5.3 Color Sensor
Car color detection (1)
setTarget(6)
while get_color()[0][0] < 128:
go(100, 100, 0.1)
Car color detection (1)
setTarget(7)
while get_color()[0][0] < 128:
go(100, 100, 0.1)
while get_color()[1][0] < 128:
go((-100), (-100), 0.1)
2.6 The trolley patrols the line
2.6.1 Tracking module design
def getLineLoc():
colors = get_color() #4 * [R,G,B,L]
res = -1
res_max = 0
for i in range(4):
if colors[i][0] > res_max:
res_max = colors[i][0]
res = i
return res
while get_color()[0][2] < 128:
res = getLineLoc()
if res == 0:
go(-20,40,1/10)
elif res == 1:
go(30,50,1/10)
elif res == 2:
go(50,30,1/10)
elif res == 3:
go(40,-20,1/10)
2.7 Car distance measurement driving
2.7.1 Open loop control walking
go(50, 70, 4)
go(70, 50, 2)
2.7.2 Closed loop control walking
get_distance()
start = get_distance()[0]
if start - get_distance()[0] > 0:
turn(10)
start = get_distance()[0]
if start - get_distance()[0] > 0:
turn(-10)
dt = 50
while get_color()[0][2] < 128:
if get_ultrasound()[0] - get_ultrasound()[1] > dt:
go(20,80,1/12)
elif get_ultrasound()[1] - get_ultrasound()[0] > dt:
go(80,20,1/12)
else:
go(90,90,1/12)
2.8 Ranging of the trolley on complex routes
2.8.1. Turning with ranging sensor
dt = 50
while inCurrentTask():
if get_ultrasound()[0] - get_ultrasound()[1] > dt:
go(20,80,1/6)
elif get_ultrasound()[1] - get_ultrasound()[0] > dt:
go(80,20,1/6)
else:
go(90,90,1/4)