Home

B. White, Sensor Integration for Autonomous Robotic Watercraft

image

Contents

1. data data data data 3 fake 2 21 fakel31 1 fake 0 0 fake 1 memcpy amp depth counter data sizeof data delay ms 1000 TEMPERATURE READING putchar 0x01 putchar 0x03 putchar 0x00 putchar 0x00 putchar 0x00 putchar 0x02 putchar 0xC4 putchar 0x0B 27 PINA 5 is guidance computer waypoint indicator do nothing when not at a waypoint when PINA 5 is 5V waypoint reached do nothing until PINA 5 returns to 0 query for depth reading ignore first three bytes of response last four bytes are relevant data number rearrangement for float calculation copy four chars into a single floating point number query for temperature reading 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 PH READING DO READING CONDUCTIVITY READING while ignore 0x04 fake 0 getchar fake 1 getchar fake 2 getchar fake 3 getchar ignore getchar ignore getchar ignore getchar data 3 fake 2 data 2 fake 3 data 1 fake 0 data 0 fake 1 me
2. last four bytes are relevant data number rearrangement for float calculation copy four chars into a single floating point number query for conductivity reading 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 DEPTH SENSOR DEPTH READING putchar 0x0A putchar 0x00 putchar 0x02 putchar 0xE4 putchar 0x09 vvhile ignore1 0x04 fake 0 getchar fake 1 getchar fake 2 getchar fake 3 getchar ignore getchar ignore getchar ignore getchar data 3 fake 2 data 2 fake 3 data 1 fake 0 data 0 fake 1 memcpy amp cond counter data sizeof data cntstop counter counter while cntstop gt 50 while PINA 4 0 UCSRC 0x86 UBRRH 0x00 UBRRL 0x33 while PINA 5 0 4 while PINA 5 0 4 while dummy 0 0x50 dummy 0 getchar dummy 1 getchar dummy 2 getchar dummy 3 getchar dummy 4 getchar dummy 5 getchar dpt counter2 dummy 3 counter2 dpt counter2 dummy 5 counter2 dummy 0 0 cntstop counter counter while cntstop gt 5
3. Port C initialization Func7 In Func6 In Func5 In Func4 In Func3 In Func2 In Func1 In 0 1 State7 T State6 T State5 T State4 T State3 T State2 T Statel T StateO T PORTC 0x00 DDRC 0x00 Port D initialization Func7 In Func6 In Func5 In Func4 In Func3 In Func2 In Func1 In FuncO In State7 T State6 T State5 T State4 T State3 T State2 T Statel T StateO T PORTD 0x00 DDRD 0x00 Timer Counter 0 initialization Clock source System Clock 25 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 mode Clock value Timer 0 Stopped Mode Normal top FFh OCO output Disconnected TCCRO 0x00 TCNTO 0x00 OCRO 0x00 Timer Counter 1 initialization Clock source System Clock Clock value Timer 1 Stopped Mode Normal top FFFFh OC1A output Discon OC1B output Discon Noise Canceler Off Input Capture on Falling Edge Timer 1 Overflow Interrupt Off Input Capture Interrupt Off Compare A Match Interrupt Off Compare B Match Interrupt Off TCCR1A 0x00 TCCR1B 0x00 1 0 00
4. Sensor Reading Low Word Low Byte 6 Varies Sensor Reading High Word High Byte 7 Varies Sensor Reading high Word Low Byte 8 Varies Cyclic Redundancy Check High Byte 9 Varies Cyclic Redundancy Check Low Byte Figure 9 Byte Designations of a Sonde Response String For correct display later the sensor result must be converted to a floating point number The 4 byte IEEE floating point number format readable by C stipulates a byte order of high vvord high byte high vvord lovv byte lovv vvord high byte lovv vvord lovv byte The four stored bytes containing the sensor reading as received from the Sonde are not in this order The issue is resolved by taking the four bytes from the dummy array and rearranging them into a second array in the correct order At this point they are copied sequentially into the memory location of a float variable and are ready for later output in the correct format 327 332 The program vvaits one second before proceeding to repeat the same query response and rearrangement process for temperature pH 12 dissolved oxygen and conductivity 338 456 Then a variable cntstop is assigned the number in the master counter and the master counter incremented 461 462 The ATmega32 has 1000 bytes of storage and each Sonde reading is 4 bytes x 5 sensors so no more than 50 readings may be taken Using the number assigned to the cntstop variable from the master counter a while loop stops d
5. printf Conductivity f mS n r n r n r cond counter counter else counter 1 counter2 1 while counter lt cntstop printf Waypoint d n r counter printf printf Lakebottom Depth putchar dpt counter2 counter2 printf putchar dpt counter2 printf meters n r n r n r counter counter2 counter 1 counter2 1 INITIALIZATIONS void main void Declare your local variables here Input Output Ports initialization Port A initialization INTERRUPT 4800 bauq 8 data bits no parity 1 stop bit max 50 readings printed print vvaypoint number print separator print depth value print temperature value print ph value print dissolved oxygen value print conductivity value max 500 readings printed print vvaypoint number print separator print Lakebottom Depth X X Func7 In Func6 In Func5 In Func4 In Func3 In Func2 In Func1 In FuncO In State7 T State6 T State5 T State4 T State3 T State2 T Statel T State0 T PORTA 0x00 DDRA 0x00 Port B initialization Func7 In Func6 In Func5 In Func4 In Func3 In Func2 In Func1 In FuncO In State7 T State6 T State5 T State4 T State3 T State2 T Statel T StateO T PORTB 0x00 DDRB 0x00
6. program flowchart Interrupt Program Flowchart Switch to 4800 baud no parity 1 stop bit Master counter reset to 1 Master counter reset to 1 Digit counter reset to 1 Master counter gt max number of readings taken Yes Master counter gt max number of readings taken Do nothing all data sent Print waypoint number depth temperature pH dissolved oxygen and conductivity reading to Print waypoint number amp depth serial port reading to serial port incrementing digit counter betvveen digits Increment master Increment master counter counter Increment digit counter 30 Sonde Program Flovvchart Sonde is selected Svvitch to 9600 baud even parity tvvo stop bits Look for Sonde plugin string has OxFB been detected Send 8 byte hex string to request Sonde single sensor reading Send 8 byte hex vvakeup string to Sonde 3x vvait 1s betvveen each Look for Sonde response string has 0x04 been detected Store next 4 returned Repeat 5x for depth characters temperature pH dissolved oxygen amp conductivity Is 5V signal from nav computer present at PINA 5 Has PINA 5 returned to OV Rearrange characters for storage as floating point number Store rearranged characters sequentially in float memory location Wait 1 second Has counter reached 50 Yes Do nothing memory full wait f
7. red vvaypoint indicator cable from the navigation computer to the same on the sensor computer Plug the Sonde cable into the DB 9 connector on the sensor computer The Sonde should emit an audible beep VVait three seconds for the Sonde to vvake up The boat S now ready for a vvater quality course and the sensor computer will proceed to take a reading vvhen alerted by the navigation computer that the boat has reached a vvaypoint 18 Data Transfer Once a sensor course is complete and the boat has returned to shore open the fore deck hatch and unplug the sensor s serial cable from the sensor computer Take care not to bump the RESET button as this will erase any stored readings Connect a null modem serial cable to the DB 9 connector on the sensor computer f a null modem cable is not used the transfer will not work Connect the other end of the null modem cable to the serial port of any laptop running a terminal program such as Hyperterminal The terminal connection should have the following properties 4800 baud no parity 1 stop bit no flovv control Once connected to an active terminal window press the DATA button on the sensor computer one time figure 17 Figure 17 Sensor Computer Data Transfer Configuration Assuming the boat passed through at least one waypoint data should appear in the terminal vvindovv If no vvaypoints vvere reached No sensor readings taken will appear 7 Results Test runs were carri
8. 00 29 ignore first three bytes of response last four bytes are relevant data number rearrangement for float calculation copy four chars into a single floating point number ADVANCE COUNTER amp RESET FOR NEXT V AYPOINT advance counter for next waypoint prevent more than 50 readings end while loop inside water sensor loop end water sensor loop depth sensor selected 4800 baud 8 data bits no parity 1 stop bit WAIT FOR V AYPOINT PINA 5 is guidance computer waypoint indicator do nothing when not at a waypoint when PINA 5 is 5V waypoint reached do nothing until PINA 5 returns to 0 look for letter P at serial port ignore letter T ignore comma store first digit of depth reading ignore period store second digit of depth reading rearrange depth reading numbers for later output prevent more than 500 readings end depth sensor loop end program while loop end main loop Initialization Program Flowchart Define libraries amp variables Redefine getchar and putchar commands to check for even parity Define data transfer interrupt Initialize registers Matrix is selected see Matrix program flowchart Sonde is selected see Sonde
9. 4 09 Figure 7 Hex Activation String for Each Sonde Sensor Each byte of a given activation string is critical to commanding the specified reading from the Sonde figure 8 If any byte is incorrect the sensor will not function The ATmega32 queries the Sonde for a sensor depth reading by sending the string 0x010300300002C404 307 314 The Sonde responds immediately vvith a result in the form of a 9 byte hex string figure 9 Byte Hex Number Assignment 1 01 Slave Address 2 03 Modbus Command 3 Read Holding Registers 3 Varies Address of First Register High Byte 4 Varies Address of First Register Lovv Byte 5 Varies Number of Registers to Read High Byte 6 Varies Number of Registers to Read Lovv Byte 7 Varies Cyclic Redundancy Check High Byte 8 Varies Cyclic Redundancy Check Low Byte Figure 8 Byte Designations of a Sonde Activation String The first tvvo bytes of the response string are ignored The ATmega32 proceeds to take in the result once the third byte 0x04 is detected The four bytes of data following contain the sensor result and are stored in a dummy array The final two cyclic redundancy check bytes are ignored 316 325 Byte Hex Number Assignment 1 01 Slave address 2 03 Modbus Command 3 Read Holding Registers 3 04 Number of Registers Read x 2 4 Varies Sensor Reading Low Word High Byte 5 Varies
10. 5 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 putchar 0x01 putchar 0x03 putchar 0x00 putchar 0x30 putchar 0x00 putchar 0x02 putchar 0xC4 putchar 0x04 delay ms 1000 putchar 0x01 putchar 0x03 putchar 0x00 putchar 0x06 putchar 0x00 putchar 0x02 putchar 0x24 putchar 0x0A delay ms 1000 putchar 0x01 putchar 0x03 putchar 0x00 putchar 0x30 putchar 0x00 putchar 0x02 putchar 0xC4 putchar 0x04 send modbus string to vvake sonde up wait 1 second send modbus string to vvake sonde up wait 1 second send modbus string to be sure sonde is avvake JE WALT FOR dedoceecededeerenscendecseesaececssee vvhile 1 while PINA 5 0 while PINA 5 0 DEPTH READING putchar 0x01 putchar 0x03 putchar 0x00 putchar 0x30 putchar 0x00 putchar 0x02 putchar 0xC4 putchar 0x04 vvhile ignore1 0x04 fake fake fake fake ignore getchar 0 getchar 1 getchar 2 getchar 3 getchar ignore getchar ignore getchar
11. 52 define RX COMPLETE 1 lt lt RXC 54 Get a character from the USART Receiver 55 ifndef _DEBUG_TERMINAL_IO_ 56 define _ALTERNATE_GETCHAR_ 57 pragma used 58 char getchar void 59 60 char status data 61 while 1 62 63 while status UCSRA amp RX_COMPLETE 0 64 data UDR 65 if status amp FRAMING_ERROR PARITY_ERROR DATA_OVERRUN 0 66 return data 67 x 68 69 pragma used 70 endif y Ta Write a character to the USART Transmitter 73 ifndef _DEBUG_TERMINAL_IO_ 74 define _ALTERNATE_PUTCHAR_ z pragma used 76 void putchar char c 77 4 78 while UCSRA amp DATA REGISTER EMPTY 0 79 UDR c 80 81 pragma used 82 endif 24 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 interrupt TEXT INTO void ext int0 isr void UCSRC 0x86 UBRRH 0x00 UBRRL 0x33 if cntstop 0 printf No sensor readings taken n r else if PINA 4 0 counter 1 while counter lt cntstop printf VVaypoint d n r counter printf lt n r printf Sensor Depth f meters n r depth counter printf Temperature f degrees C n r temp counter printf pH f pH units n r ph counter printf Dissolved Oxygen f mg I n r Ido counter
12. 8334 meters Tenperature 21 79982 degrees C pH 6 90198 pH units Dissolved Oxygen 5 53457 mg l Conductivity 0 50671 mS Waypoint 2 Sensor Depth 1 48334 meters Figure 10 Data Transfer Screenshots from Both Sensors If the Matrix is selected PINA 4 is 5V one waypoint number and its associated lake bottom depth reading are printed to the serial port figure 10 The master and digit counters set to zero at the start of 13 the interrupt code increment once and tvvice respectively in the course of printing one reading 120 129 The process ends vvhen the number in the master counter is greater than the number of total readings saved in the cntstop variable 118 See Interrupt Program Flowchart in the appendix for a visual representation of interrupt program flovv 5 Troubleshooting A number of problems were encountered during the course of this project The Sonde communicates at 9600 baud so the ATmega32 had to be set to this baud rate as well ATmega32s come with their system clock set to a default frequency of 1 MHz At this clock rate at 9600 baud an error was introduced which made communication impossible Transmissions from the Sonde were seemingly random strings of strange characters a far cry from the specific 9 byte string expected The baud rate of an ATmega32 is set via its USART Baud Rate Register UBBR which can only contain integers Communication at 9600 baud using a 1MHZ system clock requires t
13. Sensor Integration for Autonomous Robotic VVatercraft Bruce VVhite Master of Science in Electrical Engineering Applied Research Project San Francisco State University May 2006 1 Backqround 2 Logistics 3 Sensors Table of Contents General Description of Autonomous Operations General Description of Project Navigation System Description Lake Bottom Depth VVater Quality Humminbird Matrix 55 o Capabilities o Povver o Communication Hach Environmental MiniSonde MS 4a o o o 4 Sensor Computer Capabilities Povver Communication Hardvvare o Microcontroller o Povver o Main board o Interface Board o Boat Mounting Software Depth Water Quality o Data Transfer o o 5 Troubleshooting 6 Operation 7 Results 8 Conclusion 9 References 10 Appendix System Clock Stop Bits amp Frame Length Initial Byte Capture Lake Bottom Depth Water Quality Data Transfer Boat Route Result Reliability Anomaly Lessons Learned Future Work Test Run Examples ATmega32 C Code Initialization Program Flowchart Interrupt Program Flowchart Sonde Program Flowchart Matrix Program Flowchart Sensor Computer Schematic 1 Background In today s world many tasks considered dull dirty or dangerous are increasingly performed by robotic and autonomous systems Such is the case vvith the collection of scientific data Exhibiting superior efficiency precision reliability and repeatability a
14. TCNT1L 0x00 ICR1H 0x00 1 11 0 00 OCR1AH 0x00 OCR1AL 0x00 OCR1BH 0x00 OCR1BL 0x00 Timer Counter 2 initialization Clock source System Clock Clock value Timer 2 Stopped Mode Normal top FFh OC2 output Disconnected ASSR 0x00 TCCR2 0x00 TCNT2 0x00 OCR2 0x00 External Interrupt s initialization INTO On INTO Mode Falling Edge INT1 Off INT2 Off GICR 0x40 MCUCR 0x02 MCUCSR 0x00 GIFR 0x40 Timer s Counter s Interrupt s initialization TIMSK 0x00 USART initialization USART Receiver On USART Transmitter On USART Mode Asynchronous UCSRA 0x00 UCSRB 0x18 Analog Comparator initialization Analog Comparator Off Analog Comparator Input Capture by Timer Counter 1 Off ACSR 0x80 SFIOR 0x00 Global enable interrupts asm sei vvhile 1 SENSOR SELECTION while PINA 4 0 5 UBRRH 0x00 UBRRL 0x19 while plugin 0xFB plugin getchar delay ms 1000 26 if PINA 6 is low sonde is selected sensor otherwise depth sensor selected 9600 baud 8 data bits even parity 2 stop bits look for sonde plugin string ending in FB wait 1 second for sonde to go into modbus even parity 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 28
15. agementPlanReport Dec pdf 15 http sfwater org Files Statistics LLMPApp 20Bpart 2 pdf 16 http bss sfsu edu holzman lakemerced vvater htm 22 10 Appendix Test Run Examples Waypoint 1 Lakebottom Waypoint 2 Lakebottom Waypoint 3 Lakebottom Waypoint 4 Lakebottom 2 meters NANA Waypoint 1 Lakebottom Waypoint 2 Lakebottom Waypoint 3 Lakebottom Waypoint 4 Lakebottom 3 meters 23 Waypoint 1 Sensor Depth 2 18455 meters Temperature 19 55774 degrees C pH 9 31965 pH units Dissolved Oxygen 11 89111 mg 1 Conductivity 0 51776 mS Waypoint 2 Sensor Depth 2 09320 meters Temperature 19 49988 degrees C pH 9 32011 pH units Dissolved Oxygen 11 89142 mg l Conductivity 0 51667 mS Waypoint 3 Sensor Depth 2 13870 meters Temperature 19 46908 degrees C pH 9 32028 pH units Dissolved Oxygen 12 02866 mg 1 Conductivity 0 51805 mS Waypoint 4 Sensor Depth 2 07160 meters Temperature 19 53631 degrees C pH 9 32753 pH units Dissolved Oxygen 12 03609 mg 1 Conductivity 0 51494 mS VAAN Waypoint 1 Sensor Depth 2 24751 meters Temperature 20 01107 degrees C pH 8 89823 pH units Dissolved Oxygen 10 61682 mg 1 Conductivity 0 53149 mS Waypoint 2 Sensor Depth 2 15318 meters Temperature 20 18652 degrees C pH 8 94813 pH units Dissolved Oxygen 10 66874 mg 1 Conductivity 0 53187 mS Waypoint 3 Sensor Depth 2 14175 mete
16. analyzes each incoming character at the serial port until hex 0x50 ASCII letter P is detected 494 497 The only time the Matrix outputs P is just before a depth reading which can be viewed in a terminal window as DPT X X where the X s are depth digits Once P is detected the next five characters are temporarily stored 498 502 The fourth character vvhich is the first digit of the depth reading is reassigned to a slot in an array via a digit counter The digit counter is then incremented and the sixth character vvhich is the second digit of the depth reading is stored in a similar manner The digit counter is 10 then incremented again 503 506 At this point a variable cntstop is assigned the number in the master counter and the master counter incremented 508 509 The ATmega32 has 1000 bytes of storage and each Matrix reading is 2 bytes so no more than 500 depth readings may be taken Using the number assigned to the variable cntstop from the master counter a while loop stops depth operations if 500 readings have been taken 510 513 At this point the program again idles indefinitely until 5V is seen at PINA 5 vvhen the loop resumes again for another reading See Matrix Program Flovvchart in the appendix for a visual representation of Matrix program flovv In this configuration the sensor computer cannot measure lake depths greater than 9 9 meters Hovvever this is still greater than the deepest vvater level recorded
17. at Lake Merced since at least the mid 1960 s gt so it is more than adequate If Sonde mode is selected the program initializes the ATmega32 to 9600 baud 8 data bits even parity amp two stop bits required parameters for communicating with the Sonde 249 251 The Sonde specification stipulates only one stop bit but this proved problematic see Troubleshooting The program then vvaits for the Sonde s plug in string VVhen the Sonde is plugged into any active serial port it automatically sends an initial hexadecimal string of 0x3F3F3F3FFB The ATmega32 software gets each of these characters at the serial port until OxFB is detected 253 256 After vvaiting for one second an 8 byte hex string is sent to the Sonde three times with a one second delay betvveen each query to vvake the Sonde from sleep mode permanently 257 288 This is followed by an indefinite idle period until 5V is seen at PINA 5 295 302 This pin is connected to the navigation computer and a 5V signal indicates that the boat has reached a vvaypoint Once PINA 5 returns to OV a round of sensor readings begins Each of the five sensors in the Sonde can be triggered by a specific 8 byte hex string figure 7 Sensor Hex Activation String Sensor Depth m 01 03 00 30 00 02 C4 04 Temperature C 01 03 00 00 00 02 C4 OB pH pH Units 01 03 00 06 00 02 24 OA Dissolved Oxygen mg L 01 03 00 16 00 02 25 CF Conductivity mS 01 03 00 0A 00 02 E
18. eader pins for outside connections to pins on the ATmega32 Serial communication is achieved via the TLOUT transmit and R1IN receive pins of the MAX232 connected to pins 3 and 2 of a DB 9 connector respectively Pin 5 of the connector is wired to ground See figure 4 for the full schematic Atmel ATmega32 MAX232 PD2 on Nav Computer SENSOR SELECT LM7805 1 ri ovuc Matrix 55 2 10k Power DATA XFER Figure 4 Sensor Computer Schematic An interface had to be created for the sensor computer to facilitate sensor selection chip reset and data transfer A small square of prototyping PCB serves as the base for this interface board For sensor selection one terminal of a single pole single throvv svvitch connects to pin 4 of port A PA4 on the ATmega32 and the other terminal to 5Vdc When the switch is open OVdc at PA4 the ATmega32 goes into vvater quality measurement mode VVhen the svvitch is closed 5Vdc at PA4 lake bottom depth measurement mode is selected A 10kO pull dovvn resistor is also connected betvveen PA4 and ground to assure OVdc at the pin when the switch is in the open state For chip reset one terminal of a normally closed momentary svvitch is connected to the VCC pin of the ATmega32 and the other terminal to 5Vdc The switch normally allows power to flow to the ATmega32 and MAX232 chips for standard operation When pressed p
19. ed out on South Lake the largest body of water in the Lake Merced complex and meaningful data was successfully gathered The course consisted of four waypoints in a roughly rectangular shape figure 18 4175500 4175490 4175480 4 4175470 Boat Route 4175460 Waypoints 4175450 o r t n E 5 E 2 o 2 4175440 4175430 4175420 54396 54397 54398 54399 54400 54401 54402 54403 54404 54405 East m utm grid 10 Figure 18 Test Run Boat Route and Waypoints Examples of captured test run data can be found in the appendix To verify validity of results comparisons vvere made betvveen the data from the boat s first vvaypoint and past data taken by outside parties VVhere possible data from approximately the same time of year late May vvas used Although deviations vvere to be expected because of temperature rainfall and pollution variation betvveen samples the results compared well figure 19 All indications are that the boat and its sensing capabilities are a viable method of scientific data collection Measurement Autonomous Boat Outside Party Results VVaypoint 1 Depth ft 13 4 13 014 Temperature degrees C 19 6 19 15 pH pH units 9 3 8 6 Dissolved Oxygen mg L 11 9 10 01 Conductivity mS 0 51 0 6516 Figure 19 Autonomous Boat amp Outside Party Data Comparison 20 S Conclusion This project was a success The sen
20. epth operations if 50 readings have been taken 463 466 At this point the program again idles indefinitely until 5V is seen at PINA 5 when the loop resumes again for another reading See Sonde Program Flovvchart in the appendix for a visual representation of Sonde program flow Once all the required Matrix or Sonde readings are recorded the user must be able to access the data This is done by pressing the DATA button on the interface panel which briefly sends 5V to pin 2 of port D PD2 on the ATmega32 which is also the chip s external interrupt pin Once an external interrupt is detected the softvvare breaks from whatever it is doing and executes the interrupt code If the button is pressed and the cntstop variable is 0 no readings taken No sensor readings taken is printed to the serial port 93 96 Otherwise the program looks to see vvhich sensor is currently selected by detecting the voltage at PINA 4 of the ATmega32 99 If the Sonde is selected PINA 4 is OV one vvaypoint number and its associated sensor depth temperature pH dissolved oxygen and conductivity readings are all printed to the serial port figure 10 The master counter set to zero at the start of the interrupt code increments and prints the next reading in the same fashion 104 111 The process ends when the number in the master counter is greater than the number of total readings saved in the cntstop variable 102 Waypoint 1 Sensor Depth 1 4
21. eve characters from the keyboard and send characters to the screen respectively In an embedded system such as this one that has no keyboard or monitor the getchar and putchar routines use the serial port to retrieve and send characters At this point in the softvvare these routines are redefined to check for even parity vvith every character transmitted or received in even parity mode as communication with the Sonde requires this 38 82 Next comes the data transfer interrupt code which will be discussed later Various ports and timers are then initialized and the ATmega32 s USART serial port and interrupts are enabled 138 238 The program then checks PINA 4 of the ATmega32 to see whether 5V is present This pin is connected to the sensor select switch on the interface panel If the pin is at 5V the program enters Matrix lake bottom depth mode 247 Othervvise Sonde vvater quality mode is selected 473 See Initialization Program Flowchart in the appendix for a visual representation of initialization program flovv If Matrix mode is selected the program initializes the ATmega32 to 4800 baud 8 data bits no parity amp 1 stop bit required parameters for communicating with the Matrix 475 477 This is followed by an indefinite idle period until 5V is seen at PINA 5 482 489 This pin is connected to the navigation computer and a 5V signal indicates that the boat has reached a vvaypoint Once PINA 5 returns to OV the program
22. hat UBBR be set to 5 51 which is not possible The closest settings of 5 or 6 allow for baud rates of 10417 or 8929 errors of 8 5 and 6 9 respectively These errors are too large for effective communication The solution was to set the system clock to 4MHz At this frequency UBBR can be set to 25 which allows for a baud rate of 9615 The resulting error was only 0 15 off of the desired baud rate of 9600 well within reasonable limits This also required modifying all baud rate initializations in the code to comply with the new system clock frequency By far the most perplexing problem encountered was an anomaly where the Sonde would readily respond to an 8 byte hex string sent from a terminal program on a PC but would ignore the exact same string sent from the ATmega32 Cables and adaptors that allowed for viewing of transmissions between the Sonde and ATmega32 were purchased and soldered together verifying that the hex strings sent from the terminal window and the ATmega32 were seemingly identical Finally an oscilloscope was used to analyze the outputs of both devices and the results were telling At 9600 baud one bit should be 104 uS long Since one frame from each device contained one start bit 8 data bits one parity bit and one stop bit for a total of 11 bits of data the total frame length should have been 1144 uS However in this case the stop bit had to be discounted it could not be seen since it was a OV bit that blended seamles
23. mcpy amp temp counter data sizeof data delay_ms 1000 putchar 0x01 putchar 0x03 putchar 0x00 putchar 0x06 putchar 0x00 putchar 0x02 putchar 0x24 putchar 0x0A vvhile ignore1 0x04 fake 0 getchar fake 1 getchar fake 2 getchar fake 3 getchar ignore getchar ignore getchar ignore getchar data 3 fake 2 data 2 fake 3 data 1 fake 0 data 0 fake 1 memcpy amp ph counter data sizeof data delay_ms 1000 putchar 0x01 putchar 0x03 putchar 0x00 putchar 0x16 putchar 0x00 putchar 0x02 putchar 0x25 putchar OxCF while ignore 0x04 fake 0 getchar fake 1 getchar fake 2 getchar fake 3 getchar ignore getchar ignore getchar ignore getchar data 3 fake 2 data 2 fake 3 data 1 fake 0 data 0 fake 1 memcpy amp ldo counter data sizeof data delay_ms 1000 putchar 0x01 putchar 0x03 putchar 0x00 28 ignore first three bytes of response last four bytes are relevant data number rearrangement for float calculation copy four chars into a single floating point number query for ph reading ignore first three bytes of response last four bytes are relevant data number rearrangement for float calculation copy four chars into a single floating point number query for dissolved oxygen reading ignore first three bytes of response
24. olved oxygen sat mg L and specific conductivity mS uS it was an appropriate choice Figure 2 Hach Hydrolab MS4a MiniSonde The Sonde runs on 12Vdc supplied by 8 internal AA batteries This simplified povver requirements for the boat as it vvas not necessary to connect the instrument to the boat s internal battery The Sonde communicates digitally via RS 232 serial communication protocol at 9600 baud 8 data bits even parity and 1 stop bit It features Modbus 3 and TTY modes of operation that allow for both active and passive communication respectively In Modbus mode the Sonde is idle until a specific 8 byte hexadecimal string is sent to wake it up Once avvake further 8 byte hex strings can be sent to activate one or more of its internal sensors Once a sensor reading is taken the result is returned as a 9 byte hex string In TTY mode the Sonde outputs a string of 8 bit ASCII characters once per second and reading the data is a matter of recognizing and storing the desired parameters vvithin the string 4 Sensor Computer Hardvvare To take vvater quality measurements the most flexible option vvas to use the Sonde s Modbus 3 mode vvhich required active triggering and detection of a reading Conversely the Matrix s effectively constant data stream only required passive detection Either way the results had to be received and stored by an outside system Moreover a low power small form facto
25. ommunication from the navigation computer to the sensor computer via their respective SPI ports allowing latitude amp longitude to be appended to associated sensor data e The Matrix also outputs water temperature This could be used to cross check temperature readings taken by the Sonde e Code to calculate a checksum or cyclic redundancy check could be implemented to reduce errors 21 9 References 1 Holden M Autonomous VVater Quality Measurements 2 Holden M Low Cost Autonomous Vehicles Using Just GPS American Society of Engineering Education general conference Salt Lake City Utah June 2004 3 Image taken from www humminbird com 4 Humminbird Matrix 55 amp 65 Operations Manual 5 Humminbird Outputting Digital Depth from a Matrix Product to a PC 6 Hach Environmental DataSonde 4 and MiniSonde Water Quality Multiprobes User s Manual 7 Image taken from www hachenvironmental com 8 Hach Environmental Modbus Function 3 READ Holding Register 9 Atmel Corp 8 bit AVR Microcontroller with 32K Bytes In System Programmable Flash ATmega32 ATmega32L 10 Maxim Integrated Products 5V Powered Multichannel RS 232 Drivers Receivers 11 http www ece utep edu courses web3376 concepts debounce html 12 http en wikipedia org wiki IEEE floating point standard 13 http www lakemerced org Data data html water 14 http sfvvater org Files Statistics LakeLevelMan
26. or data dump interrupt 31 Matrix Program Flovvchart Matrix is selected Switch to 4800 baud no parity one stop bit Is 5V signal from nav computer present at PINA 5 Look for Matrix depth string has 0x50 been detected Has PINA 5 returned to 0V Yes Ignore next 2 returned characters Store first digit of depth reading Increment digit counter Ignore next returned character Store second digit of depth reading Increment digit counter Increment master counter Has master counter reached 500 Yes Do nothing memory full wait for data dump interrupt 32 y k 204 OLNT J2M0d SS XPW Q o 153735 S09ZWNT 155052 4aJnduoo ACN UO 204 594 LNOTY 004 Zeebawyy q uny NITL 104 AXL 90 AeW Z0 311YM anug TINGOW YOSNS TVLIDIG
27. out success to obtain the first byte of the response string The string could not be delayed because the Sonde itself could not be reprogrammed The first three bytes of any Sonde response do not vary so the problem was resolved by looking for the third byte 0x04 of the response string instead of the first one 6 Operation Lake Bottom Depth To prepare for a lake bottom contour course open the fore deck hatch on the boat Be sure that power is not connected to the sensor computer Check to see that the sonar transducer serial and povver cables are all plugged into their respective sockets on the Matrix Each socket is specific to its plug so there should be no confusion figure 12 Figure 12 Matrix Sensor Connections Right to Left Power Serial Cable amp Sonar Transducer Connect the red amp black power connector from the Matrix into either red amp black power connector on the interface board it does not matter which figure 13 Figure 13 Connecting Power to the Matrix Connect povver from the battery to the interface board on the sensor computer via the remaining red 8 black connector the povver LED should light up Connect the red vvaypoint indicator cable from the navigation computer to the same on the sensor computer figure 14 Figure 14 Connecting the Navigation Computer Waypoint Indicator Cable Press the POWER button on the Matrix 55 The device will turn on and eventually stop at a go
28. ower to both devices is cut until the switch is released at which time any data stored in the ATmega32 are erased and the program reloaded Figure 5 Fully Assembled Sensor Computer For data transfer one terminal of a normally open momentary svvitch is connected to pin 2 of port D PD2 on the ATmega32 and the other terminal to 5Vdc VVhen the svvitch is pressed the voltage of PD2 goes from 0 to 5V triggering an interrupt in the software that dumps all stored data to the serial port A 0 1uF capacitor is connected in parallel with the switch to prevent any bounces from registering as multiple presses in the software A 10kQ pull down resistor is connected between PD2 and ground to assure OVdc at the pin when the switch is in the open state The final interface connection is a simple vvire from pin 5 of port A PA5 on the ATmega32 to pin 2 of port D PD2 on the navigation computer VVhen the boat reaches a vvaypoint softvvare in the navigation computer sets its PD2 to 5V vvhich is registered at PA5 of the ATmega332 triggering the software to take a reading A 10kQ pull dovvn resistor is connected betvveen PA5 and ground to assure OVdc at the wire when not at a waypoint Between 5V and ground an LED is wired in series with a 1000 resistor to serve as a power indicator light The LM7805 voltage regulator mentioned earlier is also contained on this board as well as an input for 12V from the boat battery and a 12V output to po
29. r solution was also desired since space and battery life were at a premium These constraints were met by using an Atmel ATmega32 microcontroller as the heart of the sensor computer Power to all boat hardware with the exception of the Sonde is provided by a 12V 7Ah sealed lead acid battery From this battery an LM7805 voltage regulator provides 5Vdc to the Atmega32 and other peripherals that comprise the sensor computer Peak power usage for the entire sensing system is approximately 4 265W figure 3 Component Power ATmega32 35mvVv Power Indicator LED 160mW MAX232 696mW Matrix 55 1 344W LM7805 2 03W Total 4 265W Figure 3 Sensing System Component Power Usage To facilitate asynchronous serial communication the ATmega line of chips is commonly used in conjunction with a MAX232 RS 232 driver integrated circuit to convert between the RS 232 3 25V logic of a PC or other peripherals and the TTL 0 5V logic of the microcontroller itself Dr Michael Holden already had a printed circuit board laid out for general Atmel ATmega usage with a MAX232 This board is widely used by students in the SFSU Autonomous Vehicle Lab and vvas an appropriate choice for the main board of this profect The sensor computer vvas assembled on one of these using mostly surface mount parts Components include one Atmel ATmega32L one MAX232 five 1uF ceramic capacitors required for MAX232 operation1 and various h
30. rs Temperature 20 15548 degrees C pH 8 97146 pH units Dissolved Oxygen 10 70356 mg 1 Conductivity 0 53068 mS Waypoint 4 Sensor Depth 2 16265 meters Temperature 20 07570 degrees C pH 8 96583 pH units Dissolved Oxygen 10 76794 mg l Conductivity 0 53322 mS ATmega32 C Code 1 2 3 Project Autonomous Boat Sensor Code 4 Date Spring 2006 Finished on 17May2006 5 Author Bruce White 6 Company San Francisco State University 7 8 Chip type ATmega32 9 Clock frequency 4 000000 MHz 10 dl DK k 2K k OK k OK k k k k k OK k ok KK k k K k k K k k k OK OK K K K K OK k 12 13 include lt mega32 h gt 14 include lt mega32 h gt 15 include lt stdio h gt 16 include lt string h gt 17 include lt delay h gt 18 19 char wakeup OxFF 20 char plugin 21 char data 4 22 char ignore OxFF 23 char dummy 6 24 char fake 4 25 char dpt 75 26 char cntstop 0 27 28 int counter 1 29 int counter2 1 30 31 float depth 20 32 float temp 20 33 float ph 20 34 float 1401201 35 float cond 20 38 PARITY CHECK 40 define RXB8 1 41 define TXB8 0 42 define UPE 2 43 define OVR 3 44 define FE 4 45 define UDRE 5 46 define RXC 7 47 48 define FRAMING_ERROR 1 lt lt FE 49 define PARITY_ERROR 1 lt lt UPE 50 define DATA OVERRUN 1 lt lt OVR 51 define DATA REGISTER EMPTY 1 lt lt UDRE
31. s to take sensor readings as any data vvould be meaningless vvithout an associated location The purpose of the boat vvas to describe lake bottom contours and monitor vvater quality and each of these tasks vvould require its ovvn dedicated sensor In the early planning stages it vvas noted that the vvater quality sensor likely to be used vvould be bulky and require a deeper submersion than the hull of the boat itself whereas the depth sensor vvould not have the same constraints As such it vvas decided the boat vvould set out initially vvith only the depth sensor One course vvould be completed by the boat vvith a depth measurement taken at each vvaypoint along the route Once the course vvas completed the boat vvould return to shore and the sensor computer vvould be connected to a laptop for transfer of depth results Based on this the vvater quality sensor tovv cable length vvould then be changed to prevent the sensor from being accidentally dragged on the bottom of the lake and damaged Assuming a safe depth at each vvaypoint the boat vvould then be sent back out vvith only the vvater quality sensor to repeat the same course Upon completion of the course the boat vvould return to shore and the results vvould be transferred to the laptop for later analysis 3 Sensors Lake Bottom Depth To map lake bottom contours a depth sensor vvas required Humminbird fish finders vvas contacted and they graciously donated one of their Matri
32. sly into the OV idle signal that follovved it So the lengths of the frames vvere considered using only the visible bits which now should have been 1040 uS long 14 The oscilloscope shovved that the frame length of the terminal vvas longer than 1040 HS approximately 1175 HS and that the frame length of the ATmega32 vvas shorter approximately 1000 HS figure 11 It vvas immediately evident from this that the Sonde prefers a too long frame to a too short one The most probable explanation is that vvhile the frame from the terminal vvas too long the excess length of the stop bit easily allovved the Sonde to see the end of the string and ready itself for the next one Conversely the Sonde did not register the shortened stop bit of the ATmega32 as a full stop bit so vvas never able to recognize the end of the string The problem vvas entirely resolved by modifying the ATmega32 code to send tvvo stop bits with every frame which the Sonde could easily recognize as the end of the string Figure 11 Terminal Frame Length Top amp ATmega32 Frame Length Bottom Q 250uS Div The final problem encountered involved the ATmega32 s inability to recognize the first incoming byte of a response just after sending out a string to the Sonde Each Sonde reading was triggered by an 8 byte hex string sent by the ATmega32 and the Sonde immediately responded at a rate seemingly too quick for the ATmega32 Many different code tricks were tried with
33. sor computer on cue from the navigation computer vvas able to activate the sensors and record their returning data Once sensing vvas finished the sensor computer successfully transmitted the data to a terminal program on a PC VVithout question it is ready for future use by students looking to investigate lake bottom depth and vvater quality as vvell as scientists looking to gather large amounts of data with few logistics This profect vvas subfected to fust about every asynchronous serial communications setback possible Many lessons were learned Some of the more significant examples include e Hovv to deal with multiple devices communicating at different baud rates and parities vvithin a single program Hovv to compensate for devices that are not communicating at exactly their specified baud rates How to construct a single floating point number from four 8 bit hex characters in C Baud rate errors can be corrected by adjusting system clock frequency e Occasionally a device may not be able to react quickly enough to another device to carry out a given command Future Work There is room for much future work on this platform including but not limited to the following e Currently the data obtained from the sensor computer must be cross referenced to a separate list of waypoints reached by the boat during its water course to determine which waypoint the data came from One possible solution would be to implement serial c
34. utonomous systems allow measurement without human oversight or intervention This streamlines the scientific process allowing resources once required for data collection to be reallocated to data analysis facilitating faster interpretation and hastening breakthroughs The goal of this profect vvas to investigate sensor integration possibilities for an autonomous boat created in the San Francisco State University Autonomous Vehicle Lab Built by Mechanical amp Electrical Engineering students and overseen by Dr Michael Holden PhD Assistant Professor of Mechanical Engineering the boat was intended for use by students in San Francisco State s Civil Engineering program to autonomously describe lake bottom contours and monitor water quality in Lake Merced a reservoir in San Francisco 2 Logistics The boat vvas to be driven by a navigation computer attached to a Global Positioning System GPS The minutia of this system will not be discussed here but a brief overvievv is necessary for full comprehension of navigation and sensor system linkages A predetermined course vvould be entered into the navigation computer vvith specific vvaypoints along the route and the boat vvould be placed in the vvater and activated The navigation computer vvould then use the real time data from the GPS to determine the boat s current location and steer and throttle accordingly to reach the next vvaypoint These vvaypoints vvould be ideal location
35. vernment warning screen Press the EXIT button one time to exit this screen the Matrix will automatically go into depth mode Figure 15 Connecting The Matrix Serial Cable Connect the serial cable from the Matrix to the DB 9 connector on the sensor computer figure 15 and close the fore deck hatch The boat is novv ready for a lake bottom depth course and the sensor computer vvill proceed to take a reading vvhen alerted by the navigation computer that the boat has reached a vvaypoint V ater Quality VVith the boat on land clip the Sonde into the carabiner at the front of the boat via either screvv eye on the Sonde collar Be sure that the cable is plugged into the Sonde and the cable collar tightly screvved down to prevent water from entering Check that the other end of the cable runs through the cable stays on the deck and into the entry notch on the aft deck hatch with no slack cable on the deck Thread the Sonde cable through the hull until it is reachable at the fore deck hatch Flip the sensor select switch on the sensor computer to WATER Connect power from the battery to the interface board on the sensor computer via either red amp black connector It does not matter which figure 16 The power LED should light up Figure 16 Connecting Power to the Sensor Computer If the sensor computer is already connected to power from a previous depth reading press the RESET button before proceeding Othervvise connect the
36. wer the Matrix A 5 x 5 5 piece of tinted lexan with strategically drilled holes serves as a panel for the reset button data dump button sensor select switch and DB 9 connector The main board interface board and lexan piece are all mounted on standoffs of varying heights which are screwed onto a small piece of plywood The result is an organized and compact user interface figure 5 Figure 6 Sensor Mount Configurations Two strips of velcro adhered to the inside of the boat hull just inside of the front access hatch secure the sensor computer in place A similar system is used to secure the Matrix transceiver just aft of that The Matrix sonar transducer is screw mounted to the transom at the aft end of the boat An aluminum plate is bolted to the fore deck and a carabiner is threaded through a hole drilled in the end of it The Sonde is then secured in place by clipping it to the carabiner via a screw eye on the Sonde collar figure 6 Software The ATmega32 can be programmed using assembly or C languages For this project C was used exclusively The full code can be found in the appendix and specific line numbers will be used in this section for reference to it Upon povver up the softvvare in the ATmega32 enters an initialization process 1 35 All program variables are defined including characters arrays floating point numbers and counters In any C code written for a PC getchar and putchar routines retri
37. x 55 depth finders To detect lake bottom depth the Matrix uses a transom mount sonar transducer coupled vvith a transceiver central processing unit Figure 1 Humminbird Matrix 55 Transceiver and Sonar Transducer Between 10 20Vdc is required to power the sensor and as such it had to be vvired directly to the boat povver supp y a 12V sealed lead acid battery The Matrix transducer is connected to a transceiver vvhich performs analog to digital conversion of the sonar signal Digital data are sent from the transceiver via RS 232 serial communication protocol at 4800 baud 8 data bits no parity and 1 stop bit Only a passive mode of operation is available so the Matrix cannot be externally triggered to take a reading A string of 8 bit ASCII characters is output once per second from the device each sentence adhering to the NMEA 0183 standard and reading the data is a matter of recognizing and storing the desired parameters vvithin the string The depth reading is output only in meters Water Quality To adequately monitor water quality the obvious first choice of instrument was an integrated device with multiple sensors Selection was left to students in the San Francisco State University Civil Engineering Department who would be doing the analysis of any water quality data The final choice was the Hach Hydrolab MS4a MiniSonde Measuring water temperature C F K pH pH Units sensor depth m f psi diss

Download Pdf Manuals

image

Related Search

Related Contents

User Manual High-Bay Lighting  Samsung 653-068 User's Manual  ixSave®TBE real time RT  Microsoft SQL Server-Bedienungsanleitung  RPT-1 Nova Repeater Manual  GE Consumer & Industrial Appliances Service Manual & Installation  Butterfly Valves - ASAHI/America,Inc.  

Copyright © All rights reserved.
Failed to retrieve file