added analog sensors and cleaned up the sensor data structure a bit
diff --git a/frc971/input/gyro_sensor_receiver.cc b/frc971/input/gyro_sensor_receiver.cc
index 42b50c8..5f0ce57 100644
--- a/frc971/input/gyro_sensor_receiver.cc
+++ b/frc971/input/gyro_sensor_receiver.cc
@@ -53,11 +53,21 @@
(1.0) /*gears*/ * (2 * M_PI);
}
+// Translates values from the ADC into voltage.
+inline double adc_translate(uint16_t in) {
+ static const double kVRefN = 0;
+ static const double kVRefP = 3.3;
+ static const int kMaximumValue = 0x3FF;
+ return kVRefN +
+ (static_cast<double>(in) / static_cast<double>(kMaximumValue) *
+ (kVRefP - kVRefN));
+}
+
} // namespace
class GyroSensorReceiver : public USBReceiver {
virtual void ProcessData() override {
- if (data()->robot_id != 0) {
+ if (data()->robot_id != 2) {
LOG(ERROR, "gyro board sent data for robot id %hhd!"
" dip switches are %x\n",
data()->robot_id, data()->base_status & 0xF);
diff --git a/frc971/input/input.gyp b/frc971/input/input.gyp
index 2fa63f5..23dfda6 100644
--- a/frc971/input/input.gyp
+++ b/frc971/input/input.gyp
@@ -49,13 +49,11 @@
'dependencies': [
'<(DEPTH)/gyro_board/src/libusb-driver/libusb-driver.gyp:libusb_wrap',
'<(AOS)/build/aos.gyp:logging',
- '<(AOS)/common/util/util.gyp:wrapping_counter',
'<(AOS)/common/common.gyp:time',
'<(AOS)/common/common.gyp:controls',
],
'export_dependent_settings': [
'<(DEPTH)/gyro_board/src/libusb-driver/libusb-driver.gyp:libusb_wrap',
- '<(AOS)/common/util/util.gyp:wrapping_counter',
'<(AOS)/common/common.gyp:time',
],
},
diff --git a/frc971/input/usb_receiver.cc b/frc971/input/usb_receiver.cc
index 545e197..bd2e665 100644
--- a/frc971/input/usb_receiver.cc
+++ b/frc971/input/usb_receiver.cc
@@ -18,8 +18,8 @@
Reset();
} else {
const ::aos::time::Time received_time = ::aos::time::Time::Now();
- if (phase_locker_.IsCurrentPacketGood(received_time, sequence_.count())) {
- LOG(DEBUG, "processing data\n");
+ if (phase_locker_.IsCurrentPacketGood(received_time, sequence_)) {
+ LOG(DEBUG, "processing data %" PRIu32 "\n", sequence_);
ProcessData();
}
}
@@ -28,7 +28,7 @@
void USBReceiver::PhaseLocker::Reset() {
LOG(INFO, "resetting\n");
last_good_packet_time_ = ::aos::time::Time(0, 0);
- last_good_sequence_ = -1;
+ last_good_sequence_ = 0;
good_phase_ = guess_phase_ = kUnknownPhase;
guess_phase_good_ = guess_phase_bad_ = 0;
good_phase_early_ = good_phase_late_ = 0;
@@ -36,18 +36,23 @@
bool USBReceiver::PhaseLocker::IsCurrentPacketGood(
const ::aos::time::Time &received_time,
- int32_t sequence) {
+ uint32_t sequence) {
if (last_good_packet_time_ != ::aos::time::Time(0, 0) &&
received_time - last_good_packet_time_ > kResetTime) {
LOG(WARNING, "no good packet received in too long\n");
Reset();
return false;
}
- if (last_good_sequence_ != -1 && sequence - last_good_sequence_ > 100) {
+ if (last_good_sequence_ != 0 && sequence - last_good_sequence_ > 100) {
LOG(WARNING, "skipped too many packets\n");
Reset();
return false;
}
+ if (sequence < last_good_sequence_) {
+ LOG(WARNING, "sequence went down. gyro board reset?\n");
+ Reset();
+ return false;
+ }
using ::aos::control_loops::kLoopFrequency;
// How often we (should) receive packets.
@@ -194,13 +199,13 @@
memcpy(data(), completed_transfer_->data(),
sizeof(GyroBoardData));
- int32_t count_before = sequence_.count();
- sequence_.Update(data()->sequence);
- if (count_before == 0) {
- LOG(INFO, "count starting at %" PRId32 "\n", sequence_.count());
- } else if (sequence_.count() - count_before != 1) {
- LOG(WARNING, "count went from %" PRId32" to %" PRId32 "\n",
- count_before, sequence_.count());
+ uint32_t sequence_before = sequence_;
+ sequence_ = data()->sequence;
+ if (sequence_before == 0) {
+ LOG(INFO, "count starting at %" PRIu32 "\n", sequence_);
+ } else if (sequence_ - sequence_before != 1) {
+ LOG(WARNING, "count went from %" PRIu32" to %" PRIu32 "\n",
+ sequence_before, sequence_);
}
return false;
@@ -225,7 +230,7 @@
c->Submit();
}
- sequence_.Reset();
+ sequence_ = 0;
phase_locker_.Reset();
}
diff --git a/frc971/input/usb_receiver.h b/frc971/input/usb_receiver.h
index cda7843..a0c645a 100644
--- a/frc971/input/usb_receiver.h
+++ b/frc971/input/usb_receiver.h
@@ -4,7 +4,6 @@
#include <memory>
#include "aos/common/time.h"
-#include "aos/common/util/wrapping_counter.h"
#include "gyro_board/src/libusb-driver/libusb_wrap.h"
#include "frc971/input/gyro_board_data.h"
@@ -62,7 +61,7 @@
// Gets called for every packet received.
// Returns whether or not to process the values from this packet.
bool IsCurrentPacketGood(const ::aos::time::Time &received_time,
- int32_t sequence);
+ uint32_t sequence);
private:
// How many times the packet we guessed has to be close to right to use the
@@ -78,7 +77,7 @@
::aos::time::Time last_good_packet_time_{0, 0};
- int32_t last_good_sequence_;
+ uint32_t last_good_sequence_;
const int kUnknownPhase = -11;
// kUnknownPhase or the sequence number (%kPacketsPerLoopCycle) to
@@ -102,7 +101,7 @@
GyroBoardData data_;
- ::aos::util::WrappingCounter sequence_;
+ uint32_t sequence_;
LibUSB libusb_;
::std::unique_ptr<LibUSBDeviceHandle> dev_handle_;