2015-08-07 00:37:06 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-02-17 21:25:46 -04:00
|
|
|
#pragma once
|
2015-08-07 00:37:06 -03:00
|
|
|
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
|
|
|
|
// Maximum number of RPM measurement instances available on this platform
|
|
|
|
#define RPM_MAX_INSTANCES 2
|
|
|
|
|
2017-08-25 15:49:28 -03:00
|
|
|
class AP_RPM_Backend;
|
|
|
|
|
2015-08-07 00:37:06 -03:00
|
|
|
class AP_RPM
|
|
|
|
{
|
|
|
|
friend class AP_RPM_Backend;
|
|
|
|
|
2017-08-25 15:49:28 -03:00
|
|
|
public:
|
2017-12-12 21:06:14 -04:00
|
|
|
AP_RPM();
|
2017-08-25 15:49:28 -03:00
|
|
|
|
|
|
|
/* Do not allow copies */
|
|
|
|
AP_RPM(const AP_RPM &other) = delete;
|
|
|
|
AP_RPM &operator=(const AP_RPM&) = delete;
|
2015-08-07 00:37:06 -03:00
|
|
|
|
|
|
|
// RPM driver types
|
|
|
|
enum RPM_Type {
|
|
|
|
RPM_TYPE_NONE = 0,
|
2019-10-17 03:04:59 -03:00
|
|
|
RPM_TYPE_PWM = 1,
|
2019-11-11 00:37:44 -04:00
|
|
|
RPM_TYPE_PIN = 2,
|
2020-04-06 09:54:00 -03:00
|
|
|
RPM_TYPE_EFI = 3,
|
2021-02-25 02:21:52 -04:00
|
|
|
RPM_TYPE_HNTCH = 4,
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
RPM_TYPE_SITL = 10,
|
|
|
|
#endif
|
2015-08-07 00:37:06 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// The RPM_State structure is filled in by the backend driver
|
|
|
|
struct RPM_State {
|
|
|
|
uint8_t instance; // the instance number of this RPM
|
|
|
|
float rate_rpm; // measured rate in revs per minute
|
|
|
|
uint32_t last_reading_ms; // time of last reading
|
2015-11-19 22:00:41 -04:00
|
|
|
float signal_quality; // synthetic quality metric
|
2015-08-07 00:37:06 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// parameters for each instance
|
|
|
|
AP_Int8 _type[RPM_MAX_INSTANCES];
|
2017-04-02 00:57:59 -03:00
|
|
|
AP_Int8 _pin[RPM_MAX_INSTANCES];
|
2015-08-07 00:37:06 -03:00
|
|
|
AP_Float _scaling[RPM_MAX_INSTANCES];
|
2015-08-08 07:00:36 -03:00
|
|
|
AP_Float _maximum[RPM_MAX_INSTANCES];
|
2015-11-20 18:07:41 -04:00
|
|
|
AP_Float _minimum[RPM_MAX_INSTANCES];
|
2015-11-20 20:18:12 -04:00
|
|
|
AP_Float _quality_min[RPM_MAX_INSTANCES];
|
2015-08-07 00:37:06 -03:00
|
|
|
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
2017-08-25 15:49:28 -03:00
|
|
|
|
2015-08-07 00:37:06 -03:00
|
|
|
// Return the number of rpm sensor instances
|
|
|
|
uint8_t num_sensors(void) const {
|
|
|
|
return num_instances;
|
|
|
|
}
|
|
|
|
|
|
|
|
// detect and initialise any available rpm sensors
|
|
|
|
void init(void);
|
|
|
|
|
|
|
|
// update state of all rpm sensors. Should be called from main loop
|
|
|
|
void update(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
return RPM for a sensor. Return -1 if not healthy
|
|
|
|
*/
|
2020-03-05 19:46:27 -04:00
|
|
|
bool get_rpm(uint8_t instance, float &rpm_value) const;
|
2015-08-07 00:37:06 -03:00
|
|
|
|
2015-11-19 22:00:41 -04:00
|
|
|
/*
|
|
|
|
return signal quality for a sensor.
|
|
|
|
*/
|
|
|
|
float get_signal_quality(uint8_t instance) const {
|
|
|
|
return state[instance].signal_quality;
|
|
|
|
}
|
|
|
|
|
2015-08-07 00:37:06 -03:00
|
|
|
bool healthy(uint8_t instance) const;
|
|
|
|
|
2015-11-18 19:59:10 -04:00
|
|
|
bool enabled(uint8_t instance) const;
|
|
|
|
|
2019-02-25 12:48:19 -04:00
|
|
|
static AP_RPM *get_singleton() { return _singleton; }
|
|
|
|
|
2015-08-07 00:37:06 -03:00
|
|
|
private:
|
2019-02-25 12:48:19 -04:00
|
|
|
static AP_RPM *_singleton;
|
|
|
|
|
2015-08-07 00:37:06 -03:00
|
|
|
RPM_State state[RPM_MAX_INSTANCES];
|
|
|
|
AP_RPM_Backend *drivers[RPM_MAX_INSTANCES];
|
|
|
|
uint8_t num_instances:2;
|
|
|
|
|
|
|
|
void detect_instance(uint8_t instance);
|
|
|
|
};
|
2019-03-15 08:15:44 -03:00
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_RPM *rpm();
|
|
|
|
};
|