step_cl.h 1.68 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
/*
osap/drivers/step_cl.h

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.
*/

#ifndef STEP_CL_H_
#define STEP_CL_H_ 

#include <Arduino.h>

#include "step_a4950.h"
#include "enc_as5047.h"

class Step_CL {
    private:
        static Step_CL* instance;
26
        float calib_readings[201];
Jake Read's avatar
Jake Read committed
27
28
29
30
31

    public:
        Step_CL();
        static Step_CL* getInstance(void);
        void init(void);
32
        void print_table(void);
Jake Read's avatar
Jake Read committed
33
        void set_torque(float tc);
Jake Read's avatar
Jake Read committed
34
        float get_torque(void);
Jake Read's avatar
Jake Read committed
35
36
37
38
        void set_run_mode(uint8_t mode); 
        void set_angle_target(float ta);
        float get_angle_target(void);
        float get_output_effort(void);
Jake Read's avatar
Jake Read committed
39
        // pid set 
Jake Read's avatar
Jake Read committed
40
        void set_pid_values(float p, float i, float ilim, float d);
Jake Read's avatar
Jake Read committed
41
        void set_alpha_values(float a, float adot);
42
43
44
        // read stat 
        uint16_t get_last_enc_reading(void);
        float get_last_pos_reading(void);
Jake Read's avatar
Jake Read committed
45
        float get_last_pos_est(void);
Jake Read's avatar
Jake Read committed
46
47
        float get_last_pos_dot(void);
        // do work 
Jake Read's avatar
Jake Read committed
48
49
        void run_torque_loop(void);
        boolean calibrate(void);
Jake Read's avatar
Jake Read committed
50
        boolean is_calibrating;
Jake Read's avatar
Jake Read committed
51
52
53
54
55
        //float __attribute__((__aligned__(256))) lut[16384]; // nor does this ! 
        //float lut[16384]; // nor does this work 
        //step_cl_calib_table_t lut; // not even this works ?? too big ?? 
};

Jake Read's avatar
Jake Read committed
56
57
extern const float lut[];

Jake Read's avatar
Jake Read committed
58
59
60
extern Step_CL* step_cl;

#endif