Outsource global variables, Optimize comments
- outsource global variables and objects - move from config.hpp to global.cpp / hpp - rename config.hpp, thus change all includes - re-arrange includes -> in source files instead of header - optimize / make function comment titles more consistent - optimize comments overall - add several temporary files to gitignore - fix unused variable compiler warnings
This commit is contained in:
parent
4c149a7743
commit
4aab1e1343
14
.gitignore
vendored
14
.gitignore
vendored
@ -1,15 +1,29 @@
|
|||||||
# ESP-IDF default build directory
|
# ESP-IDF default build directory
|
||||||
build
|
build
|
||||||
|
sdkconfig.old
|
||||||
|
dependencies.lock
|
||||||
|
|
||||||
# VIM files
|
# VIM files
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
|
**/.cache
|
||||||
|
|
||||||
|
# VS-code
|
||||||
|
settings.json
|
||||||
|
|
||||||
# drawio files
|
# drawio files
|
||||||
*.bkp
|
*.bkp
|
||||||
|
|
||||||
# freecad backup files
|
# freecad backup files
|
||||||
*.FCStd1
|
*.FCStd1
|
||||||
|
*.FCBak
|
||||||
|
# stl files are usually temporary
|
||||||
|
*.stl
|
||||||
|
|
||||||
# kicad backup files
|
# kicad backup files
|
||||||
pcb/*/*backups/
|
pcb/*/*backups/
|
||||||
|
|
||||||
|
# other
|
||||||
|
octave-workspace
|
||||||
|
del
|
||||||
|
screenshots
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS
|
SRCS
|
||||||
"main.cpp"
|
"main.cpp"
|
||||||
"config.cpp"
|
"global.cpp"
|
||||||
"control.cpp"
|
"control.cpp"
|
||||||
"buzzer.cpp"
|
"buzzer.cpp"
|
||||||
"vfd.cpp"
|
"vfd.cpp"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "buzzer.hpp"
|
#include "buzzer.hpp"
|
||||||
#include "config.hpp"
|
#include "config.h"
|
||||||
|
|
||||||
static const char *TAG_BUZZER = "buzzer";
|
static const char *TAG_BUZZER = "buzzer";
|
||||||
|
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
extern "C" {
|
|
||||||
#include "driver/adc.h"
|
|
||||||
}
|
|
||||||
#include "gpio_evaluateSwitch.hpp"
|
|
||||||
#include "buzzer.hpp"
|
|
||||||
#include "switchesAnalog.hpp"
|
|
||||||
|
|
||||||
|
#include "esp_idf_version.h"
|
||||||
|
|
||||||
|
//note: global variables and objects were moved to global.hpp
|
||||||
|
|
||||||
//===================================
|
//===================================
|
||||||
//===== define output gpio pins =====
|
//===== define output gpio pins =====
|
||||||
@ -49,6 +46,7 @@ extern "C" {
|
|||||||
#define SW_CUT sw_gpio_33
|
#define SW_CUT sw_gpio_33
|
||||||
#define SW_AUTO_CUT sw_gpio_32
|
#define SW_AUTO_CUT sw_gpio_32
|
||||||
//#define ? sw_gpio_34
|
//#define ? sw_gpio_34
|
||||||
|
//note: actual objects are created in global.cpp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -68,6 +66,7 @@ extern "C" {
|
|||||||
#define DISPLAY_PIN_NUM_CLK GPIO_NUM_22
|
#define DISPLAY_PIN_NUM_CLK GPIO_NUM_22
|
||||||
#define DISPLAY_PIN_NUM_CS GPIO_NUM_27
|
#define DISPLAY_PIN_NUM_CS GPIO_NUM_27
|
||||||
#define DISPLAY_DELAY 2000
|
#define DISPLAY_DELAY 2000
|
||||||
|
#define DISPLAY_BRIGHTNESS 8
|
||||||
|
|
||||||
//--------------------------
|
//--------------------------
|
||||||
//----- encoder config -----
|
//----- encoder config -----
|
||||||
@ -100,7 +99,7 @@ extern "C" {
|
|||||||
//--------------------------
|
//--------------------------
|
||||||
//------ calibration -------
|
//------ calibration -------
|
||||||
//--------------------------
|
//--------------------------
|
||||||
//enable mode encoder test for calibration
|
//enable mode encoder test for calibration (determine ENCODER_STEPS_PER_METER)
|
||||||
//if defined, displays always show length and steps instead of the normal messages
|
//if defined, displays always show length and steps instead of the normal messages
|
||||||
//#define ENCODER_TEST
|
//#define ENCODER_TEST
|
||||||
|
|
||||||
@ -118,26 +117,3 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//============================
|
|
||||||
//===== global variables =====
|
|
||||||
//============================
|
|
||||||
//create global evaluated switch objects
|
|
||||||
//--- switches on digital gpio pins ---
|
|
||||||
//extern gpio_evaluatedSwitch sw_gpio_39;
|
|
||||||
extern gpio_evaluatedSwitch sw_gpio_34;
|
|
||||||
extern gpio_evaluatedSwitch sw_gpio_32;
|
|
||||||
extern gpio_evaluatedSwitch sw_gpio_33;
|
|
||||||
extern gpio_evaluatedSwitch sw_gpio_25;
|
|
||||||
extern gpio_evaluatedSwitch sw_gpio_26;
|
|
||||||
extern gpio_evaluatedSwitch sw_gpio_14;
|
|
||||||
|
|
||||||
//--- switches connected to 4-sw-to-analog stripboard ---
|
|
||||||
extern gpio_evaluatedSwitch sw_gpio_analog_0;
|
|
||||||
extern gpio_evaluatedSwitch sw_gpio_analog_1;
|
|
||||||
extern gpio_evaluatedSwitch sw_gpio_analog_2;
|
|
||||||
extern gpio_evaluatedSwitch sw_gpio_analog_3;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//create global buzzer object
|
|
||||||
extern buzzer_t buzzer;
|
|
@ -1,22 +1,47 @@
|
|||||||
#include "control.hpp"
|
extern "C"
|
||||||
|
{
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#include <freertos/task.h>
|
||||||
|
#include <esp_idf_version.h>
|
||||||
|
#include "freertos/queue.h"
|
||||||
|
#include "esp_system.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "driver/adc.h"
|
||||||
|
|
||||||
|
#include "max7219.h"
|
||||||
|
|
||||||
|
}
|
||||||
|
#include <cmath>
|
||||||
|
#include "config.h"
|
||||||
|
#include "gpio_evaluateSwitch.hpp"
|
||||||
|
#include "gpio_adc.hpp"
|
||||||
|
#include "buzzer.hpp"
|
||||||
|
#include "vfd.hpp"
|
||||||
|
#include "display.hpp"
|
||||||
|
#include "cutter.hpp"
|
||||||
#include "encoder.hpp"
|
#include "encoder.hpp"
|
||||||
#include "guide-stepper.hpp"
|
#include "guide-stepper.hpp"
|
||||||
|
#include "global.hpp"
|
||||||
|
#include "control.hpp"
|
||||||
|
|
||||||
|
|
||||||
//--------------------
|
//-----------------------------------------
|
||||||
//---- variables -----
|
//--------------- variables ---------------
|
||||||
//--------------------
|
//-----------------------------------------
|
||||||
static const char *TAG = "control"; //tag for logging
|
static const char *TAG = "control"; //tag for logging
|
||||||
|
|
||||||
|
//control
|
||||||
const char* systemStateStr[7] = {"COUNTING", "WINDING_START", "WINDING", "TARGET_REACHED", "AUTO_CUT_WAITING", "CUTTING", "MANUAL"};
|
const char* systemStateStr[7] = {"COUNTING", "WINDING_START", "WINDING", "TARGET_REACHED", "AUTO_CUT_WAITING", "CUTTING", "MANUAL"};
|
||||||
|
|
||||||
systemState_t controlState = systemState_t::COUNTING;
|
systemState_t controlState = systemState_t::COUNTING;
|
||||||
static uint32_t timestamp_lastStateChange = 0;
|
static uint32_t timestamp_lastStateChange = 0;
|
||||||
|
|
||||||
|
//display
|
||||||
static char buf_disp1[10];// 8 digits + decimal point + \0
|
static char buf_disp1[10];// 8 digits + decimal point + \0
|
||||||
static char buf_disp2[10];// 8 digits + decimal point + \0
|
static char buf_disp2[10];// 8 digits + decimal point + \0
|
||||||
static char buf_tmp[15];
|
static char buf_tmp[15];
|
||||||
|
|
||||||
|
//track length
|
||||||
static int lengthNow = 0; //length measured in mm
|
static int lengthNow = 0; //length measured in mm
|
||||||
static int lengthTarget = 5000; //default target length in mm
|
static int lengthTarget = 5000; //default target length in mm
|
||||||
static int lengthRemaining = 0; //(target - now) length needed for reaching the target
|
static int lengthRemaining = 0; //(target - now) length needed for reaching the target
|
||||||
@ -31,9 +56,9 @@ static bool autoCutEnabled = false; //store state of toggle switch (no hotswitch
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------
|
//-----------------------------------------
|
||||||
//---- functions -----
|
//--------------- functions ---------------
|
||||||
//--------------------
|
//-----------------------------------------
|
||||||
|
|
||||||
//========================
|
//========================
|
||||||
//===== change State =====
|
//===== change State =====
|
||||||
@ -57,12 +82,13 @@ void changeState (systemState_t stateNew) {
|
|||||||
//=================================
|
//=================================
|
||||||
//===== handle Stop Condition =====
|
//===== handle Stop Condition =====
|
||||||
//=================================
|
//=================================
|
||||||
//function that checks whether start button is released or target is reached (used in multiple states)
|
//function that checks whether start button is released or target is reached
|
||||||
//returns true when stopped, false when no action
|
//and takes according action if so (used in multiple states)
|
||||||
|
//returns true when stop condition was met, false when no action required
|
||||||
bool handleStopCondition(handledDisplay * displayTop, handledDisplay * displayBot){
|
bool handleStopCondition(handledDisplay * displayTop, handledDisplay * displayBot){
|
||||||
//--- stop conditions ---
|
//--- stop conditions ---
|
||||||
//stop conditions that are checked in any mode
|
//stop conditions that are checked in any mode
|
||||||
//target reached
|
//target reached -> reached state, stop motor, display message
|
||||||
if (lengthRemaining <= 0 ) {
|
if (lengthRemaining <= 0 ) {
|
||||||
changeState(systemState_t::TARGET_REACHED);
|
changeState(systemState_t::TARGET_REACHED);
|
||||||
vfd_setState(false);
|
vfd_setState(false);
|
||||||
@ -71,7 +97,7 @@ bool handleStopCondition(handledDisplay * displayTop, handledDisplay * displayBo
|
|||||||
buzzer.beep(2, 100, 100);
|
buzzer.beep(2, 100, 100);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//start button released
|
//start button released -> idle state, stop motor, display message
|
||||||
else if (SW_START.state == false) {
|
else if (SW_START.state == false) {
|
||||||
changeState(systemState_t::COUNTING);
|
changeState(systemState_t::COUNTING);
|
||||||
vfd_setState(false);
|
vfd_setState(false);
|
||||||
@ -120,7 +146,6 @@ void setDynSpeedLvl(uint8_t lvlMax = 3){
|
|||||||
//task that controls the entire machine
|
//task that controls the entire machine
|
||||||
void task_control(void *pvParameter)
|
void task_control(void *pvParameter)
|
||||||
{
|
{
|
||||||
|
|
||||||
//-- initialize display --
|
//-- initialize display --
|
||||||
max7219_t two7SegDisplays = display_init();
|
max7219_t two7SegDisplays = display_init();
|
||||||
//create two separate custom handled display instances
|
//create two separate custom handled display instances
|
||||||
@ -132,13 +157,16 @@ void task_control(void *pvParameter)
|
|||||||
//currently show name and date and scrolling 'hello'
|
//currently show name and date and scrolling 'hello'
|
||||||
display_ShowWelcomeMsg(two7SegDisplays);
|
display_ShowWelcomeMsg(two7SegDisplays);
|
||||||
|
|
||||||
|
// ##############################
|
||||||
//===== loop =====
|
// ######## control loop ########
|
||||||
|
// ##############################
|
||||||
|
// repeatedly handle the machine
|
||||||
while(1){
|
while(1){
|
||||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
|
|
||||||
//------ handle switches ------
|
//------ handle switches ------
|
||||||
//run handle functions for all switches
|
//run handle functions for all switches used here
|
||||||
SW_START.handle();
|
SW_START.handle();
|
||||||
SW_RESET.handle();
|
SW_RESET.handle();
|
||||||
SW_SET.handle();
|
SW_SET.handle();
|
||||||
@ -224,7 +252,7 @@ void task_control(void *pvParameter)
|
|||||||
buzzer.beep(3, 100, 60);
|
buzzer.beep(3, 100, 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
//##### custom target length using poti #####
|
//##### SET switch #####
|
||||||
//set target length to poti position when SET switch is pressed
|
//set target length to poti position when SET switch is pressed
|
||||||
if (SW_SET.state == true) {
|
if (SW_SET.state == true) {
|
||||||
//read adc
|
//read adc
|
||||||
@ -409,11 +437,11 @@ void task_control(void *pvParameter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ENCODER_TEST
|
||||||
//--------------------------
|
//--------------------------
|
||||||
//------ encoder test ------
|
//------ encoder test ------
|
||||||
//--------------------------
|
//--------------------------
|
||||||
#ifdef ENCODER_TEST
|
//mode for calibrating the cable length measurement (determine ENCODER_STEPS_PER_METER in config.h)
|
||||||
//run display handle functions
|
//run display handle functions
|
||||||
displayTop.handle();
|
displayTop.handle();
|
||||||
displayBot.handle();
|
displayBot.handle();
|
||||||
@ -432,7 +460,7 @@ void task_control(void *pvParameter)
|
|||||||
lengthBeeped = lengthNow;
|
lengthBeeped = lengthNow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else //not in encoder calibration mode
|
||||||
|
|
||||||
//--------------------------
|
//--------------------------
|
||||||
//-------- display1 --------
|
//-------- display1 --------
|
||||||
@ -452,7 +480,6 @@ void task_control(void *pvParameter)
|
|||||||
displayTop.showString(buf_disp1);
|
displayTop.showString(buf_disp1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------
|
//--------------------------
|
||||||
//-------- display2 --------
|
//-------- display2 --------
|
||||||
//--------------------------
|
//--------------------------
|
||||||
@ -485,6 +512,7 @@ void task_control(void *pvParameter)
|
|||||||
displayBot.showString(buf_tmp);
|
displayBot.showString(buf_tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // end else ifdef ENCODER_TEST
|
||||||
|
|
||||||
//----------------------------
|
//----------------------------
|
||||||
//------- control lamp -------
|
//------- control lamp -------
|
||||||
@ -501,10 +529,6 @@ void task_control(void *pvParameter)
|
|||||||
gpio_set_level(GPIO_LAMP, 0);
|
gpio_set_level(GPIO_LAMP, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} //end while(1)
|
} //end while(1)
|
||||||
|
|
||||||
} //end task_control
|
} //end task_control
|
||||||
|
@ -1,34 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <freertos/FreeRTOS.h>
|
|
||||||
#include <freertos/task.h>
|
|
||||||
#include <esp_idf_version.h>
|
|
||||||
#include "freertos/queue.h"
|
|
||||||
#include "esp_system.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "driver/adc.h"
|
|
||||||
|
|
||||||
#include "max7219.h"
|
|
||||||
|
|
||||||
}
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
#include "config.hpp"
|
|
||||||
#include "gpio_evaluateSwitch.hpp"
|
|
||||||
#include "gpio_adc.hpp"
|
|
||||||
#include "buzzer.hpp"
|
|
||||||
#include "vfd.hpp"
|
|
||||||
#include "display.hpp"
|
|
||||||
#include "cutter.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//enum describing the state of the system
|
//enum describing the state of the system
|
||||||
enum class systemState_t {COUNTING, WINDING_START, WINDING, TARGET_REACHED, AUTO_CUT_WAITING, CUTTING, MANUAL};
|
enum class systemState_t {COUNTING, WINDING_START, WINDING, TARGET_REACHED, AUTO_CUT_WAITING, CUTTING, MANUAL};
|
||||||
|
|
||||||
//array with enum as strings for logging states
|
//array with enum as strings for logging states
|
||||||
extern const char* systemStateStr[7];
|
extern const char* systemStateStr[7];
|
||||||
|
|
||||||
|
|
||||||
//task that controls the entire machine (has to be created as task in main function)
|
//task that controls the entire machine (has to be created as task in main function)
|
||||||
void task_control(void *pvParameter);
|
void task_control(void *pvParameter);
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include "cutter.hpp"
|
#include "cutter.hpp"
|
||||||
|
#include "config.h"
|
||||||
|
#include "global.hpp"
|
||||||
|
|
||||||
const char* cutter_stateStr[5] = {"IDLE", "START", "CUTTING", "CANCELED", "TIMEOUT"}; //define strings for logging the state
|
const char* cutter_stateStr[5] = {"IDLE", "START", "CUTTING", "CANCELED", "TIMEOUT"}; //define strings for logging the state
|
||||||
|
|
||||||
@ -39,7 +41,6 @@ void cutter_stop(){
|
|||||||
if(cutter_state != cutter_state_t::IDLE){
|
if(cutter_state != cutter_state_t::IDLE){
|
||||||
setState(cutter_state_t::CANCELED);
|
setState(cutter_state_t::CANCELED);
|
||||||
}
|
}
|
||||||
//starts motor on state change
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -131,7 +132,6 @@ void cutter_handle(){
|
|||||||
//SW_CUTTER_POS.minOnMs = 10;
|
//SW_CUTTER_POS.minOnMs = 10;
|
||||||
//SW_CUTTER_POS.minOffMs = 10;
|
//SW_CUTTER_POS.minOffMs = 10;
|
||||||
|
|
||||||
|
|
||||||
switch(cutter_state){
|
switch(cutter_state){
|
||||||
case cutter_state_t::IDLE:
|
case cutter_state_t::IDLE:
|
||||||
case cutter_state_t::TIMEOUT:
|
case cutter_state_t::TIMEOUT:
|
||||||
@ -142,14 +142,13 @@ void cutter_handle(){
|
|||||||
case cutter_state_t::START:
|
case cutter_state_t::START:
|
||||||
//--- moved away from idle position ---
|
//--- moved away from idle position ---
|
||||||
//if (gpio_get_level(GPIO_CUTTER_POS_SW) == 0){ //contact closed
|
//if (gpio_get_level(GPIO_CUTTER_POS_SW) == 0){ //contact closed
|
||||||
if (SW_CUTTER_POS.state == true) { //contact closed -> not at idle pos
|
if (SW_CUTTER_POS.state == true) { //contact closed -> not at idle pos anymore
|
||||||
setState(cutter_state_t::CUTTING);
|
setState(cutter_state_t::CUTTING);
|
||||||
}
|
}
|
||||||
//--- timeout ---
|
//--- timeout ---
|
||||||
else {
|
else {
|
||||||
checkTimeout();
|
checkTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case cutter_state_t::CUTTING:
|
case cutter_state_t::CUTTING:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "display.hpp"
|
#include "display.hpp"
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
//=== variables ===
|
//=== variables ===
|
||||||
static const char *TAG = "display"; //tag for logging
|
static const char *TAG = "display"; //tag for logging
|
||||||
@ -34,7 +35,7 @@ max7219_t display_init(){
|
|||||||
ESP_ERROR_CHECK(max7219_init_desc(&dev, HOST, MAX7219_MAX_CLOCK_SPEED_HZ, DISPLAY_PIN_NUM_CS));
|
ESP_ERROR_CHECK(max7219_init_desc(&dev, HOST, MAX7219_MAX_CLOCK_SPEED_HZ, DISPLAY_PIN_NUM_CS));
|
||||||
ESP_ERROR_CHECK(max7219_init(&dev));
|
ESP_ERROR_CHECK(max7219_init(&dev));
|
||||||
//0...15
|
//0...15
|
||||||
ESP_ERROR_CHECK(max7219_set_brightness(&dev, 8)); //TODO add this to config
|
ESP_ERROR_CHECK(max7219_set_brightness(&dev, DISPLAY_BRIGHTNESS));
|
||||||
return dev;
|
return dev;
|
||||||
//display = dev;
|
//display = dev;
|
||||||
ESP_LOGI(TAG, "initializing display - done");
|
ESP_LOGI(TAG, "initializing display - done");
|
||||||
@ -50,7 +51,7 @@ void display_ShowWelcomeMsg(max7219_t dev){
|
|||||||
//show name and date
|
//show name and date
|
||||||
ESP_LOGI(TAG, "showing startup message...");
|
ESP_LOGI(TAG, "showing startup message...");
|
||||||
max7219_clear(&dev);
|
max7219_clear(&dev);
|
||||||
max7219_draw_text_7seg(&dev, 0, "CUTTER 29.09.2022");
|
max7219_draw_text_7seg(&dev, 0, "CUTTER 15.03.2024");
|
||||||
// 1234567812 34 5678
|
// 1234567812 34 5678
|
||||||
vTaskDelay(pdMS_TO_TICKS(700));
|
vTaskDelay(pdMS_TO_TICKS(700));
|
||||||
//scroll "hello" over 2 displays
|
//scroll "hello" over 2 displays
|
||||||
@ -64,7 +65,7 @@ void display_ShowWelcomeMsg(max7219_t dev){
|
|||||||
//noticed rare bug that one display does not initialize / is not configured correctly after start
|
//noticed rare bug that one display does not initialize / is not configured correctly after start
|
||||||
//initialize display again after the welcome message in case it did not work the first time
|
//initialize display again after the welcome message in case it did not work the first time
|
||||||
ESP_ERROR_CHECK(max7219_init(&dev));
|
ESP_ERROR_CHECK(max7219_init(&dev));
|
||||||
ESP_ERROR_CHECK(max7219_set_brightness(&dev, 8)); //TODO add this to config
|
ESP_ERROR_CHECK(max7219_set_brightness(&dev, DISPLAY_BRIGHTNESS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -83,9 +84,9 @@ handledDisplay::handledDisplay(max7219_t displayDevice, uint8_t posStart_f) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------
|
//================================
|
||||||
//---------- showString ----------
|
//========== showString ==========
|
||||||
//--------------------------------
|
//================================
|
||||||
//function that displays a given string on the display
|
//function that displays a given string on the display
|
||||||
void handledDisplay::showString(const char * buf, uint8_t pos_f){
|
void handledDisplay::showString(const char * buf, uint8_t pos_f){
|
||||||
//calculate actual absolute position
|
//calculate actual absolute position
|
||||||
@ -103,11 +104,11 @@ void handledDisplay::showString(const char * buf, uint8_t pos_f){
|
|||||||
|
|
||||||
|
|
||||||
//TODO: blinkStrings() and blink() are very similar - can be optimized?
|
//TODO: blinkStrings() and blink() are very similar - can be optimized?
|
||||||
//only difficulty currently is the reset behaivor of blinkStrings through showString (blink does not reset)
|
//only difficulty is the reset behaivor of blinkStrings through showString (blink does not reset)
|
||||||
|
|
||||||
//----------------------------------
|
//==================================
|
||||||
//---------- blinkStrings ----------
|
//========== blinkStrings ==========
|
||||||
//----------------------------------
|
//==================================
|
||||||
//function switches between two strings in a given interval
|
//function switches between two strings in a given interval
|
||||||
void handledDisplay::blinkStrings(const char * strOn_f, const char * strOff_f, uint32_t msOn_f, uint32_t msOff_f){
|
void handledDisplay::blinkStrings(const char * strOn_f, const char * strOff_f, uint32_t msOn_f, uint32_t msOff_f){
|
||||||
//copy/update variables
|
//copy/update variables
|
||||||
@ -130,9 +131,9 @@ void handledDisplay::blinkStrings(const char * strOn_f, const char * strOff_f, u
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------
|
//===============================
|
||||||
//------------ blink ------------
|
//============ blink ============
|
||||||
//-------------------------------
|
//===============================
|
||||||
//function triggers certain count and interval of off durations
|
//function triggers certain count and interval of off durations
|
||||||
void handledDisplay::blink(uint8_t count_f, uint32_t msOn_f, uint32_t msOff_f, const char * strOff_f) {
|
void handledDisplay::blink(uint8_t count_f, uint32_t msOn_f, uint32_t msOff_f, const char * strOff_f) {
|
||||||
//copy/update parameters
|
//copy/update parameters
|
||||||
@ -156,9 +157,9 @@ void handledDisplay::blink(uint8_t count_f, uint32_t msOn_f, uint32_t msOff_f, c
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------
|
//================================
|
||||||
//------------ handle ------------
|
//============ handle ============
|
||||||
//--------------------------------
|
//================================
|
||||||
//function that handles time based modes
|
//function that handles time based modes
|
||||||
//writes text to the 7 segment display depending on the current mode
|
//writes text to the 7 segment display depending on the current mode
|
||||||
void handledDisplay::handle() {
|
void handledDisplay::handle() {
|
||||||
|
@ -16,9 +16,8 @@ extern "C"
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
#include "config.hpp"
|
|
||||||
|
|
||||||
//function for initializing the display using configuration from macros in config.hpp
|
//function for initializing the display using configuration from macros in config.h
|
||||||
max7219_t display_init();
|
max7219_t display_init();
|
||||||
|
|
||||||
//show welcome message on the entire display
|
//show welcome message on the entire display
|
||||||
@ -44,8 +43,8 @@ class handledDisplay {
|
|||||||
//TODO: blinkStrings and blink are very similar - optimize?
|
//TODO: blinkStrings and blink are very similar - optimize?
|
||||||
//TODO: add 'scroll string' method
|
//TODO: add 'scroll string' method
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
|
private:
|
||||||
//--- variables ---
|
//--- variables ---
|
||||||
//config
|
//config
|
||||||
max7219_t dev;
|
max7219_t dev;
|
||||||
|
@ -8,6 +8,8 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#include "encoder.hpp"
|
#include "encoder.hpp"
|
||||||
|
#include "config.h"
|
||||||
|
#include "global.hpp"
|
||||||
|
|
||||||
|
|
||||||
//----------------------------
|
//----------------------------
|
||||||
@ -17,10 +19,14 @@ static rotary_encoder_info_t encoder; //encoder device/info
|
|||||||
QueueHandle_t encoder_queue = NULL; //encoder event queue
|
QueueHandle_t encoder_queue = NULL; //encoder event queue
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//------- functions -------
|
//------- functions -------
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//--- encoder_init ---
|
|
||||||
|
//======================
|
||||||
|
//==== encoder_init ====
|
||||||
|
//======================
|
||||||
//initialize encoder and return event queue
|
//initialize encoder and return event queue
|
||||||
QueueHandle_t encoder_init(){
|
QueueHandle_t encoder_init(){
|
||||||
// esp32-rotary-encoder requires that the GPIO ISR service is installed before calling rotary_encoder_register()
|
// esp32-rotary-encoder requires that the GPIO ISR service is installed before calling rotary_encoder_register()
|
||||||
@ -41,7 +47,9 @@ QueueHandle_t encoder_init(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--- encoder_getSteps ---
|
//========================
|
||||||
|
//=== encoder_getSteps ===
|
||||||
|
//========================
|
||||||
//get steps counted since last reset
|
//get steps counted since last reset
|
||||||
int encoder_getSteps(){
|
int encoder_getSteps(){
|
||||||
// Poll current position and direction
|
// Poll current position and direction
|
||||||
@ -52,14 +60,18 @@ int encoder_getSteps(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--- encoder_getLenMm ---
|
//========================
|
||||||
|
//=== encoder_getLenMm ===
|
||||||
|
//========================
|
||||||
//get current length in Mm since last reset
|
//get current length in Mm since last reset
|
||||||
int encoder_getLenMm(){
|
int encoder_getLenMm(){
|
||||||
return (float)encoder_getSteps() * 1000 / ENCODER_STEPS_PER_METER;
|
return (float)encoder_getSteps() * 1000 / ENCODER_STEPS_PER_METER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--- encoder_reset ---
|
//=======================
|
||||||
|
//==== encoder_reset ====
|
||||||
|
//=======================
|
||||||
//reset counted steps / length to 0
|
//reset counted steps / length to 0
|
||||||
void encoder_reset(){
|
void encoder_reset(){
|
||||||
rotary_encoder_reset(&encoder);
|
rotary_encoder_reset(&encoder);
|
||||||
|
@ -6,7 +6,6 @@ extern "C" {
|
|||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "config.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------
|
//----------------------------
|
||||||
@ -34,7 +33,6 @@ int encoder_getSteps();
|
|||||||
int encoder_getLenMm();
|
int encoder_getLenMm();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--- encoder_reset ---
|
//--- encoder_reset ---
|
||||||
//reset counted steps / length to 0
|
//reset counted steps / length to 0
|
||||||
void encoder_reset();
|
void encoder_reset();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "config.hpp"
|
#include "global.hpp"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
//--- inputs ---
|
//--- inputs ---
|
33
main/global.hpp
Normal file
33
main/global.hpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "driver/adc.h"
|
||||||
|
}
|
||||||
|
#include "gpio_evaluateSwitch.hpp"
|
||||||
|
#include "buzzer.hpp"
|
||||||
|
#include "switchesAnalog.hpp"
|
||||||
|
|
||||||
|
//note: in the actual code macro variables to these objects from config.h are used as the objects names
|
||||||
|
|
||||||
|
//============================
|
||||||
|
//===== global variables =====
|
||||||
|
//============================
|
||||||
|
//create global evaluated switch objects for all available pins
|
||||||
|
//--- switches on digital gpio pins ---
|
||||||
|
//extern gpio_evaluatedSwitch sw_gpio_39;
|
||||||
|
extern gpio_evaluatedSwitch sw_gpio_34;
|
||||||
|
extern gpio_evaluatedSwitch sw_gpio_32;
|
||||||
|
extern gpio_evaluatedSwitch sw_gpio_33;
|
||||||
|
extern gpio_evaluatedSwitch sw_gpio_25;
|
||||||
|
extern gpio_evaluatedSwitch sw_gpio_26;
|
||||||
|
extern gpio_evaluatedSwitch sw_gpio_14;
|
||||||
|
|
||||||
|
//--- switches connected to 4-sw-to-analog stripboard ---
|
||||||
|
extern gpio_evaluatedSwitch sw_gpio_analog_0;
|
||||||
|
extern gpio_evaluatedSwitch sw_gpio_analog_1;
|
||||||
|
extern gpio_evaluatedSwitch sw_gpio_analog_2;
|
||||||
|
extern gpio_evaluatedSwitch sw_gpio_analog_3;
|
||||||
|
|
||||||
|
|
||||||
|
//create global buzzer object
|
||||||
|
extern buzzer_t buzzer;
|
@ -9,7 +9,8 @@ extern "C"
|
|||||||
}
|
}
|
||||||
|
|
||||||
#include "stepper.hpp"
|
#include "stepper.hpp"
|
||||||
#include "config.hpp"
|
#include "config.h"
|
||||||
|
#include "global.hpp"
|
||||||
#include "guide-stepper.hpp"
|
#include "guide-stepper.hpp"
|
||||||
#include "encoder.hpp"
|
#include "encoder.hpp"
|
||||||
|
|
||||||
@ -18,18 +19,18 @@ extern "C"
|
|||||||
//---------------------
|
//---------------------
|
||||||
//--- configuration ---
|
//--- configuration ---
|
||||||
//---------------------
|
//---------------------
|
||||||
//also see config.hpp
|
//also see config.h
|
||||||
//for pin definition
|
//for pin definition
|
||||||
|
|
||||||
#define STEPPER_TEST_TRAVEL 65 //mm
|
#define STEPPER_TEST_TRAVEL 65 // mm
|
||||||
|
|
||||||
#define MIN_MM 0
|
#define MIN_MM 0
|
||||||
#define MAX_MM 97 //actual reel is 110, but currently guide turned out to stay at max position for too long TODO: cad: guide rolls closer together
|
#define MAX_MM 97 //actual reel is 110, but currently guide turned out to stay at max position for too long TODO: cad: guide rolls closer together
|
||||||
#define POS_MAX_STEPS MAX_MM * STEPPER_STEPS_PER_MM
|
#define POS_MAX_STEPS MAX_MM * STEPPER_STEPS_PER_MM
|
||||||
#define POS_MIN_STEPS MIN_MM * STEPPER_STEPS_PER_MM
|
#define POS_MIN_STEPS MIN_MM * STEPPER_STEPS_PER_MM
|
||||||
|
|
||||||
#define SPEED_MIN 2.0 //mm/s
|
#define SPEED_MIN 2.0 // mm/s
|
||||||
#define SPEED_MAX 70.0 //mm/s
|
#define SPEED_MAX 70.0 // mm/s
|
||||||
|
|
||||||
#define LAYER_THICKNESS_MM 5 //height of one cable layer on reel -> increase in radius
|
#define LAYER_THICKNESS_MM 5 //height of one cable layer on reel -> increase in radius
|
||||||
#define D_CABLE 6
|
#define D_CABLE 6
|
||||||
@ -44,11 +45,11 @@ extern "C"
|
|||||||
//----------------------
|
//----------------------
|
||||||
//----- variables ------
|
//----- variables ------
|
||||||
//----------------------
|
//----------------------
|
||||||
typedef enum axisDirection_t {LEFT = 0, RIGHT} axisDirection_t;
|
typedef enum axisDirection_t {AXIS_MOVING_LEFT = 0, AXIS_MOVING_RIGHT} axisDirection_t;
|
||||||
|
|
||||||
static const char *TAG = "stepper-ctrl"; //tag for logging
|
static const char *TAG = "stepper-ctrl"; //tag for logging
|
||||||
|
|
||||||
static axisDirection_t currentAxisDirection = RIGHT;
|
static axisDirection_t currentAxisDirection = AXIS_MOVING_RIGHT;
|
||||||
static uint32_t posNow = 0;
|
static uint32_t posNow = 0;
|
||||||
|
|
||||||
static int layerCount = 0;
|
static int layerCount = 0;
|
||||||
@ -72,6 +73,9 @@ void guide_moveToZero(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------
|
||||||
|
//---- travelSteps ----
|
||||||
|
//---------------------
|
||||||
//move axis certain Steps (relative) between left and right or reverse when negative
|
//move axis certain Steps (relative) between left and right or reverse when negative
|
||||||
void travelSteps(int stepsTarget){
|
void travelSteps(int stepsTarget){
|
||||||
//TODO simplify this function, one simple calculation of new position?
|
//TODO simplify this function, one simple calculation of new position?
|
||||||
@ -83,18 +87,18 @@ void travelSteps(int stepsTarget){
|
|||||||
|
|
||||||
// invert direction in reverse mode (cable gets spooled off reel)
|
// invert direction in reverse mode (cable gets spooled off reel)
|
||||||
if (stepsTarget < 0) {
|
if (stepsTarget < 0) {
|
||||||
currentAxisDirection = (currentAxisDirection == LEFT) ? RIGHT : LEFT; //toggle between RIGHT<->Left
|
currentAxisDirection = (currentAxisDirection == AXIS_MOVING_LEFT) ? AXIS_MOVING_RIGHT : AXIS_MOVING_LEFT; //toggle between RIGHT<->Left
|
||||||
}
|
}
|
||||||
|
|
||||||
while (stepsToGo != 0){
|
while (stepsToGo != 0){
|
||||||
//--- currently moving right ---
|
//--- currently moving right ---
|
||||||
if (currentAxisDirection == RIGHT){ //currently moving right
|
if (currentAxisDirection == AXIS_MOVING_RIGHT){ //currently moving right
|
||||||
remaining = POS_MAX_STEPS - posNow; //calc remaining distance fom current position to limit
|
remaining = POS_MAX_STEPS - posNow; //calc remaining distance fom current position to limit
|
||||||
if (stepsToGo > remaining){ //new distance will exceed limit
|
if (stepsToGo > remaining){ //new distance will exceed limit
|
||||||
stepper_setTargetPosSteps(POS_MAX_STEPS); //move to limit
|
stepper_setTargetPosSteps(POS_MAX_STEPS); //move to limit
|
||||||
stepper_waitForStop(1000);
|
stepper_waitForStop(1000);
|
||||||
posNow = POS_MAX_STEPS;
|
posNow = POS_MAX_STEPS;
|
||||||
currentAxisDirection = LEFT; //change current direction for next iteration
|
currentAxisDirection = AXIS_MOVING_LEFT; //change current direction for next iteration
|
||||||
//increment/decrement layer count depending on current cable direction
|
//increment/decrement layer count depending on current cable direction
|
||||||
layerCount += (stepsTarget > 0) - (stepsTarget < 0);
|
layerCount += (stepsTarget > 0) - (stepsTarget < 0);
|
||||||
if (layerCount < 0) layerCount = 0; //negative layers are not possible
|
if (layerCount < 0) layerCount = 0; //negative layers are not possible
|
||||||
@ -110,13 +114,13 @@ void travelSteps(int stepsTarget){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--- currently moving left ---
|
//--- currently moving left ---
|
||||||
else if (currentAxisDirection == LEFT){
|
else if (currentAxisDirection == AXIS_MOVING_LEFT){
|
||||||
remaining = posNow - POS_MIN_STEPS;
|
remaining = posNow - POS_MIN_STEPS;
|
||||||
if (stepsToGo > remaining){
|
if (stepsToGo > remaining){
|
||||||
stepper_setTargetPosSteps(POS_MIN_STEPS);
|
stepper_setTargetPosSteps(POS_MIN_STEPS);
|
||||||
stepper_waitForStop(1000);
|
stepper_waitForStop(1000);
|
||||||
posNow = POS_MIN_STEPS;
|
posNow = POS_MIN_STEPS;
|
||||||
currentAxisDirection = RIGHT; //switch direction
|
currentAxisDirection = AXIS_MOVING_RIGHT; //switch direction
|
||||||
//increment/decrement layer count depending on current cable direction
|
//increment/decrement layer count depending on current cable direction
|
||||||
layerCount += (stepsTarget > 0) - (stepsTarget < 0);
|
layerCount += (stepsTarget > 0) - (stepsTarget < 0);
|
||||||
if (layerCount < 0) layerCount = 0; //negative layers are not possible
|
if (layerCount < 0) layerCount = 0; //negative layers are not possible
|
||||||
@ -134,19 +138,25 @@ void travelSteps(int stepsTarget){
|
|||||||
|
|
||||||
// undo inversion of currentAxisDirection after reverse mode is finished
|
// undo inversion of currentAxisDirection after reverse mode is finished
|
||||||
if (stepsTarget < 0) {
|
if (stepsTarget < 0) {
|
||||||
currentAxisDirection = (currentAxisDirection == LEFT) ? RIGHT : LEFT; //toggle between RIGHT<->Left
|
currentAxisDirection = (currentAxisDirection == AXIS_MOVING_LEFT) ? AXIS_MOVING_RIGHT : AXIS_MOVING_LEFT; //toggle between RIGHT<->Left
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//------------------
|
||||||
|
//---- travelMm ----
|
||||||
|
//------------------
|
||||||
//move axis certain Mm (relative) between left and right or reverse when negative
|
//move axis certain Mm (relative) between left and right or reverse when negative
|
||||||
void travelMm(int length){
|
void travelMm(int length){
|
||||||
travelSteps(length * STEPPER_STEPS_PER_MM);
|
travelSteps(length * STEPPER_STEPS_PER_MM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------
|
||||||
|
//---- init_stepper ----
|
||||||
|
//----------------------
|
||||||
//initialize/configure stepper instance
|
//initialize/configure stepper instance
|
||||||
void init_stepper() {
|
void init_stepper() {
|
||||||
//TODO unnecessary wrapper?
|
//TODO unnecessary wrapper?
|
||||||
@ -158,7 +168,10 @@ void init_stepper() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//function that updates speed value using ADC input and configured MIN/MAX
|
//--------------------------
|
||||||
|
//--- updateSpeedFromAdc ---
|
||||||
|
//--------------------------
|
||||||
|
//function that updates speed value using ADC input and configured MIN/MAX - used for testing only
|
||||||
void updateSpeedFromAdc() {
|
void updateSpeedFromAdc() {
|
||||||
int potiRead = gpio_readAdc(ADC_CHANNEL_POTI); //0-4095 GPIO34
|
int potiRead = gpio_readAdc(ADC_CHANNEL_POTI); //0-4095 GPIO34
|
||||||
double poti = potiRead/4095.0;
|
double poti = potiRead/4095.0;
|
||||||
@ -170,13 +183,13 @@ void updateSpeedFromAdc() {
|
|||||||
|
|
||||||
|
|
||||||
//============================
|
//============================
|
||||||
//==== TASK stepper=test =====
|
//==== TASK stepper_test =====
|
||||||
//============================
|
//============================
|
||||||
|
//test axis without using encoder input
|
||||||
#ifndef STEPPER_SIMULATE_ENCODER
|
#ifndef STEPPER_SIMULATE_ENCODER
|
||||||
void task_stepper_test(void *pvParameter)
|
void task_stepper_test(void *pvParameter)
|
||||||
{
|
{
|
||||||
stepper_init();
|
stepper_init();
|
||||||
int state = 0;
|
|
||||||
while(1){
|
while(1){
|
||||||
vTaskDelay(20 / portTICK_PERIOD_MS);
|
vTaskDelay(20 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
@ -192,6 +205,7 @@ void task_stepper_test(void *pvParameter)
|
|||||||
SW_AUTO_CUT.handle();
|
SW_AUTO_CUT.handle();
|
||||||
|
|
||||||
#ifdef ONE_BUTTON_TEST //test with "reset-button" only
|
#ifdef ONE_BUTTON_TEST //test with "reset-button" only
|
||||||
|
static int state = 0;
|
||||||
//cycle through test commands with one button
|
//cycle through test commands with one button
|
||||||
if (SW_RESET.risingEdge) {
|
if (SW_RESET.risingEdge) {
|
||||||
switch (state){
|
switch (state){
|
||||||
@ -242,8 +256,9 @@ void task_stepper_test(void *pvParameter)
|
|||||||
|
|
||||||
|
|
||||||
//============================
|
//============================
|
||||||
//===== TASK stepper=ctl =====
|
//===== TASK stepper_ctl =====
|
||||||
//============================
|
//============================
|
||||||
|
//task controlling the linear axis guiding the cable according to wire length spooled
|
||||||
#ifdef STEPPER_SIMULATE_ENCODER
|
#ifdef STEPPER_SIMULATE_ENCODER
|
||||||
void task_stepper_test(void *pvParameter)
|
void task_stepper_test(void *pvParameter)
|
||||||
#else
|
#else
|
||||||
@ -265,7 +280,6 @@ void task_stepper_ctl(void *pvParameter)
|
|||||||
double turns = 0;
|
double turns = 0;
|
||||||
float currentDiameter;
|
float currentDiameter;
|
||||||
|
|
||||||
float potiModifier;
|
|
||||||
|
|
||||||
//initialize stepper and define zero-position at task start
|
//initialize stepper and define zero-position at task start
|
||||||
init_stepper();
|
init_stepper();
|
||||||
@ -300,24 +314,24 @@ void task_stepper_ctl(void *pvParameter)
|
|||||||
// set locally stored axis position and counted layers to 0 (used for calculating the target axis coordinate and steps)
|
// set locally stored axis position and counted layers to 0 (used for calculating the target axis coordinate and steps)
|
||||||
posNow = 0;
|
posNow = 0;
|
||||||
layerCount = 0;
|
layerCount = 0;
|
||||||
currentAxisDirection = RIGHT;
|
currentAxisDirection = AXIS_MOVING_RIGHT;
|
||||||
ESP_LOGW(TAG, "at position 0, reset variables, resuming normal cable guiding operation");
|
ESP_LOGW(TAG, "at position 0, reset variables, resuming normal cable guiding operation");
|
||||||
}
|
}
|
||||||
|
|
||||||
//calculate change
|
//calculate change
|
||||||
encStepsDelta = encStepsNow - encStepsPrev;
|
encStepsDelta = encStepsNow - encStepsPrev;
|
||||||
// check if reset happend without moving to zero before - resulting in huge diff
|
//check if reset happend without moving to zero before - resulting in huge diff
|
||||||
if (encStepsDelta != 0 && encStepsNow == 0){ // this should not happen and causes weird movement
|
if (encStepsDelta != 0 && encStepsNow == 0){ // this should not happen and causes weird movement
|
||||||
ESP_LOGE(TAG, "encoder steps changed to 0 (reset) without previous moveToZero() call, resulting in stepsDelta=%d", encStepsDelta);
|
ESP_LOGE(TAG, "encoder steps changed to 0 (reset) without previous moveToZero() call, resulting in stepsDelta=%d", encStepsDelta);
|
||||||
}
|
}
|
||||||
|
|
||||||
//read potentiometer and normalize (0-1) to get a variable for testing
|
//read potentiometer and normalize (0-1) to get a variable for testing
|
||||||
potiModifier = (float) gpio_readAdc(ADC_CHANNEL_POTI) / 4095; //0-4095 -> 0-1
|
//float potiModifier = (float) gpio_readAdc(ADC_CHANNEL_POTI) / 4095; //0-4095 -> 0-1
|
||||||
//ESP_LOGI(TAG, "current poti-modifier = %f", potiModifier);
|
//ESP_LOGI(TAG, "current poti-modifier = %f", potiModifier);
|
||||||
|
|
||||||
//calculate steps to move
|
//calculate steps to move
|
||||||
cableLen = (double)encStepsDelta * 1000 / ENCODER_STEPS_PER_METER;
|
cableLen = (double)encStepsDelta * 1000 / ENCODER_STEPS_PER_METER;
|
||||||
// effective diameter increases each layer
|
//effective diameter increases each layer
|
||||||
currentDiameter = D_REEL + LAYER_THICKNESS_MM * 2 * layerCount;
|
currentDiameter = D_REEL + LAYER_THICKNESS_MM * 2 * layerCount;
|
||||||
turns = cableLen / (PI * currentDiameter);
|
turns = cableLen / (PI * currentDiameter);
|
||||||
travelMm = turns * D_CABLE;
|
travelMm = turns * D_CABLE;
|
||||||
@ -328,7 +342,7 @@ void task_stepper_ctl(void *pvParameter)
|
|||||||
//move axis when ready to move at least 1 full step
|
//move axis when ready to move at least 1 full step
|
||||||
if (abs(travelStepsFull) > 1){
|
if (abs(travelStepsFull) > 1){
|
||||||
travelStepsPartial = fmod(travelStepsExact, 1); //save remaining partial steps to be added in the next iteration
|
travelStepsPartial = fmod(travelStepsExact, 1); //save remaining partial steps to be added in the next iteration
|
||||||
ESP_LOGI(TAG, "dCablelen=%.2lf, dTurns=%.2lf, travelMm=%.3lf, travelStepsExact: %.3lf, travelStepsFull=%d, partialStep=%.3lf, totalLayerCount=%d, diameter=%.1f", cableLen, turns, travelMm, travelStepsExact, travelStepsFull, travelStepsPartial, layerCount, currentDiameter);
|
ESP_LOGI(TAG, "dCablelen=%.2lf, dTurns=%.2lf, travelMm=%.3lf, StepsExact: %.3lf, StepsFull=%d, StepsPartial=%.3lf, totalLayerCount=%d, diameter=%.1f", cableLen, turns, travelMm, travelStepsExact, travelStepsFull, travelStepsPartial, layerCount, currentDiameter);
|
||||||
ESP_LOGD(TAG, "MOVING %d steps", travelStepsFull);
|
ESP_LOGD(TAG, "MOVING %d steps", travelStepsFull);
|
||||||
travelSteps(travelStepsExact);
|
travelSteps(travelStepsExact);
|
||||||
encStepsPrev = encStepsNow; //update previous length
|
encStepsPrev = encStepsNow; //update previous length
|
||||||
|
@ -10,7 +10,8 @@ extern "C"
|
|||||||
#include "driver/adc.h"
|
#include "driver/adc.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.h"
|
||||||
|
#include "global.hpp"
|
||||||
#include "control.hpp"
|
#include "control.hpp"
|
||||||
#include "buzzer.hpp"
|
#include "buzzer.hpp"
|
||||||
#include "switchesAnalog.hpp"
|
#include "switchesAnalog.hpp"
|
||||||
@ -23,7 +24,10 @@ extern "C"
|
|||||||
//=================================
|
//=================================
|
||||||
//=========== functions ===========
|
//=========== functions ===========
|
||||||
//=================================
|
//=================================
|
||||||
|
|
||||||
|
//------------------------
|
||||||
//--- configure output ---
|
//--- configure output ---
|
||||||
|
//------------------------
|
||||||
//configure a gpio pin as output
|
//configure a gpio pin as output
|
||||||
void gpio_configure_output(gpio_num_t gpio_pin){
|
void gpio_configure_output(gpio_num_t gpio_pin){
|
||||||
gpio_pad_select_gpio(gpio_pin);
|
gpio_pad_select_gpio(gpio_pin);
|
||||||
@ -31,7 +35,9 @@ void gpio_configure_output(gpio_num_t gpio_pin){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--- init gpios ---
|
//--------------------
|
||||||
|
//---- init gpios ----
|
||||||
|
//--------------------
|
||||||
void init_gpios(){
|
void init_gpios(){
|
||||||
//--- outputs ---
|
//--- outputs ---
|
||||||
//4x stepper mosfets
|
//4x stepper mosfets
|
||||||
@ -77,7 +83,7 @@ extern "C" void app_main()
|
|||||||
//init outputs and adc
|
//init outputs and adc
|
||||||
init_gpios();
|
init_gpios();
|
||||||
|
|
||||||
//enable 5V volage regulator
|
//enable 5V volage regulator (needed for display)
|
||||||
gpio_set_level(GPIO_NUM_17, 1);
|
gpio_set_level(GPIO_NUM_17, 1);
|
||||||
|
|
||||||
//init encoder (global)
|
//init encoder (global)
|
||||||
@ -94,14 +100,14 @@ extern "C" void app_main()
|
|||||||
esp_log_level_set("calc", ESP_LOG_WARN); //stepper lib
|
esp_log_level_set("calc", ESP_LOG_WARN); //stepper lib
|
||||||
|
|
||||||
#ifdef STEPPER_TEST
|
#ifdef STEPPER_TEST
|
||||||
//create task for stepper testing
|
//create task for testing the stepper motor
|
||||||
xTaskCreate(task_stepper_test, "task_stepper_test", configMINIMAL_STACK_SIZE * 3, NULL, 2, NULL);
|
xTaskCreate(task_stepper_test, "task_stepper_test", configMINIMAL_STACK_SIZE * 3, NULL, 2, NULL);
|
||||||
//xTaskCreate(task_stepper_debug, "task_stepper_test", configMINIMAL_STACK_SIZE * 3, NULL, 2, NULL);
|
//xTaskCreate(task_stepper_debug, "task_stepper_test", configMINIMAL_STACK_SIZE * 3, NULL, 2, NULL);
|
||||||
#else
|
#else
|
||||||
//create task for controlling the machine
|
//create task for controlling the machine
|
||||||
xTaskCreate(task_control, "task_control", configMINIMAL_STACK_SIZE * 3, NULL, 4, NULL);
|
xTaskCreate(task_control, "task_control", configMINIMAL_STACK_SIZE * 3, NULL, 4, NULL);
|
||||||
|
|
||||||
//create task for controlling the steppermotor (linear axis that guids the cable)
|
//create task for controlling the stepper motor (linear axis that guids the cable)
|
||||||
xTaskCreate(task_stepper_ctl, "task_stepper_ctl", configMINIMAL_STACK_SIZE * 3, NULL, 2, NULL);
|
xTaskCreate(task_stepper_ctl, "task_stepper_ctl", configMINIMAL_STACK_SIZE * 3, NULL, 2, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
//custom driver for stepper motor
|
//custom driver for stepper motor
|
||||||
#include "config.hpp"
|
#include "config.h"
|
||||||
|
#include "global.hpp"
|
||||||
#include "hal/timer_types.h"
|
#include "hal/timer_types.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
@ -14,7 +15,7 @@ extern "C" {
|
|||||||
//=====================
|
//=====================
|
||||||
//=== configuration ===
|
//=== configuration ===
|
||||||
//=====================
|
//=====================
|
||||||
//used macros from config.hpp:
|
//used macros from config.h:
|
||||||
//#define STEPPER_STEP_PIN GPIO_NUM_18 //mos1
|
//#define STEPPER_STEP_PIN GPIO_NUM_18 //mos1
|
||||||
//#define STEPPER_DIR_PIN GPIO_NUM_16 //ST3
|
//#define STEPPER_DIR_PIN GPIO_NUM_16 //ST3
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include "switchesAnalog.hpp"
|
#include "switchesAnalog.hpp"
|
||||||
|
#include "config.h"
|
||||||
|
#include "global.hpp"
|
||||||
|
|
||||||
#define CHECK_BIT(var,pos) (((var)>>(pos)) & 1) //TODO duplicate code: same macro already used in vfd.cpp
|
#define CHECK_BIT(var,pos) (((var)>>(pos)) & 1) //TODO duplicate code: same macro already used in vfd.cpp
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ extern "C"
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "config.hpp"
|
|
||||||
#include "gpio_adc.hpp"
|
#include "gpio_adc.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include "vfd.hpp"
|
#include "vfd.hpp"
|
||||||
|
#include "config.h"
|
||||||
|
#include "global.hpp"
|
||||||
|
|
||||||
#define CHECK_BIT(var,pos) (((var)>>(pos)) & 1)
|
#define CHECK_BIT(var,pos) (((var)>>(pos)) & 1)
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ extern "C"
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "config.hpp"
|
|
||||||
|
|
||||||
//enum defining motor direction
|
//enum defining motor direction
|
||||||
typedef enum vfd_direction_t {FWD, REV} vfd_direction_t;
|
typedef enum vfd_direction_t {FWD, REV} vfd_direction_t;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user