From 59fa170e54a4a88b4bdad86622e75183e9fbdc51 Mon Sep 17 00:00:00 2001 From: Anton Matosov Date: Mon, 10 Nov 2014 00:09:27 +0200 Subject: Automated updates of the C++ code generated by the multi_tables script, now it is placed into the mixer_multirotor.generated.h file which is generated by makefile --- src/modules/systemlib/mixer/mixer_multirotor.cpp | 114 +---------------------- src/modules/systemlib/mixer/module.mk | 7 +- src/modules/systemlib/mixer/multi_tables | 9 ++ 3 files changed, 17 insertions(+), 113 deletions(-) (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/mixer_multirotor.cpp b/src/modules/systemlib/mixer/mixer_multirotor.cpp index eb1aef6c1..bb3868c34 100644 --- a/src/modules/systemlib/mixer/mixer_multirotor.cpp +++ b/src/modules/systemlib/mixer/mixer_multirotor.cpp @@ -73,118 +73,8 @@ float constrain(float val, float min, float max) return (val < min) ? min : ((val > max) ? max : val); } -/* - * These tables automatically generated by multi_tables - do not edit. - */ - -const MultirotorMixer::Rotor _config_quad_x[] = { - { -0.707107, 0.707107, 1.000000 }, - { 0.707107, -0.707107, 1.000000 }, - { 0.707107, 0.707107, -1.000000 }, - { -0.707107, -0.707107, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_quad_plus[] = { - { -1.000000, 0.000000, 1.000000 }, - { 1.000000, 0.000000, 1.000000 }, - { 0.000000, 1.000000, -1.000000 }, - { -0.000000, -1.000000, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_quad_v[] = { - { -0.322266, 0.946649, 0.424200 }, - { 0.322266, 0.946649, 1.000000 }, - { 0.322266, 0.946649, -0.424200 }, - { -0.322266, 0.946649, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_quad_wide[] = { - { -0.927184, 0.374607, 1.000000 }, - { 0.777146, -0.629320, 1.000000 }, - { 0.927184, 0.374607, -1.000000 }, - { -0.777146, -0.629320, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_hex_x[] = { - { -1.000000, 0.000000, -1.000000 }, - { 1.000000, 0.000000, 1.000000 }, - { 0.500000, 0.866025, -1.000000 }, - { -0.500000, -0.866025, 1.000000 }, - { -0.500000, 0.866025, 1.000000 }, - { 0.500000, -0.866025, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_hex_plus[] = { - { 0.000000, 1.000000, -1.000000 }, - { -0.000000, -1.000000, 1.000000 }, - { 0.866025, -0.500000, -1.000000 }, - { -0.866025, 0.500000, 1.000000 }, - { 0.866025, 0.500000, 1.000000 }, - { -0.866025, -0.500000, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_hex_cox[] = { - { -0.866025, 0.500000, -1.000000 }, - { -0.866025, 0.500000, 1.000000 }, - { -0.000000, -1.000000, -1.000000 }, - { -0.000000, -1.000000, 1.000000 }, - { 0.866025, 0.500000, -1.000000 }, - { 0.866025, 0.500000, 1.000000 }, -}; -const MultirotorMixer::Rotor _config_octa_x[] = { - { -0.382683, 0.923880, -1.000000 }, - { 0.382683, -0.923880, -1.000000 }, - { -0.923880, 0.382683, 1.000000 }, - { -0.382683, -0.923880, 1.000000 }, - { 0.382683, 0.923880, 1.000000 }, - { 0.923880, -0.382683, 1.000000 }, - { 0.923880, 0.382683, -1.000000 }, - { -0.923880, -0.382683, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_octa_plus[] = { - { 0.000000, 1.000000, -1.000000 }, - { -0.000000, -1.000000, -1.000000 }, - { -0.707107, 0.707107, 1.000000 }, - { -0.707107, -0.707107, 1.000000 }, - { 0.707107, 0.707107, 1.000000 }, - { 0.707107, -0.707107, 1.000000 }, - { 1.000000, 0.000000, -1.000000 }, - { -1.000000, 0.000000, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_octa_cox[] = { - { -0.707107, 0.707107, 1.000000 }, - { 0.707107, 0.707107, -1.000000 }, - { 0.707107, -0.707107, 1.000000 }, - { -0.707107, -0.707107, -1.000000 }, - { 0.707107, 0.707107, 1.000000 }, - { -0.707107, 0.707107, -1.000000 }, - { -0.707107, -0.707107, 1.000000 }, - { 0.707107, -0.707107, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_twin_engine[] = { - { -1.000000, 0.000000, 0.000000 }, - { 1.000000, 0.000000, 0.000000 }, -}; -const MultirotorMixer::Rotor *_config_index[MultirotorMixer::MAX_GEOMETRY] = { - &_config_quad_x[0], - &_config_quad_plus[0], - &_config_quad_v[0], - &_config_quad_wide[0], - &_config_hex_x[0], - &_config_hex_plus[0], - &_config_hex_cox[0], - &_config_octa_x[0], - &_config_octa_plus[0], - &_config_octa_cox[0], - &_config_twin_engine[0], -}; -const unsigned _config_rotor_count[MultirotorMixer::MAX_GEOMETRY] = { - 4, /* quad_x */ - 4, /* quad_plus */ - 4, /* quad_v */ - 4, /* quad_wide */ - 6, /* hex_x */ - 6, /* hex_plus */ - 6, /* hex_cox */ - 8, /* octa_x */ - 8, /* octa_plus */ - 8, /* octa_cox */ - 2, /* twin_engine */ -}; +// This file is generated by the multi_tables script which is invoked during the build process +#include "mixer_multirotor.generated.h" } diff --git a/src/modules/systemlib/mixer/module.mk b/src/modules/systemlib/mixer/module.mk index fc7485e20..683631324 100644 --- a/src/modules/systemlib/mixer/module.mk +++ b/src/modules/systemlib/mixer/module.mk @@ -31,13 +31,18 @@ # ############################################################################ + # # mixer library # LIBNAME = mixerlib - + SRCS = mixer.cpp \ mixer_group.cpp \ mixer_multirotor.cpp \ mixer_simple.cpp \ mixer_load.c + +SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +$(SELF_DIR)mixer_multirotor.generated.h : $(SELF_DIR)multi_tables + $(SELF_DIR)multi_tables > $(SELF_DIR)mixer_multirotor.generated.h diff --git a/src/modules/systemlib/mixer/multi_tables b/src/modules/systemlib/mixer/multi_tables index bdb62f812..1f47ca63d 100755 --- a/src/modules/systemlib/mixer/multi_tables +++ b/src/modules/systemlib/mixer/multi_tables @@ -3,6 +3,12 @@ # Generate multirotor mixer scale tables compatible with the ArduCopter layout # + +puts "/*" +puts "* These tables automatically generated by multi_tables - do not edit." +puts "*/" +puts "" + proc rad {a} { expr ($a / 360.0) * 2 * acos(-1) } proc rcos {a} { expr cos([rad $a])} @@ -133,3 +139,6 @@ foreach table $tables { puts [format "\t%u, /* %s */" [expr [llength $angles] / 2] $table] } puts "};" + +# Newline at the end of file +puts "" -- cgit v1.2.3 From 388833a1fa56b40034333ba6bbef376fabcc1320 Mon Sep 17 00:00:00 2001 From: Anton Matosov Date: Sun, 4 Jan 2015 23:58:17 +0200 Subject: Added explicit dependency into makefile, as implicit one doesn't work often. --- src/modules/systemlib/mixer/module.mk | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/module.mk b/src/modules/systemlib/mixer/module.mk index 683631324..6f4befb57 100644 --- a/src/modules/systemlib/mixer/module.mk +++ b/src/modules/systemlib/mixer/module.mk @@ -44,5 +44,9 @@ SRCS = mixer.cpp \ mixer_load.c SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) + +# Add explicit dependency, as implicit one doesn't work often. +mixer_multirotor.cpp : $(SELF_DIR)mixer_multirotor.generated.h + $(SELF_DIR)mixer_multirotor.generated.h : $(SELF_DIR)multi_tables $(SELF_DIR)multi_tables > $(SELF_DIR)mixer_multirotor.generated.h -- cgit v1.2.3 From 8fadbdcf2fee463498228abeac038260f51460b1 Mon Sep 17 00:00:00 2001 From: Anton Matosov Date: Mon, 5 Jan 2015 00:30:49 +0200 Subject: Automated generation of the Geometry enum to make addition of the new multirotor a really simple task --- src/modules/systemlib/mixer/mixer.h | 18 +-- src/modules/systemlib/mixer/mixer_multirotor.cpp | 7 +- src/modules/systemlib/mixer/multi_tables | 166 ++++++++++++----------- 3 files changed, 94 insertions(+), 97 deletions(-) (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/mixer.h b/src/modules/systemlib/mixer/mixer.h index 1fe4380ad..a0197df48 100644 --- a/src/modules/systemlib/mixer/mixer.h +++ b/src/modules/systemlib/mixer/mixer.h @@ -453,23 +453,9 @@ public: /** * Supported multirotor geometries. * - * XXX add more + * Values are generated by the multi_tables script and placed to mixer_multirotor.generated.h */ - enum Geometry { - QUAD_X = 0, /**< quad in X configuration */ - QUAD_PLUS, /**< quad in + configuration */ - QUAD_V, /**< quad in V configuration */ - QUAD_WIDE, /**< quad in wide configuration */ - HEX_X, /**< hex in X configuration */ - HEX_PLUS, /**< hex in + configuration */ - HEX_COX, - OCTA_X, - OCTA_PLUS, - OCTA_COX, - TWIN_ENGINE, /**< VTOL: one engine on each wing */ - - MAX_GEOMETRY - }; + enum Geometry : unsigned int; /** * Precalculated rotor mix. diff --git a/src/modules/systemlib/mixer/mixer_multirotor.cpp b/src/modules/systemlib/mixer/mixer_multirotor.cpp index bb3868c34..42e3513f4 100644 --- a/src/modules/systemlib/mixer/mixer_multirotor.cpp +++ b/src/modules/systemlib/mixer/mixer_multirotor.cpp @@ -55,6 +55,9 @@ #include "mixer.h" +// This file is generated by the multi_tables script which is invoked during the build process +#include "mixer_multirotor.generated.h" + #define debug(fmt, args...) do { } while(0) //#define debug(fmt, args...) do { printf("[mixer] " fmt "\n", ##args); } while(0) //#include @@ -72,10 +75,6 @@ float constrain(float val, float min, float max) { return (val < min) ? min : ((val > max) ? max : val); } - -// This file is generated by the multi_tables script which is invoked during the build process -#include "mixer_multirotor.generated.h" - } MultirotorMixer::MultirotorMixer(ControlCallback control_cb, diff --git a/src/modules/systemlib/mixer/multi_tables b/src/modules/systemlib/mixer/multi_tables index 1f47ca63d..b29bf540a 100755 --- a/src/modules/systemlib/mixer/multi_tables +++ b/src/modules/systemlib/mixer/multi_tables @@ -3,9 +3,8 @@ # Generate multirotor mixer scale tables compatible with the ArduCopter layout # - puts "/*" -puts "* These tables automatically generated by multi_tables - do not edit." +puts "* These file is automatically generated by multi_tables - do not edit." puts "*/" puts "" @@ -14,17 +13,17 @@ proc rcos {a} { expr cos([rad $a])} set quad_x { - 45 CCW - -135 CCW - -45 CW - 135 CW + 45 CCW + -135 CCW + -45 CW + 135 CW } set quad_plus { - 90 CCW - -90 CCW - 0 CW - 180 CW + 90 CCW + -90 CCW + 0 CW + 180 CW } set quad_v { @@ -35,70 +34,70 @@ set quad_v { } set quad_wide { - 68 CCW - -129 CCW - -68 CW - 129 CW + 68 CCW + -129 CCW + -68 CW + 129 CW } set hex_x { - 90 CW - -90 CCW - -30 CW - 150 CCW - 30 CCW - -150 CW + 90 CW + -90 CCW + -30 CW + 150 CCW + 30 CCW + -150 CW } set hex_plus { - 0 CW - 180 CCW - -120 CW - 60 CCW - -60 CCW - 120 CW + 0 CW + 180 CCW + -120 CW + 60 CCW + -60 CCW + 120 CW } set hex_cox { - 60 CW - 60 CCW - 180 CW - 180 CCW - -60 CW - -60 CCW + 60 CW + 60 CCW + 180 CW + 180 CCW + -60 CW + -60 CCW } set octa_x { - 22.5 CW - -157.5 CW - 67.5 CCW - 157.5 CCW - -22.5 CCW - -112.5 CCW - -67.5 CW - 112.5 CW + 22.5 CW + -157.5 CW + 67.5 CCW + 157.5 CCW + -22.5 CCW + -112.5 CCW + -67.5 CW + 112.5 CW } set octa_plus { - 0 CW - 180 CW - 45 CCW - 135 CCW - -45 CCW - -135 CCW - -90 CW - 90 CW + 0 CW + 180 CW + 45 CCW + 135 CCW + -45 CCW + -135 CCW + -90 CW + 90 CW } set octa_cox { - 45 CCW - -45 CW - -135 CCW - 135 CW - -45 CCW - 45 CW - 135 CCW - -135 CW + 45 CCW + -45 CW + -135 CCW + 135 CW + -45 CCW + 45 CW + 135 CCW + -135 CW } set twin_engine { @@ -106,39 +105,52 @@ set twin_engine { -90 0.0 } + set tables {quad_x quad_plus quad_v quad_wide hex_x hex_plus hex_cox octa_x octa_plus octa_cox twin_engine} +puts "enum MultirotorMixer::Geometry : unsigned int {" +foreach table $tables { + puts [format "\t%s," [string toupper $table]] +} +puts "\n\tMAX_GEOMETRY" +puts "}; // enum MultirotorMixer::Geometry\n" + + +puts "namespace {" + proc factors {a d} { puts [format "\t{ %9.6f, %9.6f, %9.6f }," [rcos [expr $a + 90]] [rcos $a] [expr $d]]} foreach table $tables { - puts [format "const MultirotorMixer::Rotor _config_%s\[\] = {" $table] - - upvar #0 $table angles - foreach {angle dir} $angles { - if {$dir == "CW"} { - set dd -1.0 - } elseif {$dir == "CCW"} { - set dd 1.0 - } else { - set dd $dir - } - factors $angle $dd - } - puts "};" + puts [format "const MultirotorMixer::Rotor _config_%s\[\] = {" $table] + + upvar #0 $table angles + foreach {angle dir} $angles { + if {$dir == "CW"} { + set dd -1.0 + } elseif {$dir == "CCW"} { + set dd 1.0 + } else { + set dd $dir + } + factors $angle $dd + } + puts "};\n" } -puts "const MultirotorMixer::Rotor *_config_index\[MultirotorMixer::MAX_GEOMETRY\] = {" +puts "const MultirotorMixer::Rotor *_config_index\[\] = {" foreach table $tables { - puts [format "\t&_config_%s\[0\]," $table] + puts [format "\t&_config_%s\[0\]," $table] } -puts "};" +puts "};\n" -puts "const unsigned _config_rotor_count\[MultirotorMixer::MAX_GEOMETRY\] = {" +puts "const unsigned _config_rotor_count\[\] = {" foreach table $tables { - upvar #0 $table angles - puts [format "\t%u, /* %s */" [expr [llength $angles] / 2] $table] + upvar #0 $table angles + puts [format "\t%u, /* %s */" [expr [llength $angles] / 2] $table] } -puts "};" +puts "};\n" + +puts "} // anonymous namespace\n" # Newline at the end of file puts "" -- cgit v1.2.3 From 2daf30fb251c7dc8d59f0302ecb444b116081931 Mon Sep 17 00:00:00 2001 From: Anton Matosov Date: Mon, 5 Jan 2015 02:39:13 +0200 Subject: Rewrote multi_tables with python --- src/modules/systemlib/mixer/multi_tables | 156 --------------------------- src/modules/systemlib/mixer/multi_tables.py | 159 ++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+), 156 deletions(-) delete mode 100755 src/modules/systemlib/mixer/multi_tables create mode 100755 src/modules/systemlib/mixer/multi_tables.py (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/multi_tables b/src/modules/systemlib/mixer/multi_tables deleted file mode 100755 index b29bf540a..000000000 --- a/src/modules/systemlib/mixer/multi_tables +++ /dev/null @@ -1,156 +0,0 @@ -#!/usr/bin/tclsh -# -# Generate multirotor mixer scale tables compatible with the ArduCopter layout -# - -puts "/*" -puts "* These file is automatically generated by multi_tables - do not edit." -puts "*/" -puts "" - -proc rad {a} { expr ($a / 360.0) * 2 * acos(-1) } -proc rcos {a} { expr cos([rad $a])} - - -set quad_x { - 45 CCW - -135 CCW - -45 CW - 135 CW -} - -set quad_plus { - 90 CCW - -90 CCW - 0 CW - 180 CW -} - -set quad_v { - 18.8 0.4242 - -18.8 1.0 - -18.8 -0.4242 - 18.8 -1.0 -} - -set quad_wide { - 68 CCW - -129 CCW - -68 CW - 129 CW -} - -set hex_x { - 90 CW - -90 CCW - -30 CW - 150 CCW - 30 CCW - -150 CW -} - -set hex_plus { - 0 CW - 180 CCW - -120 CW - 60 CCW - -60 CCW - 120 CW -} - -set hex_cox { - 60 CW - 60 CCW - 180 CW - 180 CCW - -60 CW - -60 CCW -} - -set octa_x { - 22.5 CW - -157.5 CW - 67.5 CCW - 157.5 CCW - -22.5 CCW - -112.5 CCW - -67.5 CW - 112.5 CW -} - -set octa_plus { - 0 CW - 180 CW - 45 CCW - 135 CCW - -45 CCW - -135 CCW - -90 CW - 90 CW -} - -set octa_cox { - 45 CCW - -45 CW - -135 CCW - 135 CW - -45 CCW - 45 CW - 135 CCW - -135 CW -} - -set twin_engine { - 90 0.0 - -90 0.0 -} - - -set tables {quad_x quad_plus quad_v quad_wide hex_x hex_plus hex_cox octa_x octa_plus octa_cox twin_engine} - -puts "enum MultirotorMixer::Geometry : unsigned int {" -foreach table $tables { - puts [format "\t%s," [string toupper $table]] -} -puts "\n\tMAX_GEOMETRY" -puts "}; // enum MultirotorMixer::Geometry\n" - - -puts "namespace {" - -proc factors {a d} { puts [format "\t{ %9.6f, %9.6f, %9.6f }," [rcos [expr $a + 90]] [rcos $a] [expr $d]]} - -foreach table $tables { - puts [format "const MultirotorMixer::Rotor _config_%s\[\] = {" $table] - - upvar #0 $table angles - foreach {angle dir} $angles { - if {$dir == "CW"} { - set dd -1.0 - } elseif {$dir == "CCW"} { - set dd 1.0 - } else { - set dd $dir - } - factors $angle $dd - } - puts "};\n" -} - -puts "const MultirotorMixer::Rotor *_config_index\[\] = {" -foreach table $tables { - puts [format "\t&_config_%s\[0\]," $table] -} -puts "};\n" - -puts "const unsigned _config_rotor_count\[\] = {" -foreach table $tables { - upvar #0 $table angles - puts [format "\t%u, /* %s */" [expr [llength $angles] / 2] $table] -} -puts "};\n" - -puts "} // anonymous namespace\n" - -# Newline at the end of file -puts "" diff --git a/src/modules/systemlib/mixer/multi_tables.py b/src/modules/systemlib/mixer/multi_tables.py new file mode 100755 index 000000000..07594ee72 --- /dev/null +++ b/src/modules/systemlib/mixer/multi_tables.py @@ -0,0 +1,159 @@ +#!/usr/bin/python +# +# Generate multirotor mixer scale tables compatible with the ArduCopter layout +# + +import math + +print "/*" +print "* These file is automatically generated by multi_tables.py - do not edit." +print "*/" +print "" + +def rcos(angleInRadians): + return math.cos(math.radians(angleInRadians)) + +CCW = 1.0 +CW = -CCW + +quad_x = [ + [ 45, CCW], + [-135, CCW], + [-45, CW], + [135, CW], +] + +quad_plus = [ + [ 90, CCW], + [ -90, CCW], + [ 0, CW], + [ 180, CW], +] + +quad_v = [ + [ 18.8, 0.4242], + [ -18.8, 1.0], + [ -18.8, -0.4242], + [ 18.8, -1.0], +] + +quad_wide = [ + [ 68, CCW], + [ -129, CCW], + [ -68, CW], + [ 129, CW], +] + +hex_x = [ + [ 90, CW], + [ -90, CCW], + [ -30, CW], + [ 150, CCW], + [ 30, CCW], + [-150, CW], +] + +hex_plus = [ + [ 0, CW], + [ 180, CCW], + [-120, CW], + [ 60, CCW], + [ -60, CCW], + [ 120, CW], +] + +hex_cox = [ + [ 60, CW], + [ 60, CCW], + [ 180, CW], + [ 180, CCW], + [ -60, CW], + [ -60, CCW], +] + +octa_x = [ + [ 22.5, CW], + [-157.5, CW], + [ 67.5, CCW], + [ 157.5, CCW], + [ -22.5, CCW], + [-112.5, CCW], + [ -67.5, CW], + [ 112.5, CW], +] + +octa_plus = [ + [ 0, CW], + [ 180, CW], + [ 45, CCW], + [ 135, CCW], + [ -45, CCW], + [-135, CCW], + [ -90, CW], + [ 90, CW], +] + +octa_cox = [ + [ 45, CCW], + [ -45, CW], + [-135, CCW], + [ 135, CW], + [ -45, CCW], + [ 45, CW], + [ 135, CCW], + [-135, CW], +] + +twin_engine = [ + [ 90, 0.0], + [-90, 0.0], +] + +def variableName(variable): + for variableName, value in list(globals().iteritems()): + if value is variable: + return variableName + +tables = [quad_x, quad_plus, quad_v, quad_wide, hex_x, hex_plus, hex_cox, octa_x, octa_plus, octa_cox, twin_engine] + + +def printEnum(): + print "enum MultirotorMixer::Geometry : unsigned int {" + for table in tables: + print "\t{},".format(variableName(table).upper()) + + print "\n\tMAX_GEOMETRY" + print "}; // enum MultirotorMixer::Geometry\n" + +def printScaleTables(): + for table in tables: + 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" + +def printScaleTablesIndex(): + print "const MultirotorMixer::Rotor *_config_index[] = {" + for table in tables: + print "\t&_config_{}[0],".format(variableName(table)) + print "};\n" + + +def printScaleTablesCounts(): + print "const unsigned _config_rotor_count[] = {" + for table in tables: + print "\t{}, /* {} */".format(len(table), variableName(table)) + print "};\n" + + + +printEnum() + +print "namespace {" +printScaleTables() +printScaleTablesIndex() +printScaleTablesCounts() + +print "} // anonymous namespace\n" -- cgit v1.2.3 From 21b45ae86b1525e052ea9b37e78c960498a95c72 Mon Sep 17 00:00:00 2001 From: Anton Matosov Date: Mon, 5 Jan 2015 03:18:14 +0200 Subject: Removed extension for multi_tables to not affect its users Fixed dependencies for the mixer_multirotor.cpp from all the modules --- src/modules/px4iofirmware/module.mk | 11 +- src/modules/systemlib/mixer/module.mk | 4 +- src/modules/systemlib/mixer/multi_tables | 159 ++++++++++++++++++++++++++++ src/modules/systemlib/mixer/multi_tables.py | 159 ---------------------------- 4 files changed, 171 insertions(+), 162 deletions(-) create mode 100755 src/modules/systemlib/mixer/multi_tables delete mode 100755 src/modules/systemlib/mixer/multi_tables.py (limited to 'src/modules') diff --git a/src/modules/px4iofirmware/module.mk b/src/modules/px4iofirmware/module.mk index eb99e8a96..bfcbaa9f8 100644 --- a/src/modules/px4iofirmware/module.mk +++ b/src/modules/px4iofirmware/module.mk @@ -1,5 +1,4 @@ - SRCS = adc.c \ controls.c \ dsm.c \ @@ -24,3 +23,13 @@ ifeq ($(BOARD),px4io-v2) SRCS += serial.c \ ../systemlib/hx_stream.c endif + +SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +MIXER_DIR:=$(SELF_DIR)../systemlib/mixer/ + +# Add explicit dependency, as implicit one doesn't work often. +$(MIXER_DIR)mixer_multirotor.cpp : $(MIXER_DIR)mixer_multirotor.generated.h + +$(MIXER_DIR)mixer_multirotor.generated.h : $(MIXER_DIR)multi_tables + $(MIXER_DIR)multi_tables > $(MIXER_DIR)mixer_multirotor.generated.h + \ No newline at end of file diff --git a/src/modules/systemlib/mixer/module.mk b/src/modules/systemlib/mixer/module.mk index 6f4befb57..5e818ff03 100644 --- a/src/modules/systemlib/mixer/module.mk +++ b/src/modules/systemlib/mixer/module.mk @@ -46,7 +46,7 @@ SRCS = mixer.cpp \ SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) # Add explicit dependency, as implicit one doesn't work often. -mixer_multirotor.cpp : $(SELF_DIR)mixer_multirotor.generated.h +$(SELF_DIR)mixer_multirotor.cpp : $(SELF_DIR)mixer_multirotor.generated.h $(SELF_DIR)mixer_multirotor.generated.h : $(SELF_DIR)multi_tables - $(SELF_DIR)multi_tables > $(SELF_DIR)mixer_multirotor.generated.h + $(SELF_DIR)multi_tables> $(SELF_DIR)mixer_multirotor.generated.h diff --git a/src/modules/systemlib/mixer/multi_tables b/src/modules/systemlib/mixer/multi_tables new file mode 100755 index 000000000..07594ee72 --- /dev/null +++ b/src/modules/systemlib/mixer/multi_tables @@ -0,0 +1,159 @@ +#!/usr/bin/python +# +# Generate multirotor mixer scale tables compatible with the ArduCopter layout +# + +import math + +print "/*" +print "* These file is automatically generated by multi_tables.py - do not edit." +print "*/" +print "" + +def rcos(angleInRadians): + return math.cos(math.radians(angleInRadians)) + +CCW = 1.0 +CW = -CCW + +quad_x = [ + [ 45, CCW], + [-135, CCW], + [-45, CW], + [135, CW], +] + +quad_plus = [ + [ 90, CCW], + [ -90, CCW], + [ 0, CW], + [ 180, CW], +] + +quad_v = [ + [ 18.8, 0.4242], + [ -18.8, 1.0], + [ -18.8, -0.4242], + [ 18.8, -1.0], +] + +quad_wide = [ + [ 68, CCW], + [ -129, CCW], + [ -68, CW], + [ 129, CW], +] + +hex_x = [ + [ 90, CW], + [ -90, CCW], + [ -30, CW], + [ 150, CCW], + [ 30, CCW], + [-150, CW], +] + +hex_plus = [ + [ 0, CW], + [ 180, CCW], + [-120, CW], + [ 60, CCW], + [ -60, CCW], + [ 120, CW], +] + +hex_cox = [ + [ 60, CW], + [ 60, CCW], + [ 180, CW], + [ 180, CCW], + [ -60, CW], + [ -60, CCW], +] + +octa_x = [ + [ 22.5, CW], + [-157.5, CW], + [ 67.5, CCW], + [ 157.5, CCW], + [ -22.5, CCW], + [-112.5, CCW], + [ -67.5, CW], + [ 112.5, CW], +] + +octa_plus = [ + [ 0, CW], + [ 180, CW], + [ 45, CCW], + [ 135, CCW], + [ -45, CCW], + [-135, CCW], + [ -90, CW], + [ 90, CW], +] + +octa_cox = [ + [ 45, CCW], + [ -45, CW], + [-135, CCW], + [ 135, CW], + [ -45, CCW], + [ 45, CW], + [ 135, CCW], + [-135, CW], +] + +twin_engine = [ + [ 90, 0.0], + [-90, 0.0], +] + +def variableName(variable): + for variableName, value in list(globals().iteritems()): + if value is variable: + return variableName + +tables = [quad_x, quad_plus, quad_v, quad_wide, hex_x, hex_plus, hex_cox, octa_x, octa_plus, octa_cox, twin_engine] + + +def printEnum(): + print "enum MultirotorMixer::Geometry : unsigned int {" + for table in tables: + print "\t{},".format(variableName(table).upper()) + + print "\n\tMAX_GEOMETRY" + print "}; // enum MultirotorMixer::Geometry\n" + +def printScaleTables(): + for table in tables: + 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" + +def printScaleTablesIndex(): + print "const MultirotorMixer::Rotor *_config_index[] = {" + for table in tables: + print "\t&_config_{}[0],".format(variableName(table)) + print "};\n" + + +def printScaleTablesCounts(): + print "const unsigned _config_rotor_count[] = {" + for table in tables: + print "\t{}, /* {} */".format(len(table), variableName(table)) + print "};\n" + + + +printEnum() + +print "namespace {" +printScaleTables() +printScaleTablesIndex() +printScaleTablesCounts() + +print "} // anonymous namespace\n" diff --git a/src/modules/systemlib/mixer/multi_tables.py b/src/modules/systemlib/mixer/multi_tables.py deleted file mode 100755 index 07594ee72..000000000 --- a/src/modules/systemlib/mixer/multi_tables.py +++ /dev/null @@ -1,159 +0,0 @@ -#!/usr/bin/python -# -# Generate multirotor mixer scale tables compatible with the ArduCopter layout -# - -import math - -print "/*" -print "* These file is automatically generated by multi_tables.py - do not edit." -print "*/" -print "" - -def rcos(angleInRadians): - return math.cos(math.radians(angleInRadians)) - -CCW = 1.0 -CW = -CCW - -quad_x = [ - [ 45, CCW], - [-135, CCW], - [-45, CW], - [135, CW], -] - -quad_plus = [ - [ 90, CCW], - [ -90, CCW], - [ 0, CW], - [ 180, CW], -] - -quad_v = [ - [ 18.8, 0.4242], - [ -18.8, 1.0], - [ -18.8, -0.4242], - [ 18.8, -1.0], -] - -quad_wide = [ - [ 68, CCW], - [ -129, CCW], - [ -68, CW], - [ 129, CW], -] - -hex_x = [ - [ 90, CW], - [ -90, CCW], - [ -30, CW], - [ 150, CCW], - [ 30, CCW], - [-150, CW], -] - -hex_plus = [ - [ 0, CW], - [ 180, CCW], - [-120, CW], - [ 60, CCW], - [ -60, CCW], - [ 120, CW], -] - -hex_cox = [ - [ 60, CW], - [ 60, CCW], - [ 180, CW], - [ 180, CCW], - [ -60, CW], - [ -60, CCW], -] - -octa_x = [ - [ 22.5, CW], - [-157.5, CW], - [ 67.5, CCW], - [ 157.5, CCW], - [ -22.5, CCW], - [-112.5, CCW], - [ -67.5, CW], - [ 112.5, CW], -] - -octa_plus = [ - [ 0, CW], - [ 180, CW], - [ 45, CCW], - [ 135, CCW], - [ -45, CCW], - [-135, CCW], - [ -90, CW], - [ 90, CW], -] - -octa_cox = [ - [ 45, CCW], - [ -45, CW], - [-135, CCW], - [ 135, CW], - [ -45, CCW], - [ 45, CW], - [ 135, CCW], - [-135, CW], -] - -twin_engine = [ - [ 90, 0.0], - [-90, 0.0], -] - -def variableName(variable): - for variableName, value in list(globals().iteritems()): - if value is variable: - return variableName - -tables = [quad_x, quad_plus, quad_v, quad_wide, hex_x, hex_plus, hex_cox, octa_x, octa_plus, octa_cox, twin_engine] - - -def printEnum(): - print "enum MultirotorMixer::Geometry : unsigned int {" - for table in tables: - print "\t{},".format(variableName(table).upper()) - - print "\n\tMAX_GEOMETRY" - print "}; // enum MultirotorMixer::Geometry\n" - -def printScaleTables(): - for table in tables: - 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" - -def printScaleTablesIndex(): - print "const MultirotorMixer::Rotor *_config_index[] = {" - for table in tables: - print "\t&_config_{}[0],".format(variableName(table)) - print "};\n" - - -def printScaleTablesCounts(): - print "const unsigned _config_rotor_count[] = {" - for table in tables: - print "\t{}, /* {} */".format(len(table), variableName(table)) - print "};\n" - - - -printEnum() - -print "namespace {" -printScaleTables() -printScaleTablesIndex() -printScaleTablesCounts() - -print "} // anonymous namespace\n" -- cgit v1.2.3 From 1bc6c44a0e30059620bc5fec85c5d096cd911df0 Mon Sep 17 00:00:00 2001 From: Anton Matosov Date: Mon, 5 Jan 2015 12:37:05 +0200 Subject: Fixed compilation of tests target in clean checkout Moved mixer_multirotor.generated.h generation to the standalone makefile to prevent copypaste --- src/modules/px4iofirmware/module.mk | 8 +----- src/modules/systemlib/mixer/module.mk | 8 +----- src/modules/systemlib/mixer/multi_tables.mk | 41 +++++++++++++++++++++++++++++ unittests/Makefile | 2 ++ 4 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 src/modules/systemlib/mixer/multi_tables.mk (limited to 'src/modules') diff --git a/src/modules/px4iofirmware/module.mk b/src/modules/px4iofirmware/module.mk index bfcbaa9f8..cc3de09e9 100644 --- a/src/modules/px4iofirmware/module.mk +++ b/src/modules/px4iofirmware/module.mk @@ -24,12 +24,6 @@ SRCS += serial.c \ ../systemlib/hx_stream.c endif -SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -MIXER_DIR:=$(SELF_DIR)../systemlib/mixer/ -# Add explicit dependency, as implicit one doesn't work often. -$(MIXER_DIR)mixer_multirotor.cpp : $(MIXER_DIR)mixer_multirotor.generated.h - -$(MIXER_DIR)mixer_multirotor.generated.h : $(MIXER_DIR)multi_tables - $(MIXER_DIR)multi_tables > $(MIXER_DIR)mixer_multirotor.generated.h +include ../systemlib/mixer/multi_tables.mk \ No newline at end of file diff --git a/src/modules/systemlib/mixer/module.mk b/src/modules/systemlib/mixer/module.mk index 5e818ff03..7ec77cd2f 100644 --- a/src/modules/systemlib/mixer/module.mk +++ b/src/modules/systemlib/mixer/module.mk @@ -43,10 +43,4 @@ SRCS = mixer.cpp \ mixer_simple.cpp \ mixer_load.c -SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) - -# Add explicit dependency, as implicit one doesn't work often. -$(SELF_DIR)mixer_multirotor.cpp : $(SELF_DIR)mixer_multirotor.generated.h - -$(SELF_DIR)mixer_multirotor.generated.h : $(SELF_DIR)multi_tables - $(SELF_DIR)multi_tables> $(SELF_DIR)mixer_multirotor.generated.h +include multi_tables.mk diff --git a/src/modules/systemlib/mixer/multi_tables.mk b/src/modules/systemlib/mixer/multi_tables.mk new file mode 100644 index 000000000..02216c3d4 --- /dev/null +++ b/src/modules/systemlib/mixer/multi_tables.mk @@ -0,0 +1,41 @@ +############################################################################ +# +# Copyright (c) 2012, 2013 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + + +SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) + +# Add explicit dependency, as implicit one doesn't work often. +$(SELF_DIR)mixer_multirotor.cpp : $(SELF_DIR)mixer_multirotor.generated.h + +$(SELF_DIR)mixer_multirotor.generated.h : $(SELF_DIR)multi_tables + $(SELF_DIR)multi_tables> $(SELF_DIR)mixer_multirotor.generated.h \ No newline at end of file diff --git a/unittests/Makefile b/unittests/Makefile index 7846638d4..719db2ca2 100644 --- a/unittests/Makefile +++ b/unittests/Makefile @@ -53,6 +53,8 @@ MIXER_FILES=../src/systemcmds/tests/test_mixer.cpp \ hrt.cpp \ mixer_test.cpp +include ../src/modules/systemlib/mixer/multi_tables.mk + SBUS2_FILES=../src/modules/px4iofirmware/sbus.c \ hrt.cpp \ sbus2_test.cpp -- cgit v1.2.3 From 6ba0b758045261906d60d772ac001d8b46d0b4c7 Mon Sep 17 00:00:00 2001 From: Anton Matosov Date: Mon, 5 Jan 2015 12:41:25 +0200 Subject: Replaced tabs with spaces as it is critical for some python builds --- src/modules/systemlib/mixer/multi_tables | 64 ++++++++++++++++---------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/multi_tables b/src/modules/systemlib/mixer/multi_tables index 07594ee72..786b63b02 100755 --- a/src/modules/systemlib/mixer/multi_tables +++ b/src/modules/systemlib/mixer/multi_tables @@ -17,14 +17,14 @@ CCW = 1.0 CW = -CCW quad_x = [ - [ 45, CCW], - [-135, CCW], - [-45, CW], + [ 45, CCW], + [-135, CCW], + [-45, CW], [135, CW], ] quad_plus = [ - [ 90, CCW], + [ 90, CCW], [ -90, CCW], [ 0, CW], [ 180, CW], @@ -38,14 +38,14 @@ quad_v = [ ] quad_wide = [ - [ 68, CCW], + [ 68, CCW], [ -129, CCW], [ -68, CW], [ 129, CW], ] hex_x = [ - [ 90, CW], + [ 90, CW], [ -90, CCW], [ -30, CW], [ 150, CCW], @@ -110,44 +110,44 @@ twin_engine = [ ] def variableName(variable): - for variableName, value in list(globals().iteritems()): - if value is variable: - return variableName + for variableName, value in list(globals().iteritems()): + if value is variable: + return variableName tables = [quad_x, quad_plus, quad_v, quad_wide, hex_x, hex_plus, hex_cox, octa_x, octa_plus, octa_cox, twin_engine] def printEnum(): - print "enum MultirotorMixer::Geometry : unsigned int {" - for table in tables: - print "\t{},".format(variableName(table).upper()) + print "enum MultirotorMixer::Geometry : unsigned int {" + for table in tables: + print "\t{},".format(variableName(table).upper()) - print "\n\tMAX_GEOMETRY" - print "}; // enum MultirotorMixer::Geometry\n" + print "\n\tMAX_GEOMETRY" + print "}; // enum MultirotorMixer::Geometry\n" def printScaleTables(): - for table in tables: - 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" - + for table in tables: + 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" + def printScaleTablesIndex(): - print "const MultirotorMixer::Rotor *_config_index[] = {" - for table in tables: - print "\t&_config_{}[0],".format(variableName(table)) - print "};\n" + print "const MultirotorMixer::Rotor *_config_index[] = {" + for table in tables: + print "\t&_config_{}[0],".format(variableName(table)) + print "};\n" def printScaleTablesCounts(): - print "const unsigned _config_rotor_count[] = {" - for table in tables: - print "\t{}, /* {} */".format(len(table), variableName(table)) - print "};\n" - - + print "const unsigned _config_rotor_count[] = {" + for table in tables: + print "\t{}, /* {} */".format(len(table), variableName(table)) + print "};\n" + + printEnum() -- cgit v1.2.3 From 3bf5dd416e58631285373a0d88a6e85406726043 Mon Sep 17 00:00:00 2001 From: Anton Matosov Date: Mon, 5 Jan 2015 13:22:53 +0200 Subject: Fixed compilation --- src/modules/px4iofirmware/module.mk | 4 ++-- src/modules/systemlib/mixer/module.mk | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src/modules') diff --git a/src/modules/px4iofirmware/module.mk b/src/modules/px4iofirmware/module.mk index cc3de09e9..844e493cd 100644 --- a/src/modules/px4iofirmware/module.mk +++ b/src/modules/px4iofirmware/module.mk @@ -24,6 +24,6 @@ SRCS += serial.c \ ../systemlib/hx_stream.c endif - -include ../systemlib/mixer/multi_tables.mk +SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(SELF_DIR)../systemlib/mixer/multi_tables.mk \ No newline at end of file diff --git a/src/modules/systemlib/mixer/module.mk b/src/modules/systemlib/mixer/module.mk index 7ec77cd2f..3fd07f5ba 100644 --- a/src/modules/systemlib/mixer/module.mk +++ b/src/modules/systemlib/mixer/module.mk @@ -43,4 +43,5 @@ SRCS = mixer.cpp \ mixer_simple.cpp \ mixer_load.c -include multi_tables.mk +SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(SELF_DIR)multi_tables.mk -- cgit v1.2.3 From 18bf501992afa8b561822615104c3868091429b9 Mon Sep 17 00:00:00 2001 From: Anton Matosov Date: Mon, 5 Jan 2015 21:59:56 +0200 Subject: Added output of the generated multi_tables to the terminal as well as to the file Changed compiler C++0x enabling flag to check if it is a cuase Updated copyrights --- src/modules/systemlib/mixer/multi_tables | 35 ++++++++++++++++++++++++++++- src/modules/systemlib/mixer/multi_tables.mk | 6 +++-- unittests/Makefile | 2 +- 3 files changed, 39 insertions(+), 4 deletions(-) (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/multi_tables b/src/modules/systemlib/mixer/multi_tables index 786b63b02..2752165cf 100755 --- a/src/modules/systemlib/mixer/multi_tables +++ b/src/modules/systemlib/mixer/multi_tables @@ -1,4 +1,37 @@ #!/usr/bin/python +############################################################################ +# +# Copyright (c) 2013, 2014 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + # # Generate multirotor mixer scale tables compatible with the ArduCopter layout # @@ -6,7 +39,7 @@ import math print "/*" -print "* These file is automatically generated by multi_tables.py - do not edit." +print "* These file is automatically generated by multi_tables - do not edit." print "*/" print "" diff --git a/src/modules/systemlib/mixer/multi_tables.mk b/src/modules/systemlib/mixer/multi_tables.mk index 02216c3d4..6429961cc 100644 --- a/src/modules/systemlib/mixer/multi_tables.mk +++ b/src/modules/systemlib/mixer/multi_tables.mk @@ -1,6 +1,6 @@ ############################################################################ # -# Copyright (c) 2012, 2013 PX4 Development Team. All rights reserved. +# Copyright (c) 2014 Anton Matosov . All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -38,4 +38,6 @@ SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) $(SELF_DIR)mixer_multirotor.cpp : $(SELF_DIR)mixer_multirotor.generated.h $(SELF_DIR)mixer_multirotor.generated.h : $(SELF_DIR)multi_tables - $(SELF_DIR)multi_tables> $(SELF_DIR)mixer_multirotor.generated.h \ No newline at end of file + $(SELF_DIR)multi_tables > $(SELF_DIR)mixer_multirotor.generated.h + $(SELF_DIR)multi_tables + \ No newline at end of file diff --git a/unittests/Makefile b/unittests/Makefile index 719db2ca2..cb08aa8fc 100644 --- a/unittests/Makefile +++ b/unittests/Makefile @@ -1,7 +1,7 @@ CC=g++ CFLAGS=-I. -I../src/modules -I ../src/include -I../src/drivers \ - -I../src -I../src/lib -D__EXPORT="" -Dnullptr="0" -lm -std=gnu++0x + -I../src -I../src/lib -D__EXPORT="" -Dnullptr="0" -lm -std=c++0x # Points to the root of Google Test, relative to where this file is. # Remember to tweak this if you move this file. -- cgit v1.2.3 From 117d43067f3c16c596a41cf0af5feaee1b11716b Mon Sep 17 00:00:00 2001 From: Anton Matosov Date: Mon, 5 Jan 2015 23:15:12 +0200 Subject: Switched to enum class out of class definition --- src/modules/systemlib/mixer/mixer.h | 17 ++++++------ src/modules/systemlib/mixer/mixer_multirotor.cpp | 33 +++++++++++++----------- src/modules/systemlib/mixer/multi_tables | 4 +-- 3 files changed, 29 insertions(+), 25 deletions(-) (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/mixer.h b/src/modules/systemlib/mixer/mixer.h index a0197df48..55c4ce6af 100644 --- a/src/modules/systemlib/mixer/mixer.h +++ b/src/modules/systemlib/mixer/mixer.h @@ -441,6 +441,14 @@ private: SimpleMixer operator=(const SimpleMixer&); }; + +/** + * Supported multirotor geometries. + * + * Values are generated by the multi_tables script and placed to mixer_multirotor.generated.h + */ +enum class MultirotorGeometry : unsigned int; + /** * Multi-rotor mixer for pre-defined vehicle geometries. * @@ -450,13 +458,6 @@ private: class __EXPORT MultirotorMixer : public Mixer { public: - /** - * Supported multirotor geometries. - * - * Values are generated by the multi_tables script and placed to mixer_multirotor.generated.h - */ - enum Geometry : unsigned int; - /** * Precalculated rotor mix. */ @@ -484,7 +485,7 @@ public: */ MultirotorMixer(ControlCallback control_cb, uintptr_t cb_handle, - Geometry geometry, + MultirotorGeometry geometry, float roll_scale, float pitch_scale, float yaw_scale, diff --git a/src/modules/systemlib/mixer/mixer_multirotor.cpp b/src/modules/systemlib/mixer/mixer_multirotor.cpp index 42e3513f4..d4bceaa27 100644 --- a/src/modules/systemlib/mixer/mixer_multirotor.cpp +++ b/src/modules/systemlib/mixer/mixer_multirotor.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include "mixer.h" @@ -77,9 +78,11 @@ float constrain(float val, float min, float max) } } +using GeometryType = typename std::underlying_type::type; + MultirotorMixer::MultirotorMixer(ControlCallback control_cb, uintptr_t cb_handle, - Geometry geometry, + MultirotorGeometry geometry, float roll_scale, float pitch_scale, float yaw_scale, @@ -89,8 +92,8 @@ MultirotorMixer::MultirotorMixer(ControlCallback control_cb, _pitch_scale(pitch_scale), _yaw_scale(yaw_scale), _idle_speed(-1.0f + idle_speed * 2.0f), /* shift to output range here to avoid runtime calculation */ - _rotor_count(_config_rotor_count[geometry]), - _rotors(_config_index[geometry]) + _rotor_count(_config_rotor_count[(GeometryType)geometry]), + _rotors(_config_index[(GeometryType)geometry]) { } @@ -101,7 +104,7 @@ MultirotorMixer::~MultirotorMixer() MultirotorMixer * MultirotorMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handle, const char *buf, unsigned &buflen) { - MultirotorMixer::Geometry geometry; + MultirotorGeometry geometry; char geomname[8]; int s[4]; int used; @@ -141,37 +144,37 @@ MultirotorMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handl debug("remaining in buf: %d, first char: %c", buflen, buf[0]); if (!strcmp(geomname, "4+")) { - geometry = MultirotorMixer::QUAD_PLUS; + geometry = MultirotorGeometry::QUAD_PLUS; } else if (!strcmp(geomname, "4x")) { - geometry = MultirotorMixer::QUAD_X; + geometry = MultirotorGeometry::QUAD_X; } else if (!strcmp(geomname, "4v")) { - geometry = MultirotorMixer::QUAD_V; + geometry = MultirotorGeometry::QUAD_V; } else if (!strcmp(geomname, "4w")) { - geometry = MultirotorMixer::QUAD_WIDE; + geometry = MultirotorGeometry::QUAD_WIDE; } else if (!strcmp(geomname, "6+")) { - geometry = MultirotorMixer::HEX_PLUS; + geometry = MultirotorGeometry::HEX_PLUS; } else if (!strcmp(geomname, "6x")) { - geometry = MultirotorMixer::HEX_X; + geometry = MultirotorGeometry::HEX_X; } else if (!strcmp(geomname, "6c")) { - geometry = MultirotorMixer::HEX_COX; + geometry = MultirotorGeometry::HEX_COX; } else if (!strcmp(geomname, "8+")) { - geometry = MultirotorMixer::OCTA_PLUS; + geometry = MultirotorGeometry::OCTA_PLUS; } else if (!strcmp(geomname, "8x")) { - geometry = MultirotorMixer::OCTA_X; + geometry = MultirotorGeometry::OCTA_X; } else if (!strcmp(geomname, "8c")) { - geometry = MultirotorMixer::OCTA_COX; + geometry = MultirotorGeometry::OCTA_COX; } else if (!strcmp(geomname, "2-")) { - geometry = MultirotorMixer::TWIN_ENGINE; + geometry = MultirotorGeometry::TWIN_ENGINE; } else { debug("unrecognised geometry '%s'", geomname); return nullptr; diff --git a/src/modules/systemlib/mixer/multi_tables b/src/modules/systemlib/mixer/multi_tables index 2752165cf..5d746fcfa 100755 --- a/src/modules/systemlib/mixer/multi_tables +++ b/src/modules/systemlib/mixer/multi_tables @@ -151,12 +151,12 @@ tables = [quad_x, quad_plus, quad_v, quad_wide, hex_x, hex_plus, hex_cox, octa_x def printEnum(): - print "enum MultirotorMixer::Geometry : unsigned int {" + print "enum class MultirotorGeometry : unsigned int {" for table in tables: print "\t{},".format(variableName(table).upper()) print "\n\tMAX_GEOMETRY" - print "}; // enum MultirotorMixer::Geometry\n" + print "}; // enum class MultirotorGeometry\n" def printScaleTables(): for table in tables: -- cgit v1.2.3 From 29d0754df633b50bc456922ff68d3e6c020f1d81 Mon Sep 17 00:00:00 2001 From: Anton Matosov Date: Mon, 5 Jan 2015 23:22:43 +0200 Subject: std::underlying_type is not supported by the g++ 4.6 used by CI server --- src/modules/systemlib/mixer/mixer.h | 3 ++- src/modules/systemlib/mixer/mixer_multirotor.cpp | 6 ++---- src/modules/systemlib/mixer/multi_tables | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/mixer.h b/src/modules/systemlib/mixer/mixer.h index 55c4ce6af..6494a314e 100644 --- a/src/modules/systemlib/mixer/mixer.h +++ b/src/modules/systemlib/mixer/mixer.h @@ -447,7 +447,8 @@ private: * * Values are generated by the multi_tables script and placed to mixer_multirotor.generated.h */ -enum class MultirotorGeometry : unsigned int; +using MultirotorGeometryUnderlyingType = unsigned int; +enum class MultirotorGeometry : MultirotorGeometryUnderlyingType; /** * Multi-rotor mixer for pre-defined vehicle geometries. diff --git a/src/modules/systemlib/mixer/mixer_multirotor.cpp b/src/modules/systemlib/mixer/mixer_multirotor.cpp index d4bceaa27..bee9d0edc 100644 --- a/src/modules/systemlib/mixer/mixer_multirotor.cpp +++ b/src/modules/systemlib/mixer/mixer_multirotor.cpp @@ -78,8 +78,6 @@ float constrain(float val, float min, float max) } } -using GeometryType = typename std::underlying_type::type; - MultirotorMixer::MultirotorMixer(ControlCallback control_cb, uintptr_t cb_handle, MultirotorGeometry geometry, @@ -92,8 +90,8 @@ MultirotorMixer::MultirotorMixer(ControlCallback control_cb, _pitch_scale(pitch_scale), _yaw_scale(yaw_scale), _idle_speed(-1.0f + idle_speed * 2.0f), /* shift to output range here to avoid runtime calculation */ - _rotor_count(_config_rotor_count[(GeometryType)geometry]), - _rotors(_config_index[(GeometryType)geometry]) + _rotor_count(_config_rotor_count[(MultirotorGeometryUnderlyingType)geometry]), + _rotors(_config_index[(MultirotorGeometryUnderlyingType)geometry]) { } diff --git a/src/modules/systemlib/mixer/multi_tables b/src/modules/systemlib/mixer/multi_tables index 5d746fcfa..01ff1b719 100755 --- a/src/modules/systemlib/mixer/multi_tables +++ b/src/modules/systemlib/mixer/multi_tables @@ -151,7 +151,7 @@ tables = [quad_x, quad_plus, quad_v, quad_wide, hex_x, hex_plus, hex_cox, octa_x def printEnum(): - print "enum class MultirotorGeometry : unsigned int {" + print "enum class MultirotorGeometry : MultirotorGeometryUnderlyingType {" for table in tables: print "\t{},".format(variableName(table).upper()) -- cgit v1.2.3 From e466e10d234c142c28b5d5a7661eb508a514ffb9 Mon Sep 17 00:00:00 2001 From: Anton Matosov Date: Mon, 5 Jan 2015 23:33:19 +0200 Subject: using type aliases are not supported by g++ 4.6 --- src/modules/systemlib/mixer/mixer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/mixer.h b/src/modules/systemlib/mixer/mixer.h index 6494a314e..864ce21a5 100644 --- a/src/modules/systemlib/mixer/mixer.h +++ b/src/modules/systemlib/mixer/mixer.h @@ -447,7 +447,7 @@ private: * * Values are generated by the multi_tables script and placed to mixer_multirotor.generated.h */ -using MultirotorGeometryUnderlyingType = unsigned int; +typedef unsigned int MultirotorGeometryUnderlyingType; enum class MultirotorGeometry : MultirotorGeometryUnderlyingType; /** -- cgit v1.2.3 From b04559e5fa856aad48d7c371806557dab9ba12a3 Mon Sep 17 00:00:00 2001 From: Anton Matosov Date: Mon, 5 Jan 2015 23:48:18 +0200 Subject: Removed include that couses compilation failure --- src/modules/systemlib/mixer/mixer_multirotor.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/mixer_multirotor.cpp b/src/modules/systemlib/mixer/mixer_multirotor.cpp index bee9d0edc..5cfbe47f0 100644 --- a/src/modules/systemlib/mixer/mixer_multirotor.cpp +++ b/src/modules/systemlib/mixer/mixer_multirotor.cpp @@ -52,7 +52,6 @@ #include #include #include -#include #include "mixer.h" -- cgit v1.2.3 From 6e144e6e42232b1ecc7a972f1d4e532694efb15a Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 5 Jan 2015 20:54:44 +0100 Subject: Multi-tables: Adjust shebang, add missing include guards --- src/modules/systemlib/mixer/multi_tables | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/multi_tables b/src/modules/systemlib/mixer/multi_tables index 786b63b02..46dfc5bff 100755 --- a/src/modules/systemlib/mixer/multi_tables +++ b/src/modules/systemlib/mixer/multi_tables @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # # Generate multirotor mixer scale tables compatible with the ArduCopter layout # @@ -6,9 +6,12 @@ import math print "/*" -print "* These file is automatically generated by multi_tables.py - do not edit." +print "* This file is automatically generated by multi_tables.py - 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)) @@ -157,3 +160,5 @@ printScaleTablesIndex() printScaleTablesCounts() print "} // anonymous namespace\n" +print "#endif /* _MIXER_MULTI_TABLES */" +print "" -- cgit v1.2.3 From cd11c4d81c976b76a0db262f43a6c09192cd0e6c Mon Sep 17 00:00:00 2001 From: Thomas Gubler Date: Tue, 6 Jan 2015 10:26:17 +0100 Subject: make multi_tables script python3 compatible The script still works with python2, I also added a file ending --- src/modules/systemlib/mixer/multi_tables | 197 --------------------------- src/modules/systemlib/mixer/multi_tables.py | 200 ++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+), 197 deletions(-) delete mode 100755 src/modules/systemlib/mixer/multi_tables create mode 100755 src/modules/systemlib/mixer/multi_tables.py (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/multi_tables b/src/modules/systemlib/mixer/multi_tables deleted file mode 100755 index a9edb357b..000000000 --- a/src/modules/systemlib/mixer/multi_tables +++ /dev/null @@ -1,197 +0,0 @@ -#!/usr/bin/env python -############################################################################ -# -# Copyright (c) 2013, 2014 PX4 Development Team. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name PX4 nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ - -# -# Generate multirotor mixer scale tables compatible with the ArduCopter layout -# - -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 "" - -def rcos(angleInRadians): - return math.cos(math.radians(angleInRadians)) - -CCW = 1.0 -CW = -CCW - -quad_x = [ - [ 45, CCW], - [-135, CCW], - [-45, CW], - [135, CW], -] - -quad_plus = [ - [ 90, CCW], - [ -90, CCW], - [ 0, CW], - [ 180, CW], -] - -quad_v = [ - [ 18.8, 0.4242], - [ -18.8, 1.0], - [ -18.8, -0.4242], - [ 18.8, -1.0], -] - -quad_wide = [ - [ 68, CCW], - [ -129, CCW], - [ -68, CW], - [ 129, CW], -] - -hex_x = [ - [ 90, CW], - [ -90, CCW], - [ -30, CW], - [ 150, CCW], - [ 30, CCW], - [-150, CW], -] - -hex_plus = [ - [ 0, CW], - [ 180, CCW], - [-120, CW], - [ 60, CCW], - [ -60, CCW], - [ 120, CW], -] - -hex_cox = [ - [ 60, CW], - [ 60, CCW], - [ 180, CW], - [ 180, CCW], - [ -60, CW], - [ -60, CCW], -] - -octa_x = [ - [ 22.5, CW], - [-157.5, CW], - [ 67.5, CCW], - [ 157.5, CCW], - [ -22.5, CCW], - [-112.5, CCW], - [ -67.5, CW], - [ 112.5, CW], -] - -octa_plus = [ - [ 0, CW], - [ 180, CW], - [ 45, CCW], - [ 135, CCW], - [ -45, CCW], - [-135, CCW], - [ -90, CW], - [ 90, CW], -] - -octa_cox = [ - [ 45, CCW], - [ -45, CW], - [-135, CCW], - [ 135, CW], - [ -45, CCW], - [ 45, CW], - [ 135, CCW], - [-135, CW], -] - -twin_engine = [ - [ 90, 0.0], - [-90, 0.0], -] - -def variableName(variable): - for variableName, value in list(globals().iteritems()): - if value is variable: - return variableName - -tables = [quad_x, quad_plus, quad_v, quad_wide, hex_x, hex_plus, hex_cox, octa_x, octa_plus, octa_cox, twin_engine] - - -def printEnum(): - print "enum class MultirotorGeometry : MultirotorGeometryUnderlyingType {" - for table in tables: - print "\t{},".format(variableName(table).upper()) - - print "\n\tMAX_GEOMETRY" - print "}; // enum class MultirotorGeometry\n" - -def printScaleTables(): - for table in tables: - 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" - -def printScaleTablesIndex(): - print "const MultirotorMixer::Rotor *_config_index[] = {" - for table in tables: - print "\t&_config_{}[0],".format(variableName(table)) - print "};\n" - - -def printScaleTablesCounts(): - print "const unsigned _config_rotor_count[] = {" - for table in tables: - print "\t{}, /* {} */".format(len(table), variableName(table)) - print "};\n" - - - -printEnum() - -print "namespace {" -printScaleTables() -printScaleTablesIndex() -printScaleTablesCounts() - -print "} // anonymous namespace\n" -print "#endif /* _MIXER_MULTI_TABLES */" -print "" diff --git a/src/modules/systemlib/mixer/multi_tables.py b/src/modules/systemlib/mixer/multi_tables.py new file mode 100755 index 000000000..21c0affd9 --- /dev/null +++ b/src/modules/systemlib/mixer/multi_tables.py @@ -0,0 +1,200 @@ +#!/usr/bin/env python +############################################################################ +# +# Copyright (c) 2013, 2014 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# +# 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("") + +def rcos(angleInRadians): + return math.cos(math.radians(angleInRadians)) + +CCW = 1.0 +CW = -CCW + +quad_x = [ + [ 45, CCW], + [-135, CCW], + [-45, CW], + [135, CW], +] + +quad_plus = [ + [ 90, CCW], + [ -90, CCW], + [ 0, CW], + [ 180, CW], +] + +quad_v = [ + [ 18.8, 0.4242], + [ -18.8, 1.0], + [ -18.8, -0.4242], + [ 18.8, -1.0], +] + +quad_wide = [ + [ 68, CCW], + [ -129, CCW], + [ -68, CW], + [ 129, CW], +] + +hex_x = [ + [ 90, CW], + [ -90, CCW], + [ -30, CW], + [ 150, CCW], + [ 30, CCW], + [-150, CW], +] + +hex_plus = [ + [ 0, CW], + [ 180, CCW], + [-120, CW], + [ 60, CCW], + [ -60, CCW], + [ 120, CW], +] + +hex_cox = [ + [ 60, CW], + [ 60, CCW], + [ 180, CW], + [ 180, CCW], + [ -60, CW], + [ -60, CCW], +] + +octa_x = [ + [ 22.5, CW], + [-157.5, CW], + [ 67.5, CCW], + [ 157.5, CCW], + [ -22.5, CCW], + [-112.5, CCW], + [ -67.5, CW], + [ 112.5, CW], +] + +octa_plus = [ + [ 0, CW], + [ 180, CW], + [ 45, CCW], + [ 135, CCW], + [ -45, CCW], + [-135, CCW], + [ -90, CW], + [ 90, CW], +] + +octa_cox = [ + [ 45, CCW], + [ -45, CW], + [-135, CCW], + [ 135, CW], + [ -45, CCW], + [ 45, CW], + [ 135, CCW], + [-135, CW], +] + +twin_engine = [ + [ 90, 0.0], + [-90, 0.0], +] + +def variableName(variable): + for variableName, value in list(globals().items()): + if value is variable: + return variableName + +tables = [quad_x, quad_plus, quad_v, quad_wide, hex_x, hex_plus, hex_cox, octa_x, octa_plus, octa_cox, twin_engine] + + +def printEnum(): + print("enum class MultirotorGeometry : MultirotorGeometryUnderlyingType {") + for table in tables: + print("\t{},".format(variableName(table).upper())) + + print("\n\tMAX_GEOMETRY") + print("}; // enum class MultirotorGeometry\n") + +def printScaleTables(): + for table in tables: + 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") + +def printScaleTablesIndex(): + print("const MultirotorMixer::Rotor *_config_index[] = {") + for table in tables: + print("\t&_config_{}[0],".format(variableName(table))) + print("};\n") + + +def printScaleTablesCounts(): + print("const unsigned _config_rotor_count[] = {") + for table in tables: + print("\t{}, /* {} */".format(len(table), variableName(table))) + print("};\n") + + + +printEnum() + +print("namespace {") +printScaleTables() +printScaleTablesIndex() +printScaleTablesCounts() + +print("} // anonymous namespace\n") +print("#endif /* _MIXER_MULTI_TABLES */") +print("") -- cgit v1.2.3 From 0d571458f5880c0fa92d20a4df1f0204277c43a0 Mon Sep 17 00:00:00 2001 From: Thomas Gubler Date: Tue, 6 Jan 2015 10:27:40 +0100 Subject: improve multi_tables makefile --- src/modules/systemlib/mixer/multi_tables.mk | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/multi_tables.mk b/src/modules/systemlib/mixer/multi_tables.mk index 6429961cc..5a1a0fa72 100644 --- a/src/modules/systemlib/mixer/multi_tables.mk +++ b/src/modules/systemlib/mixer/multi_tables.mk @@ -33,11 +33,12 @@ SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +MULTI_TABLES := $(SELF_DIR)multi_tables.py # Add explicit dependency, as implicit one doesn't work often. $(SELF_DIR)mixer_multirotor.cpp : $(SELF_DIR)mixer_multirotor.generated.h -$(SELF_DIR)mixer_multirotor.generated.h : $(SELF_DIR)multi_tables - $(SELF_DIR)multi_tables > $(SELF_DIR)mixer_multirotor.generated.h - $(SELF_DIR)multi_tables - \ No newline at end of file +$(SELF_DIR)mixer_multirotor.generated.h : $(MULTI_TABLES) + $(Q) $(PYTHON) $(MULTI_TABLES) > $(SELF_DIR)mixer_multirotor.generated.h + $(Q) $(PYTHON) $(MULTI_TABLES) + -- cgit v1.2.3 From a42febc993ae4492e0f43002a5f30f02a0e02fa7 Mon Sep 17 00:00:00 2001 From: Thomas Gubler Date: Tue, 6 Jan 2015 10:29:36 +0100 Subject: remove output of multi_tables script --- src/modules/systemlib/mixer/multi_tables.mk | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/modules') diff --git a/src/modules/systemlib/mixer/multi_tables.mk b/src/modules/systemlib/mixer/multi_tables.mk index 5a1a0fa72..c537c83a4 100644 --- a/src/modules/systemlib/mixer/multi_tables.mk +++ b/src/modules/systemlib/mixer/multi_tables.mk @@ -40,5 +40,3 @@ $(SELF_DIR)mixer_multirotor.cpp : $(SELF_DIR)mixer_multirotor.generated.h $(SELF_DIR)mixer_multirotor.generated.h : $(MULTI_TABLES) $(Q) $(PYTHON) $(MULTI_TABLES) > $(SELF_DIR)mixer_multirotor.generated.h - $(Q) $(PYTHON) $(MULTI_TABLES) - -- cgit v1.2.3