AP_RPM: added optional PWM logging

This commit is contained in:
Andrew Tridgell 2015-11-19 11:00:39 +11:00
parent cbaa57c7be
commit 7375f395f9
2 changed files with 15 additions and 0 deletions

View File

@ -32,6 +32,8 @@
#include <errno.h>
#include <math.h>
#define PWM_LOGGING 0
extern const AP_HAL::HAL& hal;
/*
@ -53,6 +55,10 @@ AP_RPM_PX4_PWM::AP_RPM_PX4_PWM(AP_RPM &_ap_rpm, uint8_t instance, AP_RPM::RPM_St
_fd = -1;
return;
}
#if PWM_LOGGING
_logfd = open("/fs/microsd/pwm.log", O_WRONLY|O_CREAT|O_TRUNC, 0644);
#endif
}
/*
@ -88,6 +94,14 @@ void AP_RPM_PX4_PWM::update(void)
sum += rpm;
count++;
}
#if PWM_LOGGING
if (_logfd != -1) {
dprintf(_logfd, "%u %u %u\n",
(unsigned)pwm.timestamp/1000,
(unsigned)pwm.period,
(unsigned)pwm.pulse_width);
}
#endif
}
if (count != 0) {

View File

@ -34,6 +34,7 @@ public:
private:
int _fd = -1;
int _logfd = -1;
uint64_t _last_timestamp = 0;
};