Make DMA pulse width work
The sensors return 1 when there is no ball...
Also fix a move before get to a get before move to fix a segfault
Change-Id: If7ebcda52c18f011eb7583a494eb52a8d038cb1b
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/frc971/wpilib/dma_edge_counting.cc b/frc971/wpilib/dma_edge_counting.cc
index ca7e095..ca2a10e 100644
--- a/frc971/wpilib/dma_edge_counting.cc
+++ b/frc971/wpilib/dma_edge_counting.cc
@@ -33,22 +33,22 @@
}
void DMAPulseSeparationReader::UpdateFromSample(const DMASample &sample) {
- // save the time of the rising edge of the input one
- if (have_prev_sample_ && sample.Get(input_one_) &&
- !prev_sample_.Get(input_one_)) {
+ // save the time of the falling edge of the input one
+ if (have_prev_sample_ && !sample.Get(input_one_) &&
+ prev_sample_.Get(input_one_)) {
input_one_time_ = sample.GetTimestamp();
}
- have_prev_sample_ = true;
- prev_sample_ = sample;
-
- // take the difference in time between the rising edge of the input one and
- // the rising edge of the input two
- if (sample.Get(input_two_) && input_one_time_.has_value()) {
+ // take the difference in time between the falling edge of the input one and
+ // the falling edge of the input two
+ if (!sample.Get(input_two_) && input_one_time_.has_value()) {
last_width_ = sample.GetTimestamp() - input_one_time_.value();
pulses_detected_++;
input_one_time_.reset();
}
+
+ have_prev_sample_ = true;
+ prev_sample_ = sample;
}
void DMASynchronizer::CheckDMA() {