Unit3 Edt1
Unit3 Edt1
Experiment: 3.1
1. Aim of the practical:: Design a two-wheel line following robot integrated with infrared
sensors.
4. Code:
CODE FOR BUBBLE ROB:
function sysCall_init()
University Institute of Engineering
Department of Computer Science & Engineering
bubbleRobBase=sim.getObject('.')
leftMotor=sim.getObject("./leftMotor")
rightMotor=sim.getObject("./rightMotor")
noseSensor=sim.getObject("./sensingNose")
minMaxSpeed={50*math.pi/180,300*math.pi/180}
floorSensorHandles={-1,-1,-1}
floorSensorHandles[1]=sim.getObject("./leftSensor")
floorSensorHandles[2]=sim.getObject("./middleSensor")
floorSensorHandles[3]=sim.getObject("./rightSensor")
robotTrace=sim.addDrawingObject(sim.drawing_linestrip+sim.drawing_cyclic,2,0,-1,200,
{1,1,0},nil,nil,{1,1,0})
</ui>
]]
ui=simUI.create(xml)
University Institute of Engineering
Department of Computer Science & Engineering
speed=(minMaxSpeed[1]+minMaxSpeed[2])*0.5
simUI.setSliderValue(ui,1,100*(speed-minMaxSpeed[1])/(minMaxSpeed[2]-
minMaxSpeed[1]))
end
function sysCall_sensing()
local p=sim.getObjectPosition(bubbleRobBase,-1)
sim.addDrawingObjectItem(robotTrace,p)
end
function speedChange_callback(ui,id,newVal)
speed=minMaxSpeed[1]+(minMaxSpeed[2]-minMaxSpeed[1])*newVal/100
end
function sysCall_actuation()
result=sim.readProximitySensor(noseSensor)
sensorReading={false,false,false}
for i=1,3,1 do
result,data=sim.readVisionSensor(floorSensorHandles[i])
if (result>=0) then
end
end
rightV=speed
leftV=speed
if sensorReading[1] then
leftV=0.03*speed
end
if sensorReading[3] then
rightV=0.03*speed
end
backUntilTime=sim.getSimulationTime()+2
end
University Institute of Engineering
Department of Computer Science & Engineering
if (backUntilTime<sim.getSimulationTime()) then
sim.setJointTargetVelocity(leftMotor,leftV)
sim.setJointTargetVelocity(rightMotor,rightV)
else
sim.setJointTargetVelocity(leftMotor,-speed/2)
sim.setJointTargetVelocity(rightMotor,-speed/8)
end
end
function sysCall_cleanup()
simUI.destroy(ui)
end
path=require('path_customization')
University Institute of Engineering
Department of Computer Science & Engineering
function path.shaping(path,pathIsClosed,upVector)
local section={-0.02,0.001,0.02,0.001}
local color={0.3,0.3,0.3}
local options=0
if pathIsClosed then
options=options|4
end
local shape=sim.generateShapeFromPath(path,section,options,upVector)
sim.setShapeColor(shape,nil,sim.colorcomponent_ambient_diffuse,color)
return shape
end
Sensor Accuracy – The infrared sensors effectively detect line contrast but may struggle
with reflective surfaces or dim lighting.
Control Precision – Fine-tuning motor speed improves smooth path tracking, preventing
oscillations or overshooting curves.
Response Time – Faster sensor readings enhance real-time corrections, ensuring stable
movement along the track.
The two-wheel line-following robot successfully detects and follows a predefined path using
infrared sensors. Performance improves with optimized control algorithms, ensuring smooth
and accurate navigation.
1.Sensor Integration – Understanding how infrared sensors detect and respond to line
contrast.
Evaluation Grid: