You are on page 1of 10

University Institute of Engineering

Department of Computer Science & Engineering

Experiment: 3.3

Student Name: Yash Singh UID: 21BCS2560


Branch: Computer Science & Engineering Section/Group:125/B
Semester: 2nd Date of Performance:24/04/22
Subject Name: Disruptive Technology
Subject Code: 21ECH-103

1. Aim of the practical: Design a collision avoidance robot in multi obstacle based
environment.

2. Tool Used: CoppeliaSim EDU

3. Code:

For PATH:

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
University Institute of Engineering
Department of Computer Science & Engineering

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

For vision sensor:

function sysCall_vision(inData)
simVision.sensorImgToWorkImg(inData.handle) -- copy the vision
sensor image to the work image
simVision.edgeDetectionOnWorkImg(inData.handle,0.2) -- perform
edge detection on the work image
simVision.workImgToSensorImg(inData.handle) -- copy the work
image to the vision sensor image buffer
end

function sysCall_init()
end

For bubble Rob:

function speedChange_callback(ui,id,newVal)
speed=minMaxSpeed[1]+(minMaxSpeed[2]-
minMaxSpeed[1])*newVal/100
end

function sysCall_init()
-- This is executed exactly once, the first time this script
is executed
bubbleRobBase=sim.getObject('.') -- this is bubbleRob's handle
leftMotor=sim.getObject("./leftMotor") -- Handle of the left
motor
University Institute of Engineering
Department of Computer Science & Engineering

rightMotor=sim.getObject("./rightMotor") -- Handle of the


right motor
noseSensor=sim.getObject("./sensingNose") -- Handle of the
proximity sensor
minMaxSpeed={50*math.pi/180,300*math.pi/180} -- Min and max
speeds for each motor
backUntilTime=-1 -- Tells whether bubbleRob is in forward or
backward mode
robotCollection=sim.createCollection(0)

sim.addItemToCollection(robotCollection,sim.handle_tree,bubbleRobB
ase,0)
distanceSegment=sim.addDrawingObject(sim.drawing_lines,4,0,-
1,1,{0,1,0})

robotTrace=sim.addDrawingObject(sim.drawing_linestrip+sim.drawing_
cyclic,2,0,-1,200,{1,1,0},nil,nil,{1,1,0})
graph=sim.getObject('./graph')
distStream=sim.addGraphStream(graph,'bubbleRob
clearance','m',0,{1,0,0})
-- Create the custom UI:
xml = '<ui
title="'..sim.getObjectAlias(bubbleRobBase,1)..' speed"
closeable="false" resizeable="false" activate="false">'..[[
<hslider minimum="0" maximum="100"
onchange="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
result,distData=sim.checkDistance(robotCollection,sim.handle_all)
if result>0 then
University Institute of Engineering
Department of Computer Science & Engineering

sim.addDrawingObjectItem(distanceSegment,nil)
sim.addDrawingObjectItem(distanceSegment,distData)
sim.setGraphStreamValue(graph,distStream,distData[7])
end
local p=sim.getObjectPosition(bubbleRobBase,-1)
sim.addDrawingObjectItem(robotTrace,p)
end

function sysCall_actuation()
result=sim.readProximitySensor(noseSensor) -- Read the
proximity sensor
-- If we detected something, we set the backward mode:
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,speed)
sim.setJointTargetVelocity(rightMotor,speed)
else
-- When in backward mode, we simply backup in a curve at
reduced speed
sim.setJointTargetVelocity(leftMotor,-speed/2)
sim.setJointTargetVelocity(rightMotor,-speed/8)
end
end

function sysCall_cleanup()
simUI.destroy(ui)
end
University Institute of Engineering
Department of Computer Science & Engineering

4. Observations, Simulation Screen Shots and Discussions:


University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering

5. Result and Summary:

We created the BOT that itself checks the obstacle in front of it and changes the direction.

6. Additional Creative Inputs (If Any):

Learning outcomes (What I have learnt):

1. We learnt how bot works.

2. Learnt Arduino for the work of the BOTS

Evaluation Grid (To be filled by Faculty):


Sr. Parameters Marks Obtained Maximum Marks
No.
1. Worksheet completion including 10
writinglearning
objectives/Outcomes.(To besubmitted
at the end of the day)
2. Post Lab Quiz Result. 5
3. Student Engagement in 5
Simulation/Demonstration/Performance
and Controls/Pre-Lab Questions.
Signature of Faculty (with Date): Total Marks Obtained: 20

You might also like