You are on page 1of 8

Project2

LinetrackingRojobot
ECE540SystemonchipdesignwithFPGAs

ArtiKalkoteandMuralidharTirupati

Introduction:
ThisprojectbuildsontheRojoBotconceptsintroducedintheProject1byplacingthe
RojoBotinavirtualworld.
Rojobotissupposedtotracktheblacklineinitsvirtualworld.Wehave
toprogramtheVGAcontrollerandwritetheblacklinetracingalgorithminPicoblazeassembly
language.
TheRojoBotanditsworldaresimulatedinanIP(intellectualproperty)blockcalled
BotSim(bot.v).BotSimisaSoCdesigninitsownrightcontainingaXilinxPicoblaze,firmware
inprogrammemoryandlogictomanageitsinterface.

TheBotSimmodulereceivesinstructionsthatcontroltheRojoBotwheelmotorsthrough
awritable8bitMotorControlInputregister.TheBotSimprovidesinformationaboutits
virtualenvironmentthroughasetofreadonly8bitregisters.Theseregistersindicatethe
RojoBotlocation,orientation(heading),directionofmovementandthevaluesofitsproximity
andlinetrackingsensors.

Functionalspecificationsandtheoryofoperationsofthebotwas
providedbytheprofessor.

Figure1:Highlevelblockdigramofrojobotcontroller

Nexys4fpga_bot_if.v:
BotSim, sevensegment display and push button inputs are configuredwith kcpsm6using
this module. The interfacing is as shown in the figure 2. Table 1providestheinformationabout
inputandoutputportsofkcpsm6usedinthisinterfacing.


Figure2:BotSiminterfacingwithkcpsm6
Table1:Input/outputportsconfigurationofkcpsm6
PortName
PA_PBTNS
PA_SLSWTCH
PA_SLSWTCH150
8
PA_LEDS
PA_DIG3
PA_DIG2

Port
Address
00
01
11

Input/Outputto
kcpsm6
Input
Input
Input

PortDescription
Pushbuttonsinput
Slideswitches[7:0]
Slideswitches[15:8]

02
03
04

Output
Output
Output

LEDs[7:0]
Sevensegmentdisplaydigits.Display
rojobotYcoordinatelocation

PA_DIG1
PA_DIG0
PA_DIG7
PA_DIG6
PA_DIG5
PA_DIG4

05
06
13
14
15
16

Output
Output
Output
Output
Output
Output

PA_DP
PA_DP0704
PA_MOTCTL_IN

07
17
09

Output
Output
Output

PA_LOCX
PA_LOCY
PA_BOTINFO

0A
0B
0C

Input
Input
Input

PA_SENSORS
PA_LMDIST
PA_RMDIST

0D
0E
0F

Input
Input
Input

Sevensegmentdisplaydigits.Display
rojobotXcoordinatelocation
Sevensegmentdisplaydigits.Display
rojobotorientation.
Sevensegmentdisplaydigits.Display
rojobotmovement.
Decimalpoints[3:0]
decimalpoints[7:4]
Rojobotmotorcontroloutputfrom
system
Xcoordinateofrojobotlocation
Ycoordinateofrojobotlocation
Rojobotorientationandmovement
register
Blacklineandobstaclesensorregister
Rojobotleftmotordistance
Rojobotrightmotordistance

LeftRightTurnstatemachine:
1. INITstate:Botisstopped.BotheadingisstoredinSP_OLDHDG.Nextstateisonlinestate.
2. ONLINE state: Reset turn counter SP_LRCNTR if the bot moved three locations in the
online state. Bot heading is stored in the SP_OLDHDG register. Bot remains in the online
state until the bot isonblackline.Botgoestoblocked stateifit finds wallinfrontofit.Next
stateisrev2linestateifthebotisofftheblackline.
3. BLOCKEDstate:Thebotisstoppedifitfaceswallinfrontofit.
4. REV2LINE state: The bot is offtheblackline.Thebotmovesinareversedirection.Thebot
remains in this state until it finds black line. The nextstateisturningstateoncethebotison
blackline.
o
5. TURNINGstate:Thebotturnsby45
totherightatatime.Oldheadingandthenewheading
o
of the bot is compared in this state. The bot remains inthis stateuntilitturns45
.Nextstate
isendturnstate.
6. ENDTURN state: Bot heading is stored in SP_OLDHDG. Turn counter SP_LRCNTR is
incremented. Bots previous third and next third X and Y locations are storedinscratchpad
memory (SP_locXP, SP_locXN, SP_locYP, SP_locYN). Next state is turning state if the
o
turning counter SP_LRCNTR isequalto4.Becauseafter takingfour45
turnsbotisheading
in the direction it came from. So to avoid bot going back ontherouteweturneditonemore
o
timeby45
.Thenextstateisonlinestatetocheckifthebotcanfindblackline.

To taketheleftturnBotistakingcontinuousrightturnsuntilit finds theblacklineonitsleft.


o
Toavoidthebotgoingbackontherouteweareskippingthe180
turn.

Figure3:LeftrightturnFSM
Table2:Truthtable
State

Inputcondition

Nextstate

Output

Init

Online

Stop

Online

wall/obstacle

Blocked

Forward

Online

Onblackline

Online

Forward

Online

Offblackline

Rev2line

Forward

Blocked

Reset

Init

Stop

Rev2line

Offblackline

Rev2line

Reverse

Rev2line

Onblackline

Turning

Reverse

Turning

Botnotturnedright
45

Turning

Turnright45

Turning

Botturnedright45

Endturn

Turnright45

Endturn

Botturned180

Turning

Stop

Endturn

Online

Stop

VideoController:
The video controller overlays an icon of the Bot onto a background generated from the
BotSim world map. The icon moves through the RojoBot world based on the current{X,Y}
coordinates of the Bot. These coordinates are returned by BotSim in the LocX and LocY. The
orientation (which way the Bot is pointing) is returned intheBotInforegister.Blockdiagramof
thevideocontrollerisasshowninthefigure4.

Figure4:Videocontrollerblockdiagram

DisplayTimingGenerator:

The Display Timing Generator (DTG) generates the video raster signals Vertical Sync
(vert_sync) Horizontal Sync (horiz_sync) video_on, which indicatestheviewableregionofthe
video screenandpixel_rowandpixel_column,whichindicatethecurrent verticalandhorizontal
pixel position on the display. The displayimage has480rowswith640pixels(columns) ineach
row. Each pixel consists of three colors: Red, Green, and Blue. The pixel information is
delivered to the monitor serially by row. The end of each row is indicated by a horizontal sync
pulse of a particular length. At the end of all 480 rows, a longer, vertical sync pulse occurs. At
the end of a horizontal sync pulse,thebeamgoesbacktopixel0ofthenextrow. At theendof a
vertical pulse, the beam goes to pixel 0 in row 0. The VGA signals redraw the entire screen 60
timespersecond.

Map:
bot.v includes logic that produces a pixel stream (world_pixel[1:0]) representing an
image of the RojobBot world. The 128 x 128 world is displayed as a 512 x 512 image on the
VGA monitor: thus implementation represents each world location as a 4 x 4pixelblockonthe
screen. Thisisdonebyrightshiftingthepixel_rowandpixel_columnbitsbytwopositionswhile
sending to bot.v. The twobitworld_pixeloutputindicatesground,obstruction,blackline,
orreservedforeachlocationonthescreen.

Icon:
Created one 2048 X 2 wide ROM to store eight icon images. The ICON.coe file is
submitted along with the report. Colors of the icon are as shown in thecolorizertable.Belowis
the16x16x2bitmapimageoftheBot.

Figure5:16X16bitmapimageoficon
Displaying Icon:
ROM requires 11 bit address to access 2048 locations. 11 bit address is
generated using LocX, LocY, vid_row, vid_col and Botinfo registers. LocX and LocY registers
are scaled according to 512X512 display (left shifted by 2 bits). Scaled values of LocX and
LocY are subtracted togettheexactlocationofthebottobedisplayedandoffsetisaddedtothis
to display the bot exact on the black line. Bot heading from BotInfo register is used to choose
thecorrecticonfromeighticonimagesstoredintheICONROM.

Colorizer:
The Colorizer module maps the two pixel streams from the Bot and Icon modules to
screen color such that the RojoBot icon appears in the foreground while the world imageforms

the background. The colorizer output is 000 (black) during the blanking interval, when the
video_onsignalfromtheDTGiszero.
Table3:ColorizerColors

World_pixel
[1:0]
00

Icon_pixel
[1:0]
00

01

00

10

00

11
xx

00
01

xx

10

xx

11

Colorcode

Color

1111_1111_111
1
0000_0000_000
0
1111_0000_000
0

0110_0110_111
1
0110_1100_000
0
1111_1001_001
1

White
Black
Red
Reserved
Iconcolor1Blue
Iconcolor2Green
Iconcolor3
Orange

ProblemsFaced:
1. While interfacing BotSim with the kcpsm6, push buttons were not working. We figured out
thatwehavetosettheRESET_POLARITY_LOWto1indebounce.v
2. There were some errors because our output pin nameswerenotmatchingwiththeconstraint
filespinnames.
3. While writing algorithm for right turn, bot traced back the pathitcamefrom.Fixedwiththe
help of a counter not to take the 4th left turn. Nowonemoreissuecameintopictureonhow
to reset this counter. Before writing this logic we thoughtwecanresetwhenbottraversethe
online_state successively two times. But It didnt work, then after manytrialsfoundanother
way to resettheleftrightcounter.Wewillresetthecounterifthe botmovesforwardandthis
isimplementedbytrackingthebotcoordinates.
4. We facedalotofissueswhiledisplayingtheiconandscalingtheicon.Firstweweremissing
the semicolon at the end of the .coe file. Second, icon was notexactlyontheline,wehadto
add one offsetwhilecalculatingourROMaddress.Atfirstouriconwasdistorted,afterlotof
trialsanderrorswehadtoadjustouriconpositioninour.coefile.

Demovideolink:
https://drive.google.com/file/d/0B4K423YyUdCJWEpZTWo0T0pWZUU/view?usp=sharing

References:
1. Project2documentationandcodefiles
2. Tbirdtaillightcodes
3. Kcpsm6userguide

You might also like