Odd response to inputs

I am trying to get a bus to follow lines on a road using sensors, if the middles detects a line its fine but if any of the others do it will turn to correct its position. The code works in theory but in reality my chip is detecting inputs that aren't there any it doesn't seem to be working correctly, the servo is just staying in the right most position. I am using a picaxe 18m2. Does anyone know why this isn't working or is there a better way to detect the inputs?
This is my code:
#picaxe 18m2
init: servo B.2,75 ; initialise servo
main:
gosub check_swtich
gosub check_sensors
goto main


check_swtich:
if pinC.5 = 1 then
gosub motor_off
high B.0
high B.1
endif
return
check_sensors:
if pinC.0 = 1 then
gosub middle
elseif pinC.2 = 1 then
gosub right
elseif pinC.0 = 1 then
gosub left
elseif pinC.1 = 1 then
gosub midright
elseif pinC.7 = 1 then
gosub midleft
else
gosub middle
end if
return


right:
high B.1
low B.0
servopos B.2,110
return
midright:
high B.1
low B.0
servopos B.2,133
return
middle:
low B.0
low B.1
servopos B.2,155
return
midleft:
high B.0
low B.1
servopos B.2,178
return
left:

high B.0
low B.1
servopos B.2,200
return
 
I think it might actually might be due to the fact I'm currently testing without the sensors connected so that may fix the issue.
 

erco

Senior Member
That would do it! Line followers are great to learn about control systems: electronics, mechanics, dynamics & coding. Be aware that there are tons of variables. Speed, line width, line contrast, line radius, sensor type, location and spacing, number of sensors, vehicle size & weight, chassis geometry and steering method, battery voltage, motor speed & torque, wheel spacing & diameter, tire traction, etc. IMO a great place to start is with one of these $5 Chinese kits.

 
Last edited:
Top