-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStepperDriver.h
More file actions
94 lines (77 loc) · 2.53 KB
/
StepperDriver.h
File metadata and controls
94 lines (77 loc) · 2.53 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef ARDUINO_STEPPER_2014_H
#define ARDUINO_STEPPER_2014_H
#include <Arduino.h>
#include <stdint.h>
/* Number of parsing axis */
#define NUM_AXIS 3
/* Configuration of enable pins.
* In most drivers, LOW level is active for ENABLE pins.
* Uncomment this line to inverse ENBALE pins level
*/
//#define INVERSE_ENABLE_LEVELS
/* Configuration of chassis; if forward direction set by HIGH
* level on DIR pin, it is a direct levels, otherwise it is
* inversed levels.
*
* Uncomment if your chassis configuration is inversed
*/
//#define INVERSE_DIR_LEVELS
/* Use timer2 for ATmega32U4 and ATmega328P to not
* crash all things in Arduino environment
*/
#ifdef INVERSE_DIR_LEVELS
typedef enum {
FORWARD = LOW,
BACKWARD = HIGH
} _dir_t;
#else
typedef enum {
FORWARD = HIGH,
BACKWARD = LOW
} _dir_t;
#endif
typedef uint8_t axis_t;
struct stepper_motor {
uint8_t step; /* step pin */
uint8_t dir; /* dir pin */
uint8_t enable; /* enable pin, 255 is empty value */
uint16_t steps; /* number of steps per revolution */
int32_t path;
int8_t _dir; /* direction coefficient */
uint8_t _state; /* current state */
uint16_t _delay; /* current timer value */
uint16_t _base_delay; /* start timer value */
uint32_t _rq_path; /* path for engine to rotate on */
};
class _StepperDriver
{
public:
void init();
axis_t newAxis(uint8_t step, uint8_t dir, uint8_t enable, uint16_t steps);
axis_t newAxis(uint8_t step, uint8_t dir, uint16_t steps);
void enable(axis_t axis);
void disable(axis_t axis);
void setDir(axis_t axis, uint8_t dir);
void setDelay(axis_t axis, uint16_t val);
void setSpeed(axis_t axis, uint16_t val); /* convert speed to delay */
void write(axis_t axis, int32_t speed); /* continious rotation of engine */
void write(axis_t axis, int32_t speed, uint32_t path); /* rotate engine to set path */
void move(axis_t axis, int32_t speed, uint32_t path); /* rotate engine to set path */
void stop(axis_t axis); /* e-stop */
uint8_t busy(axis_t axis);
void wait(axis_t axis);
int32_t getPath(axis_t axis);
void resetPath(axis_t axis);
};
class _StepperChassis
{
public:
void init(axis_t left, axis_t right);
void write(int16_t left_spd, int16_t right_spd);
void stop();
private:
axis_t _left, _right;
};
extern _StepperDriver StepperDriver;
extern _StepperChassis StepperChassis;
#endif