mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-02 20:28:37 +08:00
Mixers: use key list to select multirotor mixer
This commit is contained in:
committed by
Beat Küng
parent
aa789f5e8a
commit
4991ab5362
@@ -100,7 +100,7 @@ MultirotorMixer::~MultirotorMixer()
|
|||||||
MultirotorMixer *
|
MultirotorMixer *
|
||||||
MultirotorMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handle, const char *buf, unsigned &buflen)
|
MultirotorMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handle, const char *buf, unsigned &buflen)
|
||||||
{
|
{
|
||||||
MultirotorGeometry geometry;
|
MultirotorGeometry geometry = MultirotorGeometry::MAX_GEOMETRY;
|
||||||
char geomname[8];
|
char geomname[8];
|
||||||
int s[4];
|
int s[4];
|
||||||
int used;
|
int used;
|
||||||
@@ -129,61 +129,15 @@ MultirotorMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handl
|
|||||||
|
|
||||||
debug("remaining in buf: %d, first char: %c", buflen, buf[0]);
|
debug("remaining in buf: %d, first char: %c", buflen, buf[0]);
|
||||||
|
|
||||||
if (!strcmp(geomname, "4+")) {
|
for (MultirotorGeometryUnderlyingType i = 0; i < (MultirotorGeometryUnderlyingType)MultirotorGeometry::MAX_GEOMETRY;
|
||||||
geometry = MultirotorGeometry::QUAD_PLUS;
|
i++) {
|
||||||
|
if (!strcmp(geomname, _config_key[i])) {
|
||||||
|
geometry = (MultirotorGeometry)i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "4x")) {
|
if (geometry == MultirotorGeometry::MAX_GEOMETRY) {
|
||||||
geometry = MultirotorGeometry::QUAD_X;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "4h")) {
|
|
||||||
geometry = MultirotorGeometry::QUAD_H;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "4v")) {
|
|
||||||
geometry = MultirotorGeometry::QUAD_V;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "4w")) {
|
|
||||||
geometry = MultirotorGeometry::QUAD_WIDE;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "4s")) {
|
|
||||||
geometry = MultirotorGeometry::QUAD_S250AQ;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "4dc")) {
|
|
||||||
geometry = MultirotorGeometry::QUAD_DEADCAT;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "6+")) {
|
|
||||||
geometry = MultirotorGeometry::HEX_PLUS;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "6x")) {
|
|
||||||
geometry = MultirotorGeometry::HEX_X;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "6c")) {
|
|
||||||
geometry = MultirotorGeometry::HEX_COX;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "6t")) {
|
|
||||||
geometry = MultirotorGeometry::HEX_T;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "8+")) {
|
|
||||||
geometry = MultirotorGeometry::OCTA_PLUS;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "8x")) {
|
|
||||||
geometry = MultirotorGeometry::OCTA_X;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "8c")) {
|
|
||||||
geometry = MultirotorGeometry::OCTA_COX;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "6m")) {
|
|
||||||
geometry = MultirotorGeometry::DODECA_TOP_COX;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "6a")) {
|
|
||||||
geometry = MultirotorGeometry::DODECA_BOTTOM_COX;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "2-")) {
|
|
||||||
geometry = MultirotorGeometry::TWIN_ENGINE;
|
|
||||||
|
|
||||||
} else if (!strcmp(geomname, "3y")) {
|
|
||||||
geometry = MultirotorGeometry::TRI_Y;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
debug("unrecognised geometry '%s'", geomname);
|
debug("unrecognised geometry '%s'", geomname);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,7 +213,16 @@ dodeca_bottom_cox = [
|
|||||||
[-150, CCW],
|
[-150, CCW],
|
||||||
]
|
]
|
||||||
|
|
||||||
tables = [quad_x, quad_h, quad_plus, quad_v, quad_wide, quad_s250aq, quad_deadcat, hex_x, hex_plus, hex_cox, hex_t, octa_x, octa_plus, octa_cox, octa_cox_wide, twin_engine, tri_y, dodeca_top_cox, dodeca_bottom_cox]
|
tables = [quad_x, quad_h, quad_plus, quad_v, quad_wide, quad_s250aq, quad_deadcat,
|
||||||
|
hex_x, hex_plus, hex_cox, hex_t,
|
||||||
|
octa_x, octa_plus, octa_cox, octa_cox_wide,
|
||||||
|
twin_engine, tri_y,
|
||||||
|
dodeca_top_cox, dodeca_bottom_cox]
|
||||||
|
keys = ["4x", "4h", "4+", "4v", "4w", "4s", "4dc",
|
||||||
|
"6x", "6+", "6c", "6t",
|
||||||
|
"8x", "8+", "8c", "8cw",
|
||||||
|
"2-", "3y",
|
||||||
|
"6m", "6a"]
|
||||||
|
|
||||||
def variableName(variable):
|
def variableName(variable):
|
||||||
for variableName, value in list(globals().items()):
|
for variableName, value in list(globals().items()):
|
||||||
@@ -256,7 +265,11 @@ def printScaleTablesCounts():
|
|||||||
print("\t{}, /* {} */".format(len(table), variableName(table)))
|
print("\t{}, /* {} */".format(len(table), variableName(table)))
|
||||||
print("};\n")
|
print("};\n")
|
||||||
|
|
||||||
|
def printScaleTablesKeys():
|
||||||
|
print("const char* _config_key[] = {")
|
||||||
|
for key, table in zip(keys, tables):
|
||||||
|
print("\t\"{}\",\t/* {} */".format(key, variableName(table)))
|
||||||
|
print("};\n")
|
||||||
|
|
||||||
printEnum()
|
printEnum()
|
||||||
|
|
||||||
@@ -264,6 +277,7 @@ print("namespace {")
|
|||||||
printScaleTables()
|
printScaleTables()
|
||||||
printScaleTablesIndex()
|
printScaleTablesIndex()
|
||||||
printScaleTablesCounts()
|
printScaleTablesCounts()
|
||||||
|
printScaleTablesKeys()
|
||||||
|
|
||||||
print("} // anonymous namespace\n")
|
print("} // anonymous namespace\n")
|
||||||
print("#endif /* _MIXER_MULTI_TABLES */")
|
print("#endif /* _MIXER_MULTI_TABLES */")
|
||||||
|
|||||||
Reference in New Issue
Block a user