From 8c6a73a01f92f1a850fb98da187e9cc4bd6273fc Mon Sep 17 00:00:00 2001 From: HappyZ Date: Tue, 30 Jan 2018 15:36:32 -0600 Subject: [PATCH] init commit --- .gitignore | 1 + calibrate.sh | 6 +++++ calibration_plot.m | 39 +++++++++++++++++++++++++++++++ config_entry | 1 + iw_parser.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++ measure.sh | 6 +++++ 6 files changed, 110 insertions(+) create mode 100755 calibrate.sh create mode 100644 calibration_plot.m create mode 100755 config_entry create mode 100755 iw_parser.py create mode 100755 measure.sh diff --git a/.gitignore b/.gitignore index e1bc67a..2debb76 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +calibration_data/ iw/iw iw/*~ iw/*.o diff --git a/calibrate.sh b/calibrate.sh new file mode 100755 index 0000000..5c4560c --- /dev/null +++ b/calibrate.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +for i in `seq 1 5000`; do + sudo /usr/sbin/iw wlp58s0 measurement ftm_request config_entry | tail -n +3 >> result_$1 + sleep 0.1 +done diff --git a/calibration_plot.m b/calibration_plot.m new file mode 100644 index 0000000..5decba6 --- /dev/null +++ b/calibration_plot.m @@ -0,0 +1,39 @@ +figure(1); +clf; hold on; + +desired_result = [60:30:1200, 120, 170, 200, 430, 1000, 1300:100:2000]; +mean_result = zeros(size(desired_result)); +diff_result = zeros(size(desired_result)); +all_data = []; +for i = 1:length(desired_result) + dist = desired_result(i); + filename = ['calibration_data/result_', num2str(dist), 'cm.txt']; + + fileID = fopen(filename, 'r'); + sizeData = [9 Inf]; + formatSpec = [... + 'Target: %x:%x:%x:%x:%x:%x, status: %d, ',... + 'rtt: %d psec, distance: %d cm\n'... + ]; + data = fscanf(fileID, formatSpec, sizeData); + data(:, data(7, :) ~= 0) = []; + data(:, data(9, :) < -1000) = []; + fclose(fileID); + + fprintf('distance: %d:\n', dist); + fprintf('* mean: %.2fcm\n', mean(data(9, :))); + fprintf('* median: %.2fcm\n', median(data(9, :))); + + cdfplot(data(9, :)); + + mean_result(i) = mean(data(9, :)); + all_data = [all_data, [data(9, :); dist * ones(1, length(data(9, :)))]]; + diff_result(i) = desired_result(i) - mean_result(i); +end + +figure(2); clf; +scatter(all_data(1, :), all_data(2, :), '.'); +params = polyfit(all_data(1, :), all_data(2, :), 1) +fitted_data = params(1) * all_data(1, :) + params(2); +hold on; +plot(all_data(1, :), fitted_data, '-') \ No newline at end of file diff --git a/config_entry b/config_entry new file mode 100755 index 0000000..a6b4196 --- /dev/null +++ b/config_entry @@ -0,0 +1 @@ +34:f6:4b:5e:69:1f bw=20 cf=2462 retries=5 asap diff --git a/iw_parser.py b/iw_parser.py new file mode 100755 index 0000000..589a416 --- /dev/null +++ b/iw_parser.py @@ -0,0 +1,57 @@ +#!/usr/bin/python + + +import os +import argparse + +from numpy import min, max, median, mean, std + + +def wrapper(args): + if not args['filepath'] or not os.path.isfile(args['filepath']): + return + results = [] + with open(args['filepath']) as f: + for line in f: + tmp = line.rstrip().split(', ') + status = int(tmp[1].split(' ')[1]) + if status is not 0: + continue + psec = int(tmp[2].split(' ')[1]) + distance = int(tmp[3].split(' ')[1]) + if distance < -1000: + continue + results.append(distance * args['args'][0] + args['cali'][1]) + print('statics of results') + print('* num of valid data: {0}'.format(len(results))) + print('* min: {0:.2f}cm'.format(min(results))) + print('* max: {0:.2f}cm'.format(max(results))) + print('* mean: {0:.2f}cm'.format(mean(results))) + print('* median: {0:.2f}cm'.format(median(results))) + print('* std: {0:.2f}cm'.format(std(results))) + + +def main(): + p = argparse.ArgumentParser(description='iw parser') + p.add_argument( + 'filepath', + help="input file path for result" + ) + p.add_argument( + '--cali', + nargs=2, + default=(0.9084, 526.8163), + type=float, + help="calibrate final result" + ) + try: + args = vars(p.parse_args()) + except Exception as e: + print(e) + sys.exit() + wrapper(args) + + + +if __name__ == '__main__': + main() diff --git a/measure.sh b/measure.sh new file mode 100755 index 0000000..edbc93b --- /dev/null +++ b/measure.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +for i in `seq 1 10`; do + sudo /usr/sbin/iw wlp58s0 measurement ftm_request config_entry | tail -n +3 >> result_$1 + sleep 0.1 +done