-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·129 lines (111 loc) · 2.65 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# This is a convenience script to do things with the NXT
# It does not concern itself with the neural network beyond formatting
# data for training
# fancy argument options
# note that you shouldn't pass -n and -d
function format {
# parse the most recent test, the one we just made
# these two files should probably be combined
python dataparser.py testRuns/`ls -t testRuns/ | head -1` &&
java -cp server-pc/bin/ formatting/RebalanceData &&
echo "Files ready for training, use runTrain in $ANN_FOLDER after deleting the weights file"
}
ANN_FOLDER=LightSpeedANN
if [[ $# -eq 0 ]]
then
echo "usage: -f or --format to format the result of test runs for training"
echo "-n or --neural to run a neural motor test"
echo "-d or --datacollect to collect training data"
echo "either -n or -d is required."
exit 1
fi
while [[ $# > 0 ]]
do
key="$1"
case $key in
-f|--format)
FORMAT=1
;;
-n|--neural)
TEST=neural
TESTS="$2"
shift # past argument
;;
-p|--pid)
TEST=pid
TESTS="$2"
shift # past argument
;;
-b|--benchmark)
TEST=benchmark
TESTS="$2"
shift # past argument
;;
-d|--datacollect)
TEST=data
TESTS="$2"
shift # past argument
;;
*)
echo "Invalid Argument"
exit 1 # unknown option
;;
esac
shift # past argument or value
done
if [[ -z $TEST ]]; then
if [[ $FORMAT ]]; then
format
exit 0
else
echo $TEST
echo "Invalid arguments, please use --neural or --data"
exit 1
fi
fi
if [[ -z $TESTS ]]
then
echo "Invalid arguments, please specify number of tests, ie -n 10"
exit 1
fi
# this will only create the dir if not already there
mkdir -p testRuns &&
# load program onto the brick
nxj -r client.Receive -cp client-brick/bin/
if [[ $? -ne 0 ]]
then
echo "USB connection failed, retrying in 7 seconds..."
sleep 7
nxj -r client.Receive -cp client-brick/bin/
if [[ $? -ne 0 ]]
then
echo "USB connection failed again, please plug-in NXT and hit enter"
read null
sleep 3
# if it's not plugged in now just quit. There's no hope at this point
nxj -r client.Receive -cp client-brick/bin/ || exit 1
fi
fi
if [[ $? -eq 0 ]]; then
if [[ $TEST == "neural" ]] || [[ $TEST = "benchmark" ]]; then
cd LightSpeedANN
./eval &
PID=$!
cd ..
fi
# run our server program
nxjpc -cp server-pc/bin/ server.Send $TEST $TESTS
if [[ -n $PID ]]; then
kill $PID
fi
fi
# $? is the exit code from last script
if [[ $? -eq 0 && $FORMAT ]]; then
format
fi
if [[ $? -eq 0 && $TEST == "benchmark" ]]; then
cd benchmarks
gnuplot plot > image.png
echo "In benchmarks: plotted graph to image.png using gnuplot plot, from neural.csv and pid.csv"
fi