AP_RPM: allow for low RPM measurements on PX4

this automatically adjusts the timer resolution to allow for low RPM
measurements on PX4
This commit is contained in:
Andrew Tridgell 2016-05-14 18:05:13 +10:00
parent 78d6291e2c
commit 8571202199
3 changed files with 12 additions and 2 deletions

View File

@ -38,13 +38,13 @@ const AP_Param::GroupInfo AP_RPM::var_info[] = {
// @DisplayName: Maximum RPM // @DisplayName: Maximum RPM
// @Description: Maximum RPM to report // @Description: Maximum RPM to report
// @Increment: 1 // @Increment: 1
AP_GROUPINFO("_MAX", 2, AP_RPM, _maximum[0], 0), AP_GROUPINFO("_MAX", 2, AP_RPM, _maximum[0], 100000),
// @Param: _MIN // @Param: _MIN
// @DisplayName: Minimum RPM // @DisplayName: Minimum RPM
// @Description: Minimum RPM to report // @Description: Minimum RPM to report
// @Increment: 1 // @Increment: 1
AP_GROUPINFO("_MIN", 3, AP_RPM, _minimum[0], 0), AP_GROUPINFO("_MIN", 3, AP_RPM, _minimum[0], 10),
// @Param: _MIN_QUAL // @Param: _MIN_QUAL
// @DisplayName: Minimum Quality // @DisplayName: Minimum Quality

View File

@ -56,6 +56,9 @@ AP_RPM_PX4_PWM::AP_RPM_PX4_PWM(AP_RPM &_ap_rpm, uint8_t instance, AP_RPM::RPM_St
return; return;
} }
_resolution_usec = PWMIN_MINRPM_TO_RESOLUTION(((uint32_t)(ap_rpm._minimum[state.instance]+0.5f)));
ioctl(_fd, PWMINIOSRESOLUTION, _resolution_usec);
#if PWM_LOGGING #if PWM_LOGGING
_logfd = open("/fs/microsd/pwm.log", O_WRONLY|O_CREAT|O_TRUNC, 0644); _logfd = open("/fs/microsd/pwm.log", O_WRONLY|O_CREAT|O_TRUNC, 0644);
#endif #endif
@ -78,6 +81,12 @@ void AP_RPM_PX4_PWM::update(void)
return; return;
} }
uint32_t newres = PWMIN_MINRPM_TO_RESOLUTION(((uint32_t)(ap_rpm._minimum[state.instance]+0.5f)));
if (newres != _resolution_usec) {
ioctl(_fd, PWMINIOSRESOLUTION, newres);
_resolution_usec = newres;
}
struct pwm_input_s pwm; struct pwm_input_s pwm;
uint16_t count = 0; uint16_t count = 0;
const float scaling = ap_rpm._scaling[state.instance]; const float scaling = ap_rpm._scaling[state.instance];

View File

@ -36,6 +36,7 @@ private:
int _fd = -1; int _fd = -1;
int _logfd = -1; int _logfd = -1;
uint64_t _last_timestamp = 0; uint64_t _last_timestamp = 0;
uint32_t _resolution_usec = 1;
ModeFilterFloat_Size5 signal_quality_filter {3}; ModeFilterFloat_Size5 signal_quality_filter {3};
}; };