mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-24 07:09:48 +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 re
|
||||
import math
|
||||
|
||||
global default_var
|
||||
default_var = {}
|
||||
|
||||
@@ -39,7 +41,7 @@ class Parameter(object):
|
||||
|
||||
# Define sorting order of the fields
|
||||
priority = {
|
||||
"board": 9,
|
||||
"board": 9,
|
||||
"short_desc": 8,
|
||||
"long_desc": 7,
|
||||
"min": 5,
|
||||
@@ -52,6 +54,7 @@ class Parameter(object):
|
||||
def __init__(self, name, type, default = ""):
|
||||
self.fields = {}
|
||||
self.values = {}
|
||||
self.bitmask = {}
|
||||
self.name = name
|
||||
self.type = type
|
||||
self.default = default
|
||||
@@ -77,6 +80,12 @@ class Parameter(object):
|
||||
"""
|
||||
self.values[code] = value
|
||||
|
||||
def SetBitmaskBit(self, index, bit):
|
||||
"""
|
||||
Set named enum value
|
||||
"""
|
||||
self.bitmask[index] = bit
|
||||
|
||||
def GetFieldCodes(self):
|
||||
"""
|
||||
Return list of existing field codes in convenient order
|
||||
@@ -115,6 +124,24 @@ class Parameter(object):
|
||||
return ""
|
||||
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):
|
||||
"""
|
||||
Parses provided data and stores all found parameters internally.
|
||||
@@ -133,7 +160,7 @@ class SourceParser(object):
|
||||
re_remove_dots = re.compile(r'\.+$')
|
||||
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
|
||||
priority = {
|
||||
@@ -164,6 +191,7 @@ class SourceParser(object):
|
||||
long_desc = None
|
||||
tags = {}
|
||||
def_values = {}
|
||||
def_bitmask = {}
|
||||
elif state is not None and state != "comment-processed":
|
||||
m = self.re_comment_end.search(line)
|
||||
if m:
|
||||
@@ -187,6 +215,10 @@ class SourceParser(object):
|
||||
# Take the meta info string and split the code and description
|
||||
metainfo = desc.split(" ", 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:
|
||||
tags[tag] = desc
|
||||
current_tag = tag
|
||||
@@ -262,6 +294,8 @@ class SourceParser(object):
|
||||
param.SetField(tag, tags[tag])
|
||||
for def_value in def_values:
|
||||
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
|
||||
if group not in self.param_groups:
|
||||
self.param_groups[group] = ParameterGroup(group)
|
||||
@@ -324,6 +358,16 @@ class SourceParser(object):
|
||||
if param.GetEnumValue(code) == "":
|
||||
sys.stderr.write("Description for enum value is empty: {0} {1}\n".format(name, code))
|
||||
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
|
||||
|
||||
def GetParamGroups(self):
|
||||
|
||||
@@ -63,6 +63,14 @@ class XMLOutput():
|
||||
xml_value = ET.SubElement(xml_values, "value")
|
||||
xml_value.attrib["code"] = 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)
|
||||
self.xml_document = ET.ElementTree(xml_parameters)
|
||||
|
||||
|
||||
@@ -121,21 +121,30 @@ PARAM_DEFINE_FLOAT(EKF2_EV_DELAY, 175);
|
||||
|
||||
/**
|
||||
* Integer bitmask controlling GPS checks.
|
||||
*
|
||||
*
|
||||
* Set bits to 1 to enable checks. Checks enabled by the following bit positions
|
||||
* 0 : Minimum required sat count set by EKF2_REQ_NSATS
|
||||
* 1 : Minimum required GDoP set by EKF2_REQ_GDOP
|
||||
* 2 : Maximum allowed horizontal position error set by EKF2_REQ_EPH
|
||||
* 3 : Maximum allowed vertical position error set by EKF2_REQ_EPV
|
||||
* 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.
|
||||
* 6 : Maximum allowed vertical position rate set by EKF2_REQ_VDRIFT. 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 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 vehicle 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
|
||||
*
|
||||
* @group EKF2
|
||||
* @min 0
|
||||
* @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);
|
||||
|
||||
@@ -365,7 +374,7 @@ PARAM_DEFINE_FLOAT(EKF2_MAG_NOISE, 5.0e-2f);
|
||||
* @unit m/s
|
||||
* @decimal 1
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(EKF2_EAS_NOISE, 1.4f);
|
||||
PARAM_DEFINE_FLOAT(EKF2_EAS_NOISE, 1.4f);
|
||||
|
||||
/**
|
||||
* Magnetic declination
|
||||
@@ -402,11 +411,14 @@ PARAM_DEFINE_FLOAT(EKF2_MAG_GATE, 3.0f);
|
||||
* 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.
|
||||
* 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
|
||||
* @min 0
|
||||
* @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);
|
||||
|
||||
@@ -415,7 +427,7 @@ PARAM_DEFINE_INT32(EKF2_DECL_TYPE, 7);
|
||||
*
|
||||
* Integer controlling the type of magnetometer fusion used - magnetic heading or 3-axis magnetometer.
|
||||
* If set to automatic: heading fusion on-ground and 3-axis fusion in-flight
|
||||
*
|
||||
*
|
||||
* @group EKF2
|
||||
* @value 0 Automatic
|
||||
* @value 1 Magnetic heading
|
||||
@@ -484,10 +496,15 @@ PARAM_DEFINE_INT32(EKF2_REC_RPL, 0);
|
||||
* 2 : Set to true to inhibit IMU bias estimation
|
||||
* 3 : Set to true to enable vision position fusion
|
||||
* 4 : Set to true to enable vision yaw fusion
|
||||
* *
|
||||
*
|
||||
* @group EKF2
|
||||
* @min 0
|
||||
* @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);
|
||||
|
||||
@@ -782,16 +799,16 @@ PARAM_DEFINE_FLOAT(EKF2_EV_POS_Y, 0.0f);
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(EKF2_EV_POS_Z, 0.0f);
|
||||
|
||||
/**
|
||||
* Airspeed fusion threshold. A value of zero will deactivate airspeed fusion. Any other positive
|
||||
* value will determine the minimum airspeed which will still be fused.
|
||||
*
|
||||
* @group EKF2
|
||||
* @min 0.0
|
||||
* @unit m/s
|
||||
* @decimal 1
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(EKF2_ARSP_THR, 0.0f);
|
||||
/**
|
||||
* Airspeed fusion threshold. A value of zero will deactivate airspeed fusion. Any other positive
|
||||
* value will determine the minimum airspeed which will still be fused.
|
||||
*
|
||||
* @group EKF2
|
||||
* @min 0.0
|
||||
* @unit m/s
|
||||
* @decimal 1
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(EKF2_ARSP_THR, 0.0f);
|
||||
|
||||
/**
|
||||
|
||||
|
||||
Reference in New Issue
Block a user