function FollowLine(a,b,c) FollowLineHiTech(a,b,100,500,c) end function FollowLineHiTech(a,b,c,d,e) local x = {} local dmax,dmin local LP,GL,xLP local dcount = 0 local ret = 0 local glret = 0 local GL = 0 local i = 1 local wcount = 0 local YStat = 0 local sharp = {} local SharpCount = 0 local DriveBy = 0 repeat x[1],x[2],x[3],x[4],x[5] = snabel() x[1] = ((x[1] - cs1) * 1000) / (ch1-cs1) x[2] = ((x[2] - cs2) * 1000) / (ch2-cs2) x[3] = ((x[3] - cs3) * 1000) / (ch3-cs3) x[4] = ((x[4] - cs4) * 1000) / (ch4-cs4) x[5] = ((x[5] - cs5) * 1000) / (ch5-cs5) wcount = 0 i = 1 repeat if x[i] < 600 then wcount = wcount + 1 end i = i + 1 until i == 6 if wcount > 4 then if b == 1 then -- ohh Shit print("Ohh Shit ! ("..GL..")") if GL < 0 then motor(1,6,1,2) repeat x[1],x[2],x[3],x[4],x[5] = snabel() x[1] = ((x[1] - cs1) * 1000) / (ch1-cs1) x[2] = ((x[2] - cs2) * 1000) / (ch2-cs2) x[3] = ((x[3] - cs3) * 1000) / (ch3-cs3) x[4] = ((x[4] - cs4) * 1000) / (ch4-cs4) x[5] = ((x[5] - cs5) * 1000) / (ch5-cs5) until x[3] > 70 or ccheck() else motor(1,2,1,6) repeat x[1],x[2],x[3],x[4],x[5] = snabel() x[1] = ((x[1] - cs1) * 1000) / (ch1-cs1) x[2] = ((x[2] - cs2) * 1000) / (ch2-cs2) x[3] = ((x[3] - cs3) * 1000) / (ch3-cs3) x[4] = ((x[4] - cs4) * 1000) / (ch4-cs4) x[5] = ((x[5] - cs5) * 1000) / (ch5-cs5) until x[3] > 70 or ccheck() end end if b == 2 then -- Ingen Streg DriveBy = DriveBy + 1 if DriveBy > 5 then motor(0,0,0,0) return end end else if DriveBy > 0 then DriveBy = DriveBy - 1 end end dmax = max(x[1],x[2],x[3],x[4],x[5]) dmin = min(x[1],x[2],x[3],x[4],x[5]) x[1] = ((x[1] - dmin) * 1000) / (dmax-dmin) x[2] = ((x[2] - dmin) * 1000) / (dmax-dmin) x[3] = ((x[3] - dmin) * 1000) / (dmax-dmin) x[4] = ((x[4] - dmin) * 1000) / (dmax-dmin) x[5] = ((x[5] - dmin) * 1000) / (dmax-dmin) if b == 1 then -- Ykryds i = 1 wcount=0 repeat if x[i] > 700 then wcount=wcount+1 end i = i + 1 until i == 6 if (wcount >= 3) then YStat = YStat + 1 if YStat >= 5 then motor(0,0,0,0) return end else if YStat > 0 then print("Y = "..YStat) YStat = YStat - 1 end --YStat = 0 end end if b == 3 then -- Sharp above level --if DriveBy == 0 then -- sharp[1],sharp[2],sharp[3],sharp[4],sharp[5] = s() -- if sharp[1] > 110 then -- DriveBy = 1 -- end --else -- sharp[1],sharp[2],sharp[3],sharp[4],sharp[5] = s() -- if sharp[2] < 80 then -- motor(0,0,0,0) -- return -- end --end sharp[1],sharp[2],sharp[3],sharp[4],sharp[5] = s() if sharp[1] > 160 then SharpCount = SharpCount + 1 if SharpCount > 5 then motor(0,0,0,0) return end else if SharpCount > 0 then SharpCount = SharpCount - 1 end end end if b == 4 then -- Sample Check if dcount > e then motor(0,0,0,0) return end end LP = (-1000*x[1]-500*x[2]+500*x[4]+1000*x[5])/(x[1]+x[2]+x[3]+x[4]+x[5]) xLP = ((c * LP) + (d * (LP - GL))) / 100 if xLP > 1000 then xLP = 1000 end if xLP < -1000 then xLP = -1000 end ret = (xLP * a) /500 if ret ~= glret then if ret < 0 then motor(1,a,1,a + ret) else motor(1,a - ret,1,a) end glret = ret end GL = LP dcount = dcount + 1 until ccheck() motor(0,0,0,0) print("Samples "..dcount) end