param: automatically update calibration ID params on import

This avoids the need for recalibration, and also cleans up other driver
ID's (merge separate accel/gyro).

The SPI address was previously set to a board-specific (arbitrary) value,
and is now set to 0. This will allow extending for multiple sensors of the
same type on the same bus.
This commit is contained in:
Beat Küng
2020-03-10 10:11:43 -04:00
committed by Daniel Agar
parent 1851665fab
commit b54e5a1c23
29 changed files with 275 additions and 65 deletions
+5
View File
@@ -128,6 +128,11 @@ if ("${CONFIG_SHMEM}" STREQUAL "1")
list(APPEND SRCS parameters_shmem.cpp)
else()
list(APPEND SRCS parameters.cpp)
if(PX4_TESTING)
list(APPEND SRCS param_translation_unit_tests.cpp)
else()
list(APPEND SRCS param_translation.cpp)
endif()
endif()
if(${PX4_PLATFORM} STREQUAL "nuttx")
@@ -57,6 +57,7 @@
#include <parameters/tinybson/tinybson.h>
#include "flashparams.h"
#include "flashfs.h"
#include "../param_translation.h"
#if 0
# define debug(fmt, args...) do { warnx(fmt, ##args); } while(0)
@@ -300,6 +301,8 @@ param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node)
goto out;
}
param_modify_on_import(node->name, node->type, v);
if (param_set_external(param, v, state->mark_saved, true)) {
debug("error setting value for '%s'", node->name);
+126
View File
@@ -0,0 +1,126 @@
/****************************************************************************
*
* Copyright (c) 2020 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.
*
****************************************************************************/
#include "param_translation.h"
#include <px4_platform_common/log.h>
#include <lib/drivers/device/Device.hpp>
#include <drivers/drv_sensor.h>
bool param_modify_on_import(const char *name, bson_type_t type, void *value)
{
// translate (SPI) calibration ID parameters. This can be removed after the next release (current release=1.10)
if (type != BSON_INT32) {
return false;
}
int32_t *ivalue = (int32_t *)value;
const char *cal_id_params[] = {
"CAL_ACC0_ID",
"CAL_GYRO0_ID",
"CAL_MAG0_ID",
"TC_A0_ID",
"TC_B0_ID",
"TC_G0_ID",
"CAL_ACC1_ID",
"CAL_GYRO1_ID",
"CAL_MAG1_ID",
"TC_A1_ID",
"TC_B1_ID",
"TC_G1_ID",
"CAL_ACC2_ID",
"CAL_GYRO2_ID",
"CAL_MAG2_ID",
"TC_A2_ID",
"TC_B2_ID",
"TC_G2_ID",
"CAL_ACC_PRIME",
"CAL_GYRO_PRIME",
"CAL_MAG_PRIME",
};
bool found = false;
for (int i = 0; i < sizeof(cal_id_params) / sizeof(cal_id_params[0]); ++i) {
if (strcmp(cal_id_params[i], name) == 0) {
found = true;
break;
}
}
if (!found) {
return false;
}
device::Device::DeviceId device_id;
device_id.devid = (uint32_t) * ivalue;
// SPI board config translation
if (device_id.devid_s.bus_type == device::Device::DeviceBusType_SPI) {
device_id.devid_s.address = 0;
}
// deprecated ACC -> IMU translations
if (device_id.devid_s.devtype == DRV_ACC_DEVTYPE_MPU6000_LEGACY) {
device_id.devid_s.devtype = DRV_IMU_DEVTYPE_MPU6000;
}
if (device_id.devid_s.devtype == DRV_ACC_DEVTYPE_MPU9250_LEGACY) {
device_id.devid_s.devtype = DRV_IMU_DEVTYPE_MPU9250;
}
if (device_id.devid_s.devtype == DRV_ACC_DEVTYPE_ICM20602_LEGACY) {
device_id.devid_s.devtype = DRV_IMU_DEVTYPE_ICM20602;
}
if (device_id.devid_s.devtype == DRV_ACC_DEVTYPE_ICM20608_LEGACY) {
device_id.devid_s.devtype = DRV_IMU_DEVTYPE_ICM20608;
}
if (device_id.devid_s.devtype == DRV_ACC_DEVTYPE_ICM20689_LEGACY) {
device_id.devid_s.devtype = DRV_IMU_DEVTYPE_ICM20689;
}
int32_t new_value = (int32_t)device_id.devid;
if (new_value != *ivalue) {
PX4_INFO("param modify: %s, value=0x%x (old=0x%x)", name, new_value, *ivalue);
*ivalue = new_value;
return true;
}
return false;
}
+39
View File
@@ -0,0 +1,39 @@
/****************************************************************************
*
* Copyright (c) 2020 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.
*
****************************************************************************/
#pragma once
#include "tinybson/tinybson.h"
__EXPORT bool param_modify_on_import(const char *name, bson_type_t type, void *value);
@@ -0,0 +1,40 @@
/****************************************************************************
*
* Copyright (c) 2020 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.
*
****************************************************************************/
#include "param_translation.h"
bool param_modify_on_import(const char *name, bson_type_t type, void *value)
{
// don't modify params for unit tests
return false;
}
+3
View File
@@ -42,6 +42,7 @@
*/
#include "param.h"
#include "param_translation.h"
#include <parameters/px4_parameters.h>
#include "tinybson/tinybson.h"
@@ -1261,6 +1262,8 @@ param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node)
goto out;
}
param_modify_on_import(node->name, node->type, v);
if (param_set_internal(param, v, state->mark_saved, true)) {
PX4_DEBUG("error setting value for '%s'", node->name);
goto out;