From cd11c4d81c976b76a0db262f43a6c09192cd0e6c Mon Sep 17 00:00:00 2001 From: Thomas Gubler Date: Tue, 6 Jan 2015 10:26:17 +0100 Subject: [PATCH] make multi_tables script python3 compatible The script still works with python2, I also added a file ending --- .../mixer/{multi_tables => multi_tables.py} | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) rename src/modules/systemlib/mixer/{multi_tables => multi_tables.py} (76%) diff --git a/src/modules/systemlib/mixer/multi_tables b/src/modules/systemlib/mixer/multi_tables.py similarity index 76% rename from src/modules/systemlib/mixer/multi_tables rename to src/modules/systemlib/mixer/multi_tables.py index a9edb357b5..21c0affd95 100755 --- a/src/modules/systemlib/mixer/multi_tables +++ b/src/modules/systemlib/mixer/multi_tables.py @@ -36,15 +36,18 @@ # Generate multirotor mixer scale tables compatible with the ArduCopter layout # +# for python2.7 compatibility +from __future__ import print_function + import math -print "/*" -print "* This file is automatically generated by multi_tables - do not edit." -print "*/" -print "" -print "#ifndef _MIXER_MULTI_TABLES" -print "#define _MIXER_MULTI_TABLES" -print "" +print("/*") +print("* This file is automatically generated by multi_tables - do not edit.") +print("*/") +print("") +print("#ifndef _MIXER_MULTI_TABLES") +print("#define _MIXER_MULTI_TABLES") +print("") def rcos(angleInRadians): return math.cos(math.radians(angleInRadians)) @@ -146,7 +149,7 @@ twin_engine = [ ] def variableName(variable): - for variableName, value in list(globals().iteritems()): + for variableName, value in list(globals().items()): if value is variable: 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(): - print "enum class MultirotorGeometry : MultirotorGeometryUnderlyingType {" + print("enum class MultirotorGeometry : MultirotorGeometryUnderlyingType {") for table in tables: - print "\t{},".format(variableName(table).upper()) + print("\t{},".format(variableName(table).upper())) - print "\n\tMAX_GEOMETRY" - print "}; // enum class MultirotorGeometry\n" + print("\n\tMAX_GEOMETRY") + print("}; // enum class MultirotorGeometry\n") def printScaleTables(): 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: rollScale = rcos(angle + 90) pitchScale = rcos(angle) - print "\t{{ {:9f}, {:9f}, {:9f} }},".format(rollScale, pitchScale, yawScale) - print "};\n" - + print("\t{{ {:9f}, {:9f}, {:9f} }},".format(rollScale, pitchScale, yawScale)) + print("};\n") + def printScaleTablesIndex(): - print "const MultirotorMixer::Rotor *_config_index[] = {" + print("const MultirotorMixer::Rotor *_config_index[] = {") for table in tables: - print "\t&_config_{}[0],".format(variableName(table)) - print "};\n" + print("\t&_config_{}[0],".format(variableName(table))) + print("};\n") def printScaleTablesCounts(): - print "const unsigned _config_rotor_count[] = {" + print("const unsigned _config_rotor_count[] = {") for table in tables: - print "\t{}, /* {} */".format(len(table), variableName(table)) - print "};\n" - - + print("\t{}, /* {} */".format(len(table), variableName(table))) + print("};\n") + + printEnum() -print "namespace {" +print("namespace {") printScaleTables() printScaleTablesIndex() printScaleTablesCounts() -print "} // anonymous namespace\n" -print "#endif /* _MIXER_MULTI_TABLES */" -print "" +print("} // anonymous namespace\n") +print("#endif /* _MIXER_MULTI_TABLES */") +print("")