Add Stepper to connection-plan, Add datasheets
- Add datasheets of VFD and stepper driver
- Change pins in config for stepper driver
    - DISABLED LAMP (pin now used for stepper)
- update connection plan with stepper section and wiring
			
			
| 
		 Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								docs/linear-axis_dimensions.jpg
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 594 KiB  | 
| 
		 Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 60 KiB  | 
| 
		 Before Width: | Height: | Size: 54 KiB After Width: | Height: | Size: 54 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								docs/stepper-driver_TB6600-Manual.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 126 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								docs/vfd/T13-400W-12-H_scan.PDF
									
									
									
									
									
										Normal file
									
								
							
							
						
						@ -17,8 +17,8 @@ extern "C" {
 | 
			
		||||
#define GPIO_VFD_D1 GPIO_NUM_15     //ST1
 | 
			
		||||
//#define GPIO_VFD_D2 GPIO_NUM_15     //ST1 (D2 only used with 7.5kw vfd)
 | 
			
		||||
 | 
			
		||||
#define GPIO_MOS1 GPIO_NUM_18       //mos1 (free)
 | 
			
		||||
#define GPIO_LAMP GPIO_NUM_5        //mos2
 | 
			
		||||
#define GPIO_MOS1 GPIO_NUM_18       //mos1 (free) 2022.02.28: pin used for stepper
 | 
			
		||||
#define GPIO_LAMP GPIO_NUM_0        //mos2 (5) 2022.02.28: lamp disabled, pin used for stepper
 | 
			
		||||
#define GPIO_RELAY GPIO_NUM_13
 | 
			
		||||
#define GPIO_BUZZER GPIO_NUM_12
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -10,35 +10,113 @@ extern "C"
 | 
			
		||||
#include "DendoStepper.h"
 | 
			
		||||
#include "config.hpp"
 | 
			
		||||
#include "guide-stepper.hpp"
 | 
			
		||||
#include "encoder.hpp"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//---------------------
 | 
			
		||||
//--- configuration ---
 | 
			
		||||
//---------------------
 | 
			
		||||
//also see config.hpp
 | 
			
		||||
#define LEN_MOVE 65     //mm
 | 
			
		||||
//for pin definition
 | 
			
		||||
 | 
			
		||||
#define STEPPER_TEST_TRAVEL 65     //mm
 | 
			
		||||
                        //
 | 
			
		||||
#define MIN 0
 | 
			
		||||
#define MAX 60 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define SPEED_MIN 2.0   //mm/s
 | 
			
		||||
#define SPEED_MAX 60.0 //mm/s
 | 
			
		||||
 | 
			
		||||
#define ACCEL_MS 100.0  //ms from 0 to max
 | 
			
		||||
#define DECEL_MS 90.0   //ms from max to 0
 | 
			
		||||
 | 
			
		||||
#define STEPS_PER_ROT 1600
 | 
			
		||||
#define STEPPER_STEPS_PER_ROT 1600
 | 
			
		||||
#define STEPPER_STEPS_PER_MM STEPPER_STEPS_PER_ROT/4
 | 
			
		||||
 | 
			
		||||
#define D_CABLE 6
 | 
			
		||||
#define D_REEL 155 //actual 170
 | 
			
		||||
#define PI 3.14159
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//----------------------
 | 
			
		||||
//----- variables ------
 | 
			
		||||
//----------------------
 | 
			
		||||
DendoStepper step;
 | 
			
		||||
DendoStepper step1;
 | 
			
		||||
static DendoStepper step;
 | 
			
		||||
static const char *TAG = "stepper"; //tag for logging
 | 
			
		||||
 | 
			
		||||
static int stepp_lengthNow = 0; //length measured in mm
 | 
			
		||||
static int lengthPrev = 0; //length last check
 | 
			
		||||
 | 
			
		||||
static bool stepp_direction = true;
 | 
			
		||||
static uint64_t posNow = 0;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//----------------------
 | 
			
		||||
//----- functions ------
 | 
			
		||||
//----------------------
 | 
			
		||||
//move left and right or reverse while winding
 | 
			
		||||
void travelDist(int length){
 | 
			
		||||
    //uint64_t posNow = step.getPositionMm();
 | 
			
		||||
 | 
			
		||||
        int d, remaining;
 | 
			
		||||
    d = abs(length);
 | 
			
		||||
    if(length < 0) stepp_direction = !stepp_direction; //invert direction in reverse mode
 | 
			
		||||
 | 
			
		||||
    while (d != 0){
 | 
			
		||||
        //--- currently moving right ---
 | 
			
		||||
        if (stepp_direction == true){         //currently moving right
 | 
			
		||||
            remaining = MAX - posNow;   //calc remaining distance fom current position to limit
 | 
			
		||||
            if (d > remaining){         //new distance will exceed limit
 | 
			
		||||
                step.runAbsMm (MAX);        //move to limit
 | 
			
		||||
                                          posNow=MAX;
 | 
			
		||||
                stepp_direction = false;      //change current direction for next iteration
 | 
			
		||||
                d = d - remaining;      //decrease target length by already traveled distance
 | 
			
		||||
                printf(" --- changed direction (L) --- \n ");
 | 
			
		||||
            }
 | 
			
		||||
            else {                      //target distance does not reach the limit
 | 
			
		||||
                step.runAbsMm (posNow + d); //move by (remaining) distance to reach target length
 | 
			
		||||
                printf("moving to %lld\n", posNow+d);
 | 
			
		||||
                posNow += d;
 | 
			
		||||
                d = 0;                  //finished, reset target length (could as well exit loop/break)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //--- currently moving left ---
 | 
			
		||||
        else {
 | 
			
		||||
            remaining = posNow - MIN;
 | 
			
		||||
            if (d > remaining){
 | 
			
		||||
                step.runAbsMm (MIN);
 | 
			
		||||
                posNow=0;
 | 
			
		||||
                stepp_direction = true;
 | 
			
		||||
                d = d - remaining;
 | 
			
		||||
                printf(" --- changed direction (R) --- \n ");
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                step.runAbsMm (posNow - d); //when moving left the coordinate has to be decreased
 | 
			
		||||
                printf("moving to %lld\n", posNow-d);
 | 
			
		||||
                posNow -= d;
 | 
			
		||||
                d = 0;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(length < 0) stepp_direction = !stepp_direction; //undo inversion of stepp_direction after reverse mode is finished
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//calculate time needed for certain length (NOT NEEDED/ DELETE)
 | 
			
		||||
//float mmToS(int l){
 | 
			
		||||
//
 | 
			
		||||
@ -73,9 +151,9 @@ void home() {
 | 
			
		||||
void init_stepper() {
 | 
			
		||||
    ESP_LOGW(TAG, "initializing stepper...");
 | 
			
		||||
    DendoStepper_config_t step_cfg = {
 | 
			
		||||
        .stepPin = 18,
 | 
			
		||||
        .dirPin = 19,
 | 
			
		||||
        .enPin = 21,
 | 
			
		||||
        .stepPin = STEPPER_STEP_PIN,
 | 
			
		||||
        .dirPin = STEPPER_DIR_PIN,
 | 
			
		||||
        .enPin = STEPPER_EN_PIN,
 | 
			
		||||
        .timer_group = TIMER_GROUP_0,
 | 
			
		||||
        .timer_idx = TIMER_0,
 | 
			
		||||
        .miStep = MICROSTEP_32,
 | 
			
		||||
@ -84,13 +162,13 @@ void init_stepper() {
 | 
			
		||||
    step.init();
 | 
			
		||||
 | 
			
		||||
    step.setSpeed(1000, 1000, 1000); //random default speed
 | 
			
		||||
    step.setStepsPerMm(STEPS_PER_ROT /4); //guide: 4mm/rot
 | 
			
		||||
    step.setStepsPerMm(STEPPER_STEPS_PER_MM); //guide: 4mm/rot
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//function that updates speed value using ADC input and configured MIN/MAX
 | 
			
		||||
void updateSpeedFromAdc() {
 | 
			
		||||
    int potiRead = gpio_readAdc(ADC1_CHANNEL_6); //0-4095 GPIO34
 | 
			
		||||
    int potiRead = gpio_readAdc(ADC_CHANNEL_POTI); //0-4095 GPIO34
 | 
			
		||||
    double poti = potiRead/4095.0;
 | 
			
		||||
    int speed = poti*(SPEED_MAX-SPEED_MIN) + SPEED_MIN;
 | 
			
		||||
    step.setSpeedMm(speed, ACCEL_MS, DECEL_MS);
 | 
			
		||||
@ -102,20 +180,48 @@ void updateSpeedFromAdc() {
 | 
			
		||||
//---------------------
 | 
			
		||||
//------- TASK --------
 | 
			
		||||
//---------------------
 | 
			
		||||
void task_stepper(void *pvParameter)
 | 
			
		||||
void task_stepper_test(void *pvParameter)
 | 
			
		||||
{
 | 
			
		||||
    init_stepper();
 | 
			
		||||
    home();
 | 
			
		||||
 | 
			
		||||
    while (1) {
 | 
			
		||||
        updateSpeedFromAdc();
 | 
			
		||||
        step.runPosMm(-LEN_MOVE);
 | 
			
		||||
        step.runPosMm(-STEPPER_TEST_TRAVEL);
 | 
			
		||||
        while(step.getState() != 1) vTaskDelay(2);
 | 
			
		||||
        ESP_LOGI(TAG, "finished moving right => moving left");
 | 
			
		||||
 | 
			
		||||
        updateSpeedFromAdc();
 | 
			
		||||
        step.runPosMm(LEN_MOVE);
 | 
			
		||||
        step.runPosMm(STEPPER_TEST_TRAVEL);
 | 
			
		||||
        while(step.getState() != 1) vTaskDelay(2); //1=idle
 | 
			
		||||
        ESP_LOGI(TAG, "finished moving left => moving right");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void task_stepper_ctl(void *pvParameter)
 | 
			
		||||
{
 | 
			
		||||
    init_stepper();
 | 
			
		||||
    home();
 | 
			
		||||
 | 
			
		||||
    while(1){
 | 
			
		||||
        //get current length
 | 
			
		||||
        stepp_lengthNow = encoder_getLenMm();
 | 
			
		||||
 | 
			
		||||
        int lengthDelta = stepp_lengthNow - lengthPrev;
 | 
			
		||||
        //TODO add modifier e.g. poti value
 | 
			
		||||
        int travel = lengthDelta * D_CABLE / (PI * D_REEL); //calc distance to move
 | 
			
		||||
        ESP_LOGI(TAG, "delta: %d travel: %d",lengthDelta, travel);
 | 
			
		||||
                                                            //FIXME: rounding issue? e.g. 1.4 gets lost
 | 
			
		||||
        if (abs(travel) > 1){ //when ready to move axis by at least 1 millimeter
 | 
			
		||||
        ESP_LOGI(TAG, "EXCEEDED: delta: %d travel: %d",lengthDelta, travel);
 | 
			
		||||
            travelDist(travel);
 | 
			
		||||
            while(step.getState() != 1) vTaskDelay(2); //wait for move to finish
 | 
			
		||||
            lengthPrev = stepp_lengthNow; //update length
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            vTaskDelay(5);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -5,4 +5,8 @@
 | 
			
		||||
//  - automatically auto-homes
 | 
			
		||||
//  - moves left and right repeatedly
 | 
			
		||||
//  - updates speed from potentiometer each cycle
 | 
			
		||||
void task_stepper(void *pvParameter);
 | 
			
		||||
void task_stepper_test(void *pvParameter);
 | 
			
		||||
 | 
			
		||||
//task that initializes and controls the stepper motor
 | 
			
		||||
//  - moves stepper according to encoder movement
 | 
			
		||||
void task_stepper_ctl(void *pvParameter);
 | 
			
		||||
 | 
			
		||||
@ -95,9 +95,6 @@ extern "C" void app_main()
 | 
			
		||||
    //create task for controlling the machine
 | 
			
		||||
    xTaskCreate(task_control, "task_control", configMINIMAL_STACK_SIZE * 3, NULL, 5, NULL);
 | 
			
		||||
 | 
			
		||||
    //create task for controlling the stepper
 | 
			
		||||
    xTaskCreate(task_stepper_ctl, "task_stepper-test", configMINIMAL_STACK_SIZE * 3, NULL, 5, NULL);
 | 
			
		||||
 | 
			
		||||
    //create task for handling the buzzer
 | 
			
		||||
    xTaskCreate(&task_buzzer, "task_buzzer", 2048, NULL, 2, NULL);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||