## Line Following issues

Typically: "How do I... ", "How can I... " questions
HIGOR NERES
Posts: 1
Joined: 20 Feb 2019, 00:18

### Line Following issues

Hello Guys,

I I am creating a robot that should be capable of following line and turn things around, my professor provide a main code for us make improvements to achieve the goal, but i can not understand this piece of code, may anybody help me out ?

Check it out:

Code: Select all

``````if (proxSensDist[1]>0.25*noDetectionDistance) then
velLeft=velLeft+maxVel*braitSideSens_leftMotor[1]*(1-(proxSensDist[1]/noDetectionDistance))
velRight=velRight+maxVel*braitSideSens_leftMotor[2]*(1-(proxSensDist[1]/noDetectionDistance))``````
All of it:

Code: Select all

``````if (opMode==0) then -- We wanna follow the line
if (math.mod(st,2)>1.5) then
intensity=1
else
intensity=0
end
for i=1,9,1 do
ledColors[i]={intensity,0,0} -- red
end
-- Now make sure the light sensors have been read, we have a line and the 4 front prox. sensors didn't detect anything:
if lightSens and ((lightSens[1]<0.5)or(lightSens[2]<0.5)or(lightSens[3]<0.5)) and (proxSensDist[2]+proxSensDist[3]+proxSensDist[4]+proxSensDist[5]==noDetectionDistance*4) then
if (lightSens[1]>0.5) then
velLeft=maxVel
else
velLeft=maxVel*0.25
end
if (lightSens[3]>0.5) then
velRight=maxVel
else
velRight=maxVel*0.25
end
else
velRight=maxVel
velLeft=maxVel
if (proxSensDist[2]+proxSensDist[3]+proxSensDist[4]+proxSensDist[5]==noDetectionDistance*4) then
-- Nothing in front. Maybe we have an obstacle on the side, in which case we wanna keep a constant distance with it:
if (proxSensDist[1]>0.25*noDetectionDistance) then
velLeft=velLeft+maxVel*braitSideSens_leftMotor[1]*(1-(proxSensDist[1]/noDetectionDistance))
velRight=velRight+maxVel*braitSideSens_leftMotor[2]*(1-(proxSensDist[1]/noDetectionDistance))
end
if (proxSensDist[6]>0.25*noDetectionDistance) then
velLeft=velLeft+maxVel*braitSideSens_leftMotor[2]*(1-(proxSensDist[6]/noDetectionDistance))
velRight=velRight+maxVel*braitSideSens_leftMotor[1]*(1-(proxSensDist[6]/noDetectionDistance))
end``````