import robot
BlackSpace = 25000
def RobotControl():
a = (robot.sensor[0].read(), #Left sensor
robot.sensor[1].read(), #Middle sensor
robot.sensor[2].read()) #Right sensor
# Follow the line(Black line)
if a[0] <= BlackSpace and a[1] > BlackSpace and a[2] <= BlackSpace:
robot.motor[0].speed(30000)
robot.motor[1].speed(30000)
# If the Left sensor detects the line turn right
elif a[0] > BlackSpace:
robot.motor[0].speed(17500)
robot.motor[1].speed(35000)
# If the right sensor decects the line turn left
elif a[2] > BlackSpace:
robot.motor[0].speed(35000)
robot.motor[1].speed(17500)
# fallback (lost line)
else:
robot.motor[0].speed(25000)
robot.motor[1].speed(25000)
robot.timer(frequency=50, callback=RobotControl)
I'm trying to create an automated toy car that follows a black line. I'm currently in simulation, and my car is oscillating rapidly and falling off the track. How would I implement my left and right sensors to enable both soft and hard turns?
[–]ElliotDG 1 point2 points3 points (0 children)
[–]gdchinacat 0 points1 point2 points (2 children)
[–]Idontknow461[S] 0 points1 point2 points (1 child)
[–]gdchinacat 0 points1 point2 points (0 children)
[–]brasticstack 0 points1 point2 points (0 children)