User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
ee:hydrophones:start [2018/01/24 20:04]
Ryan Summers
ee:hydrophones:start [2018/01/28 15:16]
Ryan Summers
Line 4: Line 4:
  
 ===== Introduction ===== ===== Introduction =====
-The purpose of this page is to describe how the arrival times are acquired on a number of hydrophone channels. ​This documentation does //not// describe ​how that information is turned into bearings or how it is used in localization+//​Note: ​The purpose of this page is to describe how the arrival times are acquired on a number of hydrophone channels. ​Documentation describing ​how that information is turned into a pinger bearing ​is found {{cs:​hydrophones:​pinger_bearing|here}}.// 
 + 
  
-The arrival time calculations tend to be complicated by noise, which means that it is not possible to trivially detect rising edges. The ping can be thought of as an identical signal arriving slightly ​later on each of the hydrophones. In order to accurately calculate the time differences between each signal, a [[https://​en.wikipedia.org/​wiki/​Cross-correlation|cross correlation]] is used. A cross correlation essentially slides one signal over the top of another, and at the point where the signals maximally overlap, the amount of shifting needed is equal to the time delay of the signal.+The arrival time calculations tend to be complicated by noise, which means that it is not possible to trivially detect rising edges. The ping can be thought of as an identical signal arriving ​at slightly ​different times on each of the hydrophones. In order to accurately calculate the time differences between each signal, a [[https://​en.wikipedia.org/​wiki/​Cross-correlation|cross correlation]] is used. A cross correlation essentially slides one signal over the top of another, and at the point where the signals maximally overlap, the amount of shifting needed is equal to the time delay of the signal. Below is an example of a cross correlation with a sine wave. In the demo, you can see that at X offset = 0, the correlation result is maximum. Therefore, the time delay of the two signals is zero (as they are duplicates of eachother).
  
-Further simplifications can be applied to the problem as well. By ensuring that the hydrophones are close enough, it can be guaranteed that the arrival time difference will never exceed one half wavelength. Therefore, the cross correlation only needs to be completed within +/- half a wavelengthThe signals occur at a maximum frequency of approximately 40KHz, which means that the arrival time difference can never exceed approximately 12.5 microseconds. This means that the hydrophones must be spaced within 1.8cm of each other due to the speed of sound in water.+{{https://media.giphy.com/​media/​VVPKOXc6aY1Lq/​source.gif}}
  
 +Further simplifications can be applied to the problem as well. By ensuring that the hydrophones are close enough, it can be guaranteed that the arrival time difference will never exceed one half wavelength (the signals are sinusoidal with a maximum frequency of 40KHz). The cross correlation now only needs to be completed within +/- half a wavelength (which increases accuracy and decreases required processing). This means that the arrival time difference can never exceed approximately 12.5 microseconds. Because the speed of sound in water is 1498 m/s, the hydrophones must be spaced within 1.8cm of each other.
 +
 +To calculate a cross correlation,​ set time delays of [-12.5, 12.5] microseconds on the signal and calculate the overlapping area for each time delay. Calculating overlap is done by multiplying the value of the origin hydrophone at a time step by the value of the shifted hydrophone function at the same time step and summing up all multiplied values. When both are positive or negative, a point constructively adds to the correlation. When the signs don't match on the points, the correlation decreases. When both signals are identical, the correlation is maximal.
 +
 +==== Summary ====
 Now that the theoretical aspects are out of the way, the foundation of the problem starts to take shape. ​ Now that the theoretical aspects are out of the way, the foundation of the problem starts to take shape. ​
-1) Acquire signals on all four hydrophones (one reference and 3 along each X, Y, and Z axis) 
-2) Cross-correlate the X, Y, and Z axis signals against the reference to calculate time of flight delay. 
  
-The cross correlation step is simple mathematicsNote that cross-correlation boils down to multiplying individual points ​of two signals together ​and accumulatingso if the signals are big it can take quite bit of timeWe will discuss how to handle ​this later.+  - Acquire signals on all four hydrophones (one reference and 3 along each X, Y, and Z axis) 
 +  - Cross-correlate the X, Y, and Z axis signals against the reference to calculate time of flight delay. 
 + 
 +The main difficulty exists in sampling the signalsIt is important ​that samples are taken simultaneously on each of the hydrophones and that the signals are sampled fast enough ​to ensure that the precision is accurate enough (for example, at a sampling frequency ​of 1MHz, the time of arrival can never be more precise than a single microsecond). Therefore, the system must be capable of simultaneously sampling four channels at a minimum rate of 1MHz. 
 + 
 + 
 + 
 +===== Getting Started ===== 
 +This section is designed to help a developer get started updating and programming the HydroZynq. 
 + 
 + 
 +==== Code ==== 
 +All software and firmware is available in [[https://​github.com/​PalouseRobosub/​hydro-zynq|the GitHub repository]]. There are two primary directories:​ hardware ​and software. The hardware folder contains all the Verilog and TCL files for interracting with Vivado. TCL scripts have been generated to rebuild the block design in vivado, and a README.txt file in proj/ describes how to use them. Additionally, the IO constraints file is provided for the current hardware. 
 + 
 +The software folder contains all C source code used in programming the HydroZynq. An ELF file can be created by using the `mk` script supplied with the source file name.  
 + 
 +Example: 
 +  ./mk app/​main_bin.c 
 + 
 +All files located in src/ will be compiled against the application specified to generate the binary. Finally, ​BOOT.bin file (binary image that is used for booting off the SD cared) can be created through the utilization ​of the '​doit'​ script 
 + 
 +Example: 
 +  ./doit app/​main_bin.c bit/​adc_dma_revb.bit 
 + 
 +This will automatically mount and copy over the BOOT.bin ​to the card for the HydroZynq. This script takes in the source file name of the main application as the first argument and the bit stream file as the second parameter.  
 + 
 +**The current firmware utilizes software/​bit/​adc_dma_revb.bit as the bitstream file.** 
 + 
 +==== Programming & Debugging ==== 
 +Programming and debugging can be completed through creation of new BOOT.bin files on the SD card, but this is often extremely inefficient. The [[https://​store.digilentinc.com/​jtag-hs3-programming-cable/​|Digilent HS3]] can be used as a JTAG access point for GDB debug interfaces. To interact with the HydroZynq through JTAG, use the `xmd` command (provided by Xilinx). 
 + 
 +After executing xmd from the command line, you will enter a shell-like environment. To connect to the ARM core for programming,​ enter: 
 +  > connect arm hw 
 +   
 +Once connected, if you desired to program the FPGA or the ARM, first stop the ARM CPU. 
 +  > stop 
 + 
 +To program a new bitstream,​ 
 +  > fpga -f [bitstream_file_path] 
 +   
 +To load a new ELF onto the CPU, 
 +  > dow [elf_file_path] 
 +   
 +Finally, the CPU can be restarted,​ 
 +  > run 
 +   
 +Once XMD has been started, a remote GDB server is automatically instantiated. To connect to the GDB server, simply use the debug.sh script located in `software/` to launch up a GDB session. 
 +  [hydrozynq-repo-path]/​software/​debug.sh 
 +   
 +   
 +==== Communication ==== 
 +The HydroZynq communicates primarily through UDP. A number of user scripts have been created in the `scripts/` folder for ease of use with UDP. For example, the stdout of the application is sent to Cobalt'​s UDP port 3000 (e.g. 192.168.0.2:​3000). A simple python application ([hydrozynq-repo-path]/​scripts.debug_stream.py) can be used to view the standard output of the application (e.g. dbprintf() statements). 
 + 
 +=== Port Descriptions === 
 +^ Port Number ^ Destination ^ Description ^ 
 +| 3000        | HydroZynq ​  | Command port                      | 
 +| 3001        | Cobalt ​     | Sample data stream port           | 
 +| 3002        | Cobalt ​     | Time of Arrival Delay result port | 
 +| 3003        | Cobalt ​     | Cross-correlation stream port     | 
 +| 3004        | Cobalt ​     | Debug/​STDOUT port                 | 
 + 
 +Note that the HydroZynq does not run ROS natively, so python scripts running on cobalt are necessary for interfacing the HydroZynq with ROS. As of now, these scripts are still under initial development. 
 + 
 +The HydroZynq currently sends out all data used in the cross-correlation and the results of the final cross-correlation. These can be visualized using python and MatPlotLib through the scripts made available:​ 
 +  python [hydrozynq-repo-path]/​scripts/​data_receiver.py 
 + 
 +  python [hydrozynq-repo-path]/​scripts/​correlation_receiver.py 
 +   
 +The data and correlation results are sent using a trivial packet format: 
 +<​packet_number as unsigned, little-endian 4-byte integer> <Sample 1> ... <Sample N> 
 + 
 +Data results contain 4 channels per Sample, where each channel is a 16-bit unsigned integer (little-endian) value. (E.g. each sample is 64 bits and has 4 values). 
 + 
 +Correlation results contain 3 channels per Sample, where each channel is a 4-byte integer (little-endian) value. The first sample is the correlation between Channel 1 and reference, teh second is between Channel 2 and reference, and the last is between Channel 3 and reference.
  
-The main difficulty exists in sampling the signals. It is important that samples are taken simultaneously on each of the hydrophones and that the signals are sampled fast enough to ensure that the precision in time of flight is accurate enough (for example, at sampling frequency ​of 1MHz, the time of arrival ​can never be more precise than signal microsecond)Therefore, the system ​must be capable of simultaneously sampling four channels at minimum rate of 1MHz.+The HydroZynq allows ​for a number ​of run-time parameters to be set dynamicallyincluding ​the ping detection threshold. These can be sent to the HydroZynq command port in simple ASCII string. 
 +  [keyword]:​[value],[keyword]:​[value],​.... (etc) 
 +   
 +Note that the string ​must terminate without ​trailing comma and that it is able to only have a single key-value pair. The current supported keys are as follows: 
 +^ Key String ^ Data Type ^ Description ^ 
 +| reset      | N/A          | Causes the Zynq to perform a software reset. | 
 +| threshold ​ | unsigned int | Sets the HydroZynq ping ADC threshold value. | 
 +| debug      | unsigned int | If data is 0, HydroZynq debug mode is disabled. Otherwise, debug mode is enabled|
  
 +In debug mode, the HydroZynq records for 2.1 seconds, dumps data to the data stream port, and repeats. No correlations are performed.
  
 ===== Hardware =====  ===== Hardware ===== 
Line 49: Line 134:
  
 ==== Software Design ==== ==== Software Design ====
 +**Note that for ease of use, the HydroZynq is programmed bare-metal. There is no operating system on the board!**
 +
 The software design is straightforward,​ but the most complex of the other systems. Communication with other computers is implemented using UDP sockets provided by the lwIP (lightweight IP) library. When the CPU first boots, it loads the program off the SD card into memory. It then programs the FPGA bit stream and begins program execution after initializing most peripherals (e.g. Xilinx Ethernet). The application then initializes peripherals that were instantiated in the FPGA fabric (such as the ADC reader, the system monitor, and the SPI engine). It then configures the ADC chip and binds/​connects to a variety of UDP ports for communication. ​ The software design is straightforward,​ but the most complex of the other systems. Communication with other computers is implemented using UDP sockets provided by the lwIP (lightweight IP) library. When the CPU first boots, it loads the program off the SD card into memory. It then programs the FPGA bit stream and begins program execution after initializing most peripherals (e.g. Xilinx Ethernet). The application then initializes peripherals that were instantiated in the FPGA fabric (such as the ADC reader, the system monitor, and the SPI engine). It then configures the ADC chip and binds/​connects to a variety of UDP ports for communication. ​
  
Line 54: Line 141:
  
 After sync is acquired, the software samples for approximately 250ms during the ping period. It then locates the ping and truncates around the start to minimize the amount of data that needs to be cross-correlated. The software marks the timestamp of the ping and schedules a time that the next ping should occur at. Finally, the data is then cross-correlated to calculate the time of arrivals for each ping. The software then transmits a variety of debug information (including all sample data, correlation calculations,​ and time of arrival deltas) over ethernet. The cycle continuously repeats until a ping is not detected in the 250ms sample period. If this occurs, it will try to regain sync by continuously sampling fro 2.2 seconds. ​ After sync is acquired, the software samples for approximately 250ms during the ping period. It then locates the ping and truncates around the start to minimize the amount of data that needs to be cross-correlated. The software marks the timestamp of the ping and schedules a time that the next ping should occur at. Finally, the data is then cross-correlated to calculate the time of arrivals for each ping. The software then transmits a variety of debug information (including all sample data, correlation calculations,​ and time of arrival deltas) over ethernet. The cycle continuously repeats until a ping is not detected in the 250ms sample period. If this occurs, it will try to regain sync by continuously sampling fro 2.2 seconds. ​
- 
- 
-===== Getting Started ===== 
-This section is designed to help a developer get started updating and programming the HydroZynq. 
- 
- 
-=== Code === 
-All software and firmware is available in [[https://​github.com/​PalouseRobosub/​hydro-zynq|the GitHub repository]]. There are two primary directories:​ hardware and software. The hardware folder contains all the Verilog and TCL files for interracting with Vivado. TCL scripts have been generated to rebuild the block design in vivado, and a README.txt file in proj/ describes how to use them. Additionally,​ the IO constraints file is provided for the current hardware. 
- 
-The software folder contains all C source code used in programming the HydroZynq. An ELF file can be created by using the `mk` script supplied with the source file name. All files located in src/ will be compiled against the application specified to generate the binary. Finally, a BOOT.bin file (binary image that is used for booting off the SD cared) can be created through the utilization of the '​doit'​ script. This will automatically mount and copy over the BOOT.bin to the card for the HydroZynq. This script takes in the source file name of the main application as the first argument and the bit stream file as the second parameter. ​ 
-  The current firmware utilizes bit/​adc_dma_revb.bit as the bitstream file. 
-=== Programming === 
-=== Communicating ===