make multi_tables script python3 compatible

The script still works with python2, I also added a file ending
This commit is contained in:
Thomas Gubler 2015-01-06 10:26:17 +01:00
parent 88d7c4e447
commit cd11c4d81c
1 changed files with 31 additions and 28 deletions

View File

@ -36,15 +36,18 @@
# Generate multirotor mixer scale tables compatible with the ArduCopter layout # Generate multirotor mixer scale tables compatible with the ArduCopter layout
# #
# for python2.7 compatibility
from __future__ import print_function
import math import math
print "/*" print("/*")
print "* This file is automatically generated by multi_tables - do not edit." print("* This file is automatically generated by multi_tables - do not edit.")
print "*/" print("*/")
print "" print("")
print "#ifndef _MIXER_MULTI_TABLES" print("#ifndef _MIXER_MULTI_TABLES")
print "#define _MIXER_MULTI_TABLES" print("#define _MIXER_MULTI_TABLES")
print "" print("")
def rcos(angleInRadians): def rcos(angleInRadians):
return math.cos(math.radians(angleInRadians)) return math.cos(math.radians(angleInRadians))
@ -146,7 +149,7 @@ twin_engine = [
] ]
def variableName(variable): def variableName(variable):
for variableName, value in list(globals().iteritems()): for variableName, value in list(globals().items()):
if value is variable: if value is variable:
return variableName return variableName
@ -154,44 +157,44 @@ tables = [quad_x, quad_plus, quad_v, quad_wide, hex_x, hex_plus, hex_cox, octa_x
def printEnum(): def printEnum():
print "enum class MultirotorGeometry : MultirotorGeometryUnderlyingType {" print("enum class MultirotorGeometry : MultirotorGeometryUnderlyingType {")
for table in tables: for table in tables:
print "\t{},".format(variableName(table).upper()) print("\t{},".format(variableName(table).upper()))
print "\n\tMAX_GEOMETRY" print("\n\tMAX_GEOMETRY")
print "}; // enum class MultirotorGeometry\n" print("}; // enum class MultirotorGeometry\n")
def printScaleTables(): def printScaleTables():
for table in tables: for table in tables:
print "const MultirotorMixer::Rotor _config_{}[] = {{".format(variableName(table)) print("const MultirotorMixer::Rotor _config_{}[] = {{".format(variableName(table)))
for (angle, yawScale) in table: for (angle, yawScale) in table:
rollScale = rcos(angle + 90) rollScale = rcos(angle + 90)
pitchScale = rcos(angle) pitchScale = rcos(angle)
print "\t{{ {:9f}, {:9f}, {:9f} }},".format(rollScale, pitchScale, yawScale) print("\t{{ {:9f}, {:9f}, {:9f} }},".format(rollScale, pitchScale, yawScale))
print "};\n" print("};\n")
def printScaleTablesIndex(): def printScaleTablesIndex():
print "const MultirotorMixer::Rotor *_config_index[] = {" print("const MultirotorMixer::Rotor *_config_index[] = {")
for table in tables: for table in tables:
print "\t&_config_{}[0],".format(variableName(table)) print("\t&_config_{}[0],".format(variableName(table)))
print "};\n" print("};\n")
def printScaleTablesCounts(): def printScaleTablesCounts():
print "const unsigned _config_rotor_count[] = {" print("const unsigned _config_rotor_count[] = {")
for table in tables: for table in tables:
print "\t{}, /* {} */".format(len(table), variableName(table)) print("\t{}, /* {} */".format(len(table), variableName(table)))
print "};\n" print("};\n")
printEnum() printEnum()
print "namespace {" print("namespace {")
printScaleTables() printScaleTables()
printScaleTablesIndex() printScaleTablesIndex()
printScaleTablesCounts() printScaleTablesCounts()
print "} // anonymous namespace\n" print("} // anonymous namespace\n")
print "#endif /* _MIXER_MULTI_TABLES */" print("#endif /* _MIXER_MULTI_TABLES */")
print "" print("")