-
Notifications
You must be signed in to change notification settings - Fork 12
/
dda.h
136 lines (111 loc) · 3.23 KB
/
dda.h
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef _DDA_H
#define _DDA_H
#include <stdint.h>
#include "config.h"
#ifdef ACCELERATION_REPRAP
#ifdef ACCELERATION_RAMPING
#error Cant use ACCELERATION_REPRAP and ACCELERATION_RAMPING together.
#endif
#endif
/*
enums
*/
// wether we accelerate, run at full speed, break down, etc.
typedef enum {
RAMP_UP,
RAMP_MAX,
RAMP_DOWN
} ramp_state_t;
/*
types
*/
// target is simply a point in space/time
typedef struct {
int32_t X;
int32_t Y;
int32_t Z;
int32_t E;
uint32_t F;
} TARGET;
// this is a digital differential analyser data struct
typedef struct {
// this is where we should finish
TARGET endpoint;
union {
struct {
// status fields
uint8_t nullmove :1;
uint8_t live :1;
#ifdef ACCELERATION_REPRAP
uint8_t accel :1;
#endif
// wait for temperature to stabilise flag
uint8_t waitfor_temp :1;
// directions
uint8_t x_direction :1;
uint8_t y_direction :1;
uint8_t z_direction :1;
uint8_t e_direction :1;
};
uint8_t allflags; // used for clearing all flags
};
// distances
uint32_t x_delta;
uint32_t y_delta;
uint32_t z_delta;
uint32_t e_delta;
// bresenham counters
int32_t x_counter;
int32_t y_counter;
int32_t z_counter;
int32_t e_counter;
// total number of steps: set to max(x_delta, y_delta, z_delta, e_delta)
uint32_t total_steps;
// linear acceleration variables: c and end_c are 24.8 fixed point timer values, n is the tracking variable
uint32_t c;
#ifdef ACCELERATION_REPRAP
uint32_t end_c;
int32_t n;
#endif
#ifdef ACCELERATION_RAMPING
// start of down-ramp, intitalized with total_steps / 2
uint32_t ramp_steps;
// counts actual steps done
uint32_t step_no;
// 24.8 fixed point timer value, maximum speed
uint32_t c_min;
// tracking variable
int32_t n;
ramp_state_t ramp_state;
#endif
#ifdef ACCELERATION_TEMPORAL
uint32_t x_step_interval;
uint32_t y_step_interval;
uint32_t z_step_interval;
uint32_t e_step_interval;
#endif
} DDA;
/*
variables
*/
// steptimeout is set to zero when we step, and increases over time so we can turn the motors off when they've been idle for a while
extern uint8_t steptimeout;
// startpoint holds the endpoint of the most recently created DDA, so we know where the next one created starts
// could also be called last_endpoint
extern TARGET startpoint;
// current_position holds the machine's current position. this is only updated when we step, or when G92 (set home) is received.
extern TARGET current_position;
/*
methods
*/
uint32_t approx_distance( uint32_t dx, uint32_t dy ) __attribute__ ((hot));
uint32_t approx_distance_3( uint32_t dx, uint32_t dy, uint32_t dz ) __attribute__ ((hot));
// const because return value is always the same given the same v
const uint8_t msbloc (uint32_t v) __attribute__ ((const));
// create a DDA
void dda_create(DDA *dda, TARGET *target);
// start a created DDA (called from timer interrupt)
void dda_start(DDA *dda) __attribute__ ((hot));
// DDA takes one step (called from timer interrupt)
void dda_step(DDA *dda) __attribute__ ((hot));
#endif /* _DDA_H */