Fixed gyro board code. (Finally.)
Also fixed some math in the shooter_translate function.
diff --git a/bot3/input/gyro_sensor_receiver.cc b/bot3/input/gyro_sensor_receiver.cc
index 81e4190..a143a91 100644
--- a/bot3/input/gyro_sensor_receiver.cc
+++ b/bot3/input/gyro_sensor_receiver.cc
@@ -23,7 +23,7 @@
namespace {
const double kWheelRadius = 1.964;
-const double kTapeThickness = 3.12;
+const double kTapeThickness = 2.519;
inline double drivetrain_translate(int32_t in) {
return static_cast<double>(in) / (256.0 /*cpr*/ * 4.0 /*quad*/) *
@@ -36,7 +36,7 @@
if (in == 0) {
return 0;
}
- return 1.0 / (static_cast<double>(in) / (10 ^ 8)/*ticks per sec*/)
+ return (100000000.0/*ticks per sec*/ / static_cast<double>(in))
/ (1 - (kTapeThickness / (2 * kWheelRadius * M_PI))) * (2 * M_PI);
}
diff --git a/gyro_board/src/usb/encoder.c b/gyro_board/src/usb/encoder.c
index 45374e9..164d994 100644
--- a/gyro_board/src/usb/encoder.c
+++ b/gyro_board/src/usb/encoder.c
@@ -13,7 +13,7 @@
// How long (in ms) to wait after a falling edge on the bottom indexer sensor
// before reading the indexer encoder.
static const int kBottomFallDelayTime = 32;
-static const int kWheelStopThreshold = 2.5;
+static const uint32_t kWheelStopThreshold = 250000000;
#define ENC(gpio, a, b) readGPIO(gpio, a) * 2 + readGPIO(gpio, b)
int encoder_bits(int channel) {
@@ -92,7 +92,7 @@
// Capture
TIM2->IR = (1 << 4); // Clear the interrupt.
- shooter_cycle_ticks = TIM2->CR0 + 2;
+ shooter_cycle_ticks = TIM2->CR0;
reset_TC();
} else if (TIM2->IR & 1) {
@@ -100,10 +100,10 @@
TIM2->IR = 1; // Clear the interrupt
// Assume shooter is stopped.
- //shooter_cycle_ticks = 1;
+ shooter_cycle_ticks = 0;
// Disable timer.
- //TIM2->TCR = 0;
+ TIM2->TCR = 0;
}
// It will only handle one interrupt per run.
@@ -451,7 +451,7 @@
// Set timer to capture and interrupt on rising edge.
TIM2->CCR = 0x5;
// Set up match interrupt.
- TIM2->MR0 = kWheelStopThreshold * (10 ^ 8);
+ TIM2->MR0 = kWheelStopThreshold;
TIM2->MCR = 1;
// Enable timer IRQ, and make it lower priority than the encoders.
NVIC_SetPriority(TIMER2_IRQn, 1);