The simulator allows us to understand the different movements that a differential robot can make, this simulator generates different routines that allow us to observe the movement but in the same way routines are generated with obstacles to collect randomly, simulating the challenges to which a robot can face.
The robot simulation project is divided into two parts:
The first part is the simulation working without any obstacles and the second part is the simulation of the robot working with an obstacle that it will have to pick up.
The first part is the simulation working without any obstacles and the second part is the simulation of the robot working with an obstacle that it will have to pick up.
Part 1
Part 1
In this section, the scenario with which you will be working throughout the different challenges is created.
In[]:=
drawState[arena_Rectangle,robotPosition:{_,_}]:=Graphics[{FaceForm[Transparent],EdgeForm[Red],arena,PointSize[.05],Point[robotPosition],PointSize[0.03],}]computeNextMove[{x_,y_}]:=Module[{}, {x+1,y}]
Simulating a line movement
Simulating a line movement
This section the robot performs a linear movement.
In[]:=
startingPosition={0,25};positionsOverTime=NestList[computeNextMove,startingPosition,100];arena=Rectangle[{0,0},{100,50}];drawState[arena,startingPosition];drawings=Map[drawState[arena,#]&,positionsOverTime];ListAnimate[drawings]
Out[]=
Simulating a circle movement
Simulating a circle movement
This section simulates the movement of the robot along a circle.
In[]:=
startingPosition=50+20Sin,25-20Cos;positionsOverTime=CirclePoints[{50,25},20,300];arena=Rectangle[{0,0},{100,50}];ListAnimate[Map[drawState[arena,#]&,positionsOverTime]]
π
30
π
30
Out[]=
Using keyboard keys for movement
Using keyboard keys for movement
In this section we can control the movement of the robot with the help of the keyboard keys.
In[]:=
DynamicModule[{x=0,y=0}, Dynamic@EventHandler[ drawState[arena,{x,y}], "UpArrowKeyDown":>(If[y<50,(y+=1)]), "DownArrowKeyDown":>(If[y>0,(y-=1)]), "LeftArrowKeyDown":>(If[x>0,(x-=1)]), "RightArrowKeyDown":>(If[x<100,(x+=1)]) ]]
Out[]=
drawState[arena,{0,0}]
Part 2
Part 2
In part two of this project we will be working on the simulation of the robot but at the same time we will add an obstacle that the robot will have to pick up.
In this part, the scenario where the robot will be working is created, the obstacle is added.
In this part, the scenario where the robot will be working is created, the obstacle is added.
In[]:=
drawState[arena_Rectangle,robotPosition:{_,_},obstaclePosition:{_,_}]:=Graphics[ FaceForm[Transparent], EdgeForm[Red], arena, PointSize[.05], Point[robotPosition],PointSize[0.03],Point[obstaclePosition,VertexColors{Black,Red}]]
Simulating a line movement with an obstacle
Simulating a line movement with an obstacle
In this section the robot will be performing a linear routine and if an obstacle is found it will pick it up and continue with its linear routine.
startingPosition={0,25};obstacle={RandomInteger[100],25};positionsOverTime=NestList[computeNextMove,startingPosition,100];positionobstacle=ConstantArray[obstacle,{1}];arena=Rectangle[{0,0},{100,50}];catch=0;simulationrobot=ConstantArray[drawState[arena,startingPosition,obstacle],{1}];Do[If[positionobstacle[[i]]==positionsOverTime[[i]],(catch=i;If[i<101,AppendTo[positionobstacle,positionsOverTime[[i+1]]]]),AppendTo[positionobstacle,obstacle]];AppendTo[simulationrobot,drawState[arena,positionsOverTime[[i]],positionobstacle[[i]]]];,{i,101}];ListAnimate[simulationrobot]
Out[]=
Simulating a line movement with an obstacle to the safety area
Simulating a line movement with an obstacle to the safety area
In this part, the scenario where the robot will be working is created, the obstacle and a safe zone are added.
In[]:=
drawState[arena_Rectangle,robotPosition:{_,_},obstaclePosition:{_,_}]:=Graphics[FaceForm[White],EdgeForm[Red],arena,FaceForm[Green],EdgeForm[Red],Rectangle[{96,46},{104,54}], PointSize[.05], Point[robotPosition],PointSize[0.03],Point[obstaclePosition,VertexColors{Black,Red}],]computeNextMove[{x_,y_}]:=Module[{}, {x+1,y}]
In this part we start with a linear routine, but if the robot detects an obstacle, the robot will pick up the obstacle and take it to a safe area, it is important to clarify that the position of the obstacle is random.