mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-25 23:46:04 +08:00
[tools] some minor fixes for future python3 compatibility
This commit is contained in:
@@ -240,8 +240,8 @@ class Visualizer:
|
||||
IvyInit(_NAME,
|
||||
"",
|
||||
0,
|
||||
lambda x,y: y,
|
||||
lambda x,z: z
|
||||
lambda x, y: y,
|
||||
lambda x, z: z
|
||||
)
|
||||
|
||||
IvyStart("")
|
||||
@@ -317,14 +317,14 @@ def run():
|
||||
window_title = "Attitude_Viz"
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], "t:", ["title"])
|
||||
for o,a in opts:
|
||||
for o, a in opts:
|
||||
if o in ("-t", "--title"):
|
||||
window_title = a
|
||||
except getopt.error, msg:
|
||||
print msg
|
||||
print """usage:
|
||||
except getopt.error as msg:
|
||||
print(msg)
|
||||
print("""usage:
|
||||
-t, --title set window title
|
||||
"""
|
||||
""")
|
||||
pygame.init()
|
||||
screen = pygame.display.set_mode(SCREEN_SIZE, pygame.OPENGL|pygame.DOUBLEBUF)
|
||||
#resize(*SCREEN_SIZE)
|
||||
|
||||
@@ -47,7 +47,7 @@ def main():
|
||||
if os.path.isfile(args[0]):
|
||||
filename = args[0]
|
||||
else:
|
||||
print args[0] + " not found"
|
||||
print(args[0] + " not found")
|
||||
sys.exit(1)
|
||||
ac_ids = calibration_utils.get_ids_in_log(filename)
|
||||
# import code; code.interact(local=locals())
|
||||
@@ -72,28 +72,28 @@ def main():
|
||||
if not filename.endswith(".data"):
|
||||
parser.error("Please specify a *.data log file")
|
||||
if options.verbose:
|
||||
print "reading file "+filename+" for aircraft "+options.ac_id+" and sensor "+options.sensor
|
||||
print("reading file "+filename+" for aircraft "+options.ac_id+" and sensor "+options.sensor)
|
||||
|
||||
# read raw measurements from log file
|
||||
measurements = calibration_utils.read_log(options.ac_id, filename, options.sensor)
|
||||
if len(measurements) == 0:
|
||||
print "Error: found zero IMU_"+options.sensor+"_RAW measurements for aircraft with id "+options.ac_id+" in log file!"
|
||||
print("Error: found zero IMU_"+options.sensor+"_RAW measurements for aircraft with id "+options.ac_id+" in log file!")
|
||||
sys.exit(1)
|
||||
if options.verbose:
|
||||
print "found "+str(len(measurements))+" records"
|
||||
print("found "+str(len(measurements))+" records")
|
||||
|
||||
# filter out noisy measurements
|
||||
flt_meas, flt_idx = calibration_utils.filter_meas(measurements, noise_window, noise_threshold)
|
||||
if options.verbose:
|
||||
print "remaining "+str(len(flt_meas))+" after low pass"
|
||||
print("remaining "+str(len(flt_meas))+" after low pass")
|
||||
|
||||
# get an initial min/max guess
|
||||
p0 = calibration_utils.get_min_max_guess(flt_meas, sensor_ref)
|
||||
cp0, np0 = calibration_utils.scale_measurements(flt_meas, p0)
|
||||
print "initial guess : avg "+str(np0.mean())+" std "+str(np0.std())
|
||||
print("initial guess : avg "+str(np0.mean())+" std "+str(np0.std()))
|
||||
# print p0
|
||||
|
||||
def err_func(p,meas,y):
|
||||
def err_func(p, meas, y):
|
||||
cp, np = calibration_utils.scale_measurements(meas, p)
|
||||
err = y*scipy.ones(len(meas)) - np
|
||||
return err
|
||||
@@ -101,11 +101,11 @@ def main():
|
||||
p1, success = optimize.leastsq(err_func, p0[:], args=(flt_meas, sensor_ref))
|
||||
cp1, np1 = calibration_utils.scale_measurements(flt_meas, p1)
|
||||
|
||||
print "optimized guess : avg "+str(np1.mean())+" std "+str(np1.std())
|
||||
print("optimized guess : avg "+str(np1.mean())+" std "+str(np1.std()))
|
||||
# print p1
|
||||
|
||||
calibration_utils.print_xml(p1, options.sensor, sensor_res)
|
||||
print ""
|
||||
print("")
|
||||
|
||||
calibration_utils.plot_results(measurements, flt_idx, flt_meas, cp0, np0, cp1, np1, sensor_ref)
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ def main():
|
||||
if os.path.isfile(args[0]):
|
||||
filename = args[0]
|
||||
else:
|
||||
print args[0] + " not found"
|
||||
print(args[0] + " not found")
|
||||
sys.exit(1)
|
||||
if not filename.endswith(".data"):
|
||||
parser.error("Please specify a *.data log file")
|
||||
@@ -85,16 +85,16 @@ def main():
|
||||
if options.tt_id < 0 or options.tt_id > 255:
|
||||
parser.error("Specify a valid turntable id number!")
|
||||
if options.verbose:
|
||||
print "reading file "+filename+" for aircraft "+str(options.ac_id)+" and turntable "+str(options.tt_id)
|
||||
print("reading file "+filename+" for aircraft "+str(options.ac_id)+" and turntable "+str(options.tt_id))
|
||||
|
||||
samples = calibration_utils.read_turntable_log(options.ac_id, options.tt_id, filename, 1, 7)
|
||||
|
||||
if len(samples) == 0:
|
||||
print "Error: found zero matching messages in log file!"
|
||||
print "Was looking for IMU_TURNTABLE from id: "+str(options.tt_id)+" and IMU_GYRO_RAW from id: "+str(options.ac_id)+" in file "+filename
|
||||
print("Error: found zero matching messages in log file!")
|
||||
print("Was looking for IMU_TURNTABLE from id: "+str(options.tt_id)+" and IMU_GYRO_RAW from id: "+str(options.ac_id)+" in file "+filename)
|
||||
sys.exit(1)
|
||||
if options.verbose:
|
||||
print "found "+str(len(samples))+" records"
|
||||
print("found "+str(len(samples))+" records")
|
||||
|
||||
if options.axis == 'p':
|
||||
axis_idx = 1
|
||||
@@ -106,32 +106,32 @@ def main():
|
||||
parser.error("Specify a valid axis!")
|
||||
|
||||
#Linear regression using stats.linregress
|
||||
t = samples[:,0]
|
||||
xn = samples[:,axis_idx]
|
||||
(a_s,b_s,r,tt,stderr)=stats.linregress(t,xn)
|
||||
t = samples[:, 0]
|
||||
xn = samples[:, axis_idx]
|
||||
(a_s, b_s, r, tt, stderr)=stats.linregress(t, xn)
|
||||
print('Linear regression using stats.linregress')
|
||||
print('regression: a=%.2f b=%.2f, std error= %.3f' % (a_s,b_s,stderr))
|
||||
print('<define name="GYRO_X_NEUTRAL" value="%d"/>' % (b_s));
|
||||
print('<define name="GYRO_X_SENS" value="%f" integer="16"/>' % (pow(2,12)/a_s));
|
||||
print(('regression: a=%.2f b=%.2f, std error= %.3f' % (a_s, b_s, stderr)))
|
||||
print(('<define name="GYRO_X_NEUTRAL" value="%d"/>' % (b_s)));
|
||||
print(('<define name="GYRO_X_SENS" value="%f" integer="16"/>' % (pow(2, 12)/a_s)));
|
||||
|
||||
#
|
||||
# overlay fited value
|
||||
#
|
||||
ovl_omega = linspace(1,7.5,10)
|
||||
ovl_adc = polyval([a_s,b_s],ovl_omega)
|
||||
ovl_omega = linspace(1, 7.5, 10)
|
||||
ovl_adc = polyval([a_s, b_s], ovl_omega)
|
||||
|
||||
title('Linear Regression Example')
|
||||
subplot(3,1,1)
|
||||
plot(samples[:,1])
|
||||
plot(samples[:,2])
|
||||
plot(samples[:,3])
|
||||
legend(['p','q','r']);
|
||||
subplot(3, 1, 1)
|
||||
plot(samples[:, 1])
|
||||
plot(samples[:, 2])
|
||||
plot(samples[:, 3])
|
||||
legend(['p', 'q', 'r']);
|
||||
|
||||
subplot(3,1,2)
|
||||
plot(samples[:,0])
|
||||
subplot(3, 1, 2)
|
||||
plot(samples[:, 0])
|
||||
|
||||
subplot(3,1,3)
|
||||
plot(samples[:,0], samples[:,axis_idx], 'b.')
|
||||
subplot(3, 1, 3)
|
||||
plot(samples[:, 0], samples[:, axis_idx], 'b.')
|
||||
plot(ovl_omega, ovl_adc, 'r')
|
||||
|
||||
show();
|
||||
|
||||
@@ -33,7 +33,7 @@ def get_ids_in_log(filename):
|
||||
f = open(filename, 'r')
|
||||
ids = []
|
||||
pattern = re.compile("\S+ (\S+)")
|
||||
while 1:
|
||||
while True:
|
||||
line = f.readline().strip()
|
||||
if line == '':
|
||||
break
|
||||
@@ -51,7 +51,7 @@ def read_log(ac_id, filename, sensor):
|
||||
f = open(filename, 'r')
|
||||
pattern = re.compile("(\S+) "+ac_id+" IMU_"+sensor+"_RAW (\S+) (\S+) (\S+)")
|
||||
list_meas = []
|
||||
while 1:
|
||||
while True:
|
||||
line = f.readline().strip()
|
||||
if line == '':
|
||||
break
|
||||
@@ -68,7 +68,7 @@ def read_log(ac_id, filename, sensor):
|
||||
def filter_meas(meas, window_size, noise_threshold):
|
||||
filtered_meas = []
|
||||
filtered_idx = []
|
||||
for i in range(window_size,len(meas)-window_size):
|
||||
for i in range(window_size, len(meas)-window_size):
|
||||
noise = meas[i-window_size:i+window_size,:].std(axis=0)
|
||||
if linalg.norm(noise) < noise_threshold:
|
||||
filtered_meas.append(meas[i,:])
|
||||
@@ -104,13 +104,13 @@ def scale_measurements(meas, p):
|
||||
# print xml for airframe file
|
||||
#
|
||||
def print_xml(p, sensor, res):
|
||||
print ""
|
||||
print "<define name=\""+sensor+"_X_NEUTRAL\" value=\""+str(int(round(p[0])))+"\"/>"
|
||||
print "<define name=\""+sensor+"_Y_NEUTRAL\" value=\""+str(int(round(p[1])))+"\"/>"
|
||||
print "<define name=\""+sensor+"_Z_NEUTRAL\" value=\""+str(int(round(p[2])))+"\"/>"
|
||||
print "<define name=\""+sensor+"_X_SENS\" value=\""+str(p[3]*2**res)+"\" integer=\"16\"/>"
|
||||
print "<define name=\""+sensor+"_Y_SENS\" value=\""+str(p[4]*2**res)+"\" integer=\"16\"/>"
|
||||
print "<define name=\""+sensor+"_Z_SENS\" value=\""+str(p[5]*2**res)+"\" integer=\"16\"/>"
|
||||
print("")
|
||||
print("<define name=\""+sensor+"_X_NEUTRAL\" value=\""+str(int(round(p[0])))+"\"/>")
|
||||
print("<define name=\""+sensor+"_Y_NEUTRAL\" value=\""+str(int(round(p[1])))+"\"/>")
|
||||
print("<define name=\""+sensor+"_Z_NEUTRAL\" value=\""+str(int(round(p[2])))+"\"/>")
|
||||
print("<define name=\""+sensor+"_X_SENS\" value=\""+str(p[3]*2**res)+"\" integer=\"16\"/>")
|
||||
print("<define name=\""+sensor+"_Y_SENS\" value=\""+str(p[4]*2**res)+"\" integer=\"16\"/>")
|
||||
print("<define name=\""+sensor+"_Z_SENS\" value=\""+str(p[5]*2**res)+"\" integer=\"16\"/>")
|
||||
|
||||
|
||||
|
||||
@@ -118,36 +118,36 @@ def print_xml(p, sensor, res):
|
||||
# plot calibration results
|
||||
#
|
||||
def plot_results(measurements, flt_idx, flt_meas, cp0, np0, cp1, np1, sensor_ref):
|
||||
subplot(3,1,1)
|
||||
plot(measurements[:,0])
|
||||
plot(measurements[:,1])
|
||||
plot(measurements[:,2])
|
||||
plot(flt_idx, flt_meas[:,0], 'ro')
|
||||
plot(flt_idx, flt_meas[:,1], 'ro')
|
||||
plot(flt_idx, flt_meas[:,2], 'ro')
|
||||
subplot(3, 1, 1)
|
||||
plot(measurements[:, 0])
|
||||
plot(measurements[:, 1])
|
||||
plot(measurements[:, 2])
|
||||
plot(flt_idx, flt_meas[:, 0], 'ro')
|
||||
plot(flt_idx, flt_meas[:, 1], 'ro')
|
||||
plot(flt_idx, flt_meas[:, 2], 'ro')
|
||||
xlabel('time (s)')
|
||||
ylabel('ADC')
|
||||
title('Raw sensors')
|
||||
|
||||
subplot(3,2,3)
|
||||
plot(cp0[:,0]);
|
||||
plot(cp0[:,1]);
|
||||
plot(cp0[:,2]);
|
||||
subplot(3, 2, 3)
|
||||
plot(cp0[:, 0]);
|
||||
plot(cp0[:, 1]);
|
||||
plot(cp0[:, 2]);
|
||||
plot(-sensor_ref*scipy.ones(len(flt_meas)));
|
||||
plot(sensor_ref*scipy.ones(len(flt_meas)));
|
||||
|
||||
subplot(3,2,4)
|
||||
subplot(3, 2, 4)
|
||||
plot(np0);
|
||||
plot(sensor_ref*scipy.ones(len(flt_meas)));
|
||||
|
||||
subplot(3,2,5)
|
||||
plot(cp1[:,0]);
|
||||
plot(cp1[:,1]);
|
||||
plot(cp1[:,2]);
|
||||
subplot(3, 2, 5)
|
||||
plot(cp1[:, 0]);
|
||||
plot(cp1[:, 1]);
|
||||
plot(cp1[:, 2]);
|
||||
plot(-sensor_ref*scipy.ones(len(flt_meas)));
|
||||
plot(sensor_ref*scipy.ones(len(flt_meas)));
|
||||
|
||||
subplot(3,2,6)
|
||||
subplot(3, 2, 6)
|
||||
plot(np1);
|
||||
plot(sensor_ref*scipy.ones(len(flt_meas)));
|
||||
|
||||
@@ -164,7 +164,7 @@ def read_turntable_log(ac_id, tt_id, filename, _min, _max):
|
||||
pattern_t = re.compile("(\S+) "+str(tt_id)+" IMU_TURNTABLE (\S+)")
|
||||
last_tt = None
|
||||
list_tt = []
|
||||
while 1:
|
||||
while True:
|
||||
line = f.readline().strip()
|
||||
if line == '':
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user