This document discusses problem solving in robotics and automation using Matlab. It covers the description of the problem, description of the robot, algorithm of creating robot, and Mat Lab code. The document also includes a table of contents and references.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
Problem solving – Part A 1
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
Table of Contents 1.Introduction...................................................................................................................................2 2.Description of the Problem............................................................................................................3 3.Description of the Robot................................................................................................................3 4.Algorithm of Creating Robot.........................................................................................................3 5.Mat Lab Code................................................................................................................................4 6.Conclusion...................................................................................................................................12 References...........................................................................................................................................12 2
1.Introduction Robotics and automation can be done effectively through the software. Among the software available, Matlab is a widely used software environment for research and teaching applications. Matlab is a powerful linear algebra tool, with a very good collection of toolboxes that extend Matlab basic functionality, and as it is an interactive open environment. 2.Description of the Problem The problem is described as the robots to be placed in a hollow shape. The counts of 14 robots are chosen which has to be correctly placed in the hollow shape. 3.Description of the Robot The project describes an arrangement of a robot swarm. The robots get same input, but a desired configuration steers into wall friction.Along the surface of the walls the robots experience infinite friction(KK and S, 2016).There is a rectangular workspace is created from the code enclosed by four walls. Five steps iteration is performed that isolate one robot from the swarm. “Drift-movements” are applied to the whole swarm. Only the isolated robot experiences a different net movement as it touches a wall.Two regions are created in the workspace: a.Initialization of the robot in this zone – Staging Zone b.Goal configuration of robot is in this zone – Build Zone Colour disks are represented for robots. Black colour represents the boundary and grey colour represents the final locations. A hollow shape is formed with a default arrangement of 14 robots. The code is run with no arguments. Arguments are defined as below:Pos Goal: desired final position is represented of robots in a 2D matrix (grey). X axis position is given in Column 1, y axis position is given in Column 2.PosObstacles: position of obstacles are represented in a 2D matrix (black) given.Column 1- x axis position, Column 2- y axis positionPosCurrent: This describes the current location of all robots. Column 1 – x axis position, Column 2- y axis position, Column 3 – index, Column 4 - colorMake_Movie: A small video called is saved in the current MATLAB directory.Returnvalue: total number of movements applied to the swarm. 3
4.Algorithm of Creating Robot The robots are arranged in such a way that they are numbered and the bottom-most robot is ‘1’. The arrangement is made in ascending order row-wise (Peymany, 2010). Corresponding final locations on the robots are numbered based on descending order of y coordinate as first priority and descending x coordinate as second priority.For each of the N robots the algorithm is run once.At the beginning, robots 1 to K-1 are in their goal positions for Kth step and robots K to N are in their initial positions. Steps 1 to 5 are implemented for the Kth iteration: Step 1: The robots are moved to the left and down until kth robot touches the bottom boundary. Step 2: Until the kth robot reaches left wall,apply a “drift-move” left. Step 3: apply a “drift-move” up until Kth robot reaches its final y position. Step 4: For Kth robot to be in correct position move all robots left relative to robots 1 to K-1. Then move all robots right until the Kth robot’s x position is at its goal position. Step 5: Until the Kth robot’s y position reaches its goal position move the robot up. Final position is reached by robots 1 to K. And robots from K+1 to N have returned to the staging zone. 5.Mat Lab Code functiontotalMoves = robotsDiscrete(User_PosGoal,User_PosObstacles) totalMoves=0; closeall; clc; pauseTs = 0.01; clc formatcompact globalG MOVIE_NAME ='Friction_bots';%to make a movie 'Friction_bots.mp4' G.fig = figure(1); clf writerObj = VideoWriter(MOVIE_NAME,'MPEG- 4');%http://www.mathworks.com/help/matlab/ref/videowriterclass.html set(writerObj,'Quality',100); 4
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
writerObj.FrameRate=30; open(writerObj); functionmakemymovie()% each frame has to be added. So a function is made and called whenever an image needs to be added figure(G.fig) F = getframe; writeVideo(writerObj,F.cdata); % writeVideo(writerObj,F.cdata); end switchnargin case2 [PosGoal,G.PosObstacles,PosCurrent] = SetupWorld(User_PosGoal,User_PosObstacles); otherwise [PosGoal,G.PosObstacles,PosCurrent] = SetupWorld(); end G.EMPTY = 0; G.OBST = 1; G.maxX = size(G. PosObstacles,2); G.maxY = size(G. PosObstacles,1); %create vector of robots and draw them. A robot vector consists of an xy %position, an index number, and a color. numRobots = size(PosCurrent,1); figure(1) clf G.colormap = [ 1,1,1;%Empty = white 0,0,0;%obstacle 0.5,0.5,0.5; ]; colormap(G.colormap(1:numel(unique(G. PosObstacles)),:)); G.axis=imagesc(G. PosObstacles); set(gca,'box','off','xTick',[],'ytick',[],'ydir','normal','Visible','off'); axisequal holdon 5
G.hRobots = zeros(1, numRobots); colors = jet(numel(unique(PosCurrent(:,4)))+1); forhi = 1: numRobots G.hRobots(hi) = rectangle('Position',[PosCurrent(hi,1)-1/2,PosCurrent(hi,2)- 1/2,1,1],'Curvature',[1,1],'FaceColor',colors(PosCurrent(hi,4),:)); end %%%%%%%automatic code moveto('a');moveto('d');%Null moves to ensure the first frame is drawn count=1;%index of k'th robot extramove=0;% used to execute the step 1 and 5 for robots placed in different heights. Flag3=0 ;%Signals the completion of the algorithm whileFlag3~=1 forj=1:size(PosCurrent(1,:)) %step 1, move left and down makemymovie() moveto('a') moveto('x') moveto('x') PosCurrent=sortrows(PosCurrent,3); fori3=1:PosCurrent(count,2)-2%additional down movement untill desired robot touches the bottom boundary moveto('x') ifPosCurrent(count,2)~=2 extramove=extramove+1;%counting the number of extra down movement elseifPosCurrent(count,2)==2 break end end %end of step 1 Flag1=0 ;%step 2, Left drift move whileFlag1~=1 moveto('w'); moveto('a'); moveto('x'); 6
moveto('d'); wq=PosCurrent(:,:); wq=sortrows(wq,3);%has current position of robots ifwq(count,1)==3 Flag1=1; end end % end of step 2 ,left drift move % moving the robots a point up so that only k'th robot is allowed to drift move up. moveto('w'); % moving the robots left to put k'th robot on left wall moveto('a'); %step 3 starts. the up drift of k'th robot starts Flag2=0; whileFlag2~=1 moveto('d'); moveto('w'); wq=PosCurrent(:,:); wq=sortrows(wq,3); ifwq(count,2)== PosGoal(count,2)-extramove%checking if robot has reached required relative position Flag2=1; continue end moveto('a'); moveto('x'); end %updrift ends %Step 4 :start of movement of all robots to relative x position wrt k'th robot foric=1:PosGoal(count,1)-3 moveto('a') end %moving to k'th robot's final position foric=1:PosGoal(count,1)-2 7
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
moveto('d') end end b=size(PosGoal); ifcount==b(1) Flag3=1; end count=count+1; moveto('a') foric2=1:extramove moveto('w')% step 5:applying the correction motion of up movement by the same unit of extra move that was done in step 1 extramove=0; end moveto('d') foriin=1:20 makemymovie() end pause(pauseTs); end ifFlag3==1 forim=1:20 makemymovie() end end functionretVal = frictionOK(stVal, step, G) frictionBad = (stVal(2)==2 && step(2) <1 )...%friction if on bottom row and not trying to move up || (stVal(1) == G.maxX-1 && step(1) >-1)...%friction if on right wall and not trying to move left ||(stVal(2)==G.maxY-1 && step(2) >-1 )...%friction if on top wall and not trying to move down ||(stVal(1)==2 && step(1) <1 );%friction if on left wall and not trying to move right retVal = ~frictionBad; 8
end functionretVal = spaceFreeWithNoRobot(desVal, PosCurrent, G) % move there if no robot in the way and space is free retVal = ~ismember(desVal,PosCurrent(:,1:2),'rows')... && desVal(1) >0 && desVal(1) <= G.maxX && desVal(2) >0 && desVal(2) <= G.maxY... %check that we are not hitting the boundary && G. PosObstacles( desVal(2),desVal(1) )~=1;%check we are not hitting the obstacle end functionmoveto(Direction) totalMoves=totalMoves+1; % Maps key to moving pixels ifstrcmp(Direction,'a')%-x PosCurrent = sortrows(PosCurrent,1); step = -[1,0]; elseifstrcmp(Direction,'d')%+x PosCurrent = sortrows(PosCurrent,-1); step = [1,0]; elseifstrcmp(Direction,'w')%+y PosCurrent = sortrows(PosCurrent,-2); step = [0,1]; elseifstrcmp(Direction,'x')%-y PosCurrent = sortrows(PosCurrent,2); step = -[0,1]; end % implement the move on every robot forni = 1:size(PosCurrent,1) stVal = PosCurrent(ni,1:2); desVal = PosCurrent(ni,1:2)+step; % move there if no robot in the way and space is free ifspaceFreeWithNoRobot(desVal, PosCurrent, G) && frictionOK(stVal, step, G) PosCurrent(ni,1:2) = desVal; end %redraw the robot if~isequal( stVal, PosCurrent(ni,1:2) ) 9
map(ObstacleExtra(:,1),ObstacleExtra(:,2))=1; fori=1:d(1,1) fori2=1:d(1,2) ifmap(i,i2)==2 map(i,i2)=0; end end end fori=1:q map(Goalmap(i,2),Goalmap(i,1))=2; end otherwise numrobots =14; count1=1; fori=1:d(1,1) fori2=1:d(1,2) ifmap(i,i2)==2 Q1(count1,2)=i;%#ok<AGROW> Q1(count1,1)=i2;%#ok<AGROW> count1=count1+1; end end end Goalmap=sortrows(Q1,[-1 -2]); end pos = zeros(numrobots,2); %place robots on defined location in the staging zone away from obstacles and not overlapping fori=1:numrobots pos(i,:) = [5+i-4*floor((i-1)/4), floor((i-1)/4)+3]; end PosCurrent = [pos,(1:numrobots)',(1:numrobots)']; end 11
end Output 6.Conclusion The path of any robot can be simplified by reducing the complex tasks of robotic path through planning. The algorithm clearly mentions the step-by-step procedure for further implementation.ThefinalresultsareobtainedthroughsimulationusingMATLAB/ Simulink. 12
References KK, V. and S, S. (2016). Industry Monitoring Robot using Arduino Uno with Matlab Interface.Advances in Robotics & Automation, 05(02). Peymany, M. (2010). Matlab Code for Brownian Motion Simulation (Brownian Motion, Brownian Motion with Drift, Geometric Brownian Motion and Brownian Bridge).SSRN Electronic Journal. 13