forked from paparazzi/paparazzi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalibrate_aspirin_lisal.sh
executable file
·182 lines (176 loc) · 5.18 KB
/
calibrate_aspirin_lisal.sh
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
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
171
172
173
174
175
176
177
178
179
180
181
182
#End paparazzi processes
if [ "$(pidof paparazzicenter)" ]
then
killall "paparazzicenter"
fi
if [ "$(pidof messages)" ]
then
killall "messages"
fi
if [ "$(pidof plotter)" ]
then
killall "plotter"
fi
if [ "$(pidof server)" ]
then
killall "server"
fi
if [ "$(pidof link)" ]
then
killall "link"
fi
#Prompt user
echo ''
echo 'Plug the USB cable into the LISA/L and press enter'
echo ''
read
#Program LISA/L
make AIRCRAFT=LISA_ASCTEC_PIOTR clean_ac test_imu_aspirin.upload
wait 1s
#Prompt user
echo ''
echo 'Plug the UART cable into the LISA/L (UART2), the UART cable into the FLOSS JTAG, and the USB cable into the FLOSS JTAG and press enter. Make sure the USB cable to the Floss JTAG is the last USB device you have plugged in'
read
#Clear out logs directory
touch var/logs/tmp.txt
rm var/logs/*
#Run Paparazzi to get samples (accel and mag)
./paparazzi -session "Flight USB-serial@57600 USB1" &
#Prompt user
echo ''
echo 'Rotate the board through all 6 axes, stopping about 5 seconds at each axis. When done rotating the board through all 6 axes press enter. (getting data for mag and accel calibration)'
echo ''
read
#End paparazzi processes
if [ "$(pidof server)" ]
then
killall "server"
fi
if [ "$(pidof paparazzicenter)" ]
then
killall "paparazzicenter"
fi
if [ "$(pidof plotter)" ]
then
killall "plotter"
fi
if [ "$(pidof messages)" ]
then
killall "messages"
fi
if [ "$(pidof link)" ]
then
killall "link"
fi
if [ "$(pidof server)" ]
then
killall "server"
fi
#Get calibration values for accel and mag
cd sw/tools/calibration
./calibrate.py -s ACCEL ../../../var/logs/*.data -v
./calibrate.py -s MAG ../../../var/logs/*.data -v
./calibrate.py -s ACCEL ../../../var/logs/*.data -v > ../../../accel_results.txt
./calibrate.py -s MAG ../../../var/logs/*.data -v > ../../../mag_results.txt
cd ../../..
#Prompt user
echo ''
echo 'Place LISA/L on a stable surface, let go, and press enter (getting gyro neutral values). Let it sit until you are prompted again in 15 seconds.'
echo ''
read
#Clear out logs directory
touch var/logs/tmp.txt
rm var/logs/*
#Run Paparazzi to get samples (gyro)
./paparazzi -session "Flight USB-serial@57600 USB1" &
sleep 15s
if [ "$(pidof paparazzicenter)" ]
then
killall "paparazzicenter"
fi
if [ "$(pidof messages)" ]
then
killall "messages"
fi
if [ "$(pidof plotter)" ]
then
killall "plotter"
fi
if [ "$(pidof link)" ]
then
killall "link"
fi
if [ "$(pidof server)" ]
then
killall "server"
fi
grep "IMU_GYRO_RAW" var/logs/*.data | sed -e "s|^.*IMU_GYRO_RAW ||" > var/logs/gyro_results.txt
cd sw/tools/calibration
octave --eval gyro_mean
cd ../../..
#Find calibration values and replace them in calibration template file
#Create temp xml files
cp imu_template.xml tmp0.xml
touch tmp1.xml
#Create strings that show where to change values
accel_neutral_strs=('ACCEL_X_NEUTRAL' 'ACCEL_Y_NEUTRAL' 'ACCEL_Z_NEUTRAL')
mag_neutral_strs=('MAG_X_NEUTRAL' 'MAG_Y_NEUTRAL' 'MAG_Z_NEUTRAL')
gyro_neutral_strs=('GYRO_P_NEUTRAL' 'GYRO_Q_NEUTRAL' 'GYRO_R_NEUTRAL')
accel_sens_strs=('ACCEL_X_SENS' 'ACCEL_Y_SENS' 'ACCEL_Z_SENS')
mag_sens_strs=('MAG_X_SENS' 'MAG_Y_SENS' 'MAG_Z_SENS')
#Change accel neutral values in tmp file
for i in 0 1 2
do
tmp=$(grep "${accel_neutral_strs[i]}" accel_results.txt | sed -e "s|.*value=\"\\([0-9-]*\)\"/>|\1|")
sed -e "s|\(${accel_neutral_strs[i]}\" value=\"\)\([0-9-]*\)|\1$tmp|" tmp0.xml > tmp1.xml
mv tmp1.xml tmp0.xml
done
#Change accel sens values in tmp file
for i in 0 1 2
do
tmp=$(grep "${accel_sens_strs[i]}" accel_results.txt | sed -e "s|.*value=\"\\([0-9.]*\).*|\1|")
sed -e "s|\(${accel_sens_strs[i]}\" value=\"\)\([0-9.]*\)|\1$tmp|" tmp0.xml > tmp1.xml
mv tmp1.xml tmp0.xml
done
#Change mag neutral values in tmp file
for i in 0 1 2
do
tmp=$(grep "${mag_neutral_strs[i]}" mag_results.txt | sed -e "s|.*value=\"\([0-9-]*\)\"/>|\1|")
sed -e "s|\(${mag_neutral_strs[i]}\" value=\"\)\([0-9-]*\)|\1$tmp|" tmp0.xml > tmp1.xml
mv tmp1.xml tmp0.xml
done
#Change mag sens values in tmp file
for i in 0 1 2
do
tmp=$(grep "${mag_sens_strs[i]}" mag_results.txt | sed -e "s|.*value=\"\([0-9.]*\).*|\1|")
sed -e "s|\(${mag_sens_strs[i]}\" value=\"\)\([0-9.]*\)|\1$tmp|" tmp0.xml > tmp1.xml
mv tmp1.xml tmp0.xml
done
#Change gyro neutral values in tmp file
gyro_p=$(grep "^ " gyro_results.txt | sed -e "s|^ \([0-9-]*\) [0-9-]* [0-9-]*|\1|")
gyro_q=$(grep "^ " gyro_results.txt | sed -e "s|^ [0-9-]* \([0-9-]*\) [0-9-]*|\1|")
gyro_r=$(grep "^ " gyro_results.txt | sed -e "s|^ [0-9-]* [0-9-]* \([0-9-]*\)|\1|")
sed -e "s|\(${gyro_neutral_strs[0]}\" value=\"\)\([0-9-]*\)|\1$gyro_p|" tmp0.xml > tmp1.xml
mv tmp1.xml tmp0.xml
sed -e "s|\(${gyro_neutral_strs[1]}\" value=\"\)\([0-9-]*\)|\1$gyro_q|" tmp0.xml > tmp1.xml
mv tmp1.xml tmp0.xml
sed -e "s|\(${gyro_neutral_strs[2]}\" value=\"\)\([0-9-]*\)|\1$gyro_r|" tmp0.xml > tmp1.xml
mv tmp1.xml tmp0.xml
#Get serial number from user
echo 'Type aspirin serial number and press enter'
echo ''
read serial_number
#Name configuration file for user's serial number
cp tmp0.xml imu_aspirin_$serial_number.xml
echo ''
echo 'file name is imu_aspirin_'$serial_number'.xml'
echo ''
cat imu_aspirin_$serial_number.xml
mv imu_aspirin_$serial_number.xml ../imu_confs/
#Clean up
rm mag_results.txt
rm accel_results.txt
rm gyro_results.txt
rm tmp0.xml
echo 'Done with configuration'
echo ''