parameters: (mixer_cb, P, test_mixer_binary, test_index=None)
docstring: Run all (or a specific) tests for a certain mixer method an control
      allocation matrix P
docstring_summary: Run all (or a specific) tests for a certain mixer method an control
      allocation matrix P
docstring_tokens: Run all ( or a specific ) tests for a certain mixer method an control allocation matrix P
function: def run_tests(mixer_cb, P, test_mixer_binary, test_index=None):
      """
      Run all (or a specific) tests for a certain mixer method an control
      allocation matrix P
      """
      B = np.linalg.pinv(P)
      proc = subprocess.Popen(
          test_mixer_binary,
          #'cat > /tmp/test_'+str(mode_idx), shell=True, # just to test the output
          stdout=subprocess.PIPE,
          stdin=subprocess.PIPE)
      proc.stdin.write("{:}\n".format(mode_idx).encode('utf-8')) # airmode
      motor_count = P.shape[0]
      proc.stdin.write("{:}\n".format(motor_count).encode('utf-8')) # motor count
      # control allocation matrix
      for row in P.getA():
          for col in row:
              proc.stdin.write("{:.8f} ".format(col).encode('utf-8'))
          proc.stdin.write("\n".encode('utf-8'))
      proc.stdin.write("\n".encode('utf-8'))
  
      failed = False
      try:
          if test_index is None:
              # go through all test cases
              test_indices = range(test_cases.shape[0])
          else:
              test_indices = [test_index]
          for i in test_indices:
              actuator_controls = test_cases[[i], :].T
              proc.stdin.write("{:.8f} {:.8f} {:.8f} {:.8f}\n"
                      .format(actuator_controls[0, 0], actuator_controls[1, 0],
                          actuator_controls[2, 0], actuator_controls[3, 0]).encode('utf-8'))
  
              (u, u_new) = mixer_cb(actuator_controls, P, 0.0, 1.0)
              # Saturate the outputs between 0 and 1
              u_new_sat = np.maximum(u_new, np.matlib.zeros(u.size).T)
              u_new_sat = np.minimum(u_new_sat, np.matlib.ones(u.size).T)
              # write expected outputs
              for j in range(motor_count):
                  proc.stdin.write("{:.8f} ".format(u_new_sat[j, 0]).encode('utf-8'))
              proc.stdin.write("\n".encode('utf-8'))
  
          proc.stdin.close()
      except IOError as e:
          failed = True
      result = proc.stdout.read()
      proc.wait()
      if proc.returncode != 0: failed = True
      if failed:
          print("Error: test failed")
          print("B:\n{}".format(B))
          print("P:\n{}".format(P))
          print(result)
          raise Exception('Test failed')
function_tokens: def run_tests ( mixer_cb , P , test_mixer_binary , test_index = None ) : B = np . linalg . pinv ( P ) proc = subprocess . Popen ( test_mixer_binary , #'cat > /tmp/test_'+str(mode_idx), shell=True, # just to test the output stdout = subprocess . PIPE , stdin = subprocess . PIPE ) proc . stdin . write ( "{:}\n" . format ( mode_idx ) . encode ( 'utf-8' ) ) # airmode motor_count = P . shape [ 0 ] proc . stdin . write ( "{:}\n" . format ( motor_count ) . encode ( 'utf-8' ) ) # motor count # control allocation matrix for row in P . getA ( ) : for col in row : proc . stdin . write ( "{:.8f} " . format ( col ) . encode ( 'utf-8' ) ) proc . stdin . write ( "\n" . encode ( 'utf-8' ) ) proc . stdin . write ( "\n" . encode ( 'utf-8' ) ) failed = False try : if test_index is None : # go through all test cases test_indices = range ( test_cases . shape [ 0 ] ) else : test_indices = [ test_index ] for i in test_indices : actuator_controls = test_cases [ [ i ] , : ] . T proc . stdin . write ( "{:.8f} {:.8f} {:.8f} {:.8f}\n" . format ( actuator_controls [ 0 , 0 ] , actuator_controls [ 1 , 0 ] , actuator_controls [ 2 , 0 ] , actuator_controls [ 3 , 0 ] ) . encode ( 'utf-8' ) ) ( u , u_new ) = mixer_cb ( actuator_controls , P , 0.0 , 1.0 ) # Saturate the outputs between 0 and 1 u_new_sat = np . maximum ( u_new , np . matlib . zeros ( u . size ) . T ) u_new_sat = np . minimum ( u_new_sat , np . matlib . ones ( u . size ) . T ) # write expected outputs for j in range ( motor_count ) : proc . stdin . write ( "{:.8f} " . format ( u_new_sat [ j , 0 ] ) . encode ( 'utf-8' ) ) proc . stdin . write ( "\n" . encode ( 'utf-8' ) ) proc . stdin . close ( ) except IOError as e : failed = True result = proc . stdout . read ( ) proc . wait ( ) if proc . returncode != 0 : failed = True if failed : print ( "Error: test failed" ) print ( "B:\n{}" . format ( B ) ) print ( "P:\n{}" . format ( P ) ) print ( result ) raise Exception ( 'Test failed' )