Skip to content

Commit

Permalink
feat(flex-stacker): Motor timer bringup (#454)
Browse files Browse the repository at this point in the history
Bringing up the motor timers for XLZ axes with them ticking at 100KHz.
---------
Co-authored-by: Ryan howard <[email protected]>
  • Loading branch information
ahiuchingau authored Aug 13, 2024
1 parent 40921d4 commit 2a06ed3
Show file tree
Hide file tree
Showing 16 changed files with 470 additions and 115 deletions.
1 change: 1 addition & 0 deletions stm32-modules/flex-stacker/firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(${TARGET_MODULE_NAME}_FW_LINTABLE_SRCS
${MOTOR_CONTROL_DIR}/freertos_motor_task.cpp
${MOTOR_CONTROL_DIR}/freertos_motor_driver_task.cpp
${MOTOR_CONTROL_DIR}/motor_driver_policy.cpp
${MOTOR_CONTROL_DIR}/motor_policy.cpp
)

# Add source files that should NOT be checked by clang-tidy here
Expand Down
2 changes: 2 additions & 0 deletions stm32-modules/flex-stacker/firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "firmware/freertos_tasks.hpp"
#include "firmware/system_stm32g4xx.h"
#include "ot_utils/freertos/freertos_task.hpp"
#include "systemwide.h"
#include "task.h"

using EntryPoint = std::function<void(tasks::FirmwareTasks::QueueAggregator *)>;
Expand All @@ -28,6 +29,7 @@ static auto motor_task =
static auto ui_task =
ot_utils::freertos_task::FreeRTOSTask<tasks::UI_STACK_SIZE, EntryPoint>(
ui_task_entry);

auto main() -> int {
HardwareInit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@
#include "firmware/motor_hardware.h"
#include "firmware/motor_policy.hpp"
#include "flex-stacker/motor_task.hpp"
#include "motor_interrupt.hpp"
#include "ot_utils/freertos/freertos_timer.hpp"
#include "stm32g4xx_it.h"
#include "systemwide.h"

namespace motor_control_task {

// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto x_motor_interrupt =
motor_interrupt_controller::MotorInterruptController(MotorID::MOTOR_X);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto z_motor_interrupt =
motor_interrupt_controller::MotorInterruptController(MotorID::MOTOR_Z);
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto l_motor_interrupt =
motor_interrupt_controller::MotorInterruptController(MotorID::MOTOR_L);

enum class Notifications : uint8_t {
INCOMING_MESSAGE = 1,
};
Expand All @@ -20,15 +33,34 @@ static tasks::FirmwareTasks::MotorQueue
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static auto _top_task = motor_task::MotorTask(_queue, nullptr);

static auto callback_glue(MotorID motor_id) {
switch (motor_id) {
case MotorID::MOTOR_L:
l_motor_interrupt.tick();
break;
case MotorID::MOTOR_X:
x_motor_interrupt.tick();
break;
case MotorID::MOTOR_Z:
z_motor_interrupt.tick();
break;
default:
break;
}
}

auto run(tasks::FirmwareTasks::QueueAggregator* aggregator) -> void {
auto* handle = xTaskGetCurrentTaskHandle();
_queue.provide_handle(handle);
aggregator->register_queue(_queue);
_top_task.provide_aggregator(aggregator);

motor_hardware_init();

initialize_callbacks(callback_glue);
auto policy = motor_policy::MotorPolicy();
policy.enable_motor(MotorID::MOTOR_L);
policy.enable_motor(MotorID::MOTOR_X);
policy.enable_motor(MotorID::MOTOR_Z);
while (true) {
_top_task.run_once(policy);
}
Expand Down
Loading

0 comments on commit 2a06ed3

Please sign in to comment.