University Institute of Engineering Department of Mechanical Engineering
University Institute of Engineering Department of Mechanical Engineering
University Institute of Engineering Department of Mechanical Engineering
Experiment: 3.2
1. Aim of the practical: Design a two wheel line following robot integrated with infrared sensors.
function sysCall_init()
bubbleRobBase=sim.getObject('.')
leftMotor=sim.getObject("./leftMotor")
rightMotor=sim.getObject("./rightMotor")
noseSensor=sim.getObject("./sensingNose")
minMaxSpeed={50*math.pi/180,300*math.pi/180}
backUntilTime=-1 -- Tells whether bubbleRob is in forward or
backward mode
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})
-- Create the custom UI:
xml = '<ui title="'..sim.getObjectAlias(bubbleRobBase,1)..'
speed" closeable="false" resizeable="false" activate="false">'..[[
<hslider minimum="0" maximum="100" on-
change="speedChange_callback" id="1"/>
<label text="" style="* {margin-left: 300px;}"/>
</ui>
]]
ui=simUI.create(xml)
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
University Institute of Engineering
Department of Mechanical Engineering
end
function sysCall_actuation()
result=sim.readProximitySensor(noseSensor)
if (result>0) then backUntilTime=sim.getSimulationTime()+4 end
if (backUntilTime<sim.getSimulationTime()) then
-- When in forward mode, we simply move forward at the
desired speed
sim.setJointTargetVelocity(leftMotor,leftV)
sim.setJointTargetVelocity(rightMotor,rightV)
else
-- When in backward mode, we simply backup in a curve at
reduced speed
sim.setJointTargetVelocity(leftMotor,-speed/2)
University Institute of Engineering
Department of Mechanical Engineering
sim.setJointTargetVelocity(rightMotor,-speed/8)
end
end
function sysCall_cleanup()
simUI.destroy(ui)
end
path=require('path_customization')
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,col
or)
return shape
end
University Institute of Engineering
Department of Mechanical Engineering
6.Results:The robot succesfully detect the obstacles and change its direction.
2.We are designed mounting circuits on electronic devise e.g. mobile phone.
3.We are working where there might be danger e.g. nuclear leaks and bomb
disposal.
4.We are designed to Toy robots are good source of entertaining for like kids
e.g.dancing talking robots.
5.We are able to help the people by robots do not get bored or tired and they can
work 24/7without salary and food.