mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-02 03:49:12 +08:00
add bitmask param metadata
This commit is contained in:
committed by
Lorenz Meier
parent
9974b6f747
commit
4252511b8e
@@ -1,5 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
import math
|
||||||
|
|
||||||
global default_var
|
global default_var
|
||||||
default_var = {}
|
default_var = {}
|
||||||
|
|
||||||
@@ -52,6 +54,7 @@ class Parameter(object):
|
|||||||
def __init__(self, name, type, default = ""):
|
def __init__(self, name, type, default = ""):
|
||||||
self.fields = {}
|
self.fields = {}
|
||||||
self.values = {}
|
self.values = {}
|
||||||
|
self.bitmask = {}
|
||||||
self.name = name
|
self.name = name
|
||||||
self.type = type
|
self.type = type
|
||||||
self.default = default
|
self.default = default
|
||||||
@@ -77,6 +80,12 @@ class Parameter(object):
|
|||||||
"""
|
"""
|
||||||
self.values[code] = value
|
self.values[code] = value
|
||||||
|
|
||||||
|
def SetBitmaskBit(self, index, bit):
|
||||||
|
"""
|
||||||
|
Set named enum value
|
||||||
|
"""
|
||||||
|
self.bitmask[index] = bit
|
||||||
|
|
||||||
def GetFieldCodes(self):
|
def GetFieldCodes(self):
|
||||||
"""
|
"""
|
||||||
Return list of existing field codes in convenient order
|
Return list of existing field codes in convenient order
|
||||||
@@ -115,6 +124,24 @@ class Parameter(object):
|
|||||||
return ""
|
return ""
|
||||||
return fv
|
return fv
|
||||||
|
|
||||||
|
def GetBitmaskList(self):
|
||||||
|
"""
|
||||||
|
Return list of existing bitmask codes in convenient order
|
||||||
|
"""
|
||||||
|
keys = self.bitmask.keys()
|
||||||
|
keys.sort(key=float)
|
||||||
|
return keys
|
||||||
|
|
||||||
|
def GetBitmaskBit(self, index):
|
||||||
|
"""
|
||||||
|
Return value of the given bitmask code or None if not found.
|
||||||
|
"""
|
||||||
|
fv = self.bitmask.get(index)
|
||||||
|
if not fv:
|
||||||
|
# required because python 3 sorted does not accept None
|
||||||
|
return ""
|
||||||
|
return fv
|
||||||
|
|
||||||
class SourceParser(object):
|
class SourceParser(object):
|
||||||
"""
|
"""
|
||||||
Parses provided data and stores all found parameters internally.
|
Parses provided data and stores all found parameters internally.
|
||||||
@@ -133,7 +160,7 @@ class SourceParser(object):
|
|||||||
re_remove_dots = re.compile(r'\.+$')
|
re_remove_dots = re.compile(r'\.+$')
|
||||||
re_remove_carriage_return = re.compile('\n+')
|
re_remove_carriage_return = re.compile('\n+')
|
||||||
|
|
||||||
valid_tags = set(["group", "board", "min", "max", "unit", "decimal", "increment", "reboot_required", "value", "boolean"])
|
valid_tags = set(["group", "board", "min", "max", "unit", "decimal", "increment", "reboot_required", "value", "boolean", "bit"])
|
||||||
|
|
||||||
# Order of parameter groups
|
# Order of parameter groups
|
||||||
priority = {
|
priority = {
|
||||||
@@ -164,6 +191,7 @@ class SourceParser(object):
|
|||||||
long_desc = None
|
long_desc = None
|
||||||
tags = {}
|
tags = {}
|
||||||
def_values = {}
|
def_values = {}
|
||||||
|
def_bitmask = {}
|
||||||
elif state is not None and state != "comment-processed":
|
elif state is not None and state != "comment-processed":
|
||||||
m = self.re_comment_end.search(line)
|
m = self.re_comment_end.search(line)
|
||||||
if m:
|
if m:
|
||||||
@@ -187,6 +215,10 @@ class SourceParser(object):
|
|||||||
# Take the meta info string and split the code and description
|
# Take the meta info string and split the code and description
|
||||||
metainfo = desc.split(" ", 1)
|
metainfo = desc.split(" ", 1)
|
||||||
def_values[metainfo[0]] = metainfo[1]
|
def_values[metainfo[0]] = metainfo[1]
|
||||||
|
elif (tag == "bit"):
|
||||||
|
# Take the meta info string and split the code and description
|
||||||
|
metainfo = desc.split(" ", 1)
|
||||||
|
def_bitmask[metainfo[0]] = metainfo[1]
|
||||||
else:
|
else:
|
||||||
tags[tag] = desc
|
tags[tag] = desc
|
||||||
current_tag = tag
|
current_tag = tag
|
||||||
@@ -262,6 +294,8 @@ class SourceParser(object):
|
|||||||
param.SetField(tag, tags[tag])
|
param.SetField(tag, tags[tag])
|
||||||
for def_value in def_values:
|
for def_value in def_values:
|
||||||
param.SetEnumValue(def_value, def_values[def_value])
|
param.SetEnumValue(def_value, def_values[def_value])
|
||||||
|
for def_bit in def_bitmask:
|
||||||
|
param.SetBitmaskBit(def_bit, def_bitmask[def_bit])
|
||||||
# Store the parameter
|
# Store the parameter
|
||||||
if group not in self.param_groups:
|
if group not in self.param_groups:
|
||||||
self.param_groups[group] = ParameterGroup(group)
|
self.param_groups[group] = ParameterGroup(group)
|
||||||
@@ -324,6 +358,16 @@ class SourceParser(object):
|
|||||||
if param.GetEnumValue(code) == "":
|
if param.GetEnumValue(code) == "":
|
||||||
sys.stderr.write("Description for enum value is empty: {0} {1}\n".format(name, code))
|
sys.stderr.write("Description for enum value is empty: {0} {1}\n".format(name, code))
|
||||||
return False
|
return False
|
||||||
|
for index in param.GetBitmaskList():
|
||||||
|
if not self.IsNumber(index):
|
||||||
|
sys.stderr.write("bit value not number: {0} {1}\n".format(name, index))
|
||||||
|
return False
|
||||||
|
if not int(min) <= math.pow(2, int(index)) <= int(max):
|
||||||
|
sys.stderr.write("Bitmask bit must be between {0} and {1}: {2} {3}\n".format(min, max, name, math.pow(2, int(index))))
|
||||||
|
return False
|
||||||
|
if param.GetBitmaskBit(index) == "":
|
||||||
|
sys.stderr.write("Description for bitmask bit is empty: {0} {1}\n".format(name, index))
|
||||||
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def GetParamGroups(self):
|
def GetParamGroups(self):
|
||||||
|
|||||||
@@ -63,6 +63,14 @@ class XMLOutput():
|
|||||||
xml_value = ET.SubElement(xml_values, "value")
|
xml_value = ET.SubElement(xml_values, "value")
|
||||||
xml_value.attrib["code"] = code;
|
xml_value.attrib["code"] = code;
|
||||||
xml_value.text = param.GetEnumValue(code)
|
xml_value.text = param.GetEnumValue(code)
|
||||||
|
|
||||||
|
if len(param.GetBitmaskList()) > 0:
|
||||||
|
xml_values = ET.SubElement(xml_param, "bitmask")
|
||||||
|
for index in param.GetBitmaskList():
|
||||||
|
xml_value = ET.SubElement(xml_values, "bit")
|
||||||
|
xml_value.attrib["index"] = index;
|
||||||
|
xml_value.text = param.GetBitmaskBit(index)
|
||||||
|
|
||||||
indent(xml_parameters)
|
indent(xml_parameters)
|
||||||
self.xml_document = ET.ElementTree(xml_parameters)
|
self.xml_document = ET.ElementTree(xml_parameters)
|
||||||
|
|
||||||
|
|||||||
@@ -128,14 +128,23 @@ PARAM_DEFINE_FLOAT(EKF2_EV_DELAY, 175);
|
|||||||
* 2 : Maximum allowed horizontal position error set by EKF2_REQ_EPH
|
* 2 : Maximum allowed horizontal position error set by EKF2_REQ_EPH
|
||||||
* 3 : Maximum allowed vertical position error set by EKF2_REQ_EPV
|
* 3 : Maximum allowed vertical position error set by EKF2_REQ_EPV
|
||||||
* 4 : Maximum allowed speed error set by EKF2_REQ_SACC
|
* 4 : Maximum allowed speed error set by EKF2_REQ_SACC
|
||||||
* 5 : Maximum allowed horizontal position rate set by EKF2_REQ_HDRIFT. This check can only be used if the vehciel is stationary during alignment.
|
* 5 : Maximum allowed horizontal position rate set by EKF2_REQ_HDRIFT. This check can only be used if the vehicle is stationary during alignment.
|
||||||
* 6 : Maximum allowed vertical position rate set by EKF2_REQ_VDRIFT. This check can only be used if the vehciel is stationary during alignment.
|
* 6 : Maximum allowed vertical position rate set by EKF2_REQ_VDRIFT. This check can only be used if the vehicle is stationary during alignment.
|
||||||
* 7 : Maximum allowed horizontal speed set by EKF2_REQ_HDRIFT. This check can only be used if the vehciel is stationary during alignment.
|
* 7 : Maximum allowed horizontal speed set by EKF2_REQ_HDRIFT. This check can only be used if the vehicle is stationary during alignment.
|
||||||
* 8 : Maximum allowed vertical velocity discrepancy set by EKF2_REQ_VDRIFT
|
* 8 : Maximum allowed vertical velocity discrepancy set by EKF2_REQ_VDRIFT
|
||||||
*
|
*
|
||||||
* @group EKF2
|
* @group EKF2
|
||||||
* @min 0
|
* @min 0
|
||||||
* @max 511
|
* @max 511
|
||||||
|
* @bit 0 Min sat count (EKF2_REQ_NSATS)
|
||||||
|
* @bit 1 Min GDoP (EKF2_REQ_GDOP)
|
||||||
|
* @bit 2 Max horizontal position error (EKF2_REQ_EPH)
|
||||||
|
* @bit 3 Max vertical position error (EKF2_REQ_EPV)
|
||||||
|
* @bit 4 Max speed error (EKF2_REQ_SACC)
|
||||||
|
* @bit 5 Max horizontal position rate (EKF2_REQ_HDRIFT)
|
||||||
|
* @bit 6 Max vertical position rate (EKF2_REQ_VDRIFT)
|
||||||
|
* @bit 7 Max horizontal speed (EKF2_REQ_HDRIFT)
|
||||||
|
* @bit 8 Max vertical velocity discrepancy (EKF2_REQ_VDRIFT)
|
||||||
*/
|
*/
|
||||||
PARAM_DEFINE_INT32(EKF2_GPS_CHECK, 21);
|
PARAM_DEFINE_INT32(EKF2_GPS_CHECK, 21);
|
||||||
|
|
||||||
@@ -402,11 +411,14 @@ PARAM_DEFINE_FLOAT(EKF2_MAG_GATE, 3.0f);
|
|||||||
* Set bits in the following positions to enable functions.
|
* Set bits in the following positions to enable functions.
|
||||||
* 0 : Set to true to use the declination from the geo_lookup library when the GPS position becomes available, set to false to always use the EKF2_MAG_DECL value.
|
* 0 : Set to true to use the declination from the geo_lookup library when the GPS position becomes available, set to false to always use the EKF2_MAG_DECL value.
|
||||||
* 1 : Set to true to save the EKF2_MAG_DECL parameter to the value returned by the EKF when the vehicle disarms.
|
* 1 : Set to true to save the EKF2_MAG_DECL parameter to the value returned by the EKF when the vehicle disarms.
|
||||||
* 2 : Set to true to always use the declination as an observaton when 3-axis magnetometer fusion is being used.
|
* 2 : Set to true to always use the declination as an observation when 3-axis magnetometer fusion is being used.
|
||||||
*
|
*
|
||||||
* @group EKF2
|
* @group EKF2
|
||||||
* @min 0
|
* @min 0
|
||||||
* @max 7
|
* @max 7
|
||||||
|
* @bit 0 use geo_lookup declination
|
||||||
|
* @bit 1 save EKF2_MAG_DECL on disarm
|
||||||
|
* @bit 2 use declination as an observation
|
||||||
*/
|
*/
|
||||||
PARAM_DEFINE_INT32(EKF2_DECL_TYPE, 7);
|
PARAM_DEFINE_INT32(EKF2_DECL_TYPE, 7);
|
||||||
|
|
||||||
@@ -484,10 +496,15 @@ PARAM_DEFINE_INT32(EKF2_REC_RPL, 0);
|
|||||||
* 2 : Set to true to inhibit IMU bias estimation
|
* 2 : Set to true to inhibit IMU bias estimation
|
||||||
* 3 : Set to true to enable vision position fusion
|
* 3 : Set to true to enable vision position fusion
|
||||||
* 4 : Set to true to enable vision yaw fusion
|
* 4 : Set to true to enable vision yaw fusion
|
||||||
* *
|
*
|
||||||
* @group EKF2
|
* @group EKF2
|
||||||
* @min 0
|
* @min 0
|
||||||
* @max 28
|
* @max 28
|
||||||
|
* @bit 0 use GPS
|
||||||
|
* @bit 1 use optical flow
|
||||||
|
* @bit 2 inhibit IMU bias estimation
|
||||||
|
* @bit 3 vision position fusion
|
||||||
|
* @bit 4 vision yaw fusion
|
||||||
*/
|
*/
|
||||||
PARAM_DEFINE_INT32(EKF2_AID_MASK, 1);
|
PARAM_DEFINE_INT32(EKF2_AID_MASK, 1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user