2019-08-06 12:55:25 -04:00
|
|
|
/****************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2019 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
|
|
|
|
|
|
2019-08-07 05:05:48 -04:00
|
|
|
#include <lib/conversion/rotation.h>
|
|
|
|
|
#include <lib/mathlib/math/Limits.hpp>
|
|
|
|
|
#include <lib/matrix/matrix/math.hpp>
|
2020-01-27 10:05:33 -05:00
|
|
|
#include <lib/mathlib/math/filter/LowPassFilter2pArray.hpp>
|
|
|
|
|
#include <lib/mathlib/math/filter/LowPassFilter2pVector3f.hpp>
|
|
|
|
|
#include <lib/mathlib/math/filter/NotchFilter.hpp>
|
2019-10-25 10:56:32 +02:00
|
|
|
#include <px4_platform_common/log.h>
|
|
|
|
|
#include <px4_platform_common/module_params.h>
|
2020-01-26 17:19:47 -05:00
|
|
|
#include <px4_platform_common/px4_config.h>
|
2019-08-27 10:57:38 +02:00
|
|
|
#include <px4_platform_common/px4_work_queue/WorkItem.hpp>
|
2019-08-06 12:55:25 -04:00
|
|
|
#include <uORB/Publication.hpp>
|
|
|
|
|
#include <uORB/Subscription.hpp>
|
|
|
|
|
#include <uORB/SubscriptionCallback.hpp>
|
2020-01-26 17:19:47 -05:00
|
|
|
#include <uORB/topics/estimator_sensor_bias.h>
|
2019-08-06 12:55:25 -04:00
|
|
|
#include <uORB/topics/parameter_update.h>
|
|
|
|
|
#include <uORB/topics/sensor_correction.h>
|
2019-08-07 05:05:48 -04:00
|
|
|
#include <uORB/topics/sensor_gyro.h>
|
2020-01-26 17:19:47 -05:00
|
|
|
#include <uORB/topics/sensor_selection.h>
|
2019-08-07 05:05:48 -04:00
|
|
|
#include <uORB/topics/vehicle_angular_velocity.h>
|
2019-08-06 12:55:25 -04:00
|
|
|
|
|
|
|
|
class VehicleAngularVelocity : public ModuleParams, public px4::WorkItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
VehicleAngularVelocity();
|
2020-01-18 01:15:00 -05:00
|
|
|
~VehicleAngularVelocity() override;
|
2019-08-06 12:55:25 -04:00
|
|
|
|
2020-01-21 16:47:38 -05:00
|
|
|
bool Start();
|
|
|
|
|
void Stop();
|
2019-08-06 12:55:25 -04:00
|
|
|
|
2020-01-21 16:47:38 -05:00
|
|
|
void PrintStatus();
|
2019-08-06 12:55:25 -04:00
|
|
|
|
|
|
|
|
private:
|
2020-01-21 16:47:38 -05:00
|
|
|
void Run() override;
|
|
|
|
|
|
2020-01-27 10:05:33 -05:00
|
|
|
void CheckFilters(const matrix::Vector3f &rates);
|
2020-01-18 01:15:00 -05:00
|
|
|
void ParametersUpdate(bool force = false);
|
|
|
|
|
void SensorBiasUpdate(bool force = false);
|
|
|
|
|
void SensorCorrectionsUpdate(bool force = false);
|
|
|
|
|
bool SensorSelectionUpdate(bool force = false);
|
2019-08-06 12:55:25 -04:00
|
|
|
|
2019-08-07 05:05:48 -04:00
|
|
|
static constexpr int MAX_SENSOR_COUNT = 3;
|
2019-08-06 12:55:25 -04:00
|
|
|
|
|
|
|
|
DEFINE_PARAMETERS(
|
2020-01-27 10:05:33 -05:00
|
|
|
(ParamFloat<px4::params::IMU_GYRO_CUTOFF>) _param_imu_gyro_cutoff,
|
|
|
|
|
(ParamFloat<px4::params::IMU_GYRO_NF_FREQ>) _param_imu_gyro_nf_freq,
|
|
|
|
|
(ParamFloat<px4::params::IMU_GYRO_NF_BW>) _param_imu_gyro_nf_bw,
|
|
|
|
|
(ParamInt<px4::params::IMU_GYRO_RATEMAX>) _param_imu_gyro_rate_max,
|
|
|
|
|
|
2019-08-06 12:55:25 -04:00
|
|
|
(ParamInt<px4::params::SENS_BOARD_ROT>) _param_sens_board_rot,
|
|
|
|
|
|
|
|
|
|
(ParamFloat<px4::params::SENS_BOARD_X_OFF>) _param_sens_board_x_off,
|
|
|
|
|
(ParamFloat<px4::params::SENS_BOARD_Y_OFF>) _param_sens_board_y_off,
|
|
|
|
|
(ParamFloat<px4::params::SENS_BOARD_Z_OFF>) _param_sens_board_z_off
|
|
|
|
|
)
|
|
|
|
|
|
2020-01-21 16:47:38 -05:00
|
|
|
uORB::Publication<vehicle_angular_velocity_s> _vehicle_angular_velocity_pub{ORB_ID(vehicle_angular_velocity)};
|
2019-08-06 12:55:25 -04:00
|
|
|
|
2020-01-21 16:47:38 -05:00
|
|
|
uORB::Subscription _params_sub{ORB_ID(parameter_update)};
|
2020-01-26 17:19:47 -05:00
|
|
|
uORB::Subscription _estimator_sensor_bias_sub{ORB_ID(estimator_sensor_bias)};
|
2020-01-21 16:47:38 -05:00
|
|
|
uORB::Subscription _sensor_correction_sub{ORB_ID(sensor_correction)};
|
2019-08-06 12:55:25 -04:00
|
|
|
|
2020-01-21 16:47:38 -05:00
|
|
|
uORB::SubscriptionCallbackWorkItem _sensor_selection_sub{this, ORB_ID(sensor_selection)};
|
|
|
|
|
uORB::SubscriptionCallbackWorkItem _sensor_sub[MAX_SENSOR_COUNT] {
|
2019-08-06 12:55:25 -04:00
|
|
|
{this, ORB_ID(sensor_gyro), 0},
|
|
|
|
|
{this, ORB_ID(sensor_gyro), 1},
|
|
|
|
|
{this, ORB_ID(sensor_gyro), 2}
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-27 10:05:33 -05:00
|
|
|
perf_counter_t _interval_perf{perf_alloc(PC_INTERVAL, MODULE_NAME": interval")};
|
|
|
|
|
|
2020-01-21 16:47:38 -05:00
|
|
|
matrix::Dcmf _board_rotation;
|
2019-08-06 12:55:25 -04:00
|
|
|
|
2020-01-21 16:47:38 -05:00
|
|
|
matrix::Vector3f _bias{0.f, 0.f, 0.f};
|
|
|
|
|
matrix::Vector3f _offset{0.f, 0.f, 0.f};
|
|
|
|
|
matrix::Vector3f _scale{1.f, 1.f, 1.f};
|
2019-08-06 12:55:25 -04:00
|
|
|
|
2020-01-27 10:05:33 -05:00
|
|
|
hrt_abstime _last_publish{0};
|
|
|
|
|
hrt_abstime _filter_check_last{0};
|
|
|
|
|
static constexpr const float kInitialRateHz{1000.0f}; /**< sensor update rate used for initialization */
|
|
|
|
|
float _update_rate_hz{kInitialRateHz}; /**< current rate-controller loop update rate in [Hz] */
|
|
|
|
|
math::LowPassFilter2pVector3f _lowpass_filter{kInitialRateHz, 30};
|
|
|
|
|
math::NotchFilter<matrix::Vector3f> _notch_filter{};
|
|
|
|
|
float _filter_sample_rate{kInitialRateHz};
|
|
|
|
|
int _sample_rate_incorrect_count{0};
|
|
|
|
|
|
2020-01-21 16:47:38 -05:00
|
|
|
uint32_t _selected_sensor_device_id{0};
|
|
|
|
|
uint8_t _selected_sensor_sub_index{0};
|
|
|
|
|
int8_t _corrections_selected_instance{-1};
|
2019-08-06 12:55:25 -04:00
|
|
|
};
|