From 2dc06e8d79f6216a5143000ffb50414af3b80faf Mon Sep 17 00:00:00 2001 From: Jakob Gegeniger Date: Sat, 23 Nov 2024 22:01:01 +0100 Subject: [PATCH] including homing sensor --- .vscode/settings.json | 2 ++ CMakeLists.txt | 2 +- components/movement/include/stepperMotor.hpp | 23 ++++++++++---------- main/CMakeLists.txt | 2 +- main/watchMain.cpp | 22 ++++++++++++++++--- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 8a31c1c..28d34ea 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,6 @@ { + "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -2, NamespaceIndentation: All, FixNamespaceComments: false }", + "C_Cpp.intelliSenseEngine": "default", "idf.adapterTargetName": "esp32", "idf.customExtraPaths": "C:\\Tools\\ESP\\tools\\xtensa-esp-elf-gdb\\14.2_20240403\\xtensa-esp-elf-gdb\\bin;C:\\Tools\\ESP\\tools\\riscv32-esp-elf-gdb\\14.2_20240403\\riscv32-esp-elf-gdb\\bin;C:\\Tools\\ESP\\tools\\xtensa-esp-elf\\esp-13.2.0_20240530\\xtensa-esp-elf\\bin;C:\\Tools\\ESP\\tools\\riscv32-esp-elf\\esp-13.2.0_20240530\\riscv32-esp-elf\\bin;C:\\Tools\\ESP\\tools\\esp32ulp-elf\\2.38_20240113\\esp32ulp-elf\\bin;C:\\Tools\\ESP\\tools\\cmake\\3.24.0\\bin;C:\\Tools\\ESP\\tools\\openocd-esp32\\v0.12.0-esp32-20240318\\openocd-esp32\\bin;C:\\Tools\\ESP\\tools\\ninja\\1.11.1;C:\\Tools\\ESP\\tools\\idf-exe\\1.0.3;C:\\Tools\\ESP\\tools\\ccache\\4.8\\ccache-4.8-windows-x86_64;C:\\Tools\\ESP\\tools\\dfu-util\\0.11\\dfu-util-0.11-win64;C:\\Tools\\ESP\\tools\\esp-rom-elfs\\20240305", diff --git a/CMakeLists.txt b/CMakeLists.txt index 0678268..6a16738 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ cmake_minimum_required(VERSION 3.16) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(X_WatchController-FW) +project(X_WatchController_FW) diff --git a/components/movement/include/stepperMotor.hpp b/components/movement/include/stepperMotor.hpp index a438e07..cdbf965 100644 --- a/components/movement/include/stepperMotor.hpp +++ b/components/movement/include/stepperMotor.hpp @@ -128,17 +128,17 @@ class StepperMotor { void findRef() { ESP_LOGI("Stepper", "Homing ..."); - // if (_initSensor.read()) { - // _mode = Mode::HomingFromSensor; - // ESP_LOGI("Stepper", "First leave HomePos"); - // } else { - // _mode = Mode::HomingToSensorBegin; - // ESP_LOGI("Stepper", "Find start of HomePos"); - // } + if (_initSensor.read()) { + _mode = Mode::HomingFromSensor; + ESP_LOGI("Stepper", "First leave HomePos"); + } else { + _mode = Mode::HomingToSensorBegin; + ESP_LOGI("Stepper", "Find start of HomePos"); + } - // while (_mode != Mode::Idle) { - // fos::Task::delayTicks(1); - // } + while (_mode != Mode::Idle) { + fos::Task::delayTicks(1); + } int fullStep = _config.resolution / 4; _driver.setPos(0); @@ -252,7 +252,7 @@ class StepperMotor { Trajectory _trajectory{}; Position<50, 5> _indexPos{}; - static bool IRAM_ATTR TimerCallParam(HwTimerT &, StepperMotor &stepper) { + static bool TimerCallParam(HwTimerT &, StepperMotor &stepper) { switch (stepper._mode) { case Mode::HomingFromSensor: { if (stepper._initSensor.read() == false) { @@ -302,6 +302,7 @@ class StepperMotor { } break; case Mode::Idle: + default: break; } diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 0678c5b..4e794bc 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,2 +1,2 @@ -idf_component_register(SRCS "watch_main.cpp" +idf_component_register(SRCS "watchMain.cpp" INCLUDE_DIRS ".") diff --git a/main/watchMain.cpp b/main/watchMain.cpp index c2129d0..2548842 100644 --- a/main/watchMain.cpp +++ b/main/watchMain.cpp @@ -26,10 +26,12 @@ #include "ethernet_init.h" #include "esp_netif.h" #include "esp_eth.h" + // Component header #include "Task.hpp" #include "PwmExpanderPca9685.hpp" #include "StepperDrv8833.hpp" +#include "stepperMotor.hpp" static const char *TAG = "Watch"; static esp_eth_handle_t s_eth_handle = NULL; @@ -151,17 +153,31 @@ void MovementTask() { StepperDriverDrv8833 stepperDriver(stepperPins, MicroSteps); stepperDriver.setPos(0); - while (true) { + StepperMotor::Config stepperCfg{1.8F, MicroSteps}; + InputPort initSens(GPIO_NUM_33); + initSens.setLogic(GpioPort::Logic::Inverted); + StepperMotor stepper(stepperCfg, stepperDriver, initSens); + + int i = 0; + while (i++ < 80) { stepperDriver.step(1); stepperDriver.getSubPos(); fos::Task::delayMs(100); } + + ESP_LOGI("Stepper", "Find Home"); + stepper.findRef(); + ESP_LOGI(TAG, "Fist Position is %f.2", stepper.getScaledPos() * 6); + fos::Task::delayMs(1000); + + while (true) { + fos::Task::delayMs(100); + } } void IoTest() { ESP_LOGI(TAG, "Start IO"); - InputPort in1(GPIO_NUM_33); InputPort in2(GPIO_NUM_32); InputPort mFault(GPIO_NUM_35); @@ -169,7 +185,7 @@ void IoTest() OutputPort nReset(GPIO_NUM_5); while (true) { - ESP_LOGI("Light", "InValues %i %i %i", in1.read(), in2.read(), mFault.read()); + ESP_LOGI("Light", "InValues %i %i", in2.read(), mFault.read()); nEnable.write(true); nReset.write(true); fos::Task::delayMs(500);