Anda di halaman 1dari 26

Bluetooth Robot Controller Neven Skoro <nskoro@eagle.fgcu.edu> Mentor: Janusz Zalewski CEN !

"# Co$%uter Networks &ate Modified: Nove$'er ()t* ())# http://satnet.fgcu.edu/~nskoro

Table Of Content
1. Introduction and Overview...................................................................................................... "." +ur%ose......................................................................................................................... ".( Sco%e............................................................................................................................ "., -er$s. /cron0$s and /''reviations........................................................................... ". +ro'le$ &escri%tion..................................................................................................... ".! +ro'le$ Solution.......................................................................................................... 2. Specific Requirements.............................................................................................................. (." 1luetoot* 2e3uire$ents............................................................................................... (."." 1luetoot* Co$$unication +rotocols........................................................... (.".( 1luetoot* 4unctional 2e3uire$ents............................................................. (."., 1luetoot* Non54unctional 2e3uire$ents..................................................... (.".,." 2elia'ilit0........................................................................ (.".,.( /vaila'ilit0 ..................................................................... (.".,., Securit0............................................................................ (.". 1luetoot* Constraints................................................................................... (.( 2o'ot 2e3uire$ents..................................................................................................... (.(." 2o'ot 4unctional 2e3uire$ents................................................................... (.(.( 2o'ot Non54unctional 2e3uire$ents........................................................... (.(.(." 2elia'ilit0........................................................................ (.(.(.( /vaila'ilit0 ..................................................................... (.(.(., Securit0............................................................................ (.(., 2o'ot Constraints66666666......................................................... (.(. 2S(,( Co$$unication +rotocol................................................................. (., 7ser 8nterface 2e3uire$ents........................................................................................ (.,." S%ecific 7ser Control 2e3uire$ents............................................................ (.,.( Jo0stick Control 2e3uire$ents.................................................................... (.,., 9e0'oard Control 2e3uire$ents.................................................................. . Bac!"round Information.......................................................................................................... ,." 8ntelli1rain 1ot 8nfor$ation........................................................................................ ,.( Jo0stick 8nfor$ation.................................................................................................... #. References.................................................................................................................................. $. %ppendi&.................................................................................................................................... !." Jo0stick Code E:a$%le............................................................................................... !.( 2o'ot Code E:a$%le................................................................................................... !., Co$%uter Code E:a$%le.............................................................................................

%bstract'
8n t*e world of auto$ation. we want t*ings to 'e to work inde%endentl0 wit*out an0 *u$an interaction. ;e want co$%uter servers to run wit*out *u$an control. we want our cars. co$%uters. %*one. %lanes and ot*er co$%licated s0ste$s 'uilt auto$aticall0 wit*out too much hassle. +er*a%s 0ou would want 0our lawn $oved '0 a ro'ot. or $a0'e 0ou would want to re$otel0 $ow t*e lawn using 0our co$%uter to control t*e lawn $ower. -*is %ro<ect will infor$ 0ou. t*e reader. *ow a secure 1luetoot* co$$unication 'etween a ro'ot and a user is designed and i$%le$ented and $ost i$%ortantl0 w*0 it works. Mac*ines are a 'ig %art of t*e world=s %roduction. trans%ortation and e:%loration. Most of t*e %eo%le toda0 are unaware of *ow $uc* work is done '0 ro'ots ever0da0 for e:a$%le in car $anufacturing facilities and $ilitar0 o%erations. Mo'ile ro'ots s*all %ro'a'l0 'e t*e $ost i$%ortant $ac*ines in t*e future. /lread0. $o'ile ro'ots are 'eing used to e:%lore distant %lanets as well as for <ust si$%le *ouse *old work suc* as $owing t*e lawn or vacuu$ing. -*is re%ort focuses on a 1luetoot* Co$$unication w*ic* was esta'lis*ed 'etween t*e 8ntelli'rain 2o'ot and a +ersonal Co$%uter. -*is s%ecific design and i$%le$entation would work wit* $ost two5w*eel differential ro'ots t*at *ave a serial %ort availa'le on t*eir $ain 'oards and can run Java >irtual Mac*ine.

".

Introduction and Overview ".".+ur%ose


-*e $ain %ur%ose of t*is %ro<ect is to develo% a re$ote user interface to control a ro'ot via a wireless tec*nolog0. -*ere is a need to co$$unicate wit* t*e ro'ot re$otel0 in order to control t*e ro'ot $ove$ents and %ass critical data 'ot* wa0s. -*e current 82 controls are not good enoug* 'ecause t*e ro'ot does not *ave an 82 trans$itter 'ut onl0 a receiver. $eaning t*at t*e co$$unication is one wa0. -*e 82 co$$unication works onl0 in line of direct sig*t and an0 o'<ects in t*e wa0 will o'struct t*e co$$unication. 1luetoot* co$$unication will ena'le us to control t*e ro'ot u% to ")) $eters wit*out t*e need for direct sig*t w*ic* $eans t*at t*e ro'ot could 'e located 'e*ind a wall or so$e ot*er o'<ect and t*e co$$unication would not 'e lost.

".(.Sco%e
-*is s0ste$ will deal wit* t*e 'asic ro'ot $ove$ent functions. as well as user interface. 1luetoot* co$$unication. serial 2S(,( co$$unication 'etween t*e ro'ot and t*e 1luetoot* $odule. and 2S(,( co$$unication 'etween t*e +C and t*e 1luetoot* $odule. 4ull i$%le$entation of t*e code 'ot* for t*e ro'ot and t*e co$%uter s*all 'e develo%ed in t*is %ro<ect.

".,.-er$s. /cron0$s ? /''reviations


5 5 5 5 82 5 8nfra 2ed 2S(,( 5 Serial Co$$unication Standard /C@ 5 /s0nc*ronous connection link A4S9 5 Aaussian 4re3uenc0 s*ifting

5 5 5 5 5 5 5 5 5 5

&-E 5 &ata -er$inal E3ui%$ent &CE B &ata Carrier E3ui%$ent C-S B Clear to Send &-2 B &ata -er$inal 2ead0 &C& 5 &ata Carrier &etect 2-S B 2e3uest -o Send AN& 5 Around &S2 B &ata Set 2ead0 28 B 2ing 8ndicator /SCNCD2ENE7S B a co$$unications s0ste$ in w*ic* data trans$ission $a0 start at an0 ti$e and is indicated '0 a start 'it

SCNCD2ENE7S B a co$$unications s0ste$ in w*ic* sending and receiving of data is fi:ed '0 ti$e5clock intervals

5 5

2E1E- B 8ntelli1rain51ot 2o'ot 1@7E-EE-D ME&7@E B 4irefl0 Serial 1luetoot* Module Class "

". .+ro'le$ &escri%tion


-*ere is a need for a re$ote ro'ot controller t*at will ena'le t*e two wa0 co$$unication 'etween t*e user and t*e ro'ot. -*is controller $ust 'e wireless in order to give t*e ro'ot its $ove$ent freedo$. -*e current 82 controller works onl0 one wa0 'ecause t*e ro'ot does not *ave its own trans$itter. -*e 82 co$$unication is ver0 li$ited 'ecause t*e trans$itter *as to 'e directl0 %ointed to t*e receiver. ;it* t*e 1luetoot* tec*nolog0 we can *ave a two wa0 co$$unication w*ic* works on radio fre3uenc0 u% to ")) $eters in distance. 4urt*er$ore. we want to control t*e

ro'ot wit* a user interface suc* as a <o0stick and ke0'oard. -*e ro'ot could t*en %ass t*e data suc* as distance. s%eed. 'atter0 %ower. etc. 'ack to t*e user. -*e user could t*en decide w*at *e wants to do wit* t*e ro'ot according to t*e data received. -*e navigation s0ste$ s*all 'e relativel0 accurate wit* no deviation *ig*er t*an two centi$eters. No ro'ot is %erfect. and it s*all $ost likel0 never 'e error free. So$eti$es in ro'otics 0ou *ave to acce%t close enoug* to 'e %erfect.

".!.+ro'le$ Solution
-*e s0ste$ s*all 'e co$%osed of , $a<or co$%onents. -*e first one is t*e software t*at defines t*e $ain ro'ot $ove$ents. navigation and sensor s0ste$s. -*e second %art is t*e 7ser 8nterface w*ic* will i$%le$ent a <o0stick as t*e $ain user controller. -*e <o0stick used is an /nalog 2aider +ro Jo0stick w*ic* will 'e connected via a Male "! %in ca'le t*roug* a ga$e %ort. 1ot* t*e serial co$$unication 'etween t*e +C and t*e 1luetoot* and t*e co$$unication 'etween t*e ro'ot and t*e 1luetoot* $odule will 'e i$%le$ented. 4ro$ t*e conte:t diagra$ 5 "." we can see w*ic* co$$unication %rotocols are needed for t*is design.

4ig "." Conte:t &iagra$

-*e s%oofing of t*e serial ca'les is re3uired to $ake t*e connection 'etween t*e ro'ot and t*e co$%uter work. 1ellow we can see t*e colors used in a regular serial ca'le for corres%onding %in. -*e standard 2S(,( ca'le *as F %ins w*ic* we can see fro$ t*e ta'le ".,. Most &CE devices onl0 use %ins (. ,. ! w*ic* are 2eceive. trans$it and ground. res%ectivel0. -*is $akes at %ro'le$ for t*e 1luetoot* 'ecause it re3uires an active C-S and 2-S signals in order to know if t*e data was re3uested. -o solve t*is %ro'le$ 8 *ave connected %ins G and F to

eac* ot*er on t*e ro'ot=s 1luetoot* $odule so it alwa0s t*inks data is read0 to 'e received and trans$itted.

4ig ".( 2S(,( Serial Connections HSource: Z0tra:.co$I

/'ove we can see t*e solution to t*e %ro'le$. ;e can si$%l0 wire %ins ".

and #

toget*er so t*at t*e co$%uter t*ings it found t*e device loo%ing 'ack. &-S. &-2 and &C& 'ack to itself. En t*e co$%uter %art of t*e connection 8 *ad to wire %ins ". and # toget*er 'ecause

t*e 1luetoot* $odules onl0 use %ins (. ,. !. G. F and t*erefore it does not tell t*e co$%uter if a &C& device was detected on t*e ot*er end. -*is ter$ is know as Js%oofingK t*e connection and s*ould 'e done ver0 carefull0. En t*e ro'ot side. 8 *ave connected t*e 'rown wire to t*e send %in. red to t*e receive %in. 0ellow to t*e ground %in. and gra0 to t*e %ower %in. -*e corres%onding %in to t*e colors can 'e found in t*e coloring ta'le 'ellow 4igure ".!.

4ig "., 2S(,( ca'le %inout

(in )o. " ( ,

)ame &C& 2& -& &-2

)otes*+escription &ata Carrier &etect 2eceive &ata -rans$it &ata &ata -er$inal 2ead0 Around &ata Set 2ead0 2e3uest -o Send Clear -o Send 2ing 8ndicator

! # G L F

SAN& &S2 2-S C-S 28

4ig ". 2S(,( %inout ta'le

4ig ".! 2S(,( ca'le colors HSource: $a:strea$.netI

1ot* 1luetoot* $odules *ave to 'e %re5%rogra$$ed 'efore use in order to set t*e correct. 'aud rate. sto% 'its. %arit0. encr0%tion and w*et*er t*e device is $aster or a slave. -*ere are $an0 $ore o%tions w*ic* can 'e found in figure ".#.

4ig ".# 1luetoot* $odule o%tions Hsource: Aridconnect.co$I

/ 1luetoot* $odule can 'e %rogra$$ed '0 connecting it to t*e co$%uter via a serial ca'le and running a co$$unication %rogra$ suc* as D0%er-er$inal on ;indows ES or MiniCo$ on @inu: ES. -o %ut t*e 1luetoot* $odule into t*e configuration state it needs to 'e %lugged into t*e co$%uter and t*en %owered. /fter %owering. a ti$e count down will initiate giving 0ou #) seconds to %ut it into configuration $ode. -0%ing JMMMK into t*e ter$inal window will access t*e 1luetoot* configuration co$$ands listed in ta'le ".# and ".G. E:iting t*e configuration $ode is done '0 t0%ing JNJ. -*e ta'le ".G si$%l0 s*ows t*e advance

")

configuration o%tions for t*e res%ective $odules.

4ig ".G /dvance E%tions HSource: AridConnect.co$I

-*e 1luetoot* $odules re3uired so$e furt*er *ardware $odifications. -*e %lace$ent of t*e inner <u$%ers was c*anged to acco$$odate t*e co$$unication needs. 1ecause eac* 1luetoot* device re3uires C-S and 2-S signals 8 <u$%ed %ins " and ,. ( and . ! and #. G and L. F and ") res%ectivel0 on t*e fe$ale $odule on t*e co$%uter end. En t*e ro'ot H$aleI 1luetoot* $odule 8 *ave <u$%ed %ins " and (. , and . F and ") res%ectivel0. (.

Specific Requirements (.".1luetoot* 2e3uire$ents


(.".".1luetoot*

Co$$unication +rotocols
""

-*e 1luetoot* $odule use Aaussian 4re3uenc0 s*ifting A4S9 and work at t*e 8SM 'and of (. ADz. -*e $odules are divided into Master and Slave. -*e $aster $odule looks for an0 slave $odules in range and saves t*eir address and connects to it. -*e $aster is in c*arge of setting t*e fre3uenc0 *o%%ing se3uence w*ic* insures t*at no ot*er wireless devices are distur'ed. 1ot* devices need to agree on t*e 1/7& rate. %arit0. sto% 'its. and flow control in order to send 'its fro$ t*e +C to t*e 2o'ot and 'ack. 8n t*is design t*e 1luetoot* $odules are si$%l0 e:tending t*e serial ca'le wirelessl0. -*e 1luetoot* devices used in t*is %ro<ect are Class " w*ic* use "))$; H() d1$I and *ave a $a:i$u$ range of ")) $eters. 1luetoot* co$$unication is $uc* different t*an t*e 2S(,( co$$unication. 'ut it can rese$'le one. 8t uses /s0nc*ronous Connectionless links H/C@I for its data co$$unications. /C@ link sends data at irregular intervals w*enever data is availa'le. So$e of t*e /C@ link ensures data accurac0 '0 c*ecking for errors and re sending data if needed. -*e /ccess code. *eader and a %a0load are e$'edded into a %acket w*ic* is trans$itted. -*erefore t*e slave device will $atc* its access code to t*e inco$ing %acket. -*e control infor$ation is contained in t*e *eader %art of t*e %acket and t*e actual data $essage is contained in t*e %a0load %art of t*e %acket. 1luetoot* %rotocol uses four different access codes suc* as C*annel /ccess Code HC/CI. &evices /ccess Code H&/CI. Aeneral 8n3uir0 /ccess Code HA8/CI and &edicated 8n3uir0 /ccess Code H&8/CI. C/C is used '0 all devices t*at are e:c*anging data. &/C is used for %aging a device. A8/C is used for t*e in3uir0 %rocedures and &8/C is used for used for s%ecified range of t*e in3uir0 access code.

"(

4ig (." &ata +rotocol

-*e a'ove figure s*ows t*e 1luetoot* stack %rotocol co$%ared to t*e ES8 reference $odel. -*e 1luetoot* can 'e in $an0 different states suc* as t*e stand'0. in3uir0 state. in3uir0 scan. %age state. %age scan. active connection. connection *old. connection stiff and connection %ark. Eac* 1luetoot* device can onl0 'e in one state at one ti$e.

",

4ig (.( 1luetoot* Message Se3uence

-*e diagra$ "., s*ows *ow t*e 1luetoot* %rocesses t*e in3uir0 in t*e $essage se3uence. -*e 8n3uir0 device sends an 8& %acket wit* t*e access code. and t*e in3uir0 scanning device listens for t*e re3uest. /fter it *ears t*e first re3uest it auto$aticall0 goes into a dela0 %eriod 'efore it starts listening again. ;*en it *ears t*e second re3uest it sends t*e 4re3uenc0 *o% se3uence 'ack to t*e in3uir0 device. More t*an one device can res%ond to an in3uir0 'ut t*e0 res%ond rando$l0 at different ti$es t*erefore t*e0 do not interfere wit* eac* ot*er.

"

4ig (., 1luetoot* +aging

-*e figure (., s*ows t*e $essage se3uence c*art w*en %aging and %age scanning. ;e can see t*e $essages 'eing e:c*anged 'etween two devices w*en t*e0 are connected. -*e $aster is on t*e left side and it sends t*e slave=s access code %revious $essage se3uence. ;*en t*e slave gets t*e code it re%lies wit* t*e sa$e code 'ack. after t*at t*e $aster sends t*e 4DS again and t*e slave res%onds again to acknowledge t*e 4DS. /fter t*at. t*e /C@ %ackets are sent as well as t*e @M+ link configuration.

"!

(.".(.1luetoot* 4unctional 2e3uire$ents


5 1luetoot* fe$ale $odule s*all receive a '0te fro$ t*e Co$%uter Serial %ort and trans$it it to t*e $ale $odule connected to t*e ro'ot serial %ort 5 1luetoot* connection s*all work 'ot* wa0s

(.".,.1luetoot* Non54unctional 2e3uire$ents (.".,.".2elia'ilit0


5 -*e 1luetoot* connection s*all not e:%erience an0 s0ste$ $a<or cras*es or errors

(.".,.(./vaila'ilit0
5 -*e 1luetoot* connection s*all 'e availa'le "))O of t*e ti$e if in range of ")) $eters.

(.".,.,.Securit0
5 -*e 1luetoot* connection s*all not allow an0 ot*er slave devices to connect to t*e $aster and receive data. 5 -*e 1luetoot* connection s*all use data encr0%tion.

(.". .1luetoot* Constraints


5 -*e 1luetoot* $odules are li$ited to $a:i$u$ transfer rate of ""!())9'Ps and to t*e distance of ")) $eters. (.(.

Robot Requirements (.(.".2o'ot 4unctional 2e3uire$ents


5 5 5 2o'ot $oves s*all res%ond to <o0stick %ositions 2o'ot s*all 'e a'le to detect o'<ects in its %at*wa0 2o'ot s*all store t*e %at* : and 0 coordinates in a dou'le arra0 varia'le

"#

2o'ot s*all 'e a'le to follow its %revious $e$orized %at*

(.(.(.2o'ot Non54unctional 2e3uire$ents (.(.(.".2elia'ilit0


5 5 5 2o'ot s*all res%ond to <o0stick $ove$ent wit*in fewer t*an !)) $illiseconds 2o'ot s*all not *it an0 o'<ects in its %at*wa0 2o'ot s*all not $iss its destination wit*in $ore t*an ( inc*es

(.(.(.(./vaila'ilit0
5 2o'ot s*all res%ond to user=s co$$ands at all ti$es

(.(.(.,.Securit0
5 2o'ot s*all not allow access to its co$$ands to $ore t*an one 1luetoot* $odule

(.(.,.2o'ot Constraints
5 5 5 5 5 2o'ot cannot run $ore t*an ") t*reads successfull0 2o'ot runs on an Micro controller t*at *as " .G MDz %rocessing %ower 2o'ot *as "(L flas* %rogra$ $e$or0 2o'ot *as ",(9 2/M availa'le 2o'ot *as 9 '0tes of EE+2EM availa'le

(.(. .2S(,( co$$unication %rotocols


-*e serial connection used in t*is %ro<ect to connect t*e +C and t*e 1luetoot* $odule is /s0nc*ronous Serial -rans$ission H7/2-I. -*e sender and t*e receiver do not agree on t*e ti$ing signals 'etween t*e 'its of data 'eing send. rat*er t*e0 use a

"G

start 'it and a sto% 'it. -*e start 'it tells t*e receiver w*ere t*e data 'egins using t*e little endian order $eaning t*at t*e least significant 'it is sent first. -*e ti$e 'etween eac* 'it is t*e sa$e for all t*e 'its. and t*e receiver <ust deter$ines w*et*er t*e 'it is " or ). -*e sender c*ecks t*e clock to see if it is ti$e to send t*e ne:t word 'ut it does not *owever know w*en t*e receiver *as gotten t*e data. +arit0 $a0 'e used for si$%le c*ecking and flow control 'ut t*e0 will not 'e used in t*is %ro<ect 'ecause t*e 1luetoot* $odules do not su%%ort flow of control. /n i$%ortant t*ing to notice is t*at w*en t*e co$$unication is idle. $eaning t*at no data is 'eing sent. t*e 2S(,( will 'e trans$itting continuous " values. -*erefore a start 'it alwa0s *as a value of ) and a sto% 'it *as a value of ". -*e standard voltage 'eing sent is Q"(>&C or 5"(>&C 'ut so$e low %ower devices allow Q!>&C and 5!>&C w*ic* are still acce%ta'le 'ut in t*is case t*e ca'le lengt* s*ould 'e s*ort. 8n case t*at t*ere is no electricit0 %resent in t*e circuit. a signal called a 'reak is 'eing sent. -*is signal needs to 'e longer t*an t*e co$%lete '0te 'eing sent %lus t*e start. sto% and %arit0 'its. -*e 2S(,( s%ecification descri'es two t0%es of connection ends: &ata -er$inal E3ui%$ent H&-EI and t*e &ata Carrier E3ui%$ent H&CEI. 10 standard convention &-E is usuall0 t*e co$%uter and &CE is a $ode$. 1ut it=s i$%ortant to re$e$'er t*e 1luetoot* $odule does not work wit* $ode$s. Mode$ *ere is <ust a reference to a device 'eing connected to t*e %c.

2. .,ser Interface Requirements


(.,.".S%ecific 5

7ser Control 2e3uire$ents

-*e user s*all 'e a'le to control t*e ro'ot $ove$ents via a <o0stick

"L

5 5 5 5 5

-*e user s*all 'e a'le to give co$$ands to t*e ro'ot via a ke0'oard -*e user s*all 'e a'le to switc* 'etween <o0stick and ke0'oard controls -*e user s*all 'e a'le to start and ter$inate a connection -*e user s*all 'e a'le to receive 'atter0 c*arge infor$ation fro$ t*e ro'ot -*e user s*all not 'e a'le to run t*e ro'ot into an o'<ect

(.,.(.Jo0stick 5 5 5 5

Control 2e3uire$ents

-*e <o0stick s*all send : and 0 coordinates to t*e co$%uter -*e <o0stick s*all send t*e states of ( of its 'uttons -*e <o0stick $a:i$u$ and $ini$u$ 0 coordinates s*all 'e F and 5F res%ectivel0 -*e <o0stick $a:i$u$ and $ini$u$ : coordinates s*all 'e F and 5F res%ectivel0

(.,.,.9e0'oard Control 2e3uire$ents


5 -*e user s*all 'e a'le to enter : and 0 coordinates fro$ t*e ke0'oard w*ic* s*all 'e sent to t*e ro'ot 5 -*e user s*all 'e a'le to control ro'ot $ove$ent '0 %ressing letters w. s. a. d and 3 for forward. 'ackwards. left. rig*t and sto% res%ectivel0

. Bac!"round Information .1.IntelliBrain Bot Information


Most of t*e ro'ots 'uilt toda0 are two5w*eel differential $eaning t*at all of t*e ro'ots $ove$ent is acco$%lis*ed wit* <ust one set of w*eels. -*e 8ntelli1rain 'ot is co$%osed of t*e 8ntelli1rain $ain 'oard t*at takes t*e energ0 fro$ // 'atteries to %ower t*e two servo $otor

%orts as well as ot*er sensor %orts. -*is ro'ot *as t*e following co$%onents attac*ed to it=s $ain

"F

'oard: an @C& dis%la0 a cou%le of %us* 'uttons. a 'ee%er. an S24) sonar range sensorR two w*eels t*at are attac*ed to t*e servo $otors. a set of A+(&"( range sensors and two S21"", infrared %*oto reflector sensors used for w*eel encoding as well as line sensing. /ll of t*is *ardware sits on a well5'uilt 1oe51ot c*assis develo%ed '0 +aralla:. -*e ro'ot runs on <ava virtual $ac*ine t*at su%%orts $ulti t*reading w*ic* is essential for t*is %ro<ect 'ecause we need to *ave $ulti%le o'<ects running at t*e sa$e ti$e. -*is 8ntelli1rain 'ot uses 2o'oJ&E Java develo%$ent environ$ent software t*at is used to design. 'uild and u%load t*e %rogra$ to t*e $ain 'oard of t*e ro'ot. -*is software co$es wit* t*e /+8 s%ecification of classes and $et*ods t*at *ave alread0 'een develo%ed for %u'lic use. -*e %rogra$ is u%loaded to t*e ro'ot via a serial ca'le. -*e ro'ot=s $ain 'oard consists of ") &igital in%uts and out%uts. an infrared receiver. , 8C %orts. a 'uzzer. a "#:( @C& dis%la0. ( servo %orts. G analogPdigital in%uts. a %ower switc*. ( %us* 'uttons. a t*u$'w*eel. a *ost 8nterface H2S5(,(. ""!.(9 'audI and a wall 'rick %ower connector. -*e ro'ot runs on an /t$el /t$ega"(L Micro controller t*at *as " .G MDz. "(L flas* %rogra$ $e$or0. ",(9 2/M and 9 '0tes of EE+2EM. -*e /+8 s%ecification notes t*at t*e flas* $e$or0 *as a li$ited life of ").))) writes and t*erefore s*ould 'e used s%aringl0. w*ile t*e 9 of

EE+2EM is esti$ated to *ave a lifeti$e of ")).))) writes. -*e Java >irtual Mac*ine and t*e 'ootstra% loader use 9 '0tes of 2ando$ /ccess Me$or0 H2/MI. -*e infrared receiver works at ,L kDz and is co$%ati'le wit* $ost television re$otesR t*is receiver could also 'e used for co$$unication 'etween two ro'ots. -*e 'ootstra% leader is software on t*e ro'ot res%onsi'le for downloading t*e virtual $ac*ine to t*e ro'ot and c*anging t*e *ost %ort 'aud rate.

.2.-o.stic! Information

()

-*e <o0stick used in t*is %ro<ect was an older <o0stick t*at used a ga$e %ort rat*er t*an 7S1. Modern co$%uters do not co$e wit* ga$e %ort an0$ore t*erefore. to overco$e t*is %ro'le$ 8 *ave installed a $idi sound card Hw*ic* *as a "! %in in%ut on itI into t*e co$%uter +C8 %ort. -*e <o0stick can 'e connected to t*e $idi card w*ic* is t*en recognized '0 t*e E%erating S0ste$ as a ga$e %ort.

H$ale connector on <o0stick ca'leI


.///////////////////////. 012 3 $ # 2 1* 0 1$ 1# 1 12 11 14 5 * 6666666666666666666

" TC" HQ!vI ( Switc* " , T" Around Hfor switc* "I ! Around Hfor switc* (I # C" G Switc* ( L N.C. F TC( HQ!vI ") Switc* , "" T( "( Around Hfor switc* ,? I U ", C( " Switc* "! N.C. U
4ig (. <o0stick %inout

-*e <o0stick %ort is located on t*e 8S/ 'us 8PE address ()"* and can 'e accessed '0 t*e C+7 to read and write to t*e %ort. ;*en data is sent to t*e %ort. t*e <o0stick initializes its %osition $easure$ents 'ut t*e data sent to t*e <o0stick is not relevant and it is not saved an0w*ere.

("

#. References
V"W Julia @a0ton and Curt 4ranklin. JDow 1luetoot* ;orksK. 72@: *tt%:PPelectronics.*owstuffworks.co$P'luetoot*.*t$ V(W Dac. /nna. JMo'ile -eleco$$unications +rotocols for &ata NetworksK. +u'lication: C*ic*ester. ;est Susse:. Do'oken. NJ Jo*n ;ile0 ? Sons. @td. H79I. ()), V,W 2idgesoft @@C 8nc. J8ntelli1rain AuideK. +E 1ET L(. +leasanton. C/. 72@: *tt%:PPridgesoft.co$Pintelli'rainP8ntelli1rainAuide.%df V W Arid Connect. J4irefl0 1luetoot* Serial ManualK. June (Gt* ())#. "L " Centre +oint Circle. Suite " , Na%erville. 8@ #)!#,. 72@: *tt%:PPsite.gridconnect.co$PdocsP+&4P4irefl0XL))," Xc.%df V!W 4rank &urda. JSerial and 7/2- -utorialK. -anuar.7 1 th 1553 72@: *tt%:PPwww.free'sd.orgPdocPenX7S.8SELL!F5"ParticlesPserial5uartPinde:.*t$l

$. %ppendi& $.1 -o.stic! pro"rammin" e&ample


8N- "! 5 18ES 5 JECS-8C9 S7++E2- HT- after ""PLPL(./-.T-(L#.+SI /D Y L * &T Y su'function ))))* read <o0stick switc*es 2eturn: /@ 'its G5 Y switc* settings )))"* read %ositions of <o0sticks 2eturn: /T Y T %osition of <o0stick / 1T Y C %osition of <o0stick / CT Y T %osition of <o0stick 1 &T Y C %osition of <o0stick 1 2eturn: C4 set on error /D Y status L)* invalid co$$and H+C.+C<rI L#* function not su%%orted Hot*erI C4 clear if successful Notes: if no ga$e %ort is installed. su'function ))))* returns /@Y))* Hall switc*es o%enI and su'function )))"* returns /TY1TYCTY&TY))))* a (!)kE*$ <o0stick t0%icall0 returns ))))*5)"/)*

((

$.2 Robot/Code e&ample


PP setting u% connection tr0 Z Serial+ort co$+ort Y 8ntelli1rain.getCo$(HIR PPSerial +ara$eters co$+ort.setSerial+ort+ara$sH""!()).Serial+ort.&/-/18-SXL.Serial+ort.S-E+18-SX".Serial+ort.+/28-CXNENEIR 8n%utStrea$ in%utStrea$ Y co$+ort.get8n%utStrea$HIR Eut%utStrea$ out%utStrea$ Y co$+ort.getEut%utStrea$HIR

PP clear screen dis%la0.%rintH). [[IR dis%la0.%rintH". [[IR PP Setting 'uffer '0te VW 'uf Y new '0teV"(LWR \ %u'lic static void $ove2o'otHint i. int i(I Z $@eftMotor.set+owerHiIR $2ig*tMotor.set+owerHi(IR \ PP -urn left $otor PP -urn rig*t $otor

$. Computer/Code e&ample
PU U /ut*or: Neven Skoro U &ate Modified: Nove$'er "Lt* ())# U 4@E28&/ A7@4 CE/S- 7N8>E2S8-C U *tt%:PPsatnet.fgcu.eduP]nskoro U U UP PP SerialCo$$.<ava %ackage co$.centralne:us.in%utR i$%ort <ava:.co$$.Co$$+ort8dentifierR i$%ort <ava:.co$$.+ort8n7seE:ce%tionR i$%ort <ava:.co$$.Serial+ortR i$%ort <ava:.co$$.7nsu%%ortedCo$$E%erationE:ce%tionR i$%ort <ava.io.UR i$%ort <ava.util.Enu$erationR %u'lic class SerialCo$$ Z static 'oolean %ort4oundR static StringVW default+ortsR static Enu$eration %ort@istR static Co$$+ort8dentifier %ort8dR static String default+ortR static Serial+ort serial+ortR static 8n%utStrea$ in%utStrea$R static Eut%utStrea$ out%utStrea$R static 1uffered2eader inR

(,

static Jo0stick <o0(R static final int /T8SXT PUU Constant for a:is>alues UP static final int /T8SXC Y "R PUU Constant for a:is>alues UP %u'lic SerialCo$$HI Z tr0Z

Y )R

%ort8dY Co$$+ort8dentifier.get+ort8dentifierH[CEM,[IR \ catc*HE:ce%tion eIZS0ste$.out.%rintlnH[ no %ort [ Q eIR \ S0ste$.out.%rintlnH[found %ort [IR tr0 Z serial+ort Y HSerial+ortI %ort8d.o%enH[serial[. !)IR \ catc* H+ort8n7seE:ce%tion eI ZS0ste$.out.%rintlnHeIR\ tr0 Z serial+ort.setSerial+ort+ara$sH""!()). Serial+ort.&/-/18-SXL. Serial+ort.S-E+18-SX". Serial+ort.+/28-CXNENEIR \ catc* H7nsu%%ortedCo$$E%erationE:ce%tion eI Z\ S0ste$.out.%rintlnHserial+ort.get4lowControlModeHIIR PPEut%utStrea$ tr0 Z out%utStrea$ Y serial+ort.getEut%utStrea$HIR \ catc* HE:ce%tion eI Z\ PP8$%utStrea$ tr0 Z in%utStrea$ Y serial+ort.get8n%utStrea$HIR \ catc* H8EE:ce%tion eI Z\ \ %u'lic static '0te VW c*ar-o10te/rra0H c*ar c I Z '0te VW two10tes Y Z H'0teIHc ? ):ffI. H'0teIHc >> L ? ):ffI \R S0ste$.out.%rintlnH[c*ar to '0te [ Q two10tesV)W Q [ [ Q two10tesV"WIR return two10tesR \ %u'lic static void %us*8tH'0te 'I Z tr0 Z out%utStrea$.writeH'IR PP out%utStrea$.flus*HIR \ catc* H8EE:ce%tion e:I Z S0ste$.out.%rintlnHe:.toStringHIIR \ \ %u'lic static void %us*8tH'0teVW 'I Z tr0 Z out%utStrea$.writeH'IR PP out%utStrea$.flus*HIR \ catc* H8EE:ce%tion e:I Z S0ste$.out.%rintlnHe:.toStringHIIR \ \ %u'lic static void %us*8tH'0te '. '0te '(I Z tr0 Z out%utStrea$.writeH'IR

out%utStrea$.writeH^_r^IR out%utStrea$.writeH'(IR out%utStrea$.writeH^_r^IR out%utStrea$.flus*HIR \ catc* H8EE:ce%tion e:I Z S0ste$.out.%rintlnHe:.toStringHIIR \ \ %u'lic static '0teVW int-o10tesHint iI Z '0teVW ' Y new '0teV(WR int i". i(R if Hi YY )I Z 'V)W Y )R 'V"W Y )R \ if H) < i ? i <Y (!!I Z 'V)W Y H'0teI iR 'V"W Y )R \ if Hi > (!!I Z 'V)W Y H'0teI Hi O (!#IR 'V"W Y H'0teI Hi P (!#IR \ if H 5(!! <Y i ? i < )I Z 'V)W Y H'0teI H(!! Q iIR 'V"W Y H'0teI (!!R \ if Hi < 5(!!I Z 'V)W Y H'0teI H(!! Q Hi O (!#IIR 'V"W Y H'0teI H(!! Q Hi P (!#IIR \ return 'R \ %u'lic static void $ainHString argsVWIZ '0teVW ' Y new '0teV"(LWR int iY)R new SerialCo$$HIR in Y new 1uffered2eaderHnew 8n%utStrea$2eaderHS0ste$.inIIR S0ste$.out.%rintlnH[&-2[ Q serial+ort.is&-2HIIR S0ste$.out.%rintlnH[C-S[ Q serial+ort.isC-SHIIR S0ste$.out.%rintlnH[2-S[ Q serial+ort.is2-SHIIR S0ste$.out.%rintlnH[&S2[ Q serial+ort.is&S2HIIR S0ste$.out.%rintlnH[C&[ Qserial+ort.isC&HIIR tr0Z <o0( Y Jo0stick.create8nstanceHIR \ catc*H8EE:ce%tion eIZ\ w*ileHtrueIZ <o0(.%ollHIR 'V)W YHH'0teI5H<o0(.getCHIU")IIR S0ste$.out.%rintlnH[-*e [ Q ) Q [ '0te is [ Q 'V)WIR serial+ort.set2-SHtrueIR if Hserial+ort.isC-SHIIZ S0ste$.out.%rintlnH[Clear to send```[IR if H<o0(.getCHI < 5).LI PP forward %us*8tHH'0teIL!IR

(!

else if H<o0(.getCHI > ).LI PP 'ackwards %us*8tHH'0teIL IR else if H<o0(.getTHI < 5).LI PP left %us*8tHH'0teIL,IR else if H<o0(.getTHI > ).LI PP rig*t %us*8tHH'0teIL(IR else PP sto% %us*8tHH'0teILFIR \ if H<o0(.is1utton&ownH"IIZ S0ste$.out.%rintlnH[Connection ter$inated...[IR serial+ort.closeHIR 'reakR\ if H<o0(.is1utton&ownH(IIZ 'oolean flag YtrueR PP 2eading data fro$ ke0'oard S0ste$.out.%rintlnH[+lease in%ut a co$$and: [IR w*ile HflagIZ tr0Z i Y S0ste$.in.readHIR \ catc* H8EE:ce%tion eIZ\ if HHc*arIi YY ^w^I %us*8tHH'0teIL!IR if HHc*arIi YY ^s^I %us*8tHH'0teIL IR if HHc*arIi YY ^a^I %us*8tHH'0teIL,IR if HHc*arIi YY ^d^I %us*8tHH'0teIL(IR if HHc*arIi YY ^3^I %us*8tHH'0teILFIR if Hi YY^_t^I flag Y falseR \ \ tr0Z S0ste$.out.%rintlnH[in%ut strea$ e3uals: [ Qin%utStrea$.availa'leHIIR if Hin%utStrea$.availa'leHI > )I Z S0ste$.out.%rintlnH[in%utstrea$ is availa'le[IR '0te VW 'uffer Y new '0teV"(LWR int lengt* Y in%utStrea$.readH'ufferIR S0ste$.out.%rintlnH[lengt* of in%ut is [ Q lengt*IR S0ste$.out.%rintlnH[8n%ut 'uffer is [ Q 'uffer.toStringHIIR \ \ catc* H8EE:ce%tion eI ZS0ste$.out.%rintlnH[error reading in%ut[ Q eIR\ tr0Z -*read.slee%HG!IR \ catc* H-*rowa'le tIZ\ \ \ \ PP EN& E4 48@E

(#

Anda mungkin juga menyukai