Professional Documents
Culture Documents
Introduction
The aim of this project was very straightforward to build a robot that could solve a maze made up
of blue lines on a 5x7 grid and then find the most efficient way back to the starting point. Many
factors had to be considered while working on this project; the key ones being the mechanical
design of the robot, i.e. choosing between either a fixed light sensor, a light sensor attached to a
crank slider mechanism or a light sensor moving in a circular arc and the software corresponding to
each type design. Designing a dynamic system that would keep track of the robots position and
orientation was another challenge of this project.
Overview
The Hardware
There werent many constraints placed on the mechanical aspect of this project. There were simple
requirements the robot must keep track of the blue line efficiently as well as move along the maze
and make turns with precision. Another design aspect that we kept in mind was having a very small
turning radius so that the robot would turn right on the spot and hence eliminate the chances of its
position changing while it turned. The most important part of the mechanical structure was the light
sensor and the mechanism responsible for its movement. Table 1 explains briefly the options we
had to choose from:
Mechanism
Fixed Light Sensor
Description
Just like the name says, the light sensor is fixed in one position and is
not moved through the course of the maze.
Crank Slider Mechanism
A crank slider mechanism converts rotational motion of the servos to
linear motion the light sensor oscillates in a horizontal line.
Rotational Motion
The light sensor is directly connected to the motor via beams and the
sensor then oscillates in a circular arc
Table 1 Summary of the three different mechanisms available
Table 2 summarises the considerations that were made before taking a decision. We abandoned the
idea of a fixed light sensor as it would have been very inefficient and time consuming to get the
robot to check the sides at every vertex. We chose the crank slider over the rotational motion as
there would certainly be less error associated with it and it worked perfectly with the software ideas
we had in mind.
The precision aspect was taken care of by using gears to step down the default gear ratio of the
servos and thus reduce the error associated with the motor encoder values.
2
Mechanism Fixed Light Sensor
Type
The bad
Not very efficient the
robot needs to turn
right and left at every
node to check for
availability of turns.
The good
Rotational motion
The Software
The software was the larger chunk of work for this project. The following list outlines the objectives that
the software aimed to accomplish:
1.
2.
3.
4.
5.
6.
HARDWARE
The wheels and gear ratios
4
The red circle shows the light sensor and the orange one shows the motor. The blue line runs along
the LT Steering gear this part connects the servo and the light sensor and helps convert rotational
motion to linear motion. The green line shows the range through which the light sensor moves. The
beams that surround the central mechanism give strength to the structure and help support the
light sensor while not causing any obstruction to its movement at the same time. Image 3 shows a
side view of this structure.
The biggest advantage of this design
was its range. Due to the large
range, the light sensor could easily
cover both sides of the blue line and
thus give accurate information
relating to the availability of turns.
The flaw that came with this design
was the fact that the constant
motion of the light sensor caused
slight jerks to the entire robot
causing it to drift of path a little.
5
The robot could not move along a straight line for a given cell block but besides that, there were no
noticeable faults.
Overall, the structure served its purpose. It could very well move along the maze and get light
sensor data efficiently from both sides of the line. Good software to accompany this design would
ensure that it solved the maze. The following images show the robot from several different angles.
SOFTWARE
Global variables
Table 3 displays all the global variables that were used in the software
Variable Name
orientation
xPos
yPos
targetX
targetY
originX
originY
leftPower
rightPower
adjustPower
crankPower
maze
Data Type
Int
Description
0-N, 1-E, 2-S, 3-W keeps track of direction the
robot is facing
Int
Current x-coordinate of the robot w.r.t. the origin
Int
Current y-coordinate of the robot w.r.t. the origin
Int
Target x-coordinate of the robot w.r.t. the origin
Int
Target y-coordinate of the robot w.r.t. the origin
Int
x-coordinate of the starting point
Int
y-coordinate of the starting point
Int
Speed for the left motor
Int
Speed for the right motor
Int
Speed added to the motor speeds for adjustment
Int
Speed for the crank-slider motor
6x8 array (int*)
Matrix that stores information about each vertex
Table 3 List of the global variables used by the program
The Functions
task main
7
start. Figure 1 (previous page) shows a flowchart outlining this function.
This function uses the xPos, yPos and xTarget, yTarget global variables to check whether the robot
has reached the end of the maze. The functions it calls make use of other global variables. This task
main function does not take any arguments and does not return any value.
readSensor
The purpose of this function is to take readings from the light sensor at 3 different points the
middle, the left and the right of the blue line and then store than information in three separate
arrays. Following the analysis, it calls another function which returns an integer. readSensor then
returns that int.
One key thing to note about this function is that it depends on the light sensor being in the same
position everytime the function is called. Hence resetCrank is called at the beginning.
A lightSensor value greater than 35 indicates a white surface and that less than 33 indicates the blue
tape. Note that three ranges that are part of the conditional statements all specify three positions
of the crank the middle, the left and the right.
If more than 2/3s of an array suggests the presence of the tape, the tape is assumed to be present.
This function does not take any argumets. Fig. 2 shows the flowchart for readSensor.
resetCrank
This function was designed in order to help the readSensor function. resetCrank merely takes the
light sensor back to the starting position. This function takes an argument that is the current
position of the light sensor based on which it calculates the required movement. Fig. 3 shows the
flowchart for the resetCrank function. The only factor affected on a global scale is the change in
speeds of the crank.
combination
storeSideData
The function sotreSideData does exactly what its name suggests. Based on the orientation, the sides of
the robot can either be East/West or North/South. This function checks that and then stores the
information in the maze array for the structure corresponding to the current xPos and yPos.
storeSideData takes an integer (a combination) as its argument and it makes changes to the global
variable maze. Fig 5. shows the flowchart for this function.
storeForwardData
This function is very similar to the storeSideData function. What is diferent is the fact that it stores
data for the forward/backward directions. Again, the function takes an integer (a combination) as
the argument and it causes changes to elements of the global variable maze. Fig 6. (next page)
shows the flowchart for the storeForwardData function.
10
visitedAndGoodDirection
deleteDeadEnds
directionPriorities
11
12
goBackToStart
goBackToStart takes the robot back to the start point of the maze. It does this by making use of the
goodDirection stored for each vertex the robot visited. When run in a loop, this function traces back
to the beginning of the maze. The global variables targetX and targetY are changed to originX and
originY and the orientation, xPos and yPos are updated as the robot moves along the maze. Fig 10.
shows the flowchart for this function.
adjustment
This function is used within the goFwd function to try and keep the robot on the blue line when it
moves straight. On a global scale, this function affects the speeds of the left and right motors and
thus also affects the corresponding encoders. Fig 11 (next page) shows the flowchart for this
function. This function accepts an integer as its argument the integer represents the current
encoder value of the crank.
13
goFwd
14
goFwd2
This version of the goFwd function is used while returning to the starting position. Unlike the first
one, this function does not make any additional stops besides at the vertex itself. It affects the same
variables as goFwd on a global scale xPos and yPos along with motor encoders. A flowchart is
shown in Fig 13. for this function.
turnLeft
The function does what its name says. At the same time, it updates the orientation. It does not
affect any other global variables. Figure 14 shows the flowchart for this function.
15
turnRight
This function works pretty much the same way as the turnLeft function. The only difference is in the
way of updating the orientation. Figure shows the flowchart this function.
(Lego Digital Designer was used to obtain images of the robot. http://www.LucidChart.com was used for
the flowcharts)