step_cl.cpp 1.75 KB
Newer Older
Jake Read's avatar
Jake Read committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
osap/drivers/step_cl.cpp

stepper in closed loop mode 

Jake Read at the Center for Bits and Atoms
(c) Massachusetts Institute of Technology 2020

This work may be reproduced, modified, distributed, performed, and
displayed for any purpose, but must acknowledge the squidworks and ponyo
projects. Copyright is retained and must be preserved. The work is provided as
is; no warranty is provided, and users accept all liability.
*/

#include "step_cl.h"

Step_CL* Step_CL::instance = 0;

Step_CL* Step_CL::getInstance(void){
    if(instance == 0){
        instance = new Step_CL();
    }
    return instance;
}

Step_CL* step_cl = Step_CL::getInstance();

// https://github.com/cmaglie/FlashStorage
// flash LUT
// FlashStorage(flash_lut, step_cl_calib_table_t);
// float __attribute__((__aligned__(256))) lut[16384];

Step_CL::Step_CL(void){}

#define CALIB_CSCALE 0.4F
#define CALIB_STEP_DELAY 5

void Step_CL::init(void){
    stepper_hw->init(false, 0.4);
    enc_as5047->init();
    // this lut == stored lut 
    //lut = flash_lut.read();
}

void Step_CL::calibrate(void){
    // OK, first order is getting a step machine where I can point at
    // phase angles w/ current scalars on that angle 
    // then I use that to step thru 0->90->180->270->0 for steps 
    // then first order is just checking that if I take 200 (50) steps 
    // thru that, I get a full rotation 

    // ok, at the moment, should do 200 counts (full rev) at 200*256 
    for(uint32_t i = 0; i < 50; i ++){
        stepper_hw->point(0.0F, 0.4F);
        delay(CALIB_STEP_DELAY);
        stepper_hw->point(0.25F, 0.4F);
        delay(CALIB_STEP_DELAY);
        stepper_hw->point(0.5F, 0.4F);
        delay(CALIB_STEP_DELAY);
        stepper_hw->point(0.75F, 0.4F);
        delay(CALIB_STEP_DELAY);
    }
}