parameters: (geometries_list, use_normalized_mix=False, use_6dof=False)
return_statement: return buf.getvalue()
docstring: Generate C header file with same format as multi_tables.py
      TODO: rewrite using templates (see generation of uORB headers)
docstring_summary: Generate C header file with same format as multi_tables.py
      TODO: rewrite using templates (see generation of uORB headers)
docstring_tokens: Generate C header file with same format as multi_tables . py TODO : rewrite using templates ( see generation of uORB headers )
function: def generate_mixer_multirotor_header(geometries_list, use_normalized_mix=False, use_6dof=False):
      '''
      Generate C header file with same format as multi_tables.py
      TODO: rewrite using templates (see generation of uORB headers)
      '''
      from io import StringIO
      buf = StringIO()
  
      # Print Header
      buf.write(u"/*\n")
      buf.write(u"* This file is automatically generated by px_generate_mixers.py - do not edit.\n")
      buf.write(u"*/\n")
      buf.write(u"\n")
      buf.write(u"#ifndef _MIXER_MULTI_TABLES\n")
      buf.write(u"#define _MIXER_MULTI_TABLES\n")
      buf.write(u"\n")
  
      # Print enum
      buf.write(u"enum class MultirotorGeometry : MultirotorGeometryUnderlyingType {\n")
      for i, geometry in enumerate(geometries_list):
          buf.write(u"\t{},{}// {} (text key {})\n".format(
              geometry['info']['name'].upper(), ' ' * (max(0, 30 - len(geometry['info']['name']))),
              geometry['info']['description'], geometry['info']['key']))
      buf.write(u"\n\tMAX_GEOMETRY\n")
      buf.write(u"}; // enum class MultirotorGeometry\n\n")
  
      # Print mixer gains
      buf.write(u"namespace {\n")
      for geometry in geometries_list:
          # Get desired mix matrix
          if use_normalized_mix:
              mix = geometry['mix']['B_px']
          else:
              mix = geometry['mix']['B']
  
          buf.write(u"static constexpr MultirotorMixer::Rotor _config_{}[] {{\n".format(geometry['info']['name']))
  
          for row in mix:
              if use_6dof:
              # 6dof mixer
                  buf.write(u"\t{{ {:9f}, {:9f}, {:9f}, {:9f}, {:9f}, {:9f} }},\n".format(
                      row[0], row[1], row[2],
                      row[3], row[4], row[5]))
              else:
              # 4dof mixer
                  buf.write(u"\t{{ {:9f}, {:9f}, {:9f}, {:9f} }},\n".format(
                      row[0], row[1], row[2],
                      -row[5]))  # Upward thrust is positive TODO: to remove this, adapt PX4 to use NED correctly
  
          buf.write(u"};\n\n")
  
      # Print geometry indeces
      buf.write(u"static constexpr const MultirotorMixer::Rotor *_config_index[] {\n")
      for geometry in geometries_list:
          buf.write(u"\t&_config_{}[0],\n".format(geometry['info']['name']))
      buf.write(u"};\n\n")
  
      # Print geometry rotor counts
      buf.write(u"static constexpr unsigned _config_rotor_count[] {\n")
      for geometry in geometries_list:
          buf.write(u"\t{}, /* {} */\n".format(len(geometry['rotors']), geometry['info']['name']))
      buf.write(u"};\n\n")
  
      # Print geometry key
      buf.write(u"const char* _config_key[] {\n")
      for geometry in geometries_list:
          buf.write(u"\t\"{}\",\t/* {} */\n".format(geometry['info']['key'], geometry['info']['name']))
      buf.write(u"};\n\n")
  
      # Print footer
      buf.write(u"} // anonymous namespace\n\n")
      buf.write(u"#endif /* _MIXER_MULTI_TABLES */\n\n")
  
      return buf.getvalue()
function_tokens: def generate_mixer_multirotor_header ( geometries_list , use_normalized_mix = False , use_6dof = False ) : from io import StringIO buf = StringIO ( ) # Print Header buf . write ( u"/*\n" ) buf . write ( u"* This file is automatically generated by px_generate_mixers.py - do not edit.\n" ) buf . write ( u"*/\n" ) buf . write ( u"\n" ) buf . write ( u"#ifndef _MIXER_MULTI_TABLES\n" ) buf . write ( u"#define _MIXER_MULTI_TABLES\n" ) buf . write ( u"\n" ) # Print enum buf . write ( u"enum class MultirotorGeometry : MultirotorGeometryUnderlyingType {\n" ) for i , geometry in enumerate ( geometries_list ) : buf . write ( u"\t{},{}// {} (text key {})\n" . format ( geometry [ 'info' ] [ 'name' ] . upper ( ) , ' ' * ( max ( 0 , 30 - len ( geometry [ 'info' ] [ 'name' ] ) ) ) , geometry [ 'info' ] [ 'description' ] , geometry [ 'info' ] [ 'key' ] ) ) buf . write ( u"\n\tMAX_GEOMETRY\n" ) buf . write ( u"}; // enum class MultirotorGeometry\n\n" ) # Print mixer gains buf . write ( u"namespace {\n" ) for geometry in geometries_list : # Get desired mix matrix if use_normalized_mix : mix = geometry [ 'mix' ] [ 'B_px' ] else : mix = geometry [ 'mix' ] [ 'B' ] buf . write ( u"static constexpr MultirotorMixer::Rotor _config_{}[] {{\n" . format ( geometry [ 'info' ] [ 'name' ] ) ) for row in mix : if use_6dof : # 6dof mixer buf . write ( u"\t{{ {:9f}, {:9f}, {:9f}, {:9f}, {:9f}, {:9f} }},\n" . format ( row [ 0 ] , row [ 1 ] , row [ 2 ] , row [ 3 ] , row [ 4 ] , row [ 5 ] ) ) else : # 4dof mixer buf . write ( u"\t{{ {:9f}, {:9f}, {:9f}, {:9f} }},\n" . format ( row [ 0 ] , row [ 1 ] , row [ 2 ] , - row [ 5 ] ) ) # Upward thrust is positive TODO: to remove this, adapt PX4 to use NED correctly buf . write ( u"};\n\n" ) # Print geometry indeces buf . write ( u"static constexpr const MultirotorMixer::Rotor *_config_index[] {\n" ) for geometry in geometries_list : buf . write ( u"\t&_config_{}[0],\n" . format ( geometry [ 'info' ] [ 'name' ] ) ) buf . write ( u"};\n\n" ) # Print geometry rotor counts buf . write ( u"static constexpr unsigned _config_rotor_count[] {\n" ) for geometry in geometries_list : buf . write ( u"\t{}, /* {} */\n" . format ( len ( geometry [ 'rotors' ] ) , geometry [ 'info' ] [ 'name' ] ) ) buf . write ( u"};\n\n" ) # Print geometry key buf . write ( u"const char* _config_key[] {\n" ) for geometry in geometries_list : buf . write ( u"\t\"{}\",\t/* {} */\n" . format ( geometry [ 'info' ] [ 'key' ] , geometry [ 'info' ] [ 'name' ] ) ) buf . write ( u"};\n\n" ) # Print footer buf . write ( u"} // anonymous namespace\n\n" ) buf . write ( u"#endif /* _MIXER_MULTI_TABLES */\n\n" ) return buf . getvalue ( )