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

Private University of Tacna Alvarado.

State Machines with System Generator 1

Design of a follower of line based on State Machines


with System Generator
Alvarado Fernndez, Dilam
alvaradodilam@hotmail.com
Private University of Tacna
TECHNICAL ENGLISH COURSE

the power of the power of es more logic


Summary-The present project work is a follower of line the cycle of the the cycle of circuits
work at the level of co-simulation, using a sensor QTR-8 of 8- processor the processor
bit output (digital) which will generate 256 combinations of Intensive Resolution of Prototyping of
these combinations are discriminated against 16 combinations management computational electrical circuits
that will be given to the time to implement, these combinations of I/O tasks
will be reflected in a machine of Mealy simulated in the System Automation Management
Generator, where it will vary the PWM output to control the of Hardware
motors.
Suitable for Suitable for Focuses on the
implementatio implementatio parallel execution
Index of Terms-System Generator, follower of Line, error, n in series n in series
open loop, PWM. where the where the
speed depends speed depends
on the length on the length
I. INTRODUCTION of time the of time the
In the competitions of followers of line, the importance is instruction instruction
the response time of the micro-controllers that is used, use Alarm 16Mhz 700MHz 25,50,100MHz
an Arduino is very different than using a FPGA, to Clock clock
understand this concept compares the main plates in the Table1."Different technologies for development"
following table:
As summarized in the table above each technology has its
Arduino Raspberry FPGA own application, advantages and disadvantages. In the
The AVR Micro ARM Simulates various course of this work will be carried out in a FPGA-Basys2
micro processor processor due to its characteristics of response.
controller architectures
(AVR,ARM, II. ALGORITHM
INTEL, etc). A. Finite state machine (FSM)
Accepts You get to run There are fpga with
The FSM is a methodology of control systems that
programs up to operating different
describes the behavior of a system using 3 aspects, state,
32KB systems characteristics.
event and action. An any moment the system is active in
Open Open Altera, Cyclone,
a state and then you could move on to the next state. These
Hardware Hardware Etc.
transitional states are generally accompanied by actions
Programming i Supports Programming in
that respond to the entries.
n C/C++ several VHDL
programming
languages
Time-limited Time-limited Space-limited
The The To further
implementatio implementatio development requir
n depends on n depends on

Electronic circuits IV
Private University of Tacna Alvarado. State Machines with System Generator 2

To understand how obtain these arrays, following this


example we have an entry "X" and two outputs:
Unlock: will be 1 if and only if the sequence is "0110111"
Hint: Change to 1 if progress is made of state

Fig.1" simple state machine "

As can be seen in Figure 1 is a basic example of a state


machine, has 2 states (State0 and State1), 2 input (Event0
and event1), 4 outputs (Action 1, 2, 3, 4).As can be seen
when the system starts. We are in the state 0 and
according to the input can be a loop by using the action 1 Table 2."Example of Mealy State Machine"
and remain in state 0, 1, or move on to the state through As we can see in table 2 , in the first case, we are in the
the event 1 and performing the action 2. state 0 , if x is 0 the bit of Hint is one indicating that
B. FSM in System Generator advances the state 1 ,in the state 1 if x is 0 Hint not to 1
because it must be fulfilled the sequence "0110111" then
to advance to the state 2 x must be 1 , then there is if Hint
System generator we have two blocks of state machine
to 1.and so on until the state 7 , when you arrive at the
Mealy and Moore.In our development we will use the
state 7 bit Unlock from 0 to 1 meaning that it came to the
machine of mealy as their outputs depend on the current
last state.
status and inputs and unlike Moore that the output
depends only on the current state.
To be able to perform the arrays, see table 3 where they
are grouped in two arrays one of the next state where the
rows of matrices correspond to the current state and the
columns corresponds to the input values. And outputs
will be placed to the side of another but not in binary but
in decimal values.
Fig.2"Machines Of Mealy and Moore in System
Generator"
In Figure 2 we observe the machine of Mealy that has 1
input and two outputs.But at the time of the implement the
block, it ask us 2 arrays (Next State matrix and output
matrix).See figure 3.

Table 3 "Generation of arrays for the Mealy State


Machine"

Fig.3"Parameters of Mealy State Machine"

Electronic circuits IV
Private University of Tacna Alvarado. State Machines with System Generator 3

III. DESIGN OF THE STATE MACHINE We present the table of all possible combinations that will
To begin to work we must clarify that all will work in co- exist with the 8 sensors.
simulation mode we will have as an 8-bit digital sensor QTR-8A Infrared Sensor (inputs)
where 1 means that you are on a black surface and 0 that S1 S2 S3 S4 S5 S6 S7 S8
is on a white surface, as we will have 2 signals
PWM that Iran to the motors.

Left OUTMotor
IN (0:7)Digital
Sensors
State Machine

OUTMotor
Right

Fig.4"Inputs and outputs of the system"


Taking 8-bit input these generate 256 combinations but in
a follower of line will not be used at all as for example
never will have some combinations. See figure 5.

Everything OFF = stop or end of line


Indeterminate state => FORWARD TO 20 %
Table 4 "Combinations of 1 ,2,3 sensors , activated
sensors by the black line"

Fig.5"Combinations that you will never be able to give a The painted boxes are the sensors that will be within the
real follower" black line, for 1 sensor active means that the robot is on
For this reason there are combinations that shall not be the verge of derailed and go on the other hand the opposite
taken into account we will proceed to identify only the motor PWM output must be greater to return to the
possible combinations that will exist, it can be said that in environment and be able to correct that error.
the skills of this type of robot the line to follow is 2.00 +/- When the sensors S4 and S5 are enabled (high value 5v)
0.05 cm which in our 3 sensors sensor cover exactly, but means that the robot is in the middle will come to be our
for practical values will be taken into account set point, it's almost impossible to always be in that
combinations 2 sensors. position as in the test tracks are full of curves, were also
taken into account 3 combinations of activated sensors ,
this in practice is when the robot makes closed curves to
make these curves the robot is placed with an inclination
of 45 and 3 sensors fit into these 2 cm, you can also take
into account that 4 sensors are activated, but was not taken
into account in the work that would have to be extremely
curves Closed and according to the rules of only 45
curves.
Fig.6"Size of the regulatory black line is 2 cm aprox." Then once defined the combinations are defined the states
that will be the same, more 2 states that will be: When any
sensor is activated and when for some reason is to
generate another combination that don't take into
account. See Table 5.

Electronic circuits IV
Private University of Tacna Alvarado. State Machines with System Generator 4

13 State 80 20 114
14 State 70 10 97
Decimal value 15 State 0 0 0
Input Column State 16 State 30 30 51
B-00000001 1 State 0
B-00000011 3 State 1 Table 6 "PWM outputs the system"
B-00000110 6 State 2 In table 6 we define the PWM signal in percentage values
B-00001100 12 State 3 and also we have a column which speaks to us of the
B-00011000 24 State 4 output values, these values are for the array that asks us to
block Melay State Machine.
B-00110000 48 State 5 The outlet of the machine of Mealy will be defined
B-01100000 96 State 6 according to the 10 types of speeds, but at the exit of the
B-11000000 192 State 7 block of Mealy we will have only a decimal number and
B-10000000 128 State 8 we need to divide it in some way to control the two motors
B-11100000 224 State 9 in a different way, we have the solution to divide this
number with the blocks "Slice" that allow us to separate
B-01110000 112 10 State
the most significant bits (MSB) and the less
B-00111000 56 11 State significant (LSB) With this we give solution to the
B-00011100 28 12 State problem.
B-00001110 14 13 State
B-00000111 7 14 State
B-00000000 0 15 State
Other Another 16 State

Table 5 "Number of existing states"

Now that we have the States need to have the Fig.7"Block Slice that separates MSB to LSB"
corresponding outputs, we define 10 types of PWM
outputs where only the size of the pulse, we do this Now How many bits do we need? Although for 10 types
because there are cases such as the state 0 where the robot of speeds we may use 4-bit that gives us the possibility of
is about to get out of the black line, then you need greater 16 speeds but as we are separating the most significant
speed in the opposite direction. bits and 2-bit would be less significant for each engine
which gives us only 4 speeds for each one, given the
Output clarification we need 4-bit but for each one that makes a
Outputs (%) Values total of 8 bits.
United Engine Left Engine Right Matrix Value Vel. % # Of Speed Binary
State 0 60 20 82 0 0 B-0000
State 1 70 40 116 10 1 B-0001
State 2 90 60 133 20 2 B-0010
State 3 100 80 151 30 3 B-0011
State 4 100 100 153 40 4 B-0100
State 5 80 100 121 60 5 B-0101
State 6 60 90 88 70 6 B-0110
State 7 40 70 70 80 7 B-0111
State 8 20 60 37 90 8 B-1000
State 9 20 70 38 100 9 B-1001
10 State 30 80 55
11 State 40 90 72 Table 7 "Summary of Velocity"
12 State 90 40 132

Electronic circuits IV
Private University of Tacna Alvarado. State Machines with System Generator 5

Now as the Mealy gives us output values of output in IV. FINAL RESULT
decimal we need to find the speed in decimal to place it in
the output array.
E.j. In the state 4 the two engines have to run to the 100%
that means that the number of speed will be 9 and 1001 is
represented in binary.

Engine Left Engine Right Decimal output


1001 1001 10011001 is
MSB LSB equal to 153

As the output of the block is a single number and only we


split into two to handle the two engines. In the output
array we must put the decimal number.
Fig.8"End Result of the machine"
With this information only put the coefficients to the
Mealy.

Array of states:
[15 116 016 162 1616 1416 1613 163 1616 1616 1616 164 1616
1612 1616 1616 1616 1616 1616 1616 1616 1616 1616 1616
1616 165 1616 1616 1616 1611 1616 1616 1616 1616 1616
1616 1616 1616 1616 1616 1616 1616 1616 1616 1616 1616
1616 1616 1616 166 1616 1616 1616 1616 1616 1616 1616
1610 1616 1616 16 16 16 16 16 16 16 16 16 16 16 16 816 1616
1616 1616 1616 1616 1616 1616 1616 1616 1616 1616 1616
1616 1616 1616 1616 1616 1616 1616 1616 1616 1616 1616
1616 1616 1616 1616 1616 1616 1616 167 1616 1616 1616
1616 1616 1616 1616 1616 1616 1616 1616 1616 1616 1616
1616 169 1616 1616 1616 1616 1616 1616 16 16 16 16 16 16
16 16 16 16 16 16 16 16 16 16 16 ;

Output Array:
[51 082 133 116 9751 5151 5151 114 151 51 51 51 51 51 51 51
51 51 51 51 51 51 51 132 153 5151 5151 5151 5151 5151 5151
5151 5151 5151 5151 121 51 51 72 51 51 51 51 51 51 51 51 51 Fig.9"End Result of the machine,Simulation"
51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51
51 51 51 51 51 51 51 51 51 51 51 88 51 51 51 51 51 51 51 51
It was tested with a value entry the 56 that seeing the table
51 51 51 51 51 51 51 51 51 55 51 51 51 51 51 51 51 51 51 51
51 51 51 51 51 51 51 37 51 51 51 51 51 51 51 51 51 51 51 51 would be in the state 56 and would have an output of 40
51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 and 90 % , it was confirmed at the time to simulate.
51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51
51 51 51 51 51 51 51 70 51 51 51 51 51 51 51 51 51 51 51 51
51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51
51 51 38 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51
51 51 51 51 51 51 51 51 51 51 51 51 51 51;

These values are only for the first state but if we realize
the following states will have the same number of values,
therefore it is the same for the 16 states.

Electronic circuits IV
Private University of Tacna Alvarado. State Machines with System Generator 6

V. RECOMMENDATIONS AND CONCLUSIONS


If you want to change of sensor and use more
entries, will raise the number of bits and the
number of combinations, but you should be
careful with the number of combinations as these
do not represent the number of states, the number
of States represents the combinations than
physically possible as explained above and all the
others are discarded.
While the block Mealy State Machine changes
the logic with which it is working normally, it is
easy to understand. Add the values of state and
output is really tedious and very easy to mistake
you have 256 values, the values multiplied by the
16 states.
In subsequent work you can add controls PID for
the best response to level of actuators.
There are analog sensors QTR-8 that we not only
deliver analog, digital values but these are much
more precise.

VI. BIBLIOGRAPHY
IEEE Xplore Digital Library - Design and
Implementation of PID Control-based
Wsf Algorithm on Line Following Robot. Adnan
Rafi al Tahtawi, Yoyo Haritman Somantri, Erik.
Xilinx System Generator v2.1 for Simulink

Electronic circuits IV

You might also like