DriverFramework purge

The bulk of this change was tightly coupled and needed to be deleted in one pass. Some of the smaller changes were things that broke as a result of the initial purge and subsequently fixed by further eradicating unnecessary platform differences. Finally, I deleted any dead code I came across in the related files I touched while going through everything.

 - DriverFramework (src/lib/DriverFramework submodule) completely removed
 - added dspal submodule in qurt platform (was brought in via DriverFramework)
 - all df wrapper drivers removed
 - all boards using df wrapper drivers updated to use in tree equivalents
 - unused empty arch/board.h on posix and qurt removed
 - unused IOCTLs removed (pub block, priv, etc)
 - Integrator delete methods only used from df wrapper drivers
 - commander: sensor calibration use "NuttX version" everywhere for now
 - sensors: update to px4_{open, read, close} instead of DevMgr wrapper (adc open for analog differential pressure)
 - battery_status: update to px4_{open, read, close} instead of DevMgr wrapper (adc open for analog differential pressure)
 - cdev cleanup conflicting typedefs and names with actual OS (pollevent_t, etc)
 - load_mon and top remove from linux boards (unused)
 - delete unused PX4_MAIN_FUNCTION
 - delete unused getreg32 macro
 - delete unused SIOCDEVPRIVATE define
 - named each platform tasks consistently
 - posix list_devices and list_topics removed (list_files now shows all virtual files)
This commit is contained in:
Daniel Agar
2020-01-09 11:00:40 -05:00
parent 04ba05f5a0
commit de4f594937
165 changed files with 285 additions and 8108 deletions
-1
View File
@@ -52,7 +52,6 @@ px4_add_module(
state_machine_helper.cpp
DEPENDS
circuit_breaker
df_driver_framework
failure_detector
git_ecl
ecl_geo
@@ -132,10 +132,8 @@
#include <px4_platform_common/time.h>
#include <unistd.h>
#include <stdio.h>
#include <poll.h>
#include <fcntl.h>
#include <math.h>
#include <poll.h>
#include <float.h>
#include <mathlib/mathlib.h>
#include <string.h>
@@ -180,7 +178,7 @@ typedef struct {
int do_accel_calibration(orb_advert_t *mavlink_log_pub)
{
#ifdef __PX4_NUTTX
#if 1 // TODO: replace all IOCTL usage
int fd;
#endif
@@ -200,7 +198,7 @@ int do_accel_calibration(orb_advert_t *mavlink_log_pub)
/* reset all sensors */
for (unsigned s = 0; s < max_accel_sens; s++) {
#ifdef __PX4_NUTTX
#if 1 // TODO: replace all IOCTL usage
sprintf(str, "%s%u", ACCEL_BASE_DEVICE_PATH, s);
/* reset all offsets to zero and all scales to one */
fd = px4_open(str, 0);
@@ -422,7 +420,7 @@ int do_accel_calibration(orb_advert_t *mavlink_log_pub)
return PX4_ERROR;
}
#ifdef __PX4_NUTTX
#if 1 // TODO: replace all IOCTL usage
sprintf(str, "%s%u", ACCEL_BASE_DEVICE_PATH, uorb_index);
fd = px4_open(str, 0);
@@ -525,7 +523,7 @@ calibrate_return do_accel_calibration_measurements(orb_advert_t *mavlink_log_pub
sensor_accel_s report = {};
orb_copy(ORB_ID(sensor_accel), worker_data.subs[cur_accel], &report);
#ifdef __PX4_NUTTX
#if 1 // TODO: replace all IOCTL usage
// For NuttX, we get the UNIQUE device ID from the sensor driver via an IOCTL
// and match it up with the one from the uORB subscription, because the
@@ -47,7 +47,6 @@
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
#include <math.h>
#include <drivers/drv_hrt.h>
#include <drivers/drv_airspeed.h>
@@ -38,7 +38,6 @@
#include "baro_calibration.h"
#include <poll.h>
#include <math.h>
#include <fcntl.h>
#include <px4_platform_common/defines.h>
@@ -45,7 +45,6 @@
#include <unistd.h>
#include <math.h>
#include <float.h>
#include <poll.h>
#include <drivers/drv_hrt.h>
#include <systemlib/mavlink_log.h>
#include <lib/ecl/geo/geo.h>
+1 -29
View File
@@ -57,35 +57,8 @@ using namespace time_literals;
int do_esc_calibration(orb_advert_t *mavlink_log_pub, struct actuator_armed_s *armed)
{
int return_code = PX4_OK;
#if defined(__PX4_POSIX_OCPOC) || defined(__PX4_POSIX_BBBLUE)
hrt_abstime timeout_start = 0;
hrt_abstime timeout_wait = 60_s;
armed->in_esc_calibration_mode = true;
calibration_log_info(mavlink_log_pub, CAL_QGC_DONE_MSG, "begin esc");
timeout_start = hrt_absolute_time();
while (true) {
if (hrt_absolute_time() - timeout_start > timeout_wait) {
break;
} else {
px4_usleep(50000);
}
}
armed->in_esc_calibration_mode = false;
calibration_log_info(mavlink_log_pub, CAL_QGC_DONE_MSG, "end esc");
if (return_code == OK) {
calibration_log_info(mavlink_log_pub, CAL_QGC_DONE_MSG, "esc");
}
return return_code;
#else
int fd = -1;
bool batt_connected = true; // for safety resons assume battery is connected, will be cleared below if not the case
bool batt_connected = true; // for safety reasons assume battery is connected, will be cleared below if not the case
hrt_abstime timeout_start = 0;
calibration_log_info(mavlink_log_pub, CAL_QGC_STARTED_MSG, "esc");
@@ -207,5 +180,4 @@ Out:
}
return return_code;
#endif
}
+3 -4
View File
@@ -49,7 +49,6 @@
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
#include <math.h>
#include <mathlib/mathlib.h>
#include <string.h>
@@ -240,7 +239,7 @@ int do_gyro_calibration(orb_advert_t *mavlink_log_pub)
// Reset all offsets to 0
(void)memcpy(&worker_data.gyro_scale[s], &gyro_scale_zero, sizeof(gyro_scale_zero));
#ifdef __PX4_NUTTX
#if 1 // TODO: replace all IOCTL usage
sprintf(str, "%s%u", GYRO_BASE_DEVICE_PATH, s);
int fd = px4_open(str, 0);
@@ -301,7 +300,7 @@ int do_gyro_calibration(orb_advert_t *mavlink_log_pub)
sensor_gyro_s report{};
orb_copy(ORB_ID(sensor_gyro), worker_data.gyro_sensor_sub[cur_gyro], &report);
#ifdef __PX4_NUTTX
#if 1 // TODO: replace all IOCTL usage
// For NuttX, we get the UNIQUE device ID from the sensor driver via an IOCTL
// and match it up with the one from the uORB subscription, because the
@@ -473,7 +472,7 @@ int do_gyro_calibration(orb_advert_t *mavlink_log_pub)
(void)sprintf(str, "CAL_GYRO%u_ID", uorb_index);
failed |= (PX4_OK != param_set_no_notification(param_find(str), &(worker_data.device_id[uorb_index])));
#ifdef __PX4_NUTTX
#if 1 // TODO: replace all IOCTL usage
/* apply new scaling and offsets */
(void)sprintf(str, "%s%u", GYRO_BASE_DEVICE_PATH, uorb_index);
int fd = px4_open(str, 0);
+8 -12
View File
@@ -49,7 +49,6 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <poll.h>
#include <math.h>
#include <fcntl.h>
#include <drivers/drv_hrt.h>
@@ -153,7 +152,7 @@ int do_mag_calibration(orb_advert_t *mavlink_log_pub)
(void)append_to_existing_calibration;
for (unsigned cur_mag = 0; cur_mag < max_mags; cur_mag++) {
#ifdef __PX4_NUTTX
#if 1 // TODO: replace all IOCTL usage
// Reset mag id to mag not available
(void)sprintf(str, "CAL_MAG%u_ID", cur_mag);
result = param_set_no_notification(param_find(str), &(device_ids[cur_mag]));
@@ -210,7 +209,7 @@ int do_mag_calibration(orb_advert_t *mavlink_log_pub)
param_notify_changes();
#ifdef __PX4_NUTTX
#if 1 // TODO: replace all IOCTL usage
// Attempt to open mag
(void)sprintf(str, "%s%u", MAG_BASE_DEVICE_PATH, cur_mag);
int fd = px4_open(str, O_RDONLY);
@@ -609,7 +608,7 @@ calibrate_return mag_calibrate_all(orb_advert_t *mavlink_log_pub, int32_t cal_ma
sensor_mag_s report{};
orb_copy(ORB_ID(sensor_mag), worker_data.sub_mag[cur_mag], &report);
#ifdef __PX4_NUTTX
#if 1 // TODO: replace all IOCTL usage
// For NuttX, we get the UNIQUE device ID from the sensor driver via an IOCTL
// and match it up with the one from the uORB subscription, because the
@@ -804,7 +803,7 @@ calibrate_return mag_calibrate_all(orb_advert_t *mavlink_log_pub, int32_t cal_ma
if (device_ids[cur_mag] != 0) {
mag_calibration_s mscale;
#ifdef __PX4_NUTTX
#if 1 // TODO: replace all IOCTL usage
int fd_mag = -1;
(void)sprintf(str, "%s%u", MAG_BASE_DEVICE_PATH, cur_mag);
@@ -819,7 +818,7 @@ calibrate_return mag_calibrate_all(orb_advert_t *mavlink_log_pub, int32_t cal_ma
if (result == calibrate_return_ok) {
#ifdef __PX4_NUTTX
#if 1 // TODO: replace all IOCTL usage
// Read existing calibration
if (px4_ioctl(fd_mag, MAGIOCGSCALE, (long unsigned int)&mscale) != PX4_OK) {
@@ -852,7 +851,7 @@ calibrate_return mag_calibrate_all(orb_advert_t *mavlink_log_pub, int32_t cal_ma
#endif
}
#ifdef __PX4_NUTTX
#if 1 // TODO: replace all IOCTL usage
// Mag device no longer needed
if (fd_mag >= 0) {
@@ -875,15 +874,12 @@ calibrate_return mag_calibrate_all(orb_advert_t *mavlink_log_pub, int32_t cal_ma
(void)sprintf(str, "CAL_MAG%u_ZOFF", cur_mag);
failed |= (PX4_OK != param_set_no_notification(param_find(str), &(mscale.z_offset)));
// FIXME: scaling is not used right now on QURT
#ifndef __PX4_QURT
(void)sprintf(str, "CAL_MAG%u_XSCALE", cur_mag);
failed |= (PX4_OK != param_set_no_notification(param_find(str), &(mscale.x_scale)));
(void)sprintf(str, "CAL_MAG%u_YSCALE", cur_mag);
failed |= (PX4_OK != param_set_no_notification(param_find(str), &(mscale.y_scale)));
(void)sprintf(str, "CAL_MAG%u_ZSCALE", cur_mag);
failed |= (PX4_OK != param_set_no_notification(param_find(str), &(mscale.z_scale)));
#endif
if (failed) {
calibration_log_critical(mavlink_log_pub, CAL_ERROR_SET_PARAMS_MSG);
@@ -892,10 +888,10 @@ calibrate_return mag_calibrate_all(orb_advert_t *mavlink_log_pub, int32_t cal_ma
} else {
calibration_log_info(mavlink_log_pub, "[cal] mag #%u off: x:%.2f y:%.2f z:%.2f Ga",
cur_mag, (double)mscale.x_offset, (double)mscale.y_offset, (double)mscale.z_offset);
#ifndef __PX4_QURT
calibration_log_info(mavlink_log_pub, "[cal] mag #%u scale: x:%.2f y:%.2f z:%.2f",
cur_mag, (double)mscale.x_scale, (double)mscale.y_scale, (double)mscale.z_scale);
#endif
px4_usleep(200000);
}
}
@@ -100,7 +100,6 @@ Author: Siddharth Bharat Purohit
#include <fcntl.h>
#include <errno.h>
#include <math.h>
#include <poll.h>
#include <time.h>
#include <float.h>
#include <matrix/math.hpp>
+2
View File
@@ -47,7 +47,9 @@
#include <drivers/drv_tone_alarm.h>
#include <ecl/geo/geo.h>
#include <systemlib/px4_macros.h>
#include <math.h>
#include <poll.h>
#ifdef CONFIG_NET
#include <net/if.h>
+5 -12
View File
@@ -68,14 +68,11 @@
#include <uORB/topics/vehicle_control_mode.h>
#include <uORB/topics/vehicle_magnetometer.h>
#include <DevMgr.hpp>
#include "parameters.h"
#include "voted_sensors_update.h"
#include "vehicle_acceleration/VehicleAcceleration.hpp"
#include "vehicle_angular_velocity/VehicleAngularVelocity.hpp"
using namespace DriverFramework;
using namespace sensors;
using namespace time_literals;
@@ -128,7 +125,7 @@ private:
DataValidator _airspeed_validator; /**< data validator to monitor airspeed */
#ifdef ADC_AIRSPEED_VOLTAGE_CHANNEL
DevHandle _h_adc; /**< ADC driver handle */
int _adc_fd {-1}; /**< ADC driver handle */
hrt_abstime _last_adc{0}; /**< last time we took input from the ADC */
@@ -219,17 +216,13 @@ Sensors::adc_init()
{
if (!_hil_enabled) {
#ifdef ADC_AIRSPEED_VOLTAGE_CHANNEL
_adc_fd = px4_open(ADC0_DEVICE_PATH, O_RDONLY);
DevMgr::getHandle(ADC0_DEVICE_PATH, _h_adc);
if (!_h_adc.isValid()) {
PX4_ERR("no ADC found: %s (%d)", ADC0_DEVICE_PATH, _h_adc.getError());
if (_adc_fd == -1) {
PX4_ERR("no ADC found: %s", ADC0_DEVICE_PATH);
return PX4_ERROR;
}
#endif // ADC_AIRSPEED_VOLTAGE_CHANNEL
}
@@ -345,7 +338,7 @@ Sensors::adc_poll()
/* make space for a maximum of twelve channels (to ensure reading all channels at once) */
px4_adc_msg_t buf_adc[PX4_MAX_ADC_CHANNELS];
/* read all channels available */
int ret = _h_adc.read(&buf_adc, sizeof(buf_adc));
int ret = px4_read(_adc_fd, &buf_adc, sizeof(buf_adc));
if (ret >= (int)sizeof(buf_adc[0])) {
+74 -122
View File
@@ -49,7 +49,6 @@
#define CAL_ERROR_APPLY_CAL_MSG "FAILED APPLYING %s CAL #%u"
using namespace sensors;
using namespace DriverFramework;
using namespace matrix;
VotedSensorsUpdate::VotedSensorsUpdate(const Parameters &parameters, bool hil_enabled)
@@ -202,26 +201,24 @@ void VotedSensorsUpdate::parametersUpdate()
/* set offset parameters to new values */
bool failed = false;
char str[30] {};
unsigned gyro_count = 0;
unsigned accel_count = 0;
unsigned gyro_cal_found_count = 0;
unsigned accel_cal_found_count = 0;
/* run through all gyro sensors */
unsigned gyro_count = 0;
unsigned gyro_cal_found_count = 0;
for (unsigned driver_index = 0; driver_index < GYRO_COUNT_MAX; driver_index++) {
_gyro.enabled[driver_index] = true;
char str[30] {};
(void)sprintf(str, "%s%u", GYRO_BASE_DEVICE_PATH, driver_index);
DevHandle h;
DevMgr::getHandle(str, h);
int fd = px4_open(str, O_RDWR);
if (!h.isValid()) {
if (fd < 0) {
continue;
}
uint32_t driver_device_id = h.ioctl(DEVIOCGDEVICEID, 0);
uint32_t driver_device_id = px4_ioctl(fd, DEVIOCGDEVICEID, 0);
bool config_ok = false;
/* run through all stored calibrations that are applied at the driver level*/
@@ -231,11 +228,11 @@ void VotedSensorsUpdate::parametersUpdate()
(void)sprintf(str, "CAL_GYRO%u_ID", i);
int32_t device_id = 0;
failed = failed || (OK != param_get(param_find(str), &device_id));
failed = failed || (PX4_OK != param_get(param_find(str), &device_id));
(void)sprintf(str, "CAL_GYRO%u_EN", i);
int32_t device_enabled = 1;
failed = failed || (OK != param_get(param_find(str), &device_enabled));
failed = failed || (PX4_OK != param_get(param_find(str), &device_enabled));
if (failed) {
continue;
@@ -249,28 +246,27 @@ void VotedSensorsUpdate::parametersUpdate()
if ((uint32_t)device_id == driver_device_id) {
_gyro.enabled[driver_index] = (device_enabled == 1);
if (!_gyro.enabled[driver_index]) { _gyro.priority[driver_index] = 0; }
if (!_gyro.enabled[driver_index]) {
_gyro.priority[driver_index] = 0;
}
struct gyro_calibration_s gscale = {};
gyro_calibration_s gscale{};
(void)sprintf(str, "CAL_GYRO%u_XOFF", i);
failed = failed || (OK != param_get(param_find(str), &gscale.x_offset));
failed = failed || (PX4_OK != param_get(param_find(str), &gscale.x_offset));
(void)sprintf(str, "CAL_GYRO%u_YOFF", i);
failed = failed || (OK != param_get(param_find(str), &gscale.y_offset));
failed = failed || (PX4_OK != param_get(param_find(str), &gscale.y_offset));
(void)sprintf(str, "CAL_GYRO%u_ZOFF", i);
failed = failed || (OK != param_get(param_find(str), &gscale.z_offset));
failed = failed || (PX4_OK != param_get(param_find(str), &gscale.z_offset));
if (failed) {
PX4_ERR(CAL_ERROR_APPLY_CAL_MSG, "gyro", i);
} else {
/* apply new scaling and offsets */
config_ok = applyGyroCalibration(h, &gscale, device_id);
config_ok = (px4_ioctl(fd, GYROIOCSSCALE, (long unsigned int)&gscale) == 0);
if (!config_ok) {
PX4_ERR(CAL_ERROR_APPLY_CAL_MSG, "gyro ", i);
@@ -284,35 +280,41 @@ void VotedSensorsUpdate::parametersUpdate()
if (config_ok) {
gyro_count++;
}
px4_close(fd);
}
// There are less gyros than calibrations
// There are fewer gyros than calibrations
// reset the board calibration and fail the initial load
if (gyro_count < gyro_cal_found_count) {
PX4_ERR("fewer accels than calibrations, resetting all CAL_GYROx_ID");
// run through all stored calibrations and reset them
for (unsigned i = 0; i < GYRO_COUNT_MAX; i++) {
int32_t device_id = 0;
char str[30] {};
(void)sprintf(str, "CAL_GYRO%u_ID", i);
int32_t device_id = 0;
(void)param_set(param_find(str), &device_id);
}
}
/* run through all accel sensors */
unsigned accel_count = 0;
unsigned accel_cal_found_count = 0;
for (unsigned driver_index = 0; driver_index < ACCEL_COUNT_MAX; driver_index++) {
_accel.enabled[driver_index] = true;
char str[30] {};
(void)sprintf(str, "%s%u", ACCEL_BASE_DEVICE_PATH, driver_index);
DevHandle h;
DevMgr::getHandle(str, h);
int fd = px4_open(str, O_RDWR);
if (!h.isValid()) {
if (fd < 0) {
continue;
}
uint32_t driver_device_id = h.ioctl(DEVIOCGDEVICEID, 0);
uint32_t driver_device_id = px4_ioctl(fd, DEVIOCGDEVICEID, 0);
bool config_ok = false;
/* run through all stored calibrations */
@@ -322,11 +324,11 @@ void VotedSensorsUpdate::parametersUpdate()
(void)sprintf(str, "CAL_ACC%u_ID", i);
int32_t device_id = 0;
failed = failed || (OK != param_get(param_find(str), &device_id));
failed = failed || (PX4_OK != param_get(param_find(str), &device_id));
(void)sprintf(str, "CAL_ACC%u_EN", i);
int32_t device_enabled = 1;
failed = failed || (OK != param_get(param_find(str), &device_enabled));
failed = failed || (PX4_OK != param_get(param_find(str), &device_enabled));
if (failed) {
continue;
@@ -340,40 +342,36 @@ void VotedSensorsUpdate::parametersUpdate()
if ((uint32_t)device_id == driver_device_id) {
_accel.enabled[driver_index] = (device_enabled == 1);
if (!_accel.enabled[driver_index]) { _accel.priority[driver_index] = 0; }
if (!_accel.enabled[driver_index]) {
_accel.priority[driver_index] = 0;
}
struct accel_calibration_s ascale = {};
accel_calibration_s ascale{};
(void)sprintf(str, "CAL_ACC%u_XOFF", i);
failed = failed || (OK != param_get(param_find(str), &ascale.x_offset));
failed = failed || (PX4_OK != param_get(param_find(str), &ascale.x_offset));
(void)sprintf(str, "CAL_ACC%u_YOFF", i);
failed = failed || (OK != param_get(param_find(str), &ascale.y_offset));
failed = failed || (PX4_OK != param_get(param_find(str), &ascale.y_offset));
(void)sprintf(str, "CAL_ACC%u_ZOFF", i);
failed = failed || (OK != param_get(param_find(str), &ascale.z_offset));
failed = failed || (PX4_OK != param_get(param_find(str), &ascale.z_offset));
(void)sprintf(str, "CAL_ACC%u_XSCALE", i);
failed = failed || (OK != param_get(param_find(str), &ascale.x_scale));
failed = failed || (PX4_OK != param_get(param_find(str), &ascale.x_scale));
(void)sprintf(str, "CAL_ACC%u_YSCALE", i);
failed = failed || (OK != param_get(param_find(str), &ascale.y_scale));
failed = failed || (PX4_OK != param_get(param_find(str), &ascale.y_scale));
(void)sprintf(str, "CAL_ACC%u_ZSCALE", i);
failed = failed || (OK != param_get(param_find(str), &ascale.z_scale));
failed = failed || (PX4_OK != param_get(param_find(str), &ascale.z_scale));
if (failed) {
PX4_ERR(CAL_ERROR_APPLY_CAL_MSG, "accel", i);
} else {
/* apply new scaling and offsets */
config_ok = applyAccelCalibration(h, &ascale, device_id);
config_ok = (px4_ioctl(fd, ACCELIOCSSCALE, (long unsigned int)&ascale) == 0);
if (!config_ok) {
PX4_ERR(CAL_ERROR_APPLY_CAL_MSG, "accel ", i);
@@ -387,17 +385,20 @@ void VotedSensorsUpdate::parametersUpdate()
if (config_ok) {
accel_count++;
}
px4_close(fd);
}
// There are less accels than calibrations
// There are fewer accels than calibrations
// reset the board calibration and fail the initial load
if (accel_count < accel_cal_found_count) {
PX4_ERR("fewer accels than calibrations, resetting all CAL_ACCx_ID");
// run through all stored calibrations and reset them
for (unsigned i = 0; i < ACCEL_COUNT_MAX; i++) {
int32_t device_id = 0;
char str[30] {};
(void)sprintf(str, "CAL_ACC%u_ID", i);
int32_t device_id = 0;
(void)param_set(param_find(str), &device_id);
}
}
@@ -417,37 +418,38 @@ void VotedSensorsUpdate::parametersUpdate()
for (int topic_instance = 0; topic_instance < MAG_COUNT_MAX
&& topic_instance < _mag.subscription_count; ++topic_instance) {
sensor_mag_s report;
sensor_mag_s report{};
if (orb_copy(ORB_ID(sensor_mag), _mag.subscription[topic_instance], &report) != 0) {
continue;
}
int topic_device_id = report.device_id;
uint32_t topic_device_id = report.device_id;
bool is_external = report.is_external;
_mag_device_id[topic_instance] = topic_device_id;
// find the driver handle that matches the topic_device_id
DevHandle h;
int fd = -1;
char str[30] {};
for (unsigned driver_index = 0; driver_index < MAG_COUNT_MAX; ++driver_index) {
(void)sprintf(str, "%s%u", MAG_BASE_DEVICE_PATH, driver_index);
DevMgr::getHandle(str, h);
fd = px4_open(str, O_RDWR);
if (!h.isValid()) {
if (fd < 0) {
/* the driver is not running, continue with the next */
continue;
}
int driver_device_id = h.ioctl(DEVIOCGDEVICEID, 0);
uint32_t driver_device_id = (uint32_t)px4_ioctl(fd, DEVIOCGDEVICEID, 0);
if (driver_device_id == topic_device_id) {
break; // we found the matching driver
} else {
DevMgr::releaseHandle(h);
px4_close(fd);
}
}
@@ -460,11 +462,11 @@ void VotedSensorsUpdate::parametersUpdate()
(void)sprintf(str, "CAL_MAG%u_ID", i);
int32_t device_id = 0;
failed = failed || (OK != param_get(param_find(str), &device_id));
failed = failed || (PX4_OK != param_get(param_find(str), &device_id));
(void)sprintf(str, "CAL_MAG%u_EN", i);
int32_t device_enabled = 1;
failed = failed || (OK != param_get(param_find(str), &device_enabled));
failed = failed || (PX4_OK != param_get(param_find(str), &device_enabled));
if (failed) {
continue;
@@ -476,38 +478,32 @@ void VotedSensorsUpdate::parametersUpdate()
// the mags that were published after the initial parameterUpdate
// would be given the priority even if disabled. Reset it to 0 in this case
if (!_mag.enabled[topic_instance]) { _mag.priority[topic_instance] = 0; }
if (!_mag.enabled[topic_instance]) {
_mag.priority[topic_instance] = 0;
}
struct mag_calibration_s mscale = {};
mag_calibration_s mscale{};
(void)sprintf(str, "CAL_MAG%u_XOFF", i);
failed = failed || (OK != param_get(param_find(str), &mscale.x_offset));
failed = failed || (PX4_OK != param_get(param_find(str), &mscale.x_offset));
(void)sprintf(str, "CAL_MAG%u_YOFF", i);
failed = failed || (OK != param_get(param_find(str), &mscale.y_offset));
failed = failed || (PX4_OK != param_get(param_find(str), &mscale.y_offset));
(void)sprintf(str, "CAL_MAG%u_ZOFF", i);
failed = failed || (OK != param_get(param_find(str), &mscale.z_offset));
failed = failed || (PX4_OK != param_get(param_find(str), &mscale.z_offset));
(void)sprintf(str, "CAL_MAG%u_XSCALE", i);
failed = failed || (OK != param_get(param_find(str), &mscale.x_scale));
failed = failed || (PX4_OK != param_get(param_find(str), &mscale.x_scale));
(void)sprintf(str, "CAL_MAG%u_YSCALE", i);
failed = failed || (OK != param_get(param_find(str), &mscale.y_scale));
failed = failed || (PX4_OK != param_get(param_find(str), &mscale.y_scale));
(void)sprintf(str, "CAL_MAG%u_ZSCALE", i);
failed = failed || (OK != param_get(param_find(str), &mscale.z_scale));
failed = failed || (PX4_OK != param_get(param_find(str), &mscale.z_scale));
(void)sprintf(str, "CAL_MAG%u_ROT", i);
int32_t mag_rot;
int32_t mag_rot = 0;
param_get(param_find(str), &mag_rot);
if (is_external) {
@@ -543,7 +539,7 @@ void VotedSensorsUpdate::parametersUpdate()
} else {
/* apply new scaling and offsets */
config_ok = applyMagCalibration(h, &mscale, device_id);
config_ok = (px4_ioctl(fd, MAGIOCSSCALE, (long unsigned int)&mscale) == 0);
if (!config_ok) {
PX4_ERR(CAL_ERROR_APPLY_CAL_MSG, "mag ", i);
@@ -553,6 +549,8 @@ void VotedSensorsUpdate::parametersUpdate()
break;
}
}
px4_close(fd);
}
}
@@ -848,7 +846,7 @@ void VotedSensorsUpdate::baroPoll(vehicle_air_data_s &airdata)
orb_check(_baro.subscription[uorb_index], &baro_updated);
if (baro_updated) {
sensor_baro_s baro_report;
sensor_baro_s baro_report{};
int ret = orb_copy(ORB_ID(sensor_baro), _baro.subscription[uorb_index], &baro_report);
@@ -1050,52 +1048,6 @@ void VotedSensorsUpdate::printStatus()
_temperature_compensation.print_status();
}
bool
VotedSensorsUpdate::applyGyroCalibration(DevHandle &h, const struct gyro_calibration_s *gcal, const int device_id)
{
#if defined(__PX4_NUTTX)
/* On most systems, we can just use the IOCTL call to set the calibration params. */
return !h.ioctl(GYROIOCSSCALE, (long unsigned int)gcal);
#else
/* On QURT, the params are read directly in the respective wrappers. */
return true;
#endif
}
bool
VotedSensorsUpdate::applyAccelCalibration(DevHandle &h, const struct accel_calibration_s *acal, const int device_id)
{
#if defined(__PX4_NUTTX)
/* On most systems, we can just use the IOCTL call to set the calibration params. */
return !h.ioctl(ACCELIOCSSCALE, (long unsigned int)acal);
#else
/* On QURT, the params are read directly in the respective wrappers. */
return true;
#endif
}
bool
VotedSensorsUpdate::applyMagCalibration(DevHandle &h, const struct mag_calibration_s *mcal, const int device_id)
{
#if defined(__PX4_NUTTX)
if (!h.isValid()) {
return false;
}
/* On most systems, we can just use the IOCTL call to set the calibration params. */
return !h.ioctl(MAGIOCSSCALE, (long unsigned int)mcal);
#else
/* On QURT & POSIX, the params are read directly in the respective wrappers. */
return true;
#endif
}
void VotedSensorsUpdate::sensorsPoll(sensor_combined_s &raw, vehicle_air_data_s &airdata,
vehicle_magnetometer_s &magnetometer)
{
@@ -62,8 +62,6 @@
#include <uORB/topics/vehicle_magnetometer.h>
#include <uORB/topics/subsystem_info.h>
#include <DevMgr.hpp>
#include "temperature_compensation.h"
#include "common.h"
@@ -211,37 +209,6 @@ private:
*/
bool checkFailover(SensorData &sensor, const char *sensor_name, const uint64_t type);
/**
* Apply a gyro calibration.
*
* @param h: reference to the DevHandle in use
* @param gscale: the calibration data.
* @param device: the device id of the sensor.
* @return: true if config is ok
*/
bool applyGyroCalibration(DriverFramework::DevHandle &h, const struct gyro_calibration_s *gcal, const int device_id);
/**
* Apply a accel calibration.
*
* @param h: reference to the DevHandle in use
* @param ascale: the calibration data.
* @param device: the device id of the sensor.
* @return: true if config is ok
*/
bool applyAccelCalibration(DriverFramework::DevHandle &h, const struct accel_calibration_s *acal,
const int device_id);
/**
* Apply a mag calibration.
*
* @param h: reference to the DevHandle in use
* @param gscale: the calibration data.
* @param device: the device id of the sensor.
* @return: true if config is ok
*/
bool applyMagCalibration(DriverFramework::DevHandle &h, const struct mag_calibration_s *mcal, const int device_id);
SensorData _accel {};
SensorData _gyro {};
SensorData _mag {};
+27 -4
View File
@@ -64,6 +64,21 @@ void Simulator::parameters_update(bool force)
}
}
void Simulator::print_status()
{
PX4_INFO("accelerometer");
_px4_accel.print_status();
PX4_INFO("gyroscope");
_px4_gyro.print_status();
PX4_INFO("magnetometer");
_px4_mag.print_status();
PX4_INFO("barometer");
_px4_baro.print_status();
}
int Simulator::start(int argc, char *argv[])
{
_instance = new Simulator();
@@ -79,9 +94,8 @@ int Simulator::start(int argc, char *argv[])
_instance->set_port(atoi(argv[3]));
}
#ifndef __PX4_QURT
_instance->run();
#endif
return 0;
} else {
@@ -92,7 +106,7 @@ int Simulator::start(int argc, char *argv[])
static void usage()
{
PX4_INFO("Usage: simulator {start -[spt] [-u udp_port / -c tcp_port] |stop}");
PX4_INFO("Usage: simulator {start -[spt] [-u udp_port / -c tcp_port] |stop|status}");
PX4_INFO("Start simulator: simulator start");
PX4_INFO("Connect using UDP: simulator start -u udp_port");
PX4_INFO("Connect using TCP: simulator start -c tcp_port");
@@ -119,7 +133,7 @@ int simulator_main(int argc, char *argv[])
Simulator::start,
argv);
#if !defined(__PX4_QURT) && defined(ENABLE_LOCKSTEP_SCHEDULER)
#if defined(ENABLE_LOCKSTEP_SCHEDULER)
// We want to prevent the rest of the startup script from running until time
// is initialized by the HIL_SENSOR messages from the simulator.
@@ -143,6 +157,15 @@ int simulator_main(int argc, char *argv[])
g_sim_task = -1;
}
} else if (argc == 2 && strcmp(argv[1], "status") == 0) {
if (g_sim_task < 0) {
PX4_WARN("Simulator not running");
return 1;
} else {
Simulator::getInstance()->print_status();
}
} else {
usage();
return 1;
+3 -5
View File
@@ -95,9 +95,11 @@ public:
void set_port(unsigned port) { _port = port; }
#if defined(ENABLE_LOCKSTEP_SCHEDULER)
bool has_initialized() {return _has_initialized.load(); }
bool has_initialized() { return _has_initialized.load(); }
#endif
void print_status();
private:
Simulator() : ModuleParams(nullptr)
{
@@ -172,8 +174,6 @@ private:
}
} _battery;
#ifndef __PX4_QURT
void run();
void handle_message(const mavlink_message_t *msg);
void handle_message_distance_sensor(const mavlink_message_t *msg);
@@ -248,6 +248,4 @@ private:
(ParamInt<px4::params::MAV_SYS_ID>) _param_mav_sys_id,
(ParamInt<px4::params::MAV_COMP_ID>) _param_mav_comp_id
)
#endif
};
+14 -11
View File
@@ -33,22 +33,25 @@
*
****************************************************************************/
#include <termios.h>
#include "simulator.h"
#include <simulator_config.h>
#include <px4_platform_common/log.h>
#include <px4_platform_common/time.h>
#include <px4_platform_common/tasks.h>
#include "simulator.h"
#include <simulator_config.h>
#include "errno.h"
#include <lib/ecl/geo/geo.h>
#include <drivers/drv_pwm_output.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <pthread.h>
#include <conversion/rotation.h>
#include <mathlib/mathlib.h>
#include <errno.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <poll.h>
#include <pthread.h>
#include <sys/socket.h>
#include <termios.h>
#include <limits>
#ifdef ENABLE_UART_RC_INPUT
@@ -957,7 +960,7 @@ int Simulator::publish_flow_topic(const mavlink_hil_optical_flow_t *flow_mavlink
_flow_pub.publish(flow);
return OK;
return PX4_OK;
}
int Simulator::publish_odometry_topic(const mavlink_message_t *odom_mavlink)
@@ -1062,7 +1065,7 @@ int Simulator::publish_odometry_topic(const mavlink_message_t *odom_mavlink)
/** @note: frame_id == MAV_FRAME_VISION_NED) */
_visual_odometry_pub.publish(odom);
return OK;
return PX4_OK;
}
int Simulator::publish_distance_topic(const mavlink_distance_sensor_t *dist_mavlink)
@@ -1087,5 +1090,5 @@ int Simulator::publish_distance_topic(const mavlink_distance_sensor_t *dist_mavl
_dist_pub.publish(dist);
return OK;
return PX4_OK;
}
+5 -1
View File
@@ -43,6 +43,10 @@
#include <px4_platform_common/sem.hpp>
#include <systemlib/px4_macros.h>
#ifndef __PX4_QURT // QuRT has no poll()
#include <poll.h>
#endif // PX4_QURT
uORB::DeviceMaster::DeviceMaster()
{
px4_sem_init(&_lock, 0, 1);
@@ -330,7 +334,7 @@ void uORB::DeviceMaster::showTop(char **topic_filter, int num_filters)
PX4_ERR("addNewDeviceNodes failed (%i)", ret);
}
#ifdef __PX4_QURT //QuRT has no poll()
#ifdef __PX4_QURT // QuRT has no poll()
only_once = true;
#else
const int stdin_fileno = 0;
+2 -2
View File
@@ -480,7 +480,7 @@ int16_t uORB::DeviceNode::topic_unadvertised(const orb_metadata *meta, int prior
*/
#endif /* ORB_COMMUNICATOR */
pollevent_t
px4_pollevent_t
uORB::DeviceNode::poll_state(cdev::file_t *filp)
{
SubscriberData *sd = filp_to_sd(filp);
@@ -496,7 +496,7 @@ uORB::DeviceNode::poll_state(cdev::file_t *filp)
}
void
uORB::DeviceNode::poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events)
uORB::DeviceNode::poll_notify_one(px4_pollfd_struct_t *fds, px4_pollevent_t events)
{
SubscriberData *sd = filp_to_sd((cdev::file_t *)fds->priv);
+2 -2
View File
@@ -235,9 +235,9 @@ public:
protected:
pollevent_t poll_state(cdev::file_t *filp) override;
px4_pollevent_t poll_state(cdev::file_t *filp) override;
void poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events) override;
void poll_notify_one(px4_pollfd_struct_t *fds, px4_pollevent_t events) override;
private:
+1 -1
View File
@@ -113,7 +113,7 @@ uorb_main(int argc, char *argv[])
return -errno;
}
#if !defined(__PX4_QURT) && !defined(__PX4_POSIX_EAGLE) && !defined(__PX4_POSIX_EXCELSIOR)
#if !defined(__PX4_QURT)
/* FIXME: this fails on Snapdragon (see https://github.com/PX4/Firmware/issues/5406),
* so we disable logging messages to the ulog for now. This needs further investigations.
*/
@@ -37,7 +37,6 @@
#include <px4_platform_common/time.h>
#include <stdio.h>
#include <errno.h>
#include <poll.h>
#include <math.h>
#include <lib/cdev/CDev.hpp>
@@ -36,9 +36,7 @@
#include "../uORB.h"
#include "../uORBCommon.hpp"
#ifndef __PX4_QURT
#include "uORBTest_UnitTest.hpp"
#endif
extern "C" { __EXPORT int uorb_tests_main(int argc, char *argv[]); }
@@ -50,9 +48,6 @@ static void usage()
int
uorb_tests_main(int argc, char *argv[])
{
#ifndef __PX4_QURT
/*
* Test the driver/device.
*/
@@ -88,8 +83,6 @@ uorb_tests_main(int argc, char *argv[])
}
}
#endif
usage();
return -EINVAL;
}