Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

First the code makes that the system waits 3 second before start the system and it indicates

that
you can send the number ‘’0’’ to stop the process and later it will show that you can send the
number ‘’1’’ to restart the process. After the showing information this code calls the functions ‘’
openGateBelt1’’ and ‘’ openGateBelt2’’ to open the belt’s gates before start the process to avoid
problems and make this code like a loop or with a good cycle, after that it calls the ‘’startMotor’’
function to start the conveyor’s motor.

Then the code will fall into an infinite loop, and here is where is everything, because here is the
infinite cycle of the process. Here the code is constantly asking information from the user using
this function ‘’r = getchar’’ and saving this information in the ‘’r’’ variable, then, the variable ‘’r’’
where the user’s information is will be constantly evaluated using a ‘’if’’ condition. In the ‘’r’’
variable is where the number ‘’1’’ or ‘’0’’ received from the user will be saved and evaluated to
proceed to execute the action to stop the process or restart the process. This is to make a good
flow and cyclically code. After the line ‘’r = getchar();’’ , ‘’ if (r == '0')’’ and ‘’ if (r == '1')’’
(conditionals) you can see the functions ‘’ioctl’’ using in its argument two types of options, this
function and these options are good explained its functions in the file ‘’cinterface.pdf’’ on the page
2 and 3. Inside of this ‘’if (r == '0')’’ condition you can see the how the stop process is and inside of
‘’if (r == '1')’’ condition you can see how the restart process is. You can see in the stop process that
many timers and variables are reset and in the final of these process the variable ‘’r’’ is set in other
value to prevent reenter in these conditions.

After the conditions’ evaluations comes the ‘’stop’’ condition to control the total process, because
the variable ‘’stop’’ is set and unset in the conditions before mentioned, variable that can be
changed by the user. And inside of the ‘’stop’’ condition there are the two most important
functions of this code ‘’ ConveyerBelt1()’’ and ‘’ ConveyerBelt2()’’ these functions are the
responsible of the constantly process evaluation, the reading sensors, the timers and the counting
of the blocks.

Functions ‘’ConveyerBelt1()’’ and ‘’ConveyerBelt2()’’ have the same logic, they first read the size
sensor using this function ‘’readSizeSensors(N)’’, remember in its argument, in this case N, you
can choose 0 or 1 and this indicates the number of sensor. After the function get the size of the
block it will be evaluated using the conditional ‘’switch’’ and in this way you can have many case,
in this case, case 0: no object, case 1: an object in front of the first sensor (Small Block), case 2: an
object in front of the second sensor (Small Block) and case 3: An object in front of both sensors
(Large Block). In every of these cases is activated a timer and flags to determinate if the block
arrives or not and in this way, using timers, the flow code could continue and the functions
‘’ConveyerBelt1()’’ and ‘’ConveyerBelt2()’’ can work in parallel at the same time, because if one
case is activated this task can be constantly evaluated and temporized and the flow code can
continue to the cases of the other function and both functions are evaluated constantly thanks to
the use of timers.

Thanks to the work of the timers these two function can be evaluated at the same time and the
flow code can continue to ask for the user if the he/she wants stop or restart the process, even in
middle of the process, if not, the flow code continue evaluating the two most important functions
in the infinite loop.
Functions ‘’ closeGateBelt1’’, ‘’ closeGateBelt2’’, ‘’ openGateBelt1’’ and ‘’ openGateBelt2’’ these
functions work synchronically because when one gate is closed the other is open, when one gate is
open the other is closed or both closed. ‘’setGates(N)’’ is the important function inside of these
functions, because it coordinates the doors in a way to avoid problems, in its argument, in this
case N, you should put the value to get the best combination for your process. This function is
explained in the page 2 of the file ‘’cinterface.pdf’’

You might also like