diff --git a/Firmware/MotorControl/axis.cpp b/Firmware/MotorControl/axis.cpp index 5ff333fd..e7e8d0bb 100644 --- a/Firmware/MotorControl/axis.cpp +++ b/Firmware/MotorControl/axis.cpp @@ -97,10 +97,10 @@ void Axis::clear_config() { config_.can_node_id = axis_num_; } -// @brief Sets up all components of the axis, -// such as gate driver and encoder hardware. +// @brief Does Nothing bool Axis::setup() { - return motor_.setup(); + // Does nothing - Motor and encoder setup called separately. + return true; } static void run_state_machine_loop_wrapper(void* ctx) { diff --git a/Firmware/MotorControl/encoder.hpp b/Firmware/MotorControl/encoder.hpp index e2c5db07..645f3811 100644 --- a/Firmware/MotorControl/encoder.hpp +++ b/Firmware/MotorControl/encoder.hpp @@ -6,9 +6,10 @@ #include "utils.hpp" #include + class Encoder : public ODriveIntf::EncoderIntf { public: - const uint32_t MODE_FLAG_ABS = 0x100; + static constexpr uint32_t MODE_FLAG_ABS = 0x100; struct Config_t { Mode mode = MODE_INCREMENTAL; diff --git a/Firmware/MotorControl/main.cpp b/Firmware/MotorControl/main.cpp index 1befd9cf..01a37299 100644 --- a/Firmware/MotorControl/main.cpp +++ b/Firmware/MotorControl/main.cpp @@ -259,19 +259,28 @@ static void rtos_main(void*) { // must happen after communication is initialized pwm0_input.init(); - // Set up hardware for all components - for (size_t i = 0; i < AXIS_COUNT; ++i) { - if (!axes[i].setup()) { - for (;;) { - osDelay(10); // TODO: proper error handling - } + // Set up the CS pins for absolute encoders + for(auto& axis : axes){ + if(axis.encoder_.config_.mode & Encoder::MODE_FLAG_ABS){ + axis.encoder_.abs_spi_cs_pin_init(); } } + // Setup motors (DRV8301 SPI transactions here) + for(auto& axis : axes){ + axis.motor_.setup(); + } + + // Setup encoders (Starts encoder SPI transactions) for(auto& axis : axes){ axis.encoder_.setup(); } + // Setup anything remaining in each axis + for(auto& axis : axes){ + axis.setup(); + } + // Start PWM and enable adc interrupts/callbacks start_adc_pwm();