Merge changes Id8c2db11,I5d0e43d8,I9e1cadea
* changes:
Move ADC code into individual boards where it belongs
Move all the motors stuff into a saner namespace
Name big motor controller files appropriately
diff --git a/motors/BUILD b/motors/BUILD
index 0a63da0..50a4bce 100644
--- a/motors/BUILD
+++ b/motors/BUILD
@@ -1,23 +1,6 @@
load("//motors:macros.bzl", "hex_from_elf")
load("//tools:environments.bzl", "mcu_cpus")
-cc_binary(
- name = "medium_salsa.elf",
- srcs = [
- "medium_salsa.cc",
- ],
- restricted_to = mcu_cpus,
- deps = [
- ":motor",
- ":motor_controls",
- ":util",
- "//motors/core",
- "//motors/peripheral:adc",
- "//motors/peripheral:can",
- "//motors/usb:legacy",
- ],
-)
-
cc_library(
name = "motor",
srcs = [
@@ -39,11 +22,6 @@
],
)
-hex_from_elf(
- name = "medium_salsa",
- restricted_to = mcu_cpus,
-)
-
cc_library(
name = "util",
hdrs = [
@@ -122,23 +100,6 @@
],
)
-cc_library(
- name = "motor_controls",
- srcs = [
- "motor_controls.cc",
- ],
- hdrs = [
- "motor_controls.h",
- ],
- restricted_to = mcu_cpus,
- deps = [
- ":math",
- ":motor",
- "//motors/peripheral:configuration",
- "//third_party/eigen",
- ],
-)
-
cc_binary(
name = "button_board.elf",
srcs = [
diff --git a/motors/algorithms.cc b/motors/algorithms.cc
index 1d655ef..6edb532 100644
--- a/motors/algorithms.cc
+++ b/motors/algorithms.cc
@@ -1,7 +1,7 @@
#include "motors/algorithms.h"
namespace frc971 {
-namespace salsa {
+namespace motors {
BalancedReadings BalanceReadings(const ReadingsToBalance to_balance) {
// TODO(Brian): Get rid of the floating point divides.
@@ -46,5 +46,5 @@
return result;
}
-} // namespace salsa
+} // namespace motors
} // namespace frc971
diff --git a/motors/algorithms.h b/motors/algorithms.h
index 8b397f8..63d6d19 100644
--- a/motors/algorithms.h
+++ b/motors/algorithms.h
@@ -4,7 +4,7 @@
#include <stdint.h>
namespace frc971 {
-namespace salsa {
+namespace motors {
struct ReadingsToBalance {
// Adds a single reading at index.
@@ -39,7 +39,7 @@
return r;
}
-} // namespace salsa
+} // namespace motors
} // namespace frc971
#endif // MOTORS_ALGORITHMS_H_
diff --git a/motors/algorithms_test.cc b/motors/algorithms_test.cc
index 32ca8b7..18b89c3 100644
--- a/motors/algorithms_test.cc
+++ b/motors/algorithms_test.cc
@@ -6,7 +6,7 @@
#include "gtest/gtest.h"
namespace frc971 {
-namespace salsa {
+namespace motors {
namespace testing {
class BalanceReadingsTest : public ::testing::Test {
@@ -97,5 +97,5 @@
}
} // namespace testing
-} // namespace salsa
+} // namespace motors
} // namespace frc971
diff --git a/motors/big/BUILD b/motors/big/BUILD
new file mode 100644
index 0000000..8ce81f1
--- /dev/null
+++ b/motors/big/BUILD
@@ -0,0 +1,41 @@
+load("//motors:macros.bzl", "hex_from_elf")
+load("//tools:environments.bzl", "mcu_cpus")
+
+cc_binary(
+ name = "medium_salsa.elf",
+ srcs = [
+ "medium_salsa.cc",
+ ],
+ restricted_to = mcu_cpus,
+ deps = [
+ ":motor_controls",
+ "//motors:motor",
+ "//motors:util",
+ "//motors/core",
+ "//motors/peripheral:adc",
+ "//motors/peripheral:can",
+ "//motors/usb:legacy",
+ ],
+)
+
+hex_from_elf(
+ name = "medium_salsa",
+ restricted_to = mcu_cpus,
+)
+
+cc_library(
+ name = "motor_controls",
+ srcs = [
+ "motor_controls.cc",
+ ],
+ hdrs = [
+ "motor_controls.h",
+ ],
+ restricted_to = mcu_cpus,
+ deps = [
+ "//motors:math",
+ "//motors:motor",
+ "//motors/peripheral:configuration",
+ "//third_party/eigen",
+ ],
+)
diff --git a/motors/medium_salsa.cc b/motors/big/medium_salsa.cc
similarity index 84%
rename from motors/medium_salsa.cc
rename to motors/big/medium_salsa.cc
index 0b9d89d..80263cb 100644
--- a/motors/medium_salsa.cc
+++ b/motors/big/medium_salsa.cc
@@ -4,18 +4,91 @@
#include <atomic>
+#include "motors/big/motor_controls.h"
#include "motors/core/time.h"
#include "motors/motor.h"
-#include "motors/motor_controls.h"
#include "motors/peripheral/adc.h"
#include "motors/peripheral/can.h"
#include "motors/usb/usb_serial.h"
#include "motors/util.h"
namespace frc971 {
-namespace salsa {
+namespace motors {
namespace {
+struct MediumAdcReadings {
+ uint16_t motor_currents[3][2];
+ uint16_t motor_current_ref;
+ uint16_t input_voltage;
+};
+
+void AdcInitMedium() {
+ AdcInitCommon();
+
+ // M_CH2V ADC0_SE14
+ PORTC_PCR0 = PORT_PCR_MUX(0);
+
+ // M_CH0V ADC0_SE13
+ PORTB_PCR3 = PORT_PCR_MUX(0);
+
+ // M_CH1V ADC0_SE12
+ PORTB_PCR2 = PORT_PCR_MUX(0);
+
+ // M_CH0F ADC1_SE14
+ PORTB_PCR10 = PORT_PCR_MUX(0);
+
+ // M_CH1F ADC1_SE15
+ PORTB_PCR11 = PORT_PCR_MUX(0);
+
+ // M_VREF ADC0_SE18
+ PORTE_PCR25 = PORT_PCR_MUX(0);
+
+ // VIN ADC1_SE5B
+ PORTC_PCR9 = PORT_PCR_MUX(0);
+
+ // M_CH2F ADC1_SE17
+ PORTA_PCR17 = PORT_PCR_MUX(0);
+}
+
+MediumAdcReadings AdcReadMedium(const DisableInterrupts &) {
+ MediumAdcReadings r;
+
+ ADC1_SC1A = 14;
+ while (!(ADC1_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC1_SC1A = 15;
+ r.motor_currents[0][0] = ADC1_RA;
+ while (!(ADC1_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC1_SC1A = 17;
+ ADC0_SC1A = 18;
+ r.motor_currents[1][0] = ADC1_RA;
+ while (!(ADC1_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC1_SC1A = 5;
+ r.motor_currents[2][0] = ADC1_RA;
+ while (!(ADC0_SC1A & ADC_SC1_COCO)) {
+ }
+ r.motor_current_ref = ADC0_RA;
+ while (!(ADC1_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC1_SC1A = 14;
+ r.input_voltage = ADC1_RA;
+ while (!(ADC1_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC1_SC1A = 15;
+ r.motor_currents[0][1] = ADC1_RA;
+ while (!(ADC1_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC1_SC1A = 17;
+ r.motor_currents[1][1] = ADC1_RA;
+ while (!(ADC1_SC1A & ADC_SC1_COCO)) {
+ }
+ r.motor_currents[2][1] = ADC1_RA;
+
+ return r;
+}
+
::std::atomic<Motor *> global_motor{nullptr};
extern "C" {
@@ -269,5 +342,5 @@
return 0;
}
-} // namespace salsa
+} // namespace motors
} // namespace frc971
diff --git a/motors/motor_controls.cc b/motors/big/motor_controls.cc
similarity index 98%
rename from motors/motor_controls.cc
rename to motors/big/motor_controls.cc
index 029f98d..82dcc0b 100644
--- a/motors/motor_controls.cc
+++ b/motors/big/motor_controls.cc
@@ -1,9 +1,9 @@
-#include "motors/motor_controls.h"
+#include "motors/big/motor_controls.h"
#include "motors/peripheral/configuration.h"
namespace frc971 {
-namespace salsa {
+namespace motors {
namespace {
template <int kRows, int kCols>
@@ -239,5 +239,5 @@
return debug_[theta];
}
-} // namespace salsa
+} // namespace motors
} // namespace frc971
diff --git a/motors/motor_controls.h b/motors/big/motor_controls.h
similarity index 97%
rename from motors/motor_controls.h
rename to motors/big/motor_controls.h
index 1f19e6d..b9514fd 100644
--- a/motors/motor_controls.h
+++ b/motors/big/motor_controls.h
@@ -10,7 +10,7 @@
#include "Eigen/Dense"
namespace frc971 {
-namespace salsa {
+namespace motors {
class MotorControlsImplementation : public MotorControls {
public:
@@ -56,7 +56,7 @@
int16_t debug_[9];
};
-} // namespace salsa
+} // namespace motors
} // namespace frc971
#endif // MOTORS_MOTOR_CONTROLS_H_
diff --git a/motors/button_board.cc b/motors/button_board.cc
index 7e4a43c..676331b 100644
--- a/motors/button_board.cc
+++ b/motors/button_board.cc
@@ -18,6 +18,46 @@
namespace motors {
namespace {
+struct JoystickAdcReadings {
+ uint16_t analog0, analog1, analog2, analog3;
+};
+
+void AdcInitJoystick() {
+ AdcInitCommon();
+
+ // ANALOG0 ADC0_SE5b
+ PORTD_PCR1 = PORT_PCR_MUX(0);
+ // ANALOG1 ADC0_SE14
+ PORTC_PCR0 = PORT_PCR_MUX(0);
+ // ANALOG2 ADC0_SE13
+ PORTB_PCR3 = PORT_PCR_MUX(0);
+ // ANALOG3 ADC0_SE12
+ PORTB_PCR2 = PORT_PCR_MUX(0);
+}
+
+JoystickAdcReadings AdcReadJoystick(const DisableInterrupts &) {
+ JoystickAdcReadings r;
+
+ ADC0_SC1A = 5;
+ while (!(ADC0_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC0_SC1A = 14;
+ r.analog0 = ADC0_RA;
+ while (!(ADC0_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC0_SC1A = 13;
+ r.analog1 = ADC0_RA;
+ while (!(ADC0_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC0_SC1A = 12;
+ r.analog2 = ADC0_RA;
+ while (!(ADC0_SC1A & ADC_SC1_COCO)) {
+ }
+ r.analog3 = ADC0_RA;
+
+ return r;
+}
+
::std::atomic<teensy::AcmTty *> global_stdout{nullptr};
// The HID report descriptor we use.
@@ -69,12 +109,12 @@
teensy::HidFunction *joystick1) {
uint32_t start = micros();
while (true) {
- salsa::JoystickAdcReadings adc;
+ JoystickAdcReadings adc;
char report0[report_size()];
char report1[report_size()];
{
DisableInterrupts disable_interrupts;
- adc = salsa::AdcReadJoystick(disable_interrupts);
+ adc = AdcReadJoystick(disable_interrupts);
}
FTM0->C1V = adc.analog0 / 4;
@@ -334,7 +374,7 @@
usb_device.Initialize();
can_init(0, 1);
- salsa::AdcInitJoystick();
+ AdcInitJoystick();
SetupLedFtm(FTM0);
SetupLedFtm(FTM3);
diff --git a/motors/math.cc b/motors/math.cc
index 291ca43..8441e97 100644
--- a/motors/math.cc
+++ b/motors/math.cc
@@ -3,7 +3,7 @@
#include <math.h>
namespace frc971 {
-namespace salsa {
+namespace motors {
namespace math_internal {
float sin_int_table[SinCosTableSize()];
@@ -33,5 +33,5 @@
}
}
-} // namespace salsa
+} // namespace motors
} // namespace frc971
diff --git a/motors/math.h b/motors/math.h
index fce3a56..16cdf92 100644
--- a/motors/math.h
+++ b/motors/math.h
@@ -10,7 +10,7 @@
// controls in a minimal number of cycles.
namespace frc971 {
-namespace salsa {
+namespace motors {
inline constexpr unsigned int Log2RoundUp(unsigned int x) {
return (x < 2) ? x : (1 + Log2RoundUp(x / 2));
@@ -126,7 +126,7 @@
void MathInit();
-} // namespace salsa
+} // namespace motors
} // namespace frc971
#endif // MOTORS_MATH_H_
diff --git a/motors/math_test.cc b/motors/math_test.cc
index 1c7708e..06f168f 100644
--- a/motors/math_test.cc
+++ b/motors/math_test.cc
@@ -4,7 +4,7 @@
#include "gmock/gmock.h"
namespace frc971 {
-namespace salsa {
+namespace motors {
namespace testing {
class SinCosIntTest : public ::testing::Test {
@@ -76,5 +76,5 @@
}
} // namespace testing
-} // namespace salsa
+} // namespace motors
} // namespace frc971
diff --git a/motors/motor.cc b/motors/motor.cc
index af7a3c7..93f2a4d 100644
--- a/motors/motor.cc
+++ b/motors/motor.cc
@@ -13,7 +13,7 @@
extern "C" float absolute_wheel(uint16_t reading);
namespace frc971 {
-namespace salsa {
+namespace motors {
Motor::Motor(BigFTM *pwm_ftm, LittleFTM *encoder_ftm, MotorControls *controls,
const ::std::array<volatile uint32_t *, 3> &output_registers)
@@ -451,5 +451,5 @@
return (counts_per_cycle() + width) / 2;
}
-} // namespace salsa
+} // namespace motors
} // namespace frc971
diff --git a/motors/motor.h b/motors/motor.h
index c59458c..ec96efb 100644
--- a/motors/motor.h
+++ b/motors/motor.h
@@ -14,7 +14,7 @@
#include "motors/core/time.h"
namespace frc971 {
-namespace salsa {
+namespace motors {
class MotorControls {
public:
@@ -131,31 +131,6 @@
}
private:
- // Represents the ADC reading which is closest to an edge.
- struct CloseAdcReading {
- // Adds a new reading to the readings to balance or pushes the previous
- // closest one there and saves off this one.
- //
- // Returns true if it saves off the new reading.
- bool MaybeUse(int new_distance, const MediumAdcReadings &adc_readings,
- int phase, int sample, ReadingsToBalance *to_balance) {
- if (new_distance < distance) {
- if (distance != INT_MAX) {
- to_balance->Add(index, value);
- }
- distance = new_distance;
- value = adc_readings.motor_currents[phase][sample];
- index = phase;
- return true;
- }
- return false;
- }
-
- int distance = INT_MAX;
- int32_t value = 0;
- int index = 0;
- };
-
inline int counts_per_cycle() const {
return BUS_CLOCK_FREQUENCY / SWITCHING_FREQUENCY / switching_divisor_;
}
@@ -182,7 +157,7 @@
teensy::AcmTty *debug_tty_ = nullptr;
};
-} // namespace salsa
+} // namespace motors
} // namespace frc971
#endif // MOTORS_MOTOR_H_
diff --git a/motors/peripheral/adc.cc b/motors/peripheral/adc.cc
index 90b1d0d..756e166 100644
--- a/motors/peripheral/adc.cc
+++ b/motors/peripheral/adc.cc
@@ -3,7 +3,7 @@
#include "motors/core/kinetis.h"
namespace frc971 {
-namespace salsa {
+namespace motors {
namespace {
#define ADC_SC2_BASE (ADC_SC2_REFSEL(0) /* Use the external reference pins. */)
@@ -44,6 +44,8 @@
ADC##n##_SC3 = 0 /* Disable hardware averaging. */; \
} while (0)
+} // namespace
+
void AdcInitCommon() {
SIM_SCGC3 |= SIM_SCGC3_ADC1;
SIM_SCGC6 |= SIM_SCGC6_ADC0;
@@ -52,223 +54,5 @@
ADC_INIT_SINGLE(1);
}
-} // namespace
-
-void AdcInitMedium() {
- AdcInitCommon();
-
- // M_CH2V ADC0_SE14
- PORTC_PCR0 = PORT_PCR_MUX(0);
-
- // M_CH0V ADC0_SE13
- PORTB_PCR3 = PORT_PCR_MUX(0);
-
- // M_CH1V ADC0_SE12
- PORTB_PCR2 = PORT_PCR_MUX(0);
-
- // M_CH0F ADC1_SE14
- PORTB_PCR10 = PORT_PCR_MUX(0);
-
- // M_CH1F ADC1_SE15
- PORTB_PCR11 = PORT_PCR_MUX(0);
-
- // M_VREF ADC0_SE18
- PORTE_PCR25 = PORT_PCR_MUX(0);
-
- // VIN ADC1_SE5B
- PORTC_PCR9 = PORT_PCR_MUX(0);
-
- // M_CH2F ADC1_SE17
- PORTA_PCR17 = PORT_PCR_MUX(0);
-}
-
-void AdcInitSmall() {
- AdcInitCommon();
-
- // M0_CH0F ADC1_SE17
- PORTA_PCR17 = PORT_PCR_MUX(0);
-
- // M0_CH1F ADC1_SE14
- PORTB_PCR10 = PORT_PCR_MUX(0);
-
- // M0_CH2F ADC1_SE15
- PORTB_PCR11 = PORT_PCR_MUX(0);
-
- // M0_ABS ADC0_SE5b
- PORTD_PCR1 = PORT_PCR_MUX(0);
-
- // M1_CH0F ADC0_SE13
- PORTB_PCR3 = PORT_PCR_MUX(0);
-
- // M1_CH1F ADC0_SE12
- PORTB_PCR2 = PORT_PCR_MUX(0);
-
- // M1_CH2F ADC0_SE14
- PORTC_PCR0 = PORT_PCR_MUX(0);
-
- // M1_ABS ADC0_SE17
- PORTE_PCR24 = PORT_PCR_MUX(0);
-
- // WHEEL_ABS ADC0_SE18
- PORTE_PCR25 = PORT_PCR_MUX(0);
-
- // VIN ADC1_SE5B
- PORTC_PCR9 = PORT_PCR_MUX(0);
-}
-
-void AdcInitJoystick() {
- AdcInitCommon();
-
- // ANALOG0 ADC0_SE5b
- PORTD_PCR1 = PORT_PCR_MUX(0);
- // ANALOG1 ADC0_SE14
- PORTC_PCR0 = PORT_PCR_MUX(0);
- // ANALOG2 ADC0_SE13
- PORTB_PCR3 = PORT_PCR_MUX(0);
- // ANALOG3 ADC0_SE12
- PORTB_PCR2 = PORT_PCR_MUX(0);
-}
-
-void AdcInitSimple() {
- AdcInitCommon();
-
- // ENC_SIN ADC0_SE23
- // ENC_COS ADC1_SE23
-}
-
-MediumAdcReadings AdcReadMedium(const DisableInterrupts &) {
- MediumAdcReadings r;
-
- ADC1_SC1A = 14;
- while (!(ADC1_SC1A & ADC_SC1_COCO)) {
- }
- ADC1_SC1A = 15;
- r.motor_currents[0][0] = ADC1_RA;
- while (!(ADC1_SC1A & ADC_SC1_COCO)) {
- }
- ADC1_SC1A = 17;
- ADC0_SC1A = 18;
- r.motor_currents[1][0] = ADC1_RA;
- while (!(ADC1_SC1A & ADC_SC1_COCO)) {
- }
- ADC1_SC1A = 5;
- r.motor_currents[2][0] = ADC1_RA;
- while (!(ADC0_SC1A & ADC_SC1_COCO)) {
- }
- r.motor_current_ref = ADC0_RA;
- while (!(ADC1_SC1A & ADC_SC1_COCO)) {
- }
- ADC1_SC1A = 14;
- r.input_voltage = ADC1_RA;
- while (!(ADC1_SC1A & ADC_SC1_COCO)) {
- }
- ADC1_SC1A = 15;
- r.motor_currents[0][1] = ADC1_RA;
- while (!(ADC1_SC1A & ADC_SC1_COCO)) {
- }
- ADC1_SC1A = 17;
- r.motor_currents[1][1] = ADC1_RA;
- while (!(ADC1_SC1A & ADC_SC1_COCO)) {
- }
- r.motor_currents[2][1] = ADC1_RA;
-
- return r;
-}
-
-SmallAdcReadings AdcReadSmall0(const DisableInterrupts &) {
- SmallAdcReadings r;
-
- ADC1_SC1A = 17;
- while (!(ADC1_SC1A & ADC_SC1_COCO)) {
- }
- ADC1_SC1A = 14;
- r.currents[0] = ADC1_RA;
- while (!(ADC1_SC1A & ADC_SC1_COCO)) {
- }
- ADC1_SC1A = 15;
- r.currents[1] = ADC1_RA;
- while (!(ADC1_SC1A & ADC_SC1_COCO)) {
- }
- r.currents[2] = ADC1_RA;
-
- return r;
-}
-
-SmallAdcReadings AdcReadSmall1(const DisableInterrupts &) {
- SmallAdcReadings r;
-
- ADC0_SC1A = 13;
- while (!(ADC0_SC1A & ADC_SC1_COCO)) {
- }
- ADC0_SC1A = 12;
- r.currents[0] = ADC0_RA;
- while (!(ADC0_SC1A & ADC_SC1_COCO)) {
- }
- ADC0_SC1A = 14;
- r.currents[1] = ADC0_RA;
- while (!(ADC0_SC1A & ADC_SC1_COCO)) {
- }
- r.currents[2] = ADC0_RA;
-
- return r;
-}
-
-SmallInitReadings AdcReadSmallInit(const DisableInterrupts &) {
- SmallInitReadings r;
-
- ADC0_SC1A = 5;
- while (!(ADC0_SC1A & ADC_SC1_COCO)) {
- }
- ADC0_SC1A = 17;
- r.motor0_abs = ADC0_RA;
- while (!(ADC0_SC1A & ADC_SC1_COCO)) {
- }
- ADC0_SC1A = 18;
- r.motor1_abs = ADC0_RA;
- while (!(ADC0_SC1A & ADC_SC1_COCO)) {
- }
- r.wheel_abs = ADC0_RA;
-
- return r;
-}
-
-JoystickAdcReadings AdcReadJoystick(const DisableInterrupts &) {
- JoystickAdcReadings r;
-
- ADC0_SC1A = 5;
- while (!(ADC0_SC1A & ADC_SC1_COCO)) {
- }
- ADC0_SC1A = 14;
- r.analog0 = ADC0_RA;
- while (!(ADC0_SC1A & ADC_SC1_COCO)) {
- }
- ADC0_SC1A = 13;
- r.analog1 = ADC0_RA;
- while (!(ADC0_SC1A & ADC_SC1_COCO)) {
- }
- ADC0_SC1A = 12;
- r.analog2 = ADC0_RA;
- while (!(ADC0_SC1A & ADC_SC1_COCO)) {
- }
- r.analog3 = ADC0_RA;
-
- return r;
-}
-
-SimpleAdcReadings AdcReadSimple(const DisableInterrupts &) {
- SimpleAdcReadings r;
-
- ADC0_SC1A = 23;
- ADC1_SC1A = 23;
- while (!(ADC0_SC1A & ADC_SC1_COCO)) {
- }
- while (!(ADC1_SC1A & ADC_SC1_COCO)) {
- }
- r.sin = ADC0_RA;
- r.cos = ADC1_RA;
-
- return r;
-}
-
-} // namespace salsa
+} // namespace motors
} // namespace frc971
diff --git a/motors/peripheral/adc.h b/motors/peripheral/adc.h
index 04caff7..9ca5506 100644
--- a/motors/peripheral/adc.h
+++ b/motors/peripheral/adc.h
@@ -5,49 +5,12 @@
#include "motors/util.h"
-// TODO(Brian): Avoid cramming all the code for each specific application into a
-// single file like this.
-
namespace frc971 {
-namespace salsa {
+namespace motors {
-struct MediumAdcReadings {
- uint16_t motor_currents[3][2];
- uint16_t motor_current_ref;
- uint16_t input_voltage;
-};
+void AdcInitCommon();
-struct SmallAdcReadings {
- uint16_t currents[3];
-};
-
-struct SmallInitReadings {
- uint16_t motor0_abs;
- uint16_t motor1_abs;
- uint16_t wheel_abs;
-};
-
-struct JoystickAdcReadings {
- uint16_t analog0, analog1, analog2, analog3;
-};
-
-struct SimpleAdcReadings {
- uint16_t sin, cos;
-};
-
-void AdcInitMedium();
-void AdcInitSmall();
-void AdcInitJoystick();
-void AdcInitSimple();
-
-MediumAdcReadings AdcReadMedium(const DisableInterrupts &);
-SmallAdcReadings AdcReadSmall0(const DisableInterrupts &);
-SmallAdcReadings AdcReadSmall1(const DisableInterrupts &);
-SmallInitReadings AdcReadSmallInit(const DisableInterrupts &);
-JoystickAdcReadings AdcReadJoystick(const DisableInterrupts &);
-SimpleAdcReadings AdcReadSimple(const DisableInterrupts &);
-
-} // namespace salsa
+} // namespace motors
} // namespace frc971
#endif // MOTORS_PERIPHERAL_ADC_H_
diff --git a/motors/pistol_grip/controller.cc b/motors/pistol_grip/controller.cc
index 162ac2f..9d8a1c8 100644
--- a/motors/pistol_grip/controller.cc
+++ b/motors/pistol_grip/controller.cc
@@ -26,7 +26,7 @@
extern const float kTriggerCoggingTorque[4096];
namespace frc971 {
-namespace salsa {
+namespace motors {
namespace {
using ::frc971::control_loops::drivetrain::MakeIntegralHapticTriggerPlant;
@@ -34,6 +34,107 @@
using ::frc971::control_loops::drivetrain::MakeIntegralHapticWheelPlant;
using ::frc971::control_loops::drivetrain::MakeIntegralHapticWheelObserver;
+struct SmallAdcReadings {
+ uint16_t currents[3];
+};
+
+struct SmallInitReadings {
+ uint16_t motor0_abs;
+ uint16_t motor1_abs;
+ uint16_t wheel_abs;
+};
+
+void AdcInitSmall() {
+ AdcInitCommon();
+
+ // M0_CH0F ADC1_SE17
+ PORTA_PCR17 = PORT_PCR_MUX(0);
+
+ // M0_CH1F ADC1_SE14
+ PORTB_PCR10 = PORT_PCR_MUX(0);
+
+ // M0_CH2F ADC1_SE15
+ PORTB_PCR11 = PORT_PCR_MUX(0);
+
+ // M0_ABS ADC0_SE5b
+ PORTD_PCR1 = PORT_PCR_MUX(0);
+
+ // M1_CH0F ADC0_SE13
+ PORTB_PCR3 = PORT_PCR_MUX(0);
+
+ // M1_CH1F ADC0_SE12
+ PORTB_PCR2 = PORT_PCR_MUX(0);
+
+ // M1_CH2F ADC0_SE14
+ PORTC_PCR0 = PORT_PCR_MUX(0);
+
+ // M1_ABS ADC0_SE17
+ PORTE_PCR24 = PORT_PCR_MUX(0);
+
+ // WHEEL_ABS ADC0_SE18
+ PORTE_PCR25 = PORT_PCR_MUX(0);
+
+ // VIN ADC1_SE5B
+ PORTC_PCR9 = PORT_PCR_MUX(0);
+}
+
+SmallAdcReadings AdcReadSmall0(const DisableInterrupts &) {
+ SmallAdcReadings r;
+
+ ADC1_SC1A = 17;
+ while (!(ADC1_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC1_SC1A = 14;
+ r.currents[0] = ADC1_RA;
+ while (!(ADC1_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC1_SC1A = 15;
+ r.currents[1] = ADC1_RA;
+ while (!(ADC1_SC1A & ADC_SC1_COCO)) {
+ }
+ r.currents[2] = ADC1_RA;
+
+ return r;
+}
+
+SmallAdcReadings AdcReadSmall1(const DisableInterrupts &) {
+ SmallAdcReadings r;
+
+ ADC0_SC1A = 13;
+ while (!(ADC0_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC0_SC1A = 12;
+ r.currents[0] = ADC0_RA;
+ while (!(ADC0_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC0_SC1A = 14;
+ r.currents[1] = ADC0_RA;
+ while (!(ADC0_SC1A & ADC_SC1_COCO)) {
+ }
+ r.currents[2] = ADC0_RA;
+
+ return r;
+}
+
+SmallInitReadings AdcReadSmallInit(const DisableInterrupts &) {
+ SmallInitReadings r;
+
+ ADC0_SC1A = 5;
+ while (!(ADC0_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC0_SC1A = 17;
+ r.motor0_abs = ADC0_RA;
+ while (!(ADC0_SC1A & ADC_SC1_COCO)) {
+ }
+ ADC0_SC1A = 18;
+ r.motor1_abs = ADC0_RA;
+ while (!(ADC0_SC1A & ADC_SC1_COCO)) {
+ }
+ r.wheel_abs = ADC0_RA;
+
+ return r;
+}
+
constexpr float kHapticWheelCurrentLimit = static_cast<float>(
::frc971::control_loops::drivetrain::kHapticWheelCurrentLimit);
constexpr float kHapticTriggerCurrentLimit = static_cast<float>(
@@ -870,5 +971,5 @@
return 0;
}
-} // namespace salsa
+} // namespace motors
} // namespace frc971
diff --git a/motors/pistol_grip/motor_controls.cc b/motors/pistol_grip/motor_controls.cc
index b123378..2f4f00f 100644
--- a/motors/pistol_grip/motor_controls.cc
+++ b/motors/pistol_grip/motor_controls.cc
@@ -3,7 +3,7 @@
#include "motors/peripheral/configuration.h"
namespace frc971 {
-namespace salsa {
+namespace motors {
namespace {
template <int kRows, int kCols>
@@ -208,5 +208,5 @@
return debug_[theta];
}
-} // namespace salsa
+} // namespace motors
} // namespace frc971
diff --git a/motors/pistol_grip/motor_controls.h b/motors/pistol_grip/motor_controls.h
index ca965d0..88ef8a2 100644
--- a/motors/pistol_grip/motor_controls.h
+++ b/motors/pistol_grip/motor_controls.h
@@ -10,7 +10,7 @@
#include "Eigen/Dense"
namespace frc971 {
-namespace salsa {
+namespace motors {
class LittleMotorControlsImplementation : public MotorControls {
public:
@@ -57,7 +57,7 @@
int16_t debug_[9];
};
-} // namespace salsa
+} // namespace motors
} // namespace frc971
#endif // MOTORS_PISTOL_GRIP_MOTOR_CONTROLS_H_
diff --git a/motors/python/BUILD b/motors/python/BUILD
index 299f4d2..408f3cd 100644
--- a/motors/python/BUILD
+++ b/motors/python/BUILD
@@ -1,7 +1,7 @@
py_binary(
- name = "phase_current",
+ name = "big_phase_current",
srcs = [
- "phase_current.py",
+ "big_phase_current.py",
],
restricted_to = ["//tools:k8"],
deps = [
diff --git a/motors/python/phase_current.py b/motors/python/big_phase_current.py
similarity index 100%
rename from motors/python/phase_current.py
rename to motors/python/big_phase_current.py
diff --git a/motors/simple_receiver.cc b/motors/simple_receiver.cc
index 910d2ae..20ca298 100644
--- a/motors/simple_receiver.cc
+++ b/motors/simple_receiver.cc
@@ -29,6 +29,32 @@
using ::frc971::control_loops::DrivetrainQueue_Output;
using ::motors::seems_reasonable::Spring;
+struct SimpleAdcReadings {
+ uint16_t sin, cos;
+};
+
+void AdcInitSimple() {
+ AdcInitCommon();
+
+ // ENC_SIN ADC0_SE23
+ // ENC_COS ADC1_SE23
+}
+
+SimpleAdcReadings AdcReadSimple(const DisableInterrupts &) {
+ SimpleAdcReadings r;
+
+ ADC0_SC1A = 23;
+ ADC1_SC1A = 23;
+ while (!(ADC0_SC1A & ADC_SC1_COCO)) {
+ }
+ while (!(ADC1_SC1A & ADC_SC1_COCO)) {
+ }
+ r.sin = ADC0_RA;
+ r.cos = ADC1_RA;
+
+ return r;
+}
+
const ShifterHallEffect kThreeStateDriveShifter{0.0, 0.0, 0.25, 0.75};
const DrivetrainConfig<float> &GetDrivetrainConfig() {
@@ -468,7 +494,7 @@
}
struct EncoderReading {
- EncoderReading(const salsa::SimpleAdcReadings &adc_readings) {
+ EncoderReading(const SimpleAdcReadings &adc_readings) {
const float sin = ConvertEncoderChannel(adc_readings.sin);
const float cos = ConvertEncoderChannel(adc_readings.cos);
@@ -491,10 +517,10 @@
global_polydrivetrain.load(::std::memory_order_acquire);
Spring *spring = global_spring.load(::std::memory_order_acquire);
- salsa::SimpleAdcReadings adc_readings;
+ SimpleAdcReadings adc_readings;
{
DisableInterrupts disable_interrupts;
- adc_readings = salsa::AdcReadSimple(disable_interrupts);
+ adc_readings = AdcReadSimple(disable_interrupts);
}
EncoderReading encoder(adc_readings);
@@ -724,7 +750,7 @@
PIT_TCTRL3 = PIT_TCTRL_TIE | PIT_TCTRL_TEN;
can_init(0, 1);
- salsa::AdcInitSimple();
+ AdcInitSimple();
SetupPwmFtm(FTM0);
SetupPwmFtm(FTM3);