Home
MANE 6980 Vito Guardi Project Draft 4-22-14
Contents
1. transmit1 jmpret txcode1 rxcode2 run a chunk of receive code then return txcts1 test ctsmaskl ina wc ifflow controlled dont send rdlong tl tx_head_ptr1 cmp tl tx_taill wz ctsil if z jmp transmitl may be patched to if_z_or_c or if_z_or_nc rdbyte txdatal txbuff_tail_ptr1 add tx_taill 1 cmpsub tx_taill txsizel wz TTA for individually sized buffers will zero at rollover wrlong tx_taill tx_tail_ptr1 if z moy txbuff_tail_ptr1 txbuff_ptr1 reset tail_ptr if we wrapped if _nz add txbuff_tail_ptr1 1 otherwise add 1 96 txbitl txoutl waitl if_nc txjmp 1 Transmit2 transmit2 txcts2 ctsi2 if z jmpret txcodel rxcode2 shl txdatal 2 txdatal txbitor txbits1 11 or mov moy txcntl cnt shr txdatal 1 we muxc outa txmask1 add txcntl bit_ticks1 jmpret txcodel rxcode2 moy tl txcntl sub tl cnt cmps tl 0 we jmp waitl djnz txbits1 txbit1 jmp ctsil jmpret txcode2 rxcode3 test ctsmask2 ina we rdlong tl tx_head_ptr2 cmp tl tx_tail2 wz jmp transmit2 run a chunk of receive code then return ready byte to transmit maybe patched to muxnc dira txmask ready next cnt run a chunk of receive code then return check if bit transmit period done another bit to transmit byte done transmit next byte run a chunk of receive code then return if flow controlled dont send
2. test rxtx_model OCTX wz init tx pin according to mode test rxtx_model INVERTTX we if z nec or outa txmask1 if z or dira txmask1 if_z_eq_c or txoutl domuxnc patch muxc to muxnc if_nz movd_ txoutl dira change destination from outa to dira test rxtx_model INVERTRX wz wait for start bit on rx pin if_nz xor startl doifc2ifnc if_c jmp to if_nc or ctsmaskl 0 wz if_nz test rxtx_model INVERTCTS we 86 if _nz_and_c or ctsil doif_z_or_nc if_nc jmp TTA reversed order to correctly invert CTS if_nz_and_nc or ctsil doif_z_or_c if_c jmp if z moy txctsl transmitl copy the jmpret over the cts test if z moys ctsil txcts1 patch the jmps to transmit to txcts0 if_z add txcodel 1 change co routine entry to skip first jmpret patch rx routine depending on whether rts is used and if it is inverted or rtsmaskl 0 wz if_nz or dira rtsmask1 TTA rts needs to be an output if_nz test rxtx_model INVERTRTS we if nz_and_nc or _ rtsl domuxnc patch muxc to muxnc if_z moy norts1 recli patch to a jmp receive 1 if_z moys startl receivel skip all rts processing or txmaskl 0 wz if tx pin not used if_z movi transmitl 010111_000 patch it out entirely by making the jmpret into a jmp TTA or rxmaskl 0 wz ditto for rx routine if_z movi receivel 010111_000 TTA port O initialization
3. mmSocket close End try catch IOException E2 End catch connectionFailed return End catch Reset the ConnectThread because we re don synchronized BluetoothDataTransferService this mConnectThread null Start the connected thread connected mmSocket mmDevice mSocketType End run public void cancel try mmSocket close catch IOException e End of cancel End of ConnectThread private class 48 public void write byte out Create temporary object ConnectedThread r Synchronize a copy of the connected thread synchronized this should check for a connected thread here first need to add code r mConnectedThread End of synchronized Perform the write unsynchronized r write out Log d Data Transfer Sent End of write private void connectionFailed End of connection failed public synchronized void connected BluetoothSocket socket BluetoothDevice device final String socketType Start the thread to manage the connection and perfor transmission mConnectedThread new ConnectedThread socket socketType mConnectedThread start End of connected private class ConnectedThread extends Thread private final BluetoothSocket mmSocket private final InputStream mmiInStream private final OutputStream mmOutStream public Connec
4. layout_alignParentLeft true android layout_alignParentTop true android text t gt 36 lt TextView android id tid textView2 android layout_width wrap_content android layout_height wrap_content android layout_alignParentLeft true android layout_below id txtOut android text H gt lt TextView android id tid vTextView android layout_width wrap_content android layout_height wrap_content android layout_above id hText View android layout_toRightOf tid textView2 android text 50 gt lt TextView android id tid hTextView android layout_width wrap_content android layout_height wrap_content android layout_alignBaseline tid textView2 android layout_alignBottom tid textView2 android layout_alignLeft tid vTextView android text 50 gt lt SeekBar android id tid vSeekBari android layout_width 250dip android layout_height wrap_content android layout_alignParentLeft true android layout_centerVertical true android rotation 270 gt lt SeekBar android id tid hSeekBari android layout_width 250dip android layout_height wrap_content android layout_alignParentRight true android layout_alignTop tid vSeekBari gt 6 3 2 Discovered and Connected Bluetooth Device List lt xml version 1 0 encoding utf 8 gt lt LinearLayout xmlns android http schemas andr
5. mmOutStream write buffer end of try catch IOException e end of catch 50 End of write End of ConnectedThread End of BluetoothData 6 4 3 Device List Activity package com dynamicsolutions bluetest3 import java util Set import android app Activity import android bluetooth BluetoothAdapter import android bluetooth BluetoothDevice import android content BroadcastReceiver import android content Context import android content Intent import android content IntentFilter import android os Bundle import android view View import android view View OnClickListener import android view Window import android widget AdapterView import android widget AdapterView OnItemClickListener import android widget ArrayAdapter import android widget Button import android widget ListView import android widget TextView import android widget Toast public class DeviceListActivity extends Activity private BluetoothAdapter mBtAdapter private ArrayAdapter lt String gt mPairedDevicesArrayAdapter private ArrayAdapter lt String gt mNewDevicesArrayAdapter Return Intent extras public static String EXTRA_DEVICE_ADDRESS device_address Override protected void onCreate Bundle savedInstanceState super onCreate savediInstanceState Set up the display window requestWindowFeature Window FEATURE_INDETERMINATE_PROGRESS setConte
6. rxmask1 long 0 rxmask2 long 0 rxmask3 long 0 txmask long 0 a single bit set a mask for the pin used for transmit zero if port not used for transmit txmask1 long 0 txmask2 long 0 txmask3 long 0 103 ctsmask long 0 a single bit set a mask for the pin used for cts input zero if port not using cts ctsmask1 long 0 ctsmask2 long 0 ctsmask3 long 0 rtsmask long 0 a single bit set a mask for the pin used for rts output zero if port not using rts rtsmask1 long 0 rtsmask2 long 0 rtsmask3 long 0 bit4_ticks long 0 bit ticks for start bit 1 4 of standard bit bit4_ticks1 long 0 bit4_ticks2 long 0 bit4_ticks3 long 0 bit_ticks long 0 clock ticks per bit bit_ticks1 long 0 bit_ticks2 long 0 bit_ticks3 long 0 rtssize long 0 threshold in count of bytes above which will assert rts to stop flow rtssizel long 0O rtssize2 long 0O rtssize3 long 0 rxbuff_head_ptr long 0 Hub address of data received base plus offset rxbuff_head_ptr1 long O pasm writes WRBYTE to hub at this address initialized in spin to base address rxbuff_head_ptr2 long 0 rxbuff_head_ptr3 long 0 txbuff_tail_ptr long 0O Hub address of data tranmitted base plus offset txbuff_tail_ptr1 long 0 pasm reads RDBYTE from hub at this address initialized in spin to base address 104 txbuff_tail_ptr2 long 0 txbuff_tail_ptr3 long 0 rx_head_ptr long 0O pointer to the hub address of where the head and tail offset pointers are store
7. vSeek setProgress 50 Override public void onStartTrackingTouch SeekBar seekBar TODO Auto generated method stub Override public void onProgressChanged SeekBar seekBar int progress boolean fromUser String stringV Integer toString progress vText setText stringV String messageA A String messageF byte sendA messageA getBytes mDataService write sendA try Thread sleep 1 catch InterruptedException e TODO Auto generated catch block e printStackTrace Log d OutputService Output A Complete byte sendV stringV getBytes mDataService write sendvV try Thread sleep 1 catch InterruptedException e TODO Auto generated catch block e printStackTrace Log d OutputService Output V Complete byte sendF messageF getBytes mDataService write sendF try Thread sleep 1 catch InterruptedException e TODO Auto generated catch block e printStackTrace Log d OutputService Output F Complete p btnSend setOnClickListener new OnClickListener 43 public void onClick View arg0 vSeek setEnabled true hSeek setEnabled true oo End of onCreate Override public void onStart super onStart If bluetooth is not enabled request that it is enabled if mBluetoothAdapter isEnabled Intent enableBTIntent new Inten
8. 10 else 66 dataH dataH inByteArr Index 48 rawDirection dataH dio dec DEBUG dataH fds tx DEBUG 13 PUB Values fds str DEBUG String Values Started Outputs Program Started to the terminal screen fds tx DEBUG 13 repeat waitcnt clkfreq 20 cnt if rawSpeed gt 50 and rawDirection lt 50 Forward and Left range 100 speed range rawSpeed 50 100 50 100 direction speed 100 50 rawDirection 100 50 100 Servo 750 direction rServo 750 speed elseif rawSpeed gt 50 and rawDirection gt 50 Forward and Right range 100 speed range rawSpeed 50 100 50 100 direction speed 100 rawDirection 50 100 50 100 IServo 750 speed rServo 750 direction elseif rawSpeed lt 50 and rawDirection lt 50 Reverse and Right range 100 speed range 50 rawSpeed 100 50 100 direction speed 100 50 rawDirection 100 50 100 Servo 750 direction rServo 750 speed elseif rawSpeed lt 50 and rawDirection gt 50 Reverse and Left 67 range 100 speed range 50 rawSpeed 100 50 100 direction speed 100 rawDirection 50 100 50 100 Servo 750 speed rServo 750 direction elseif rawDirection 50 and rawSpeed gt 50 speed rawSpeed 50 2 IServo 750 speed rServo 750 speed elseif rawD
9. 10 Propeller Activity Board Manufactured by Parallax http www parallax com product 32910 11 RN 42 Bluetooth Adapter manufactured by parallax http www parallax com product 30086 12 Android Developers Website http developer android com index html 13 Android SDK download link http developer android com sdk index html 14 Parallax Main Webpage http www parallax com 28 15 Propeller software and driver download http www parallax com downloads propeller tool software 16 You Tube video of application and robotic platform in action http youtu be ytDogEmw2ZQ 29 6 APPENDECIES 6 1 Table of the first 128 Characters of the ASCII Code Table 4 First 128 Characters of the ASCII code Decimal Symbol Description Decimal Description 0 0 NUL Null char 64 1000000 At symbol 1 1 SOH Start of Heading 65 1000001 A Uppercase A 2 10 STX Start of Text 66 1000010 B Uppercase B 3 11 ETX End of Text 67 1000011 c Uppercase C 4 100 EOT End of Transmission 68 1000100 D Uppercase D 5 101 ENQ Enquiry 69 1000101 E Uppercase E 6 110 ACK Acknowledgment 70 1000110 F Uppercase F 7 111 BEL Bell 71 1000111 G Uppercase G 8 1000 BS Back Space 72 1001000 H Uppercase H 9 1001 HT Horizontal Tab 73 1001001 l Uppercase 10 1010 LF Line Feed 74 1001010 J Uppercase J 11 1011 VT Vertical Tab 75 1001011 K Uppercase
10. PUB rxflush port Flush receive buffer here until empty repeat while rxcheck port gt 0 PUB rxHowFull port TTA added method returns number of chars in rx buffer return rx_head port rx_tail port rxsize port rxsize port rx_head and rx_tail are values in the range 0 lt lt RX_BUFSIZE 80 PUB rxcheck port rxbyte Check if byte received never waits returns 1 if no byte received 00 FF if byte TTA simplified references if port gt 3 abort rxbyte if rx_tail port lt gt rx_head port rxbyte rxchar port byte rxbuff_ptr port rx_tail port rx_tail port rx_tail port 1 rxsize port PUB rxtime port ms rxbyte t Wait ms milliseconds for a byte to be received returns 1 if no byte received 00 FF if byte t cnt repeat until rxbyte rxcheck port gt 0 or cnt t clkfreq 1000 gt ms PUB rx port rxbyte Receive byte may wait for byte returns 00 FF repeat while rxbyte rxcheck port lt 0 PUB tx port txbyte Send byte may wait for room in buffer if port gt 3 abort repeat until tx_tail port lt gt tx_head port 1 txsize port byte txbuff_ptr port tx_head port txbyte tx_head port tx_head port 1 txsize port 81 if rxtx_mode port amp NOECHO rx port PUB txflush port repeat until long tx_tail port long tx_head port PUB str port stringptr Send zstring str
11. Set pin 26 amp 27 to low dira A_TX 1 outa A_TX 1 rawSpeed 50 rawDirection 50 64 lServo 750 rServo 750 Pause 100 outa A_TX 0 fds Init fds AddPort A_PORT A_RX A_TX A_CTS A_RTS 0 000000 BAUD fds AddPort DEBUG 31 30 1 1 0 000000 BAUD Debug to the terminal screen fds Start fds str DEBUG String Program Started Outputs Program Started to the terminal screen fds tx DEBUG 13 Pause 2000 UART startup delay cognew Values stack 0 Start a new cog to manage the servo pulses Pause 250 cognew ServoPulse stack 300 repeat repeat ctr 0 inByteArr ctr fds rx A_PORT until inByteArr ctr A or inByteArr ctr B if inByteArr ctr A 65 repeat ctr inByteArr ctr fds rx A_PORT until inByteArr ctr dataV 0 scale 0 repeat Index from 1 to ctr 1 scale ctr 1 Index if scale 2 dataV dataV inByteArr Index 48 100 elseif scale 1 dataV dataV inByteArr Index 48 10 else dataV dataV inByteArr Index 48 rawSpeed dataV dio dec DEBUG dataV fds tx DEBUG 13 if inByteArr ctr B repeat ctr inByteArr ctr fds rx A_PORT until inByteArr ctr dataH 0 scale 0 repeat Index from 1 to ctr 1 scale ctr 1 Index if scale 2 dataH dataH inByteArr Index 48 100 elseif scale 1 dataH dataH inByteArr Index 48
12. 5 Relative number of devices by platform number API level Code Name 8 8 Figure 6 Mobile platform Samsung Galaxy Note II running Android 4 3 Ice Cream LS 1d 6 EA E EE EAE E E EE E EE 9 Figure 7 ActivityBot Robot Kit 9 neseeeseseeosesnsseesseseessessessesssssesssesesssesesssesesssessssse 10 Figure 8 Propeller Activity Board 10 ocsstcrinssrssactsasegetatoatdoedobcesnasisequaptybielgevadtusasrndnede 11 Figure 9 RN 42 Bluetooth Adapter 11 neneeseeeeseeeeseesessessessessesressesesserressessesseesesse 12 Figure 10 Assembled robotic platform with Bluetooth adapter esseeeseeeeeeereesseees 12 Figure 11 System wiring diagram for the robotic platform and Bluetooth adapter 13 Figure 12 Android Environment and Eclipse IDE with code snippet from BlueTest3 PPP CAN OU cesta ates Sos ch watn a st dads a a wganuduene edd ea taciS se ap 14 Figure 13 Spin IDE with code snippet from the PBAA_v0 7 spin program 15 Figure 14 Example Message per the Communication Protocol cece eeeeeseeeeeees 16 Figure 15 Level O System Block Diagram ii 2 sccesdssstasavavendsestesdencesadsscveesneasesssesusiens 18 Figure 16 Android User Interface for Controlling the Robotic Platform 19 Figure 17 Android User Interface Code Snippet eeeeseeseeseesessreserrresesresserressrrsesseesrsse 20 Figure 18 Level 1 Block Diagram Android Process for Connecting to a Remote Blu toogth Devic pik ai
13. K 12 1100 FF Form Feed 76 1001100 L Uppercase L 13 1101 CR Carriage Return 77 1001101 M Uppercase M 14 1110 SO Shift Out X On 78 1001110 N Uppercase N 15 1111 SI Shift In X Off 79 1001111 oO Uppercase O 16 10000 DLE Data Line Escape 80 1010000 P Uppercase P 17 10001 DC1 Device Control 1 oft XON 81 1010001 Q Uppercase Q 18 10010 DC2 Device Control 2 82 1010010 R Uppercase R 19 10011 DC3 Device Control 3 oft XOFF 83 1010011 S Uppercase S 20 10100 DC4 Device Control 4 84 1010100 T Uppercase T 21 10101 NAK Negative Acknowledgement 85 1010101 U Uppercase U 22 10110 SYN Synchronous Idle 86 1010110 V Uppercase V 23 10111 ETB End of Transmit Block 87 1010111 Ww Uppercase W 24 11000 CAN Cancel 88 1011000 X Uppercase X 25 11001 EM End of Medium 89 1011001 Y Uppercase Y 26 11010 SUB Substitute 90 1011010 Z Uppercase Z 27 11011 ESC Escape 91 1011011 Opening bracket 28 11100 FS File Separator 92 1011100 Backslash 29 11101 GS Group Separator 93 1011101 Closing bracket 30 11110 RS Record Separator 94 1011110 a Caret circumflex 31 11111 US Unit Separator 95 1011111 Z Underscore 32 100000 Space 96 1100000 Grave accent 33 100001 Exclamation mark 97 1100001 a Lowercase a 34 100010 a Double quotes or speech marks 98 1100010 b Lowercase b 35 100011 Number 99 1100011 Cc Lowercase c 30 36 100100 Dollar 100 1100100 Lowercase d 37 100101 P
14. PST Converts a zero terminated string representation of a number to a value in the designated base Ignores all non digit characters except negative when base is decimal 10 value index 0 repeat until chr byte stringptr index 0 chr 15 chr amp 11011111 39 chr gt 56 Make 0 9 A B a f be 0 15 others out of range if chr gt 1 and chr lt base Accumulate valid values into result ignore others value value base chr 114 if base 10 and byte stringptr If decimal address negative sign ignore otherwise value value DAT PEK KOK K K K K K K K K K K K K K KKK K K K K K K K 2K K K K K K K K Assembly language serial driver PEK KOK K K K K KK K K K K K K K KKK K K K K K K K 2K 2K K K K K OK K gi TERMS OF USE MIT License PQ m pm m Permission is hereby granted free of charge to any person obtaining a copy of this software and associated documentation files the Software to deal in the Software without restriction including without limitation the rights to use copy modify merge publish distribute sublicense and or sell copies of the Software and to permit persons to whom the Software is furnished to do so subject to the following conditions The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software 115 T
15. T AT amp T Task Killet Scanner Connect EamilyMap i G A hy AT amp T AT amp T AT amp T AT amp T Smart BlueTest3 Cocker NEW lef ol mada i talep sere WEEt A hese Calculator Calendaf saerae ChatON Chat i me Contacts Downloads Matchen Er AN lt Np Drive Dropbox Ean Figure 21 BlueTest 3 Application Launched from the Application Menu BRS 4 9 22 PM 1 BlueTest3 V 50 H 50 Start Scan and Connect Make device discoverable Figure 22 User Menu within the Application 32 m gi Select a device to connect to Paired Devices ECES AECI EZES RN42 966D 00 06 66 48 96 6D asyBT gt 0 17 A0 01 6D 5C UConnect 00 06 F5 FB 4E 82 UConnect 04 98 F3 E6 AF 0D Figure 23 List of Bluetooth Devices Found for Pairing m ENE OR ae 9 23 PM gi BlueTest3 V 50 H 50 Start gt Figure 24 Screen Prior to Selecting Start Slider Bars Disabled 33 e V 50 H 50 re BlueTest3 Start Figure 25 Screen after Selecting Start Slider Bars Enabled Yona 6 32 PM Bluetooth permission request Application is requesting permission to turn on Bluetooth Allow Copied to clipboard Figure 26 Screen Requesting the User to Enable Bluetooth on the Device 34 Poo D ETACSE V 50 H 50 Start Bluetooth Enabled Figure 27 Alerting the User of Successfully Enabling Bluetooth ae Saving screenshot Apps amp mm 0 Gy a he AdVahced AIDE AT amp
16. T Code AT amp T A AT amp T Task Killet Scanner Connect EamilyMap fi G a e AT amp T AT amp T AT amp T AT amp T Smart TESE Locker NEEL LEEENA Wi Fi gt F O EJ Bluetooth Calculator Calenda a ChatON Chat i 5 Ba Color Gontacts Downloads WE ka A o E Drive Bluetooth failed to initialize exiting ebook Figure 28 Alerting the User Bluetooth Failed to Initialize 35 a m m E FSN BlueTest3 V 80 H 30 Start Figure 29 Example of User Input 6 3 XML Code for Android User Interface and Context Menus 6 3 1 Main User Interface XML Code lt Relative Layout xmlns android http schemas android com apk res android tools http schemas android com tools xmins androi androi tools andro d layout_width fill_parent d layout_height fill_parent context MainActivity id orientation horizontal gt lt TextView android id tid txtoOut roid layout_width fill_parent roid layout_height wrap_content gt and and lt Button androi androi androi androi androi androi aaaaada id id btn_Send ayout_width wrap_content ayout_height wrap_content ayout_alignParentTop true ayout_centerHorizontal true lt pext Start gt lt TextView android android id tid textViewl layout_width wrap_content android layout_height wrap_content android
17. and Robotic Platform sesseseeeeeeeeseeees 9 2 2 3 Setting up the Development Environment Android amp Propeller 13 2 3 Communication Protocol and Control Logic Design eee eee eeeeeeee 15 2 3 1 Development of a Communication Protocol eee eeseeeeeeeeees 15 2 3 2 Implementing and Demonstrating the Communication Protocol 17 3 JRESUL TS AND DISCUSSION reena eaaa lanea a Eaa S EE S E A TRER 25 AZ CONC EWS IONS Jrs m mana er e a aaao a ea aiaa rase ae E aaaea orir 27 Do REFERENCES prseter are e a Ea E Ea O AE nea E EESE A 28 G APPENDECIES rrsan r T AE a a A E E R 30 6 1 Table of the first 128 Characters of the ASCII Code eeeeeeeeeeeeeeeeeeeee 30 6 2 Android Device User Interface Screen Captures eeeeeseeeeeereeersrrrererrrerrersees 32 6 3 XML Code for Android User Interface and Context Menus cee 36 6 4 6 5 6 3 1 Main User Interface XML Code cfs se ccscetesccticeit teats steestaetbevcnyiaterst 36 6 3 2 Discovered and Connected Bluetooth Device List eee 37 6 3 3 Display Format of Device Names 00 0 cece ceseesseceseceeeeeeeeeseeseeeeeeees 38 6 3 4 XML Code for Options MERU sid sciiedstacsatarcersterdsescasiatotettedgorsszeisonivasy 38 6 3 5 String Constants Referenced in the User Interface eee 39 6 3 6 Android Mamifest Pil 6 cc2s0tdinsssxeavedtetaticaatedonssininapiee er SE Ea ESES 39 Java Source Code for Android Device ee eee esceseesseceeeceseeseenseceaeeneeeaees 40 G
18. as discussed earlier I also expect to have implemented the communication protocol and demonstrate its use on a physical device 2 METHODOLOGY IMPLEMENTATION Developing a communication protocol for use between typical electronic devices and mobile devices such as tablets and cell phones is possible in that the foundation and principals rules i e the protocol should be transferable across any platform However due to the number of mobile platforms available Windows iOS Blackberry Android the number of data transfer methods Bluetooth Peer to Peer Wi Fi Internet Cell Network and the number or electronic devices it would be an extensive task to demonstrate implement the communication protocol across all of the available platforms It would also be a trivial task in that relatively no unique work would be required For the most part it would be a task of translating the code from one language to another Instead I plan to demonstrate a communication protocol and the communication between an android device and a microcontroller over Bluetooth using only open source hardware and software This will allow me to develop the communication protocol in a cost effective manner while still remaining flexible so that it can be expanded to other operating systems and devices as need dictates 2 1 Required resources To develop and implement a communication protocol between a mobile device and another electronic device there are several pieces o
19. cc eaea erra Anaa a roa AA E EE EE AAST EE ES 21 Figure 19 Level 1 Block Diagram for Reading User Input and Transmitting to a Remote Device ae a a Eo suns Ea oE T Aa EEES E 22 Figure 20 Level 1 Block Diagram of the Propeller microcontroller and the interaction Between COGS aye ereen sles eaa EAE EO a aa P Aa a E OE o ALARE ESERIA 24 Figure 21 BlueTest 3 Application Launched from the Application Menu 0 32 Figure 22 User Menu within the Application eseeeeesseseeseesessrsserressrrressrrressersessersrsse 32 Figure 23 List of Bluetooth Devices Found for Pairing eseeeeseeereseeeeesrreersrrrersrere 33 Figure 24 Screen Prior to Selecting Start Slider Bars Disabled eee 33 Figure 25 Screen after Selecting Start Slider Bars Enabled eee eeeeeeeeee 34 iv Figure 26 Screen Requesting the User to Enable Bluetooth on the Device 0 34 Figure 27 Alerting the User of Successfully Enabling Bluetooth eee 35 Figure 28 Alerting the User Bluetooth Failed to Initialize eee eeeeeeeees 35 Fig re29 Exampleof User Tnp tnsscsenn enesenn aa a a a 36 ACKNOWLEDGMENT To my parents who have taught me the importance and value of education and to my loving wife whose support has kept me going when I might have otherwise quit Vi ABSTRACT The intent of this paper is to show that it is possible to create a single Android application that is capable of working with an extensive numbe
20. endIdX masterString delete 0 endIdX 1 return completeSegment else return Working End of DataResolver 6 5 ActivityBot Propeller Spin Source Code 6 5 1 RN 42 Bluetooth Module Configuration Spin Source Code File PBAA_v0 2 spin PBAA Propeller Bluetooth and Android v0 2 This application programs the RN 42 to communicate with a 9600 Baud rate 55 n It also demonstrates how to enter command mode and also how to exit it The program also demonstrates how to record the responses received after issuing commands New to Version 0 2 CON _xinfreq 5_000_000 _clkmode xtall pll16x Bluetooth Constants DEBUG 0 Debug port sends results to Parallax Serial Terminal A_PORT 1 Bluetooth Module A_RESET 0 To RST pin on RN 42 Bluetooth Module A_TX l To RX pin on RN 42 Bluetooth Module A RX 2 To TX pin on RN 42 Bluetooth Module A CTS 3 To RTS pin on RN 42 Bluetooth Module A_ RTS 4 To CTS pin on RN 42 Bluetooth Module BAUD 9600 Baud Rate 9600 bps VAR long tLow tHigh T dt stack 700 cntr inByte inString ctr testStr 15 milis char word cntMin byte i inByteArr 25 bufferSize 56 OBJ fds FullDuplexSerial4port dio datalO4port pst Parallax Serial Terminal V1 0 Create the Parallax Serial Terminal Object for the LCD Screen amp Bluetooth module Need to use pst file in this folder as it has been modified to use Pin 1 am
21. not used if_z movi transmit 010111_000 patch it out entirely by making the jmpret into a jmp TTA or rxmask 0 wz ditto for rx routine if z movi receive 010111_000 TTA i MAIN LOOP 88 ReceiveO receive jmpret rxcode txcode run a chunk of transmit code then return patched to a jmp if pin not used test rxmask ina we start0 if_c jmp nortsO go check rts if no start bit have to check rts because other process may remove chars will be patched to jmp receive if no rts moy rxbits 9 ready to receive byte moy rxcnt bit4_ticks 1 4 bits add rxcnt cnt bit add rxcnt bit_ticks bit period wait jmpret rxcode txcode run a chuck of transmit code then return mov tl rxcnt check if bit receive period done sub tl cnt cmps tl 0 we if_ne jmp wait test rxmask ina wc receive bit on rx pin rcr rxdata 1 djnz rxbits bit get remaining bits test rxtx_mode INVERTRX wz find out if rx is inverted if_z nec jmp receive abort if no stop bit TTA from serialMirror jmpret rxcode txcode run a chunk of transmit code then return shr rxdata 32 9 justify and trim received byte 89 nortsO rts WC if_c rtsO recOi 1 Receivel receivel startl if_c wrbyte rxdata rxbuff_head_ptr 7 22 lwr add rx_head 1 cmpsub rx_head rxsize TTA allows non binary buffer size wrlong rx_head rx_h
22. on tx buffer Used by Cog ys Cog constants 4 words a A significant amount of space 4 x 16 words is used for pre calculated information hub addresses per port configuration This speeds up the tx rx routines at the cost of this space i x Note There are 8 longs remaining in the cog s memory expect to do some work to add features i x DWD Note from Duane Many of the longs in the cog image are only used in hub RAM There is still lots of room in cog RAM TTA agreed thanks DWD x 7 1 08 Fixed bug of not receiving with only 1 port enabled Fixed bug of rts not working on ports 0 2 and3 7 22 08 Missed a jmpret call in port and 3 tx Fixed a bug in port 3 tx not increasing tx ptr 7 24 08 Added version variable to change if need multiple copies of the driver x TREK K KE K KE KE K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K 2K 2K 2K 2K CON NOMODE 000000 INVERTRX 000001 INVERTTX 000010 OCTX 000100 75 NOECHO 001000 INVERTCTS 010000 INVERTRTS 100000 PINNOTUSED l tx tx cts rts pin is not used DEFAULTTHRESHOLD 0 zero defaults to 3 4 of buffer length BAUD1200 1200 BAUD2400 2400 BAUD4800 4800 BAUD9600 9600 BAUD19200 19200 BAUD38400 38400 BAUDS57600 57600 BAUD115200 115200 The following constants declare the sizes of the rx and tx buffers Ent
23. protocol on the Android and robotic platforms it is important to create a roadmap or high level system block diagram that will govern the flow of input form the user to the eventual signals that will be sent to the motors on the robotic platform The block diagram governing the entire system can be seen in Figure 15 This diagram shows what tasks will be the responsibility of the Android device and what operations the robotic platform will be responsible for Additional block diagrams of greater detail of operations on the individual devices as well as their interaction are included in later sections of this report eee oe meee ee Oe meee A A eee eee os Android Device User scans for and connects User input on to a remote BT Android Device Device l Input converted to data amp sent l via Bluetooth l eoa ee a A Speed B Direction l l Data received by Serial Microcontroller l BT module and commands read sends i converted to amp interpreted by commandsto i serial commands microcontroller servo motors i L Robotic Platform j Figure 15 Level 0 System Block Diagram 18 2 3 2 1 Implementation of the Communication Protocol on the Android Device To implement the communication protocol on the Android powered mobile device one must first create an Android application In addition to the behind the scenes code that runs the Android application which is responsible for taking the users input an
24. rx_head3 rdlong rx_tail3 rx_tail_ptr3 7 22 or 8 may be patched to jmp r3 if moy tl rx_head3 sub tl rx_tail3 wc add tl rxsize3 fix wrap TTA change cmps tl rtssize3 wc is buffer more that 3 4 full 94 transmit txctsO ctsi0 if_z muxc outa rtsmask3 jmp receive3 byte done receive next byte TRANSMIT jmpret txcode rxcodel run a chunk of receive code then return patched to a jmp if pin not used test ctsmask ina wc if flow controlled dont send rdlong tl tx_head_ptr 7 22 head 0 cmp tl tx_tail wz tail 0 jmp transmit may be patched to if_z_or_c or if_z_or_ne rdbyte txdata txbuff_tail_ptr 8 add tx_tail 1 cmpsub tx_tail txsize wz TTA for individually sized buffers will zero at rollover if z if _nz wrlong tx_tail tx_tail_ptr 8 moy txbuff_tail_ptr txbuff_ptr reset tail_ptr if we wrapped add txbuff_tail_ptr 1 otherwise add 1 jmpret txcode rxcode1 shl txdata 2 or txdata txbitor ready byte to transmit moy txbits 11 moy txcnt cnt 95 txbit shr txdata 1 wc txout0 muxc outa txmask maybe patched to muxnc dira txmask add txcnt bit_ticks ready next cnt wait jmpret txcode rxcodel run a chunk of receive code then return mov tl txcnt check if bit transmit period done sub tl cnt cmps tl 0 wc if_ne jmp wait djnz txbits txbit another bit to transmit txjmp0 jmp ctsi0 byte done transmit next byte Transmit
25. streaming video from an onboard camera Due to the high bandwidth requirements to support streaming video the device utilizes WIFI instead of Bluetooth or other lower frequency RF communication protocols 2 Note that this software nor the communication protocol is distributed as open source software for others to modify or implement in their own projects and applications Figure 1 Rover Revolution Available from Brookstone 2 Parallax a popular supplier of microcontrollers and other components commonly used by armature robotic developers offers tutorials and educational material for many of their products In one such tutorial as seen in Figure 2 Parallax demonstrates the ability to send commands to a Propeller microcontroller remotely from a PC via a Bluetooth Serial Port Profile 3 Additionally the example provides open source software for the microcontroller mainly programs that were already available as published open source library s tied together with a single custom application The example utilizes an RN 42 Bluetooth adapter and the user sends commands to the microcontroller via a serial terminal like HyperTerminal or in the case of the example the Parallax Serial Terminal This example will be used as the foundation for my work on the microcontroller side of the task Figure 2 Parallax RN 42 Bluetooth Demo 3 An alternative approach to controlling a robot via a cell phone was demonstrated by MicroTronics Technologi
26. those to be their own object calling rx tx str and strn methods See companion object DatalO4port spin in order to maintain compatibility with methods in the original pcFullDuplexSerial4fe lvO1 init method returns pointer rxsize for data buffers and data structure 1v00 documentation Ov91 restored DEFAULTTHRESHOLD constant made default buffer sizes in the DAT section rather than init removed the numeric methods to their own companion object datalO4port 0v3 first public release with the jitter and flow control issues fixed and large buffers Links Development of this version http forums parallax com showthread php 137349 yet another variant fullDuplexSerial4portplus Tim Moore s original pcFullDuplexSerial4fc and updates to allow flow control http forums parallaxinc com forums default aspx f 25 amp p 1 amp m 27329 1 m276667 http obex parallax com objects 340 7 24 08 version http forums parallaxinc com forums default aspx f 25 amp p 1 amp m 349 173 8 14 08 update flow polarity correction not in obex Duane Degn s thread larger 128 or 512 byte buffers and reusing buffer space discussion of issues http forums parallax com showthread php 1297 14 Tim Moore s pcFullDuplexSerial4 FC with larger 285 12 byte 29 rx buffer Juergen Buchmueller 2 port trimmed down version 71 http forums parallax com showthread php 128 184 Serial Objects for SPIN Programming amp p
27. user with additional visual feedback and helps to verify that the 19 user input is being understood by the Android application this was also very helpful in the development and debugging of the application This feature could be removed in a final production version of the application and is not critical to the functionality of the application Finally the user interface and its various sub menus and screens is written in the XML language format Figure 17 is a Code Snippet of the XML code written to display two text views and a button on the user interface The XML code used to generate the Android User interface can be found in Appendix 6 3 XML Code for Android User Interface and Context Menus Java BlueTest3 res layout activity_main xt File Edit Refactor Source Navigate Search Project Run Window Help Mres CERE i Ha e a SE ao Ee EH C E E Package Explorer B 7 G MainActivityjava d activity_main xml amp J DataResolverServicejava DeviceListActivityjava i Bluett G appcompat_v7 lt RelativeLayout xmlns android http schemas android com apk res android i appcompat_v7_2 xmins tools http schemas android com tools android layout_width fill parent appcompat_v7_3 Stone android layout_height fill parent ad RENA tools context MainActivity sliderTest android orientation horizontal gt G sliderTest2 GG sliderTest3 lt TextView android id id txt0ut T testApp android layout_width fill_p
28. 50 hSeek setEnabled false vSeek setProgress 50 vSeek setEnabled false 41 hSeek setOnSeekBarChangeListener new OnSeekBarChangeListener Override public void onStopTrackingTouch SeekBar seekBar hSeek setProgress 50 Override public void onStartTrackingTouch SeekBar seekBar TODO Auto generated method stub Override public void onProgressChanged SeekBar seekBar int progress boolean fromUser String stringH Integer toString progress hText setText stringH String messageB B String messageF byte sendB messageB getBytes mDataService write sendB try Thread sleep 1 catch InterruptedException e TODO Auto generated catch block e printStackTrace Log d OutputService Output B Complete byte sendH stringH getBytes mDataService write sendH try Thread sleep 1 catch InterruptedException e TODO Auto generated catch block e printStackTrace Log d OutputService Output H Complete byte sendF messageF getBytes mDataService write sendF try Thread sleep 1 catch InterruptedException e TODO Auto generated catch block e printStackTrace Log d OutputService Output F Complete 42 vSeek setOnSeekBarChangeListener new OnSeekBarChangeListener Override public void onStopTrackingTouch SeekBar seekBar
29. 9 manufactured by Parallax 11 will provide Bluetooth 2 1 2 0 1 2 1 1 communication support to the project The RN 42 Bluetooth adapter provides a standard pin breakout connector which can easily be connected to the breadboard on the Parallax Activity Board and wired to its I O pins Additionally it can be set to operate off of and controlled by 3 3V which aligns with the 3 3V powered Propeller microcontroller 11 t1111 Figure 9 RN 42 Bluetooth Adapter 11 The RN 42 module communicates with the Propeller microcontroller via asynchronous serial interface with RTS CTS flow control at a user programmed baud rate which was set to 9600 bps for compatibility with the microcontroller Further support information and examples of use with the Propeller microcontroller can be found on the products web page 11 The fully assembled Robotic Platform can be seen in Figure 10 Status LEDs Bluetooth Module Propeller Chip USB Programming amp Debug Port Figure 10 Assembled Robotic Platform with Bluetooth Adapter Additionally the system wiring schematic can be seen in Figure 11 12 Figure 11 System Wiring Diagram for the Robotic Platform and Bluetooth Adapter 2 2 3 Setting up the Development Environment Android amp Propeller Providing a full description of how to download install and configure the Android and Propeller development environments is outside the scope of this project However below is a brief descri
30. 967075 amp viewfull 1 post967075 Serial Mirror single port but same idea regarding buffers in the DATa space http forums parallax com showthread php 943 1 1 SerialMirror A FullDuplexSerial enhancement http obex parallax com objects 189 Re baud rates attainable hiccups http forums parallaxinc com forums default aspx f 25 amp p 1 amp m 282923 m282978 http forums parallaxinc com forums default aspx f 25 amp p 1 amp m 334784 http forums parallax com showthread php 120868 FullDuplexSerial hiccups Jitter discussions of jitter in different Prop serial programs PhiPi s development of PBnJ full duplex http forums parallax com showthread php 129776 Anybody aware of high accuracy 0 7 or less serial full duplex driver http forums parallax com showthread php 13643 1 Serial objects question Humanoido s catalog of serial port objects http forums parallax com showthread php 128 184 Serial Objects for SPIN Programming Tim Moore s release notes follow Also note by Duane Degn Not all these comments apply to FullDuplexSerial4port J TREK K KOK K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K 2K 2K 2K K Based on j Full Duplex Serial Driver v1 1 Author Chip Gracey j Copyright c 2006 Parallax Inc 4 x See end of file for terms of use x Wk x x Tim Moore 2008 72 Wk Wk Wk Wk
31. AL Main Activity Java Code nau nude cacti haiti ia 40 6 4 2 Bluetooth Data Transfer Servicecs ns ctntinusi hie tenia 46 OAS Device List ACH vity once satis itunes eatin aictea iesaae aceasta 51 6 4 4 Data Resolver Sery ices ainn icleah iaaie nung 55 ActivityBot Propeller Spin Source Code eesseeeeeseeeseresesseesesreesrrrersrsseesresees 55 6 5 1 RN 42 Bluetooth Module Configuration Spin Source Code 55 6 5 2 RN 42 Bluetooth Module Verification Spin Source Code 0 59 6 5 3 ActivityBot Spin Source Code Implemented on the Propeller Microcontroller cic istivenecshacavssdesbiveietliieaveeaacanoes sebuabbece a 63 6 5 4 FullDuplexSerial4port Spin Library 00 ees eee eeeeeeeeeeeeeeneeees 70 6 5 5 DatalO4 port S pitt Library ic sicssesdktiins sev ctlenteacenssiiee ciectteentecdtaessesenseies 107 LIST OF TABLES Table 1 List of Android API Levels and Corresponding Code Names 6 0 7 Table 2 Correlation between Index its Meaning on the Android Device and the Robot ill LIST OF FIGURES Figure 1 Rover Revolution available from Brookstone 2 escessecsseeeeseeeeeneeeeees 2 Figure 2 Parallax RN 42 Bluetooth Demo 3 sescsic5ssgat escosadinacesyiosaceatedenteav ease Saeiviatees 3 Figure 3 MicroTronics Technologies Mobile Control Robot 4 cece eeeeeeeeees 3 Figure 4 World Wide Mobile OS Market Share 5 0 0 cee eeeeceeseecesseeceeeeeeneeenseeeseaees 6 Figure
32. HE SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND EXPRESS OR IMPLIED INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM DAMAGES OR OTHER LIABILITY WHETHER IN AN ACTION OF CONTRACT TORT OR OTHERWISE ARISING FROM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE a E E 116
33. Index B Prefix Figure 19 Level 1 Block Diagram for Reading User Input and Transmitting to a Remote Device 2 3 2 2 Implementation of the Communication Protocol on the Robotic Platform The task of implementing the communication protocol on the robotic platform and Propeller microcontroller is similar to that of its implementation on the Android device However there is one key difference that simplifies to some degree the task on the robotic platform no user interface is required While instead of interfacing with a 22 user and obtaining input the Propeller microcontroller is tasked with reading input per the communication protocol and outputting signals to drive the platforms motors First to establish a proper communication between the Bluetooth module and the Propeller microcontroller as well as setting the module in the correct mode for accepting connection attempts the module must first be configured This is done via the asynchronous serial interface with RTS CTS flow control which can be established between the Propeller and the Bluetooth module Supporting documentation and the products user manual go into sufficient detail on how to set up and configure the Bluetooth module based on the desired application both are available off of the products webpage 11 Additionally the Propeller spin code used to configure and then verify the state of the Bluetooth adapter can be found in Appendix sections 6 5 1 and 6 5 2 The task of i
34. Remote Communication with a Microcontroller via a Bluetooth Enabled Android Device by Vito M Guardi An Engineering Project Submitted to the Graduate Faculty of Rensselaer Polytechnic Institute in Partial Fulfillment of the Requirements for the degree of MASTER OF ENGINEERING Major Subject Mechanical Engineering Approved Ernesto Gutierrez Miravete Thesis Adviser Rensselaer Polytechnic Institute Hartford CT May 2014 Copyright 2014 by Vito M Guardi All Rights Reserved CONTENTS Remote Communication with a Microcontroller via a Bluetooth Enabled Android Device Singing obi valbed Suicuiitsnasbawiteiod bull dbeecu etn E E E N i LISTOF TABLES reee e EEE ERE EEE E TEE E E a a E iii LIST OBR FIGURES erne E E EE AA E RAs iv ACKNOWLEDGMENT orei ei erea a N AE A Ea E Ai vi PE SR AGT MAAA TT A vii 1 INTRODUCTION BACKGROUND ssseeeeseeseeseeseesrrrerressesrersesrersrsreesreseestesreneesrenes 1 UAT gt ECT UIA Se ara EEE RA T AA ET E aan aie nea enero 1 L2 Prior Woke Sissi n era LRA AR ET A EAR E EE A RA a 1 Lid Obj ctiye neenake a eiei E E EEA A EE E a GE 4 2 METHODOLOGY IMPLEMENTAT ION cccscstsssssssseteessesscsesseescesssesseesosesenes 5 Balk Reg ir d TES OULCES nasora a e a A a a a a Eie 5 2 2 Component and Software Selection sseeseessesessessesresseresereestserestreesresrererssese 6 2 2 1 Selecting a Mobile Operating System amp a Mobile Device 6 2 2 2 Selecting a Microcontroller
35. T fds tx DEBUG inByteArr ctr fds str A_PORT String Message sent that tells the RN 42 to Exit command mode fds tx A_PORT 13 Tf successfull END is returned fds tx A_PORT 10 ctr 0 inByteArr ctr fds rx A_PORT fds tx DEBUG inByteArr ctr repeat until inByteArr ctr 13 ctr inByteArr ctr fds rx A_PORT fds tx DEBUG inByteArr ctr 6 5 2 RN 42 Bluetooth Module Verification Spin Source Code File PBAA_v0 3 spin PBAA Propeller Bluetooth and Android v0 3 Test the use of get commands on the RN 42 Bluetooth Module n Assumption is that the module is set to 9600 Baud rate CON _xinfreq 5_000_000 _clkmode xtall pll16x 59 Bluetooth Constants DEBUG 0 Debug port sends results to Parallax Serial Terminal A_ PORT 1 Bluetooth Module A_RESET 0 To RST pin on RN 42 Bluetooth Module A_TX l To RX pin on RN 42 Bluetooth Module A RX 2 To TX pin on RN 42 Bluetooth Module A CTS 3 To RTS pin on RN 42 Bluetooth Module A_ RTS 4 To CTS pin on RN 42 Bluetooth Module BAUD 9600 Baud Rate 9600 bps VAR long tLow tHigh T dt stack 700 cntr inByte inString ctr testStr 15 milis char word cntMin byte i inByteArr 300 bufferSize OBJ fds FullDuplexSerial4port dio datalO4port pst Parallax Serial Terminal V1 0 Create the Parallax Serial Terminal Object for the LCD Screen amp Bluetooth module Need to use pst file in this fo
36. TX_SIZE3 Object memory from here to the end is zeroed in the init stop method Some locations within the next set of values after being initialized to zero are then filled with alternative options 100 That are accessed from both spin and pasm Dont Change the order of these initialized variables within port groups of 4 without modifying the code to match both spin and assembler startfill rxchar rxchar1 rxchar2 rxchar3 cog rxtx_mode rxtx_mode 1 rxtx_mode2 rxtx_mode3 rx_head spin and pasm rx_head1 rxbuff_ptr rx_head2 rx_head3 rx_tail rx_taill rxbuff_ptr rx_tail2 rx_tail3 tx_head spin and pasm tx_head1 txbuff_ptr tx_head2 byte 0 used by spin rxcheck for inversion of received data byte 0 byte 0 byte 0 long 0O cog flag id long 0O mode setting from values passed in by addport long 0 long 0 long 0 long 0 rx head pointer from 0 to size of rx buffer used in long 0 data is enqueued to this offset above base long 0 long 0 long 0 rx tail pointer ditto zero to size of rx buffer long 0 data is dequeued from this offset above base long 0O long 0O long O tx head pointer from 0 to size of tx buffer used in long 0 data is enqueued to this offset above base long 0O 101 tx_head3 tx_tail tx_taill txbuff_ptr tx_tail2 tx_tail3 rxbuff_ptr buffers rxbuff_ptr1 rxbuff_ptr2 rxbuff_ptr3 txbuff_ptr buffers txbuff_ptr1 txbuff_ptr2 txbuff_ptr3
37. Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Modified to support 4 serial ports It should run 1 port faster than FullDuplexSerial or run up to 4 ports X Merged 64 byte rx buffer change Merged Debug_PC Jon Williams TTA cut the numeric methods see datalO4port spin to maintain compatibility with pcFullDuplexSerial4fc or use other numeric methods such as simpleNumbers Uses DAT rather than VAR so can be used in multiple objects If you want multiple objects using this driver you must copy the driver to a new file and make sure version long is unique in each version Added txflush Optimization perf x 1 port up to 750kbps 2 port up to 230kbps 3 port up to 140kbps x 4 port up to 100kbps X Tested 4 ports to 115Kbps with 6MHz crystal These are approx theoretical worse case you may get faster if port is active but idle Added RTS CTS flow control X x There is no perf penalty supporting 4 serial ports when they are not enabled i There is no perf penalty supporting CTS and RTS Enabling CTS on any port costs 4 clocks per port 5 Enabling RTS on any port costs 32 clocks per port Main Rx Tx loop is 256 clocks per port without CTS RTS compared with FullDuplexSerial at 356 clocks x 73 Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk W
38. _tail_ptr3 txbuff_ptr3 reset tail_ptr if we wrapped add txbuff_tail_ptr3 1 otherwise add 1 jmpret txcode3 rxcode shl txdata3 2 or txdata3 txbitor ready byte to transmit moy txbits3 11 mov txcnt3 cnt shr txdata3 1 we muxc outa txmask3 maybe patched to muxnc dira txmask add txcnt3 bit_ticks3 ready next cnt jmpret txcode3 rxcode run a chunk of receive code then return mov tl txcnt3 check if bit transmit period done sub tl cnt cmps tl 0 wc jmp wait3 99 djnz txbits3 txbit3 another bit to transmit txjmp3 jmp ctsi3 byte done transmit next byte The following are constants used by pasm for patching the code depending on options required doifce2ifne long 003c0000 patch condition if_c to if_nc using xor doif_z_or_c long 00380000 patch condition if_z to if_z_or_c using or doif_z_or_nc long 002c0000 patch condition if_z to if_z_or_nc using or domuxnc long 04000000 patch muxc to muxnc using or txbitor long 0401 bits to or for transmitting adding start and stop bits Buffer sizes initialized from CONstants and used by both spin and pasm rxsize long RX_SIZEO TTA size of the rx and tx buffers is available to pasm and spin rxsizel long RX_SIZE1 these values are transfered from the declared CONstants rxsize2 long RX_SIZE2 at startup individually configurable rxsize3 long RX_SIZE3 txsize long TX_SIZEO txsizel long TX_SIZE1 txsize2 long TX_SIZE2 txsize3 long
39. arent android layout_height wrap content gt lt Button android id id btn_Send android layout_width wrap content android layout_height wrap content android layout_alignParentTop true android layout_centerHorizontal true android text Start gt lt TextView android id id textViewl android layout_width wrap content android layout_height wrap content android layout_alignParentLeft true android layout_alignParentTop true amp android text V gt Figure 17 Android User Interface Code Snippet In addition to the user Interface the behind the scenes control logic written in Java for the Android application has an even larger role to play This is where all of the activity takes place to support the user interface interpret user input manage the Bluetooth connection data transmissions and last but certainly not least implementation of mistake proofing features like ensuring the Bluetooth device is enabled before starting the application Figure 18 is a block diagram that represents the process for connecting to a remote discoverable Bluetooth enabled device from the Android device Note that the application ensures that Bluetooth is enabled on the mobile device requesting user input when required or else the application is terminated 20 Note that it is possible to write an application that will on its own enable Bluetooth communication without notifying or requesting permission from the use
40. axcount lt MAXSTR_LENGTH repeat maxcount While maxcount not reached if byte stringptr uarts rx 0 NL Get chars until NL quit byte stringptr byte stringptr 1 NL Zero terminate string overwrite NL or append 0 char PUB StrInB port stringptr seconds char ticks ticks clkfreq seconds cnt repeat MAXSTR_LENGTH repeat char uarts rxcheck port until char gt 1 case char 32 126 byte stringptr char encompasses all numeric chars in dec and hex 8 127 stringptr 13 quit if ticks cnt lt 0 quit byte stringptr PUB DeclIn port value PST Receive carriage return terminated string of characters representing a decimal value Returns the corresponding decimal value StrInMax port str_buffer MAXSTR_LENGTH value StrToBase str_buffer 10 113 PUB HexIn port value from PST Receive carriage return terminated string of characters representing a hexadecimal value Returns the corresponding hexadecimal value StrInMax port str_buffer MAXSTR_LENGTH value StrToBase str_buffer 16 PUB BinIn port value from PST Receive carriage return terminated string of characters representing a binary value Returns the corresponding binary value Note that the constant MAXSTR_LENGTH limits the of digits StrInMax port str_buffer MAXSTR_LENGTH value StrToBase str_buffer 2 PRI StrToBase stringptr base value chr index from
41. blishes statistics on a monthly basis that tells us the relative number of devices that run a given platform version 8 2 2 1 1 Froyo 8 2 3 3 Gingerbread 10 17 8 2 3 7 3 2 Honeycomb 13 0 1 4 0 3 Ice Cream 15 14 3 4 0 4 Sandwich 4 1 x Jelly Bean 16 34 4 4 2 x 17 18 1 ice Cream Sandwic 4 3 18 8 9 4 4 KitKat 19 5 3 Data collected during a 7 day period ending on April 1 2014 Any versions with less than 0 1 distribution are not shown Figure 5 Relative Number of Devices by Platform Number API level Code Name 8 Based on Figure 5 as of April 2014 approximately 81 of android devices run Android 4 0 API 15 or later Since we want to maintain a similar user experience and style to what the majority of users are currently used to experiencing and selecting an older android version as the target version may make the application appear older and outdated compared to newer applications Android 4 0 API15 Ice Cream Sandwich will be selected as the target Android platform With a target mobile operating system selected the next choice is selecting a mobile device that utilizes the selected operating system Fortunately I currently own two mobile device that uses the Android operating system a cellphone and a tablet Both devices run Android Ice Cream Sandwich or later operating systems and while the tablet may boast higher performance processing power I have selected the cell phone Figure 6 as the test p
42. ctr 62 fds str A_PORT String Message sent that tells the RN 42 to Exit command mode fds tx A_PORT 13 Tf successfull END is returned fds tx A_PORT 10 ctr 0 inByteArr ctr fds rx A_PORT fds tx DEBUG inByteArr ctr repeat until inByteArr ctr 13 ctr inByteArr ctr fds rx A_PORT fds tx DEBUG inByteArr ctr 6 5 3 ActivityBot Spin Source Code Implemented on the Propeller Microcontroller File PBAA_v0 7 spin PBAA Propellar Bluetooth and Android v0 7 Working control of platfrom and successfull bluetooth comm CON _xinfreq 5_000_000 _clkmode xtall pll16x Bluetooth Constants DEBUG 0 Debug port sends results to Parallax Serial Terminal A_ PORT 1 Bluetooth Module A_RESET 0 To RST pin on RN 42 Bluetooth Module A_TX l To RX pin on RN 42 Bluetooth Module 63 A RX 2 To TX pin on RN 42 Bluetooth Module A CTS 3 To RTS pin on RN 42 Bluetooth Module A RTS 4 To CTS pin on RN 42 Bluetooth Module BAUD 9600 Baud Rate 9600 bps VAR long tLow tHigh T dt stack 700 cntr inByte inString ctr testStr 15 milis char us dataV dataH scale rawSpeed rawDirection speed IServo rServo direction range word cntMin byte i inByteArr 300 bufferSize cntB temp Index OBJ fds FullDuplexSerial4port dio datalO4port PUB Main milis clkfreq 1_000 dira 26 27 11 Set Pin 26 amp 27 to output outa 26 27 00
43. d rx_head_ptrl long 0 these pointers are initialized in spin but then used only by pasm rx_head_ptr2 long 0 the pasm cog has to know where in the hub to find those offsets rx_head_ptr3 long 0 rx_tail_ptr long 0O rx_tail_ptr1 long 0 rx_tail_ptr2 long 0 rx_tail_ptr3 long 0 tx_head_ptr long 0 tx_head_ptr1 long 0 tx_head_ptr2 long 0O tx_head_ptr3 long 0 tx_tail_ptr long 0 tx_tail_ptr1 long 0 tx_tail_ptr2 long 0O tx_tail_ptr3 long 0O End of the object memory zeroed from startfill to endfill in the init stop method endfill FIT The above is all of the necessary code that must fit in the cog The following are extra bytes if necessary to provide the required rx and tx buffers the number required is computed from the aggregate buffer size declared minus the above initialized but recycled variables 105 extra byte 0 RXTX_BUFSIZE RXTX_BUFSIZE lt extra overlay tt TERMS OF USE MIT License Permission is hereby granted free of charge to any person obtaining a copy of this software and associated documentation files the Software to deal in the Software without restriction including without limitation the rights to use copy modify merge publish distribute sublicense and or sell copies of the Software and to permit persons to whom the Software is furnished to do so subject to the following conditions The above c
44. d converts it into what will eventually become messages sent via the communication protocol a large part of the Android application development is the user interface To create the user interface for controlling a wheeled robotic platform I decided to mimic as closely as possible a standard remote that would be used to control a RC car Figure 16 A vertical scrolling bar will be used to control the speed of the robot while a similar horizontal scrolling bar will be used to control the direction of the robot Py BlueTest3 V 50 H 50 Forward Start Left Neutral Right gt Neutral Reverse Figure 16 Android User Interface for Controlling the Robotic Platform In addition to the controls of the robotic platform the GUI Graphical User Interface needs to provide the user with a method to search for and connect to other discoverable Bluetooth enabled devices This was implemented utilizing the menu button one of the three standard buttons on all android devices upon selecting the menu button the user is presented with the option to search for and connect to remote Bluetooth devices After which the user is presented with the Names and MAC Addresses of devices found See Appendix 6 2 for screen captures of the various screens a user will interact with on the android device In addition to the movement of the sliding bars the values of the sliders is displayed in the top left corner of the application this was done to provide the
45. dded string and numeric input methods These methods are called with reference to a port as defined when FullDuplexSerial4port is initialized n Tf you do want to merge these methods back into the main object simply remove all the uarts object references 107 Wk I made these separate because for my own work I often use a 1 completely different set of string amp numeric i o methods Wk x TREK K K K KE K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K 2K 2K 2K K CON FF 12 form feed CR 13 carriage return NL 13 MAXSTR_LENGTH 32 this limits the size of a binary string that can be entered VAR byte str_buffer MAXSTR_LENGTH 1 String buffer for numerical string input only This is in VAR space If multiple cogs will be _inputing_ numerical data simultaneously it is necessary to delare another instance so that the buffers do not clash That applies to numerical parsing only OBJ uarts FullDuplexSerial4port PUB str port stringptr 108 Send string repeat strsize stringptr uarts tx port byte stringptr PUB strln port strAddr Print a zero terminated string str port strAddr uarts tx port CR PUB dec port value i Print a decimal number decl port value 10 0 PUB decf port value width li Prints signed decimal value in space padded fixed width field decl p
46. did it by changing the affected jmpret to jmp Now the jitter is MUCH reduced port 2 initialization test rxtx_mode2 OCTX wz init tx pin according to mode test rxtx_mode2 INVERTTX we if_z nec or outa txmask2 if z or dira txmask2 if_z_eq_c or txout2 domuxnc patch muxc to muxnc if_nz movd_ txout2 dira change destination from outa to dira test rxtx_mode2 INVERTRX wz wait for start bit on rx pin if_nz xor start2 doifc2ifnc if_c jmp to if_nc or ctsmask2 0 wz if_nz test rxtx_mode2 4 INVERTCTS we 85 if_nz_and_c or ctsi2 doif_z_or_nc if_nc jmp TTA reversed order to correctly invert CTS if_nz_and_nc or ctsi2 doif_z_or_c if_c jmp if_z moy txcts2 transmit2 copy the jmpret over the cts test if_z moys ctsi2 txcts2 patch the jmps to transmit to txcts0 if_z add txcode2 1 change co routine entry to skip first jmpret or rtsmask2 0 wz if_nz or dira rtsmask2 TTA rts needs to be an output if_nz test rxtx_mode2 4INVERTRTS we if nz_and_nce or _ rts2 domuxnc patch muxc to muxnc if_z mov _ norts2 rec2i patch to a jmp receive2 if_z moys start2 receive2 skip all rts processing or txmask2 0 wz if tx pin not used if_z movi transmit2 010111_000 patch it out entirely by making the jmpret into a jmp TTA or rxmask2 40 wz ditto for rx routine if z movi receive2 010111_000 TTA port initialization
47. e Propeller microcontroller has a unique architecture unlike many others including the Arduino while most contain a single processor or cog the Propeller contains 8 independent 32 bit processors 10 Activity Board Figure 8 Propeller Activity Board 10 This allows for a consolidated package that can perform multiple time sensitive tasks without issues or delays What this translates into is the ability to constantly monitor the incoming Bluetooth communication channel while simultaneously updating and sending the time sensitive pulse commands required to control the servo motors driving the platform To do this with an Arduino a second motor controller board would be required to off load the time sensitive pulse commands from the main microcontroller The second reason for selecting the Parallax Propeller platform Propeller Activity Board for this project was a matter of convenience and available documentation product support From a compatibility standpoint by selecting a robotic platform and microcontroller both from the same manufacture compatibility was guaranteed Additionally Parallax offered supporting documentation for the use of the Propeller Activity Board with the ActivityBot which can be found on the products web page 9 The same methodology of selecting components from the same vendor Parallax in this case was also leveraged when selecting a Bluetooth adapter for use on the project The RN 42 Bluetooth adapter Figure
48. ead_ptr 8 2wr moy rxbuff_head_ptr rxbuff_ptr calculate next byte head_ptr add rxbuff_ head_ptr rx_head rdlong rx_tail rx_tail_ptr 7 22 or 8 will be patched to jmp r3 if no Ird mov tl rx_head sub tl rx_tail wc calculate number bytes in buffer TTA add and t1 7F fix wrap add tl rxsize fix wrap TTA change cmps tl rtssize wc is it more than the threshold muxc outa rtsmask set rts correctly jmp receive byte done receive next byte jmpret rxcodel txcodel run a chunk of transmit code then return test rxmaskl ina we jmp norts1 go check rts if no start bit moy rxbits1 9 ready to receive byte moy rxcntl bit4_ticks1 1 4 bits add rxcntl cnt 90 bit1 waitl if_nc if z nec serialMirror norts1 no rts if c add rxcntl bit_ticks1 1 bit period jmpret rxcodel txcodel run a chuck of transmit code then return moy tl rxcntl check if bit receive period done sub tl cnt cmps tl 0 wc jmp waitl test rxmaskl ina wc receive bit on rx pin rcr rxdatal 1 djnz rxbits1 bitl test rxtx_model INVERTRX wz _ find out if rx is inverted jmp receivel abort if no stop bit TTA from jmpret rxcodel txcodel run a chunk of transmit code then return shr rxdatal 32 9 justify and trim received byte wrbyte rxdatal rxbuff_head_ptr1 7 22 add rx_head1 1 cmpsub rx_head1 rxsizel TTA allows non binary buffer size wrlong rx_head1 rx_head_ptr1 moy _rxbuff_head_ptr1 rxbu
49. er in the needed size in bytes for each rx and tx buffer These values can be any size within available memory They do not have to be a power of two Unused buffers can be reduced to 1 byte RX_SIZEO 200 receive buffer allocations RX_SIZE1 200 RX_SIZE2 80 RX_SIZE3 80 TX_SIZEO 20 transmit buffer allocations TX_SIZE1 20 TX_SIZE2 20 TX_SIZE3 20 76 RXTX_BUFSIZE TX_SIZEO TX_SIZE1 TX_SIZE2 TX_SIZE3 RX_SIZEO RX_SIZE1 RX_SIZE2 RX_SIZE3 total buffer footprint in bytes 77 longs 308 bytes are available for buffers within the hub footprint of the object the final instruction in this program allocates additional buffer space beyond that if necessary to accomodate all of the buffers if the sum totals to 308 then the buffers exactly fit within the object footprint PUB Init Always call init before adding ports Stop bytefill startfill 0 endfill startfill initialize head tails port info and hub buffer pointers return rxsize TTA returns pointer to data structure buffer sizes PUB AddPort port rxpin txpin ctspin rtspin rtsthreshold mode baudrate Call AddPort to define each port port 0 3 port index of which serial port rx tx cts rtspin pin number XXX PINNOTUSED if not used rtsthreshold buffer threshold before rts is used XXX DEFAULTTHRSHOLD means use default mode bit 0 invert rx XXX INVERTRX mode bit 1 invert tx XXX INVERTTX m
50. eraction between Cogs A block diagram of the processes executed on each cog as well as the interaction between cogs and the shared global memory can be seen in Figure 20 Additionally the spin source code implemented on the Propeller microcontroller can be found in Appendix 6 5 3 with supporting libraries in appendix sections 6 5 4 and 6 5 5 24 3 RESULTS AND DISCUSSION To determine if the attempt to create and implement a communication protocol between a mobile device and a robotic platform was successful I determined it was best to implement the device on physical hardware This would provide means of comparison between existing radio controlled robotic platforms even something as simple as an R C car would serve as an acceptable analog for comparison Along the way I uncovered several unforeseen challenges that did create good learning opportunities some directly relevant to my work and others not as much One such example was the use of the Easy Bluetooth Module which was offered by Parallax for some period of time The most notable difference between the Easy Bluetooth Module and the RN 42 Bluetooth Adapter was the lack of RTS CTS flow control for the asynchronous serial interface between the Bluetooth module and the microcontroller While initially I did not believe this would cause an issue I was unable to write an application that was able to maintain a good connection with each other The adapter and the Propeller were consta
51. ercent 101 1100101 Lowercase e 38 100110 amp Ampersand 102 1100110 Lowercase f 39 100111 Single quote 103 1100111 Lowercase g 40 101000 Open parenthesis or open bracket 104 1101000 Lowercase h 41 101001 Close parenthesis or close bracket 105 1101001 Lowercase i 42 101010 Asterisk 106 1101010 Lowercase j 43 101011 Plus 107 1101011 Lowercase k 44 101100 P Comma 108 1101100 Lowercase 45 101101 Hyphen 109 1101101 Lowercase m 46 101110 Period dot or full stop 110 1101110 Lowercase n 47 101111 Slash or divide 111 1101111 Lowercase o 48 110000 0 Zero 112 1110000 Lowercase p 49 110001 1 One 113 1110001 Lowercase q 50 110010 2 Two 114 1110010 Lowercase r 51 110011 3 Three 115 1110011 Lowercase s 52 110100 4 Four 116 1110100 Lowercase t 53 110101 5 Five 117 1110101 Lowercase u 54 110110 6 Six 118 1110110 Lowercase v 55 110111 7 Seven 119 1110111 Lowercase w 56 111000 8 Eight 120 1111000 Lowercase x 57 111001 9 Nine 121 1111001 Lowercase y 58 111010 Colon 122 1111010 Lowercase z 59 111011 Semicolon 123 1111011 Opening brace 60 111100 lt Less than or open angled bracket 124 1111100 Vertical bar 61 111101 Equals 125 1111101 Closing brace 62 111110 X Greater than or close angled 126 1111110 Equivalency sign bracket tilde 63 111111 Question mark 127 1111111 Delete 31 6 2 Android Device User Interface Screen Captures BS 4 udm 9 22 PM 4 a A rA Advanced AIDE AT amp T Code AT amp
52. erts or snacks in alphabetical order Table 1 contains a list of the current API levels Android version numbers and platform code names from version 1 0 or Base to their latest version Android 4 4 API 19 or Kit Kat Table 1 List of Android API Levels and Corresponding Code Names 6 Platform Version API Level VERSION_CODE 19 Android 4 4 KITKAT Android 4 3 18 JELLY BEAN MR2 Android 4 2 4 2 2 i JELLY_BEAN_MR1 Android 4 1 4 1 1 16 JELLY _BEAN Android 4 0 3 4 0 4 15 ICE CREAM SANDWICH MR1 Android 4 0 4 0 1 4 0 2 14 ICE CREAM SANDWICH Android 3 2 13 HONEYCOMB _MR2 Android 3 1 x 12 HONEYCOMB MR1 Android 3 0 x 11 HONEYCOMB Android 2 3 4 10 GINGERBREAD _MR1 Android 2 3 3 Android 2 3 2 9 GINGERBREAD Android 2 3 1 Android 2 3 Android 2 2 x 8 FROYO Android 2 1 x 7 ECLAIR_MR1 Android 2 0 1 6 ECLAIR 0 1 Android 2 0 5 ECLAIR Android 1 6 4 DONUT Android 1 5 3 CUPCAKE Android 1 1 2 BASE_1 1 Android 1 0 1 BASE Like selecting which mobile operating platform to pursue we must again down select to determine which of the many Android platforms will be targeted for the development of the application Since our application will require Bluetooth functionality we can eliminate any platform versions that did not support Bluetooth The Bluetooth Adapter Class 7 was first incorporated into Android 2 0 API level 5 AKA Eclair which sets the minimum API level that will be able to support our needs Additionally Android pu
53. es 4 and can be seen in Figure 3 In this application a call is placed from a user s cell phone to a cell phone mounted on the remote platform The platform mounted cell is connected to the microcontroller through a decoding module which interprets the tones of the numeric keys being pressed through the headphone jack Commands are sent by pressing one of the numeric key on the operator s cell phone frequencies are transmitted over the cell network towers received on the platform mounted cell and interpreted by the microcontroller as commands The benefits of this set up is that it requires no additional software needs to be installed on the cellphone as it utilizes existing functionality built in to make phone calls Figure 3 MicroTronics Technologies Mobile Control Robot 4 The downside is that the system is limited to only 12 unique codes correlating to the 12 keys on frequencies created by a phone 10 Numeric keys 0 through 9 the pound key and the asterisk key and only one command can be sent at a time Another difference is that the signals are sent over a cellphone network so the range is only limited by the size of the cell network however the devices will only work where cell service exists and are dependent on a network outside the users control 1 3 Objective At the conclusion of my work I expect that I will have developed a communication protocol that meets the prescribe definition of a communication protocol
54. exSerial4port Spin Library FullDuplexSerial4portPlus version 1 01 Tracy Allen TTA c 22 Jan 2011 MIT license see end of file for terms of use Extends existing terms of use Can open up to 4 independent serial ports using only one pasm cog for all 4 Supports flow control and open and inverted baud modes Individually configurable tx and rx buffers for all 4 ports any size set in CONstants section at compile time Part of the buffer fits within the object s hub footprint but even so the object is restartable Buffers are DAT type variables therefore a single instance of the object can be accessed throughout a complex project Modified from Tim Moore s pcFullDuplexSerial4fc with further motivation and ideas from Duane Degn s pcFullDuplexSerial4fc128 Changes and bug fixes include Flow control is now operational when called for with correct polarity bug correction Jitter is reduced unused ports are properly skipped over bug correction operation speed is increased Stop bit on reception is now checked and if there is a framing error the byte is not put in the buffer Buffer sizes are arbitrary each port separate rx amp tx up to available memory Changes in pasm and in Spin methods to accomodate larger buffers major reorganization of DAT section Added strn method for counted string and rxHowFull method for buffer size 70 Cut out most of the format methods such as DEC and HEX expecting
55. f both software and hardware that are required On the mobile device side both an IDE Integrated Development Environment and SDK Software Development Kit are required for programming the electronic device Additionally a physical device will be required for implementation testing On the Electronic device side an IDE and SDK are required for programming the microcontroller as well a physical microcontroller and robotic platform for implementation testing Additionally since Bluetooth will be used for data transfer between the devices a Bluetooth module that is compatible with the selected microcontroller will be required 2 2 Component and Software Selection 2 2 1 Selecting a Mobile Operating System and a Mobile Device There are many choices to pick from when it comes to selecting a mobile platform operating system to demonstrate communication via Bluetooth with a microcontroller The leading operating systems include Google s Android Apple s IOS Windows Mobile and Blackberry which all offer products of similar technological implementations That is all of these devices are available with similar processing power memory RAM and ROM screen size screen resolution touch screen capability battery life Bluetooth Wi Fi GPS and cell network capabilities With no limiting factors on the selection of an OS from an available required hardware standpoint the decision came down to two factors the market share or number of devices in
56. fc2ifnc if_c jmp to if_nc patch tx routine depending on whether cts is used and if it is inverted or ctsmask3 0 wz cts pin z not set if in use if_nz test rxtx_mode3 INVERTCTS we c set if inverted if_nz_and_c or ctsi3 doif_z_or_nc if_nc jmp TTA reversed order to correctly invert CTS if_nz_and_nc or ctsi3 doif_z_or_c if_c jmp if not cts remove the test by moving the transmit entry point down 1 instruction and moving the jmpret over the cts test and changing co routine entry point if_z moy txcts3 transmit3 copy the jmpret over the cts test if_z moys ctsi3 txcts3 patch the jmps to transmit to txcts0 if_z add txcode3 1 change co routine entry to skip first jmpret patch rx routine depending on whether rts is used 84 and if it is inverted or rtsmask3 0 wz if_nz or dira rtsmask3 TTA rts needs to be an output if_nz test rxtx_mode3 INVERTRTS we if nz_and_nc or _ rts3 domuxnc patch muxc to muxnc if_z mov norts3 rec3i patch rts code to a jmp receive3 if z moys start3 receive3 skip all rts processing or txmask3 0 wz if tx pin not used if z movi transmit3 010111_000 patch it out entirely by making the jmpret into a jmp TTA or rxmask3 0 wz ditto for rx routine if z movi receive3 010111_000 TTA in pcFullDuplexSerial4fc the bypass was ostensibly done by patching the co routine variables but it was commented out and didn t work when restored so I
57. ff_ptr1 calculate next byte head_ptr add rxbuff_head_ptr1 rx_head1 rdlong rx_taill rx_tail_ptrl 7 22 or 8 will be patched to jmp r3 if moy _ tl rx_head1 sub tl rx_taill we add tl rxsizel fix wrap TTA change 91 rtsl rec li cmps tl rtssizel we muxc outa rtsmask1 jmp receivel byte done receive next byte Receive receive2 start2 if_c bit2 wait2 if _nc if_z nec serial Mirror jmpret rxcode2 txcode2 run a chunk of transmit code then return test rxmask2 ina we jmp norts2 go check rts if no start bit mov rxbits2 9 ready to receive byte mov rxcent2 bit4 ticks2 1 4 bits add rxcnt2 cnt add rxcnt2 bit_ticks2 1l bit period jmpret rxcode2 txcode2 run a chuck of transmit code then return mov tl rxcnt2 check if bit receive period done sub tl cnt cmps t1l 0 wc jmp wait2 test rxmask2 ina wc receive bit on rx pin rcr rxdata2 1 djnz rxbits2 bit2 test rxtx_mode2 INVERTRX wz _ find out if rx is inverted jmp receive2 abort if no stop bit TTA from 92 norts2 no rts if_c rts2 rec2i Receive3 receive3 start3 if_c jmpret rxcode2 txcode2 run a chunk of transmit code then return shr rxdata2 32 9 justify and trim received byte wrbyte rxdata2 rxbuff_head_ptr2 7 22 add rx_head2 1 cmpsub rx_head2 rxsize2 TTA allows no
58. ffer txbuff_tail_ptr2 txbuff_ptr2 txbuff_ptrl txsizel txbuff_tail_ptr3 txbuff_ptr3 txbuff_ptr2 txsize2 rxbuff_head_ptr rxbuff_ptr txbuff_ptr3 txsize3 rx buffers follow immediately after the tx buffers by size rxbuff_head_ptr1 rxbuff_ptr1 rxbuff_ptr rxsize rxbuff_head_ptr2 rxbuff_ptr2 rxbuff_ptrl rxsizel rxbuff_head_ptr3 rxbuff_ptr3 rxbuff_ptr2 rxsize2 note that txbuff_ptr rxbuff_ptr3 are the base addresses fixed in memory for use by both spin and pasm while txbuff_tail_ptr rxbuff_head_ptr3 are dynamic addresses used only by pasm and here initialized to point to the start of the buffers the rx buffer 3 comes last up through address endfill rx_head_ptr rx_head TTA note addresses of the head and tail counts are passed to the cog rx_head_ptr1 rx_head1 if that is confusing take heart These are pointers to pointers to pointers rx_head_ptr2 rx_head2 rx_head_ptr3 rx_head3 79 rx_tail_ptr rx_tail rx_tail_ptrl rx_taill rx_tail_ptr2 rx_tail2 rx_tail_ptr3 rx_tail3 tx_head_ptr tx_head tx_head_ptrl tx_head1 tx_head_ptr2 tx_head2 tx_head_ptr3 tx_head3 tx_tail_ptr tx_tail tx_tail_ptrl tx_taill tx_tail_ptr2 tx_tail2 tx_tail_ptr3 tx_tail3 okay cog cognew entry rx_head 1 PUB Stop Stop serial driver frees a cog if cog cogstop cog 1 PUB getCogID result return cog 1
59. hed filter new IntentFilter BluetoothAdapter ACTION_DISCOVERY_FINISHED this registerReceiver mReceiver filter Get the local bluetooth adapter mBtAdapter BluetoothAdapter getDefaultAdapter Get a set of currently paired devices Set lt BluetoothDevice gt pairedDevices mBtAdapter getBondedDevices If there are paired devices add them to the Array Adapter if pairedDevices size gt 0 findViewByld R id title_paired_devices setVisibility View VISIBL E for BluetoothDevice device pairedDevices mPairedDevicesArrayAdapter add device getName n device getAddress End for End of if else 52 String noDevices getResources getText R string none_paired toString mPairedDevicesArrayAdapter add noDevices End else End of OnCreate protected void onDestroy super onDestroy Make sure we are not still discovering devices mBtAdapter cancelDiscovery j Unregister broadcast listeners this unregisterReceiver mReceiver End of on destroy Starts device discovery with the bluetooth adapter private void discoverDevices indicate scanning in the title setProgressBarIndeterminateVisibility true setTitle R string scanning Turn on the subtitle for new devices findViewBylId R id title_new_devices setVisibility View VISIBLE T we are already discover
60. ic device that allows the end user to control said electronic device from their smart phone or tablet since there is currently no standard communication protocol they would be forced to develop their own basic protocol They would not only have to develop the software on the electronic device side but they would also have to design a custom application for the end users cell phone or tablet As a basic example consider a company which designs keyboards for computers There is a standard communication protocol and standard human interface driver for all modern USB keyboards This allows the keyboard manufacture to develop and produce a keyboard without requiring them to write custom software for the computer 1 2 Prior Work Much work has been done amongst the amateur robotic community to develop platforms that are controlled by mobile devices Additionally several companies offer small robotic devices that can be controlled by mobile devices typically from the Android of Apple operating systems These systems come with proprietary software for both the robot and the mobile device that is specifically designed to control only the device sold by the manufacture Figure 1 the Rover Revolution available from Brookstone is one such example which allows the end user to remotely operate the device from an application on an Apple or Android device This device also has advanced capabilities that allow the user to remotely control the vehicle while also
61. ic final int REQUEST_CONNECT_DEVICE 2 Message types sent form the BluetoothDataTransferService handler public static final int MESSAGE_READ 2 public static final int MESSAGE_TOAST 5 Key names received from the BluetoothDataTransferService handler public static final String TOAST toast public static String EXTRA_DEVICE_ADDRESS device_address Member of object for the data transfer service private BluetoothDataTransferService mDataService null Member of object for the data resolver servic private DataResolverService mResolverService null Override public void onCreate Bundle savedInstanceState super onCreate savediInstanceState setContentView R layout activity_main Get the default bluetooth adapter mBluetoothAdapter BluetoothAdapter getDefaultAdapter Check to see if bluetooth is supported and if not alert the user if mBluetoothAdapter null Toast makeText this Bluetooth is not supported on this device Toast LENGTH_LONG show Finish return mResolverService new DataResolverService this mHandler Send Button btnSend Button findViewById R id btn_Sena hText TextView findViewById R id hTextView hSeek SeekBar findViewById R id hSeekBarl j vText TextView findViewBylId R id vTextView vSeek SeekBar findViewById R id vSeekBarl hSeek setProgress
62. ication protocols purpose is to serve as a common language that can be interpreted by any device design to accept the language and rules of the communication protocol A device receiving a message per the communication protocol would not care how the message was generated or by what type of device the message was generated from Additionally the device generating the message would not care what type of device the message is going to This is because compatibility between the two devices is guaranteed based on following the rules of the protocol To suit the needs of this project while remaining general enough that its implementation could be widely accepted I set out to create as basic of a communication protocol as possible This was in an attempt to make the requirements imposed on 15 devices as basic as possible in order to capture as many devices as possible The rules of the protocol are as follows l The device should parse all messages and transmit them a single byte of data at a time The data must be transmitted as 8 bit ASCII American Standard Code for Information Interchange characters The first character must be an Alpha and is the Index that represents the parameter the following data will be relative to The characters following the index i e the second and so forth bytes must be numeric as the expectation is they will be converted to and stored as a single number This number can contain up to 10 characters and its n
63. ing on the Android Device and the Robot Android Correlation Robotic Platform Correlation Vertical Slider Position B Horizontal slider Position Furthermore to properly implement the communication protocol limits and boundaries of the parameters being transmitted must be defined and correlated between numeric value their physical appearance on the user interface and their expected effect on the robotic platform Table 3 contains the numeric value boundaries and their correlation to the Android application and the Robotic platform Note that the values are 17 to a degree arbitrary as the important item is consistency in their meaning between the Android application and the robot The values selected and their correlations were chosen based as they appeared convenient and logical Table 3 Correlation between Numerical Value its Physical Implementation on the Android Application and the Robotic Platform for Parameters A amp B N Parameter A Parameter B umeric Value z z Android Correlation Robotic Platform Correlation Android Correlation Robotic Platform Correlation 100 Slider in topmost position Full speed forward Slider in rightmost position Full turn right 50 Slider in central position Neutral Slider in center position Neutral 0 Slider in bottommost position Full speed reverse Slider in leftmost position Full turn left Additionally before we can dive into the implementation of the
64. ing stop it if mBtAdapter isDiscovering mBtAdapter cancelDiscovery j end if Request discovery from Bluetooth Adapter mBtAdapter startDiscovery end of discoverDevices The on click listener for all of the devices in the ListViews private OnItemClickListener mDeviceSelectedListener new OnItemClickListener public void onItemClick AdapterView lt gt av View v int arg2 long arg3 Cancel discovery if it is still active mBtAdapter cancelDiscovery j Get the MAC address which is the last 17 characters in the View String info TextView v getText toString String address info substring info length 17 create the result Intent and include the MAC address Intent intent new Intent intent putExtra EXTRA_DEVICE_ADDRESS address 53 Toast makeText getBaseContext address toString Toast LENGTH_SHORT show Set the results and finish the activity setResult Activity RESULT_OK intent finish End of on item click End mDeviceSelectedListener The Broadcast Receiver for when devices are found and discovery is finished private final BroadcastReceiver mReceiver new BroadcastReceiver Override public void onReceive Context context Intent intent String action intent getAction When discovery finds a device if BluetoothDevice ACTION_FOUND equals action Get the Bluetooth Device fr
65. irection 50 and rawSpeed lt 50 speed 50 rawSpeed 2 IServo 750 speed rServo 750 speed elseif rawSpeed 50 and rawDirection gt 50 speed rawDirection 50 2 IServo 750 speed rServo 750 speed elseif rawSpeed 50 and rawDirection lt 50 speed 50 rawDirection 2 IServo 750 speed rServo 750 speed else IServo 750 rServo 750 PUB ServoPulse fds str DEBUG String Pulse out Started terminal screen 68 Outputs Program Started to the fds tx DEBUG 13 us clkfreq 1_000_000 define what a micro second is tLow clkfreq 50 Duration of time between pulses standard 20 mS or 0 020 Seconds dira 14 15 Set P14 and P15 to output T cnt T is set to the current number of clock ticks when line is executed repeat T tLow waitcnt T PULSOUT I5 IServo PULSOUT 14 rServo PUB PULSOUT Pin duration clkcycles Produces an opposite pulse on the pin for the duration in 2uS increments Smallest value is 10 at clkfreq 80Mhz Largest value is around 50 seconds at 80Mhz BS2 Pulsout 500 1 mS pulse H ClkCycles Duration us 2 1250 gt cntMin duration clk cycles for 2us inst time min cntMin dira pin Set to output louta pin set to opposite state waitcnt clkcycles cnt wait until clk gets there fouta pin 69 PRI Pause ms waitcnt clkfreq 1000 ms cnt Convert to mS 6 5 4 FullDupl
66. k Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk There is a cost to read write a byte in the transmit receive routines The transmit cost is greater than the receive cost so between propellors you can run at max baud rate If receiving from another device the sending device needs a delay between each byte once you are above 470kbps with 1 port enabled x TTA I have not updated the following comments Size k Cog Initialzation code 1 x 8 4 x 25 a Cog Receive code 4 x 30 words Cog Transmit code 4 x 26 words i Spin Cog circular buffer indexes 4 x 4 words Used in both spin and Cog and read written in both directions Spin Cog per port info 4 x 8 words i Passed from Spin to Cog on cog initialization Spin per port info 4 x 1 byte T Used by Spin Spin Cog rx tx buffer hub address 4 x 4 words Passed from Spin to Cog on cog initialization Spin Cog rx tx index hub address 4 x 4 words Passed from Spin to Cog on cog initialization Spin per port rx buffer 4 x 64 byte x DWD Changed to 4 x 128 bytes Read by Spin written by cog ca x Cog per port rx state 4 x 4 words overlayed on rx buffer Used by Cog X Spin per port tx buffer 4 x 16 byte X 74 Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Wk Written by Spin read by Cog Cog per port tx state 4 x 4 words overlayed
67. latform The reason for this selection was due to the form factor of the device the 10 tablet was difficult to hold with two hands and still use my thumbs to control the device however the smaller 5 cell phone fit nicely within my hands similar to a game controller or an R C car controller Additionally a 7 or 8 tablet would also likely work just as well and ultimately it s a matter of personal taste SAMSUNG 12 45 Thu Nov 15 71r Dallas Figure 6 Mobile Platform Samsung Galaxy Note II Running Android 4 3 Ice Cream Sandwich 2 2 2 Selecting a Microcontroller and Robotic Platform The robotic platform could take many forms for one to demonstrate control of it It could be as simple as just a microcontroller with an output to a monitor terminal showing the change in variables being controlled However this method of implementation would not provide a good feel for the speed and responsiveness of the control of the robot To better perceive judge these qualities I decided it would be best to implement a robotic platform capable of movement This would provide a platform that could be compared to the responsiveness found and expected by users of existing Radio controlled robotic platforms I selected the ActivityBot Robot Kit Figure 7 as shown with optional Propeller Activity Board Attached manufactured by Parallax The ActivityBot Kit provides a platform that is capable of movement as provided b
68. lder as it has been modified to use Pin 1 amp 12 for serial comm 60 PUB Main milis clkfreq 1_000 dira 26 27 11 Set Pin 26 amp 27 to output outa 26 27 00 Set pin 26 amp 27 to low dira A_TX 1 outa A_TX 1 Pause 100 outa A_TX 0 fds Init fds AddPort A_PORT A_RX A_TX A_CTS A_RTS 0 000000 BAUD fds AddPort DEBUG 31 30 1 1 0 000000 BAUD Debug to the terminal screen fds Start fds str DEBUG String Program Started Outputs Program Started to the terminal screen fds tx DEBUG 13 Pause 2000 UART startup delay fds str A_PORT String Sends to the RN 42 to enter command mode 61 ctr 0 This block of code reads in characters until 13 is found inByteArr ctr fds rx A_PORT 13 represents the Carraige Return which is sent at the end of fds tx DEBUG inByteArr ctr every message from the RN 42 Unit repeat until inByteArr ctr 13 Tf successfull CMD is returned ctr inByteArr ctr fds rx A_PORT fds tx DEBUG inByteArr ctr Pause 1200 Pause for 1 2 seconds the message will be ignored if additional messages are sent within 1 second of the fds str A_PORT String D fds tx A_PORT 13 fds tx A_PORT 10 repeat 11 ctr 0 inByteArr ctr fds rx A_PORT fds tx DEBUG inByteArr ctr repeat until inByteArr ctr 13 ctr inByteArr ctr fds rx A_PORT fds tx DEBUG inByteArr
69. ler microcontroller Additionally the software and drivers required to set up the Propeller development environment can be found off the company s main web page 15 One downside to the Propeller microcontroller is the language used to program it is specific to the microcontroller and is known as Spin seen in Figure 13 with a code snippet However in recent months Parallax has launched a new complier for the Propeller microcontroller that utilizes the C programming language information about this compiler can also be found on the company s webpage 16 I have chosen to use the Spin language for this project as at the time of writing this paper there are more support libraries and examples written for the spin language and compiler than its C based counterp arts 14 ry Propeller Tool PBAA_v0 7 PBAAvO7 FulSouce C Condensed Summary C Documentation ly Programs RN 42 Bluetooth to PC Der paan Figure 13 Spin IDE with Code Snippet from the PBAA_v0 7 spin Program 2 3 Communication Protocol and Control Logic Design In the next section I will elaborate on the communication protocol designed and created for implementation between the mobile operating system and the robotic platform Additionally I will describe at a high level the control logic implemented on both the Android device and the Propeller controlled robotic platform 2 3 1 Development of a Communication Protocol In its most basic form the commun
70. lic boolean onOptionsItemSelected MenulItem item Intent serverIntent null switch item getItemId case R id scan_and_connect Launch the device list activity to see existing find new and select a device to connect to serverIntent new Intent this DeviceListActivity class startActivityForResult serverIntent REQUEST_CONNECT_DEVICE return true case R id discoverable Enable bluetooth device discovery Toast makeText getBaseContext Discover Toast LENGTH_SHORT show return true end switch return false end of onOptionsItemSelected private void connectDevice Intent data Initialize the BluetoothDataTransferService to perform bluetooth connections mDataService new BluetoothDataTransferService this mHandler Get the MAC Address String address data getExtras getString DeviceListActivity EXTRA_DEVICE_ADDRESS Get the bluetooth Device object BluetoothDevice device mBluetoothAdapter getRemoteDevice address 45 Attempt to connect to the device Toast makeText getBaseContext Attempting to connect to address Toast LENGTH_SHORT show mDataService connect device The Handler that gets information back from the BluetoothDataTransferService private final Handler mHandler new Handler Override public void handleMessage Message msg switch msg what case MESSAGE TOAST Toast makeText getBaseCo
71. long 0O long 0 tx tail pointer ditto zero to size of rx buffer long 0 data is transmitted from this offset above base long 0O long 0O long 0 These are the base hub addresses of the receive long 0 initialized in spin referenced in pasm and spin long 0 these buffers and sizes are individually configurable long 0 long 0 These are the base hub addresses of the transmit long long long Start of HUB overlay Some locations within the next set of values after being init d to zero are then filled from spin with options That are transferred to and accessed by the pasm cog once started but no longer needed in spin Therefore tx and rx buffers start here and overlays the hub footprint of these variables tx_buffers come first 0 1 2 3 then rx buffers 0 1 2 3 by offset from buffers overlay buffers txdata txbits txcnt txdatal txbits1 long 0 long 0O long 0 long 0O long 0O 102 txcnt1 long 0 txdata2 long 0O txbits2 long 0 txcnt2 long 0O txdata3 long 0 txbits3 long 0 txcnt3 long 0 rxdata long 0 rxbits long 0O rxcnt long 0 rxdatal long 0 rxbits 1 long 0O rxcntl long 0 rxdata2 long 0 rxbits2 long 0O rxcnt2 long 0 rxdata3 long 0 rxbits3 long 0 rxcnt3 long 0 tl long 0O this is a temporary variable used by pasm rxmask long 0 a single bit set a mask for the pin used for receive zero if port not used for receive
72. may be patched to if_z_or_c or if_z_or_nc rdbyte txdata2 txbuff_tail_ptr2 97 add tx_tail2 1 cmpsub tx_tail2 txsize2 wz TTA for individually sized buffers will zero at rollover wrlong tx_tail2 tx_tail_ptr2 if z moy txbuff_tail_ptr2 txbuff_ptr2 reset tail_ptr if we wrapped if_nz add txbuff_tail_ptr2 1 otherwise add 1 jmpret txcode2 rxcode3 shl txdata2 2 or txdata2 txbitor ready byte to transmit moy txbits2 11 mov txcnt2 cnt txbit2 shr txdata2 1 we txout2 muxc outa txmask2 maybe patched to muxnc dira txmask add txcnt2 bit_ticks2 ready next cnt wait2 jmpret txcode2 rxcode3 run a chunk of receive code then return mov tl txcnt2 check if bit transmit period done sub tl cnt cmps t1l 0 wc if_ne jmp wait2 djnz txbits2 txbit2 another bit to transmit txjmp2 jmp ctsi2 byte done transmit next byte Transmit3 transmit3 jmpret txcode3 rxcode run a chunk of receive code then return 98 txcts3 ctsi3 if z test ctsmask3 ina wc ifflow controlled dont send rdlong tl tx_head_ptr3 cmp tl tx_tail3 wz jmp transmit3 may be patched to if_z_or_c or if_z_or_nc rdbyte txdata3 txbuff_tail_ptr3 add tx_tail3 1 cmpsub tx_tail3 txsize3 wz _ TTA for individually sized buffers will zero at rollover if z if_nz txbit3 txout3 wait3 if_nc wrlong tx_tail3 tx_tail_ptr3 moy txbuff
73. mplementing the communication protocol on the ActivityBot robotic platform utilizes the multiple cores of the Propeller microcontroller Since the communication protocol does not specify when or how frequent data will be transmitted and received the robotic platform must be ready and capable of receiving a message at any time For example on a single processor microcontroller if a message was received while the microcontroller was processing a piece of data that was received earlier or outputting a pulse command to one of the servo motors the incoming message could be missed However since the Propeller microcontroller is capable of preforming multiple tasks simultaneously by utilizing its 8 processors or cogs it can have one processor that is solely devoted to listening for incoming data helping to ensure a message is not missed This can be done while other cogs work to interpret the data received and generate the pulse commands require to run the platforms motors 23 Oe eee Cog 0 Initialize drive variables to neutral values Initialize serial communication ports Launch cog 1 Launch cog 2 Wait to receive data Interpret data and store og 1 Interpret and convert to usable servo I Shared Global Memory Refined servo l position commands og 2 Read Commands Generate Pulse to servos Pause 20 milli seconds Figure 20 Level 1 Block Diagram of the Propeller Microcontroller and the Int
74. n binary buffer size wrlong rx_head2 rx_head_ptr2 moy rxbuff_head_ptr2 rxbuff_ptr2 calculate next byte head_ptr add rxbuff_head_ptr2 rx_head2 rdlong rx_tail2 rx_tail_ptr2 7 22 or 8 will be patched to jmp 13 if mov tl rx_head2 sub tl rx_tail2 we add tl rxsize2 fix wrap TTA change cmps tl rtssize2 wc muxc outa rtsmask2 jmp receive2 byte done receive next byte jmpret rxcode3 txcode3 run a chunk of transmit code then return test rxmask3 ina we jmp norts3 go check rts if no start bit moy rxbits3 9 ready to receive byte mov _rxcent3 bit4_ticks3 1 4 bits add rxcnt3 cnt 93 bit3 wait3 if_nc if_z nec serialMirror norts3 no rts ifc add rxcnt3 bit_ticks3 1 bit period jmpret rxcode3 txcode3 run a chuck of transmit code then return mov tl rxcnt3 check if bit receive period done sub tl cnt cmps tl 0 we jmp wait3 test rxmask3 ina wc receive bit on rx pin rcr rxdata3 1 djnz rxbits3 bit3 test rxtx_mode3 INVERTRX wz _ find out if rx is inverted jmp receive3 abort if no stop bit TTA from jmpret rxcode3 txcode3 run a chunk of transmit code then return shr rxdata3 32 9 justify and trim received byte wrbyte rxdata3 rxbuff_head_ptr3 7 22 add rx_head3 1 cmpsub rx_head3 rxsize3 TTA allows non binary buffer size wrlong rx_head3 rx_head_ptr3 8 moy rxbuff_head_ptr3 rxbuff_ptr3 calculate next byte head_ptr add rxbuff_ head_ptr3
75. n port stringptr strsize stringptr PUB strn port stringptr nchar Send counted string repeat nchar tx port byte stringptr DAT PEK KK K K K K K K K K K K K K K KKK K K K K K K K 2K K K K K K OK K Assembly language serial driver PEK KOK K K K K KK K K K K K K K KKK K K K K K K K 2K K K K K K OK K 1 org 0 Entry To maximize the speed of rx and tx processing all the mode checks are no longer inline The initialization code checks the modes and modifies the rx tx code for that mode e g the if condition for rx checking for a start bit will be inverted if mode INVERTRX is it similar for other mode flags The code is also patched depending on whether a cts or rts pin are supplied The normal routines support cts rts processing If the cts rts mask is 0 then the code is patched 82 to remove the addtional code This means I O modes and CTS RTS handling adds no extra code in the rx tx routines which not required Similar with the co routine variables If a rx or tx pin is not configured the co routine variable for the routine that handles that pin is modified so the routine is never called We start with port 3 and work down to ports because we will be updating the co routine pointers and the order matters e g we can update txcode3 and then update rxcode3 based on txcode3 TTA coroutine patch was not working in the way originally described TTA patched unused coroutines jm
76. ng The reason for the 10 character 2 147 483 647 numeric value limitation is due to the 32 bit architecture of the Propeller microcontroller The value 2 147 483 647 which can be represented in binary as 1111111111111111111111111111111 is the largest value that can be stored in a single variable or register of a 32 bit microcontroller 2 3 2 Implementing and Demonstrating the Communication Protocol To demonstrate the applicability of the protocol designed I will implement its use on the communication between a mobile operating system Android and a robotic platform the Parallax ActivityBot over Bluetooth In the actual implementation of the communication protocol an additional level of detail is required As noted earlier the first character transmitted in the message represents the Index or parameter of the data being transferred In practical terms it s a label for the data so that when the data is received the reviving device knows how to handle it To properly use the index I must establish the index values required and assign them their respective functions Due to the simple nature of the robotic platform selected all that is needed to control its movement is a value to control its speed and a value for its direction This will also be true for almost all wheeled robotic platforms Indexes and their corresponding incarnations on the Android device and ActivityBot are listed in Table 2 Table 2 Correlation between Index its Mean
77. ntView R layout device_list Set results as canceled in case the user backs out setResult Activity RESULT_CANCELED Initialize the button to perform device discovery Button btnScan Button findViewById R id btn_scan btnScan setOnClickListener new OnClickListener public void onClick View v 51 discoverDevices v setVisibility View GONE End of setOnClickListener Initialize the array adapters One for the paired devices and one for the newly discovered devices mPairedDevicesArrayAdapter new ArrayAdapter lt String gt this R layout device_name mNewDevicesArrayAdapter new ArrayAdapter lt String gt this R layout device_name Find and set up the list view for paired devices ListView lstPairedDevices ListView findViewBylId R id paired_devices_list lstPairedDevices setAdapter mPairedDevicesArrayAdapter lstPairedDevices setOnItemClickListener mDeviceSelectedListener Find and set up list view for new devices ListView lstNewDevices ListView findViewBylId R id new_device_list lstNewDevices setAdapter mNewDevicesArrayAdapter lstNewDevices setOnItemClickListener mDeviceSelectedListener Register for broadcasts when a device is found IntentFilter filter new IntentFilter BluetoothDevice ACTION_FOUND this registerReceiver mReceiver filter Register for broadcasts when discovery has finis
78. ntext msg getData getString TOAST Toast LENGTH_SHORT show break case MESSAGE READ resolveData msgFull break End of switch End of handleMessage End of mHandler private void resolveData String inputString String message ABCDE String test mResolverService SortInputData inputString Toast makeText getBaseContext test Toast LENGTH_SHORT show TextView txtOut TextView findViewById R id txtOut txtOut setText test byte send message getBytes mDataService write send End if end main 6 4 2 Bluetooth Data Transfer Service package com dynamicsolutions bluetest3 import java io IOException import java io InputStream 46 import java io OutputStream import java nio charset Charset import java util UUID import android bluetooth BluetoothAdapter import android bluetooth BluetoothDevice import android bluetooth BluetoothSocket import android content Context import android os Build import android os Handler import android util Log import android widget Toast public class BluetoothDataTransferService Member Fields private ConnectThread mConnectThread private final BluetoothAdapter mAdapter private final Handler mHandler private ConnectedThread mConnectedThread UUID for this application MY_UUID is the secure UUID from the google bluetooth chat example
79. ntly getting out of sync causing slow transfer rates and data loss This issue was especially challenging to debug as it was difficult to determine if the issue was with the data being transmitted over Bluetooth or if it was the sync between the module and the Propeller However I am now confident that the lack of flow control was the source of the problem as all sync issues were resolved with the implementation of the RN 42 module with no major changes to the structure of the Propeller code It is also worth noting that the Easy Bluetooth module is now discontinued however Parallax does still offer support for the product on their web page As an additional means for measuring success I set a bench mark for the minimum number of data transfers or parameter updates that needed to be able to occur per second This was in an attempt to quantify the responsiveness of the platform and the implementation of the communication protocol Additionally it would help flush out if the protocol had any inherent attributes that were not conducive to rapid data transfer I initially had set out to show that the given parameters could be updated 4 times per second this should ensure that the robotic platform would be responsive and react to user input without a significant visual delay With some simple testing I observed that the configuration was capable of preforming over 20 updates per second The capability 25 for this high of a refresh rate meant that the r
80. obotic platform would be able to react to the users input with virtually no visual delay on par with existing R C solutions and products currently on the market A link to a video of the application and robotic platform in action has been uploaded to You Tube 16 26 4 CONCLUSIONS The intent of this project was to show that it was possible to create a communication protocol that could be implemented over Bluetooth between a mobile device and a robotic platform The intent being that if the robotic platform was designed to receive messages per the protocol it could be implemented without creating unique application on the mobile device for each robotic platform I have shown in my creation of an Android application that outputs messages per the communication protocol and development of a robotic platform that accepts messages per the communication protocol and response with the appropriate actions that it is possible to implement such a communication protocol However there is still further work to be done as I have thus far only defined two parameters in the communication protocol speed and direction or A and B While these two parameters are sufficient for a simple two wheeled robot they would not be sufficient for control of say a helicopter which would require at least 4 parameters for control over roll pitch yaw and elevation I can envision a protocol that takes advantage of the full 52 upper and lower case characters for all sor
81. ode bit 2 open drain source tx XXX OCTX T1 mode bit 3 ignore tx echo on rx XXX NOECHO mode bit 4 invert cts XXX INVERTCTS mode bit 5 invert rts XXX INVERTRTS baudrate if cog OR port gt 3 abort if rxpin lt gt 1 long rxmask port I lt rxpin if txpin lt gt 1 long txmask port I lt txpin if ctspin lt gt 1 long ctsmask port I lt ctspin if rtspin lt gt 1 long rtsmask port I lt rtspin if rtsthreshold gt 0 AND rtsthreshold lt rxsize port variable buffer size long rtssize port rtsthreshold else long rtssize port rxsize port 3 4 buffer TTS ref RX BUFSIZE long rxtx_mode port mode if mode amp INVERTRX byte rxchar port ff long bit_ticks port clkfreq baudrate long bit4_ticks port long bit_ticks port gt gt 2 PUB Start okay Call start to start cog Start serial driver starts a cog returns false if no cog available n 78 TTA modified for default rts threshold 3 4 of tx buffers will start within the object footprint overlaying certain locations that were initialized in spin for use within the cog but are not needed by spin thereafter and are not needed for object restart txbuff_tail_ptr txbuff_ptr buffers TTA all buffers are calculated as offsets from this address txbuff_tail_ptrl txbuff_ptrl txbuff_ptr txsize base addresses of the corresponding port bu
82. oid com apk res android android layout_width match_parent android layout_height match_parent android orientation vertical gt lt TextView android id tid title_paired_devices android layout_width match_parent android layout_height wrap_content android text string title_paired_devices android visibility gone android background 666 android textColor fff 37 android paddingLeft 5dip gt lt ListView android id tid paired_devices_list android layout_width match_parent android layout_height wrap_content android stackFromBottom true android layout_weight 1 gt lt TextView android id id title_new_devices a a a a a a a ndroid layout_width match_parent ndroid layout_height wrap_content ndroid text string title_new_devices ndroid visibility gone ndroid background 666 ndroid textColor fff ndroid paddingLeft 5dip gt lt ListView android id tid new_device_list android layout_width match_parent a a ndroid layout_height wrap_content ndroid stackFromBottom true android layout_weight 1 gt lt Butt a on android id tid btn_scan ndroid layout_width match_parent android layout_height wrap_content android text string btn_scan gt lt LinearLayout gt 6 3 3 Display Format of Device Names lt xml ver lt TextView androi androi id textSize 18s
83. om the Intent BluetoothDevice device intent getParcelableExtra BluetoothDevice EXTRA_DEVICE If its already paired skip is since its already been listed if device getBondState BluetoothDevice BOND_BONDED mNewDevicesArrayAdapter add device getName n device getAddress End if End if else if BluetoothAdapter ACTION_DISCOVERY_FINISHED equals action setProgressBarIndeterminateVisibility false setTitle R string select_device if mNewDevicesArrayAdapter getCount 0 String noDevices getResources getText R string none_found toString mNewDevicesArrayAdapter add noDevices End if End else if End onRecieve End Broadcast Receiver End of DeviceListActivity Class 54 6 4 4 Data Resolver Service package com dynamicsolutions bluetest3 import android content Context import android os Handler public class DataResolverService Member Fields private final Handler mHandler private StringBuilder masterString new StringBuilder private String end public DataResolverService Context context Handler handler mHandler handler public String SortInputData String inputString String completeSegment masterString append inputString String temp masterString toString int endIdX masterString indexOf end if 1 endIdx completeSegment masterString substring 0
84. opyright notice and this permission notice shall be included in all copies or substantial portions of the Software THE SOFTWARE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND EXPRESS OR IMPLIED INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT IN NO EVENT SHALL THE AUTHORS OR 106 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM DAMAGES OR OTHER LIABILITY WHETHER IN AN ACTION OF CONTRACT TORT OR OTHERWISE ARISING FROM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE lee ee ee 6 5 5 DatalO4port Spin Library TREK K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K K 2K 2K 2K K DatalO4port version 1 0 1 22 2012 Author Tracy Allen Copyright c EME Systems and others under MIT licence See end of file for terms of use a adapted from pcFullDuplexSerial4fc by Tim Moore 2008 Merged Debug PC Jon Williams Merged Parallax Serial Terminal numeric input Jeff Martin Andy Lindsay Chip Gracey ok x Release Notes These are methods for string and numeric output and input using fullDuplexSerial4port my adaptation of Tim Moore s pcFullDuplexSerial4fc In the original these were included in the main program but here I have broken them off as pass through routines and a
85. ort value width 1 PUB decx port value digits i Prints zero padded signed decimal string if value is negative field width is digits 1 decl port value digits 2 PUB decl port value digits flag i x digits 1 gt digits lt 10 x value NEGX Check for max negative if value lt 0 value Il value x If negative make positive adjust for max negative uarts tx port i 1_000_000_000 109 if flag amp 3 if digits lt 10 less than 10 digits repeat 10 digits yes adjust divisor i 10 repeat digits if value gt i uarts tx port value i 0 value i result elseif i 1 OR result OR flag amp 2 uarts tx port 0 elseif flag amp 1 uarts tx port i 10 PUB decDp port value places divisor prints out a fixed point number with a decimal point places divisor 1 repeat places divisor divisor 10 dec port value divisor uarts tx port decx port lvalue divisor places PUB hex port value digits Print a hexadecimal number value lt lt 8 digits lt lt 2 repeat digits uarts tx port lookupz value lt 4 amp F 0 9 A F 110 PUB ihex port value digits Print an indicated hexadecimal number uarts tx port hex port value digits PUB bin port value digits Print a binary number value lt lt 32 digits repeat digits uarts tx port value lt 1 amp 1 0 PUB padchar
86. p id padding 5dip gt andro andro sion 1 0 encoding ut f 8 gt xmlns android http schemas android com apk res android d layout_width match_parent d layout_height wrap_content 6 3 4 XML Code for Options Menu lt xml version 1 0 encoding utf 8 gt lt menu xmlns android http schemas android com apk res android gt lt item lt item android id tid scan_and_connect android icon android drawable ic_menu_search android title string scan_and_connect gt android id id discoverable android icon android drawable ic_menu_mylocation android title string discoverable gt lt menu gt lt xml version 1 0 encoding utf 8 gt lt menu xmlns android http schemas android com apk res android gt lt item android id tid scan_and_connect android icon android drawable ic_menu_search android title string scan_and_connect gt 38 lt item android id tid discoverable android icon android drawable ic_menu_mylocation android title string discoverable gt lt menu gt 6 3 5 String Constants Referenced in the User Interface lt xml version 1 0 encoding utf 8 gt lt resources gt lt string name app_name gt BlueTest3 lt string gt lt string name scan_and_connect gt Scan and Connect lt string gt lt string name discoverable gt Make device discoverable lt string gt l
87. p 12 for serial comm PUB Main milis clkfreq 1_000 dira 26 27 11 Set Pin 26 amp 27 to output outa 26 27 00 Set pin 26 amp 27 to low dira A_TX 1 outa A_TX 1 Pause 100 outa A_TX 0 fds Init fds AddPort A_PORT A_RX A_TX A_CTS A_RTS 0 000000 BAUD fds AddPort DEBUG 31 30 1 1 0 000000 BAUD Debug to the terminal screen fds Start 57 fds str DEBUG String Program Started Outputs Program Started to the terminal screen Pause 2000 UART startup delay fds str A_PORT String Sends to the RN 42 to enter command mode ctr 0 This block of code reads in characters until 13 is found inByteArr ctr fds rx A_PORT 13 represents the Carraige Return which is sent at the end of fds tx DEBUG inByteArr ctr every message from the RN 42 Unit repeat until inByteArr ctr 13 If successfull CMD is returned ctr inByteArr ctr fds rx A_PORT fds tx DEBUG inByteArr ctr Pause 1200 Pause for 1 2 seconds the message will be ignored if additional messages are sent within 1 second of the fds str A_PORT String SU 96 Set up message that sets the programmed serial baud rate to 9600 fds tx A_PORT 13 If successfull AOK is returned fds tx A_PORT 10 ctr 0 58 inByteArr ctr fds rx A_PORT fds tx DEBUG inByteArr ctr repeat until inByteArr ctr 13 ctr inByteArr ctr fds rx A_POR
88. port count txbyte repeat count uarts tx port txbyte PUB ibin port value digits Print an indicated binary number uarts tx port bin port value digits PUB putc port txbyte Send a byte to the terminal uarts tx port txbyte PUB newline port putc port CR PUB cls port putc port FF PUB getc port 111 Get a character will not block if nothing in uart buffer return uarts rxcheck port return rx con the following added from PST primarily for data input PUB StrIn port stringptr TTA from PST Receive a string carriage return terminated and stores it zero terminated starting at stringptr Waits until full string received Parameter stringptr pointer to memory in which to store received string characters Memory reserved must be large enough for all string characters plus a zero terminator StrInMax port stringptr 1 PUB StrInMax port stringptr maxcount char ticks from PST modified Receive a string of characters either carriage return terminated or maxcount in length and stores it zero terminated starting at stringptr Waits until either full string received or maxcount characters received Parameters stringptr pointer to memory in which to store received string characters Memory reserved must be large enough for all string characters plus a zero terminator maxcount 1 maxcount maximum length of string to receive or 1 for unlimited 112 m
89. prets become simple jmps Tim s comments about the order from 3 to 0 no longer apply The following 8 locations are skipped at entry due to if_never The mov instruction and the destination address are here only for syntax the important thing are the source field primed to contain the start address of each port routine When jmpret instructions are executed the source adresses here are used for jumps And new source addresses will be written in the process entry rxcode if_never moy rxcode receive set source fields to initial entry points txcode if_never mov __ txcode transmit rxcodel if_never mov__ rxcodel receivel txcodel if_never moy txcodel transmit1 rxcode2 if_never mov rxcode2 receive2 txcode2 if_never mov __ txcode2 transmit2 rxcode3 if_never mov rxcode3 receive3 txcode3 if_never mov__ txcode3 transmit3 83 INITIALIZATIONS port 3 initialization test rxtx_mode3 OCTX wz init tx pin according to mode test rxtx_mode3 INVERTTX we if_z ne_cor outa txmask3 if z or dira txmask3 patch tx routine depending on invert and oc if invert change muxc to muxnc if oc change outa to dira if_z_eq_c or txout3 domuxnc patch muxc to muxnc if_nz movd txout3 dira change destination from outa to dira patch rx wait for start bit depending on invert test rxtx_mode3 INVERTRX wz wait for start bit on rx pin if_nz xor start3 doi
90. private static final UUID MY_UUID UUID fromSt ring 00001101 0000 1000 8000 O0805f 9b34fb UUID fromString fa87c0d0 afac 1llde 8a39 0800200c9a66 public BluetoothDataTransferService Context context Handler handler ll mAdapter BluetoothAdapter getDefaultAdapter mHandler handler public synchronized void connect BluetoothDevice device Start the tread to connect with the given devic mConnectThread new ConnectThread device mConnectThread start private class ConnectThread extends Thread private final BluetoothSocket mmSocket private final BluetoothDevice mmDevice private String mSocketType Secure public ConnectThread BluetoothDevice device mmDevice device BluetoothSocket tmp null 47 Get a bluetoothSocket for a connection with the given BluetoothDevice try tmp device createRfcommSocketToServiceRecord MY_UUID End try catch IOException e End Catch mmSocket tmp End of ConnectThread public method public void run setName ConnectThread mSocketType Always cancel discovery because it will slow down the connection mAdapter cancelDiscovery Make a connection to the bluetooth socket try This is a blocking call and will only return on a successful connection or an exception mmSocket connect End try catch IOException e Close the socket try
91. ption of the software required as well as links to web pages that will go into full detail on the subject Google has a website 12 completely devoted to Android Developers this site provides developers with free training modules full library support of the Android APIs Application Programming Interfaces and instructions on how to download and install the latest Android development environment also called the Android SDK Software Development Kit 13 The kit includes the Eclipse IDE Integrated Development Environment the ADT Android Developer Tools plugin and other required items A full list of system and software requirements is available on the webpage as well Java is the foundation or base of the Android programming language with specific libraries added for the increased or specific functionality of Android powered devices The 13 Android development environment and Eclipse IDE can be seen in Figure 12 with a code snippet from the BlueTest3 application o Java BlueTest3 src com dynamicsolutions bluetest3 MainActivity java ADT Edit Refactor Source Navigate Search Project Br w He Ce o E BPS eee se BD Manaciwyaa acivty_ main sen i DalaRescherSersce java ar int progress Wotabie Smart ieet 162 30 79M 0tZ33M 0 sign in to Googie Figure 12 Android Environment and Eclipse IDE with Code Snippet from BlueTest3 Application Parallax 14 also provides an abundant amount of support information for the Propel
92. r However this is generally frowned upon by the Android development community as well as most application users as there is a trust given by users that you have not written an application that may harm their device or act in any malicious manner When applications start to modify the state of the device without first requesting permission that trust can be lost very quickly and is not likely to be regained Java source code supporting the Android application can be found in Appendix 6 4 Additionally screen captures of the user interface showing the automated prompts as well as the other screens the user will see during the Bluetooth connection process can be seen in Appendix 6 2 Android Device User Interface Screen Captures User launches Application User selection Terminate program Application Starts Bluetooth Enabled User selects List of Paired Scan for List of Scan and Paired Device devices Connect Devices Selected found Attempt to connect to selected device Alert User Figure 18 Level 1 Block Diagram Android Process for Connecting to a Remote Bluetooth Device In addition to detecting and connecting to a remote Bluetooth device the Android application is also responsible for obtain the users input through the user interface and convert the gestures and motions of the users hand on the touch screen into input for controlling the robotic platform Ultimately the application is
93. r of electronic devices without the devices creator having to know anything about developing an Android application To do this a standard communication protocol must be established between Android powered devices and other electronic devices To limit the scope of this task this paper will consider communication to be between an electronic device powered by a typical microcontroller and an Android 4 0 Jelly Bean or later powered device Additionally communication between the two devices will occur over Bluetooth communication channels V2 1 or later vii 1 INTRODUCTION BACKGROUND 1 1 Background All communications between devices require that the devices agree on the format of the data The set of rules defining said format is called a protocol 1 Communication protocols are almost everywhere we look from computers to televisions to basic mp3 players They can even be compared to social mannerisms in today s culture Take the activity of answering a phone when someone answers the phone they say Hello or some other equivalent greeting This first phrase lets the person on the other end of the phone know that its their turn to speak and that the person they have called is ready to receive information This can be equated to flow control within a communication protocol which is used to let one device know that another device is ready for some communication or data transfer to occur If a product developer wishes to make an electron
94. service for the operating system and the ability to provide an open source solution Googles Android OS is known for its open source developer friendly environment and as of May 2012 it has surpassed Apple IOS in terms of market share in mobile devices Figure 4 As of the end of 2013 Android represents over 43 of the market compared to Apple its closest competitor which has just over 20 of the market LATE 2009 Ma aS may 1002 HTC Sainsamg and Google Launches its first mobile device For the first time Androl surpasses Motorsia lavec Ihe Ners Over I mot very successful kopie IOS market phare Android poweres devices Mar 2010 GReoghe Larches Android 2 2 Froyo the first mobile OS capable of mutitissking Apple s IOS still lacked this type of furctionality NOW Ardrotd has more than Coubte Apple iOS market share Andeoid 43 iOS 20 6 Symbian 5 8 Nokia Series 40 13 2 Nokia BlackBerry 5 5 Samsung 4 7 Windows 1 8 Figure 4 World Wide Mobile OS Market Share 5 6 With the Android OS selected as the operating system of choice for development the next question that arises is which variant or platform version will be targeted for the application development Platform versions in Android are tracked by API level and to most they are known by their clever nick names like Gingerbread Ice Cream Sandwich or Kit Kat Google has made a pattern out of naming their new platform versions after dess
95. t BluetoothAdapter ACTION_REQUEST_ENABLE startActivityForResult enableBTIntent REQUEST_ENABLE_BT End of onStart Override public synchronized void onResume super onResume End of on resume Override public void onDestroy super onDestroy if timer null timer cancel End of if End of on destroy O Override public void onActivityResult int requestCode int resultCode Intent data switch requestCode case REQUEST_CONNECT_DEVICE When DeviceListActivity returns with a device to connect to if results ok then launch connectDevice if resultCode Activity RESULT_OK connectDevice data break case REQUEST _ ENABLE BT if resultCode Activity RESULT_OK Bluetooth is now enabled notify the user 44 Bluetooth Enabled Toast makeText this Toast LENGTH_SHORT show else The user chose not to enable bluetooth or there was an error Toast makeText this Bluetooth failed to initialize exiting Toast LENGTH_SHORT show finish end request code switch end on activity result Creates an option menu for when the user presses the menu key Override public boolean onCreateOptionsMenu Menu menu MenuInflater inflater getMenuInflater inflater inflate R menu option_menu menu return true End of onCreateOptionsMenu Override pub
96. t string name title_paired_devices gt Paired Devices lt string gt lt string name title_new_devices gt New Devices lt string gt lt string name btn_scan gt Scan for Devices lt string gt lt string name scanning gt Scanning for devices lt string gt lt string name none_paired gt No devices have been paired lt string gt lt string name select_device gt Select a device to connect to lt string gt lt string name none_found gt No devices found lt string gt lt resources gt 6 3 6 Android Manifest File lt xml version 1 0 encoding utf 8 gt lt manifest xmlns android http schemas android com apk res android package com dynamicsolutions bluetest3 android versionCode 1 android versionName 1 0 gt lt uses sdk android minSdkVersion 9 android targetSdkVersion 17 gt lt uses permission android name android permission BLUETOOTH gt lt uses permission android name android permission BLUETOOTH_ADMIN gt lt application android allowBackup true android icon drawable ic_launcher android label string app_name android theme style AppTheme gt lt activity android name com dynamicsolutions bluetest3 MainActivity android label string app_name gt lt intent filter gt lt action android name android intent action MAIN gt lt category android name android intent category LAUNCHER gt lt intent filter gt lt ac
97. taking the users input constructing messages that fit the established communication protocol and then transmitting them over the Bluetooth connection A block diagram of the process 21 implemented can be seen in Figure 19 Note that at this point it is understood that a successful connection with a remote device has already been established Also note that this process is repeated as to continuously monitor user input and transfer data to the remote device It is also worth noting that data transmission is triggered by user input if user input is not received or remains changed over a period of time data is not transmitted Keep in mind that this is just one method for implementing the communication protocol another approach could have been to transmit updated values of the sliders at a fixed time interval independent of if the input had changed The Java source code associated with the block diagram from Figure 19 can be found in Appendix 6 3 6 Likewise relevant screen captures of the user interface can be found in Appendix 6 2 User lifted finger off lider User selects start from the mobile device Wait for user input change in status of slider bars slider bar Horizontal Return slider to a Transmit bytes Neutral a device over Bluetooth Vertical Index Slider Position Add Index A Prefix Parse message Construct full into bytes message Add
98. tedThread BluetoothSocket socket String socketType mmSocket socket InputStream tmpIn null OutputStream tmpOut null Get the bluetooth socket input and output streams try tmpin socket getInputStream tmpOut socket getOutputStream End of try catch IOException e Log e TAG temp sockets not created e End of Catch mminStream tmpIin mmOutstream tmpOut public void run byte buffer new byte 1024 49 int bytes String end StringBuilder curMsg new StringBuilder Keep listening to the input stream while connected while true try while 1 bytes mmInStream read buffer curMsg append new String buffer 0 bytes Charset forName UTF 8 String fullMessage curMsg toString mHandler obtainMessage MainActivity MESSAGE_READ fullMessage sendToTarget curMsg delete 0 bytes End of try catch IOException e connectionLost break End of Catch End of while End of run public void cancel try mmSocket close end of try catch IOException e TODO handle exception End of cancel End of cancel Write to the connected OutStream param buffer The bytes to write ay public void write byte buffer String good new String buffer Charset forName ISO 8859 1 buffer good getBytes Charset forName ISO 8859 ODDS try
99. test rxtx_mode OCTX wz init tx pin according to mode test rxtx_mode INVERTTX we if_z nec or outa txmask if z or dira txmask patch tx routine depending on invert and oc if invert change muxc to muxnc if oc change out to dira if_z_eq_c or txout0 domuxnc patch muxc to muxnc if_nz movd_ txout0 dira change destination from outa to dira 87 patch rx wait for start bit depending on invert test rxtx_mode INVERTRX wz wait for start bit on rx pin if_nz xor startO doifc2ifnc 1f_c jmp to if_ne patch tx routine depending on whether cts is used and if it is inverted or ctsmask 0 wz cts pin z not set if in use if_nz or dira rtsmask TTA rts needs to be an output if_nz test rxtx_mode INVERTCTS we c set if inverted if nz_and_c or ctsi0 doif_z_or_nc if_nc jmp TTA reversed order to correctly invert CTS if_nz_and_nc or _ ctsi0 doif_z_or_c if_c jmp if z moy txcts0 transmit copy the jmpret over the cts test if_z moys ctsi0 txctsO patch the jmps to transmit to txcts0 if_z add txcode 1 change co routine entry to skip first jmpret patch rx routine depending on whether rts is used and if it is inverted or rtsmask 0 wz rts pin z not set if in use if_nz test rxtx_mode INVERTRTS we if nz_and_nc or rts0 domuxnc patch muxc to muxnc if z moy norts0 rec0i patch to a jmp receive if z moys _ start0 receive skip all rts processing if not used or txmask 0 wz if tx pin
100. tivity gt lt activity android name DeviceListActivity 39 android label string select_device gt lt application gt lt manifest gt 6 4 Java Source Code for Android Device 6 4 1 Main Activity Java Code package com dynamicsolutions bluetest3 import android os Bundle import android os Handler import android os Message import android util Log import android view Menu import android view MenuInflater import android view MenuItem import android view View import android view View OnClickListener import android widget Button import android widget SeekBar import android widget TextView import android widget Toast import android widget SeekBar OnSeekBarChangeListener import android app Activity import android bluetooth BluetoothAdapter import android bluetooth BluetoothDevice import android content Intent import java util Timer import java util TimerTask public class MainActivity extends Activity Declare variables and constants Declare buttons Button btnSend Declare Seek Bars SeekBar hSeek SeekBar vSeek TextView hText TextView vText Timer declarations static final int UPDATE_INTERVAL 250 private Timer timer new Timer Int i The local Bluetooth Adapter private BluetoothAdapter mBluetoothAdapter null 40 Intent request codes private static final int REQUEST_ENABLE_BT 1 private stat
101. ts of different parameters and for all sorts of different robotic platforms Additionally the protocol can also be utilized to transmit data from the robotic platform back to the Android application possible using upper versus lower case letters to distinguish the difference of in the direction of flow of the data 27 5 REFERENCES 1 Definition of a communication protocol http www webopedia com TERM C communications_protocol html 2 Rover Revolution App Controlled Wireless Spy Vehicle http www brookstone com rover revolution wireless spy vehicle 3 Parallax RN 42 Bluetooth to PC demo http learn parallax com project rn 42 bluetooth pc demo 4 MicroTronics Technologies Mobile Controlled Robot http www projectsof805 1 com mobile controlled robot 5 Mobile Operating System World Wide Market Share International Business Times http www ibtimes com android vs ios whats most popular mobile operating system your country 1464892 6 Android platform names API levels and Code names http developer android com guide topics manifest uses sdk element html 7 Bluetooth Adapter Class http developer android com reference android bluetooth BluetoothAdapter html 8 Relative number of devices running a given Android version or API level http developer android com about dashboards index html 9 ActivityBot Robot Kit manufactured by Parallax http www parallax com product 32500
102. umeric value must not exceed 2 147 483 647 This value may be positive or negative oop The last character of the message must be an Exclamation Point This acts as a stop byte and lets the program know that the message is complete An example of a message written to the rules of the communication can be seen in Figure 14 Note that the example message shown X123 is displayed in its symbol format per the ASCII code A conversion chart between the Symbol Decimal and Binary formats for the first 128 ASCII characters is included in Appendix 6 1 Communication Protocol X 123 The first character or The characters to The character is Index represents the follow will represent used as a unique parameter being sent the value of the stop byte or in the message In this parameter specified identifier Upon program the character by Index A They will receiving this A or Index A be interpreted as a character the designates the value of number and program knows the the vertical slider bar therefore must be message has ended numeric Figure 14 Example Message per the Communication Protocol 16 As an example X123 broken down and converted to binary format would be displayed as 1011000110001110000110011100001 This communication protocol establishes the ability to send up to 52 unique parameters includes upper and lower case alphas with assigned values up to 10 characters lo
103. y the two wheels connected directly to continuous rotation servos Since it only has two wheels a third sliding post is provided for stability It also changes direction using skid steering that is to turn left the right wheel must be rotating faster than the left wheel It is also capable of turning in place by rotating the wheels in opposite directions Additionally the ActivityBot is compatible with a number of microcontroller boards produced by Parallax Figure 7 ActivityBot Robot Kit 9 When selecting a microcontroller for this project I considered a number of factors to help make my decision Factors considered included startup cost open source IDE compatibility with existing add ons robotic platforms the availability of documentation and the architecture processing power of the microcontroller I found that there were two microcontroller platforms at the forefront of the hobby armature robotics community the Arduino platform and the Parallax Propeller platform Both platforms compared equally across many aspects as both offered products with a 32 bit processor both offer free open source IDE s both are in the same price range both offer a large number of add ons compatible robotic platforms and both have a large online support community I did however find two differences that for my application were the deciding factor in selecting the Propeller Activity Board Figure 8 from Parallax over a similar board from Arduino Th
Download Pdf Manuals
Related Search
Related Contents
Attenzione - Viessmann Kidde Ba ery Carbon Monoxide Alarms Unitech K2724U-B How to Read&Write information with TeSysT&U TU-508 Manuel Instruction Page 1 Meat Slicer Series Users` Manual Page 2 Honorific customer Gemüse- und Zwiebelschneider Vegetable and Onion Chopper X80 Feeder Controller User`s Manual Mode d emploi inscription sejour Copyright © All rights reserved.
Failed to retrieve file