mixer_multirotor.py: fixes for Python3

This fixed running `make tests` on Arch Linux where Python 3 is the
default.
This commit is contained in:
Julian Oes
2019-03-15 10:12:16 +01:00
committed by Beat Küng
parent bfa0a4a8f1
commit 2ebb9d2ab5
+8 -8
View File
@@ -256,15 +256,15 @@ def run_tests(mixer_cb, P, test_mixer_binary, test_index=None):
#'cat > /tmp/test_'+str(mode_idx), shell=True, # just to test the output #'cat > /tmp/test_'+str(mode_idx), shell=True, # just to test the output
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stdin=subprocess.PIPE) stdin=subprocess.PIPE)
proc.stdin.write("{:}\n".format(mode_idx)) # airmode proc.stdin.write("{:}\n".format(mode_idx).encode('utf-8')) # airmode
motor_count = P.shape[0] motor_count = P.shape[0]
proc.stdin.write("{:}\n".format(motor_count)) # motor count proc.stdin.write("{:}\n".format(motor_count).encode('utf-8')) # motor count
# control allocation matrix # control allocation matrix
for row in P.getA(): for row in P.getA():
for col in row: for col in row:
proc.stdin.write("{:.8f} ".format(col)) proc.stdin.write("{:.8f} ".format(col).encode('utf-8'))
proc.stdin.write("\n") proc.stdin.write("\n".encode('utf-8'))
proc.stdin.write("\n") proc.stdin.write("\n".encode('utf-8'))
failed = False failed = False
try: try:
@@ -277,7 +277,7 @@ def run_tests(mixer_cb, P, test_mixer_binary, test_index=None):
actuator_controls = test_cases[[i], :].T actuator_controls = test_cases[[i], :].T
proc.stdin.write("{:.8f} {:.8f} {:.8f} {:.8f}\n" proc.stdin.write("{:.8f} {:.8f} {:.8f} {:.8f}\n"
.format(actuator_controls[0, 0], actuator_controls[1, 0], .format(actuator_controls[0, 0], actuator_controls[1, 0],
actuator_controls[2, 0], actuator_controls[3, 0])) actuator_controls[2, 0], actuator_controls[3, 0]).encode('utf-8'))
(u, u_new) = mixer_cb(actuator_controls, P, 0.0, 1.0) (u, u_new) = mixer_cb(actuator_controls, P, 0.0, 1.0)
# Saturate the outputs between 0 and 1 # Saturate the outputs between 0 and 1
@@ -285,8 +285,8 @@ def run_tests(mixer_cb, P, test_mixer_binary, test_index=None):
u_new_sat = np.minimum(u_new_sat, np.matlib.ones(u.size).T) u_new_sat = np.minimum(u_new_sat, np.matlib.ones(u.size).T)
# write expected outputs # write expected outputs
for j in range(motor_count): for j in range(motor_count):
proc.stdin.write("{:.8f} ".format(u_new_sat[j, 0])) proc.stdin.write("{:.8f} ".format(u_new_sat[j, 0]).encode('utf-8'))
proc.stdin.write("\n") proc.stdin.write("\n".encode('utf-8'))
proc.stdin.close() proc.stdin.close()
except IOError as e: except IOError as e: