time to save
This commit is contained in:
parent
6fb725a813
commit
aa9b59996e
60
mendel/dda.c
60
mendel/dda.c
|
|
@ -48,8 +48,8 @@ void enqueue(TARGET *t) {
|
||||||
h++;
|
h++;
|
||||||
if (h == MOVEBUFFER_SIZE)
|
if (h == MOVEBUFFER_SIZE)
|
||||||
h = 0;
|
h = 0;
|
||||||
mb_head = h;
|
|
||||||
dda_create(t, &movebuffer[h]);
|
dda_create(t, &movebuffer[h]);
|
||||||
|
mb_head = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void next_move() {
|
void next_move() {
|
||||||
|
|
@ -57,15 +57,15 @@ void next_move() {
|
||||||
// queue is empty
|
// queue is empty
|
||||||
disable_steppers();
|
disable_steppers();
|
||||||
setTimer(DEFAULT_TICK);
|
setTimer(DEFAULT_TICK);
|
||||||
disableTimerInterrupt();
|
// disableTimerInterrupt();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
uint8_t t = mb_tail;
|
uint8_t t = mb_tail;
|
||||||
t++;
|
t++;
|
||||||
if (t == MOVEBUFFER_SIZE)
|
if (t == MOVEBUFFER_SIZE)
|
||||||
t = 0;
|
t = 0;
|
||||||
mb_tail = t;
|
|
||||||
dda_start(&movebuffer[t]);
|
dda_start(&movebuffer[t]);
|
||||||
|
mb_tail = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,7 +143,7 @@ uint32_t abs32(int32_t v) {
|
||||||
void dda_create(TARGET *target, DDA *dda) {
|
void dda_create(TARGET *target, DDA *dda) {
|
||||||
uint32_t distance;
|
uint32_t distance;
|
||||||
|
|
||||||
serial_writestr_P("\n{DDA_CREATE: [");
|
serial_writestr_P(PSTR("\n{DDA_CREATE: ["));
|
||||||
|
|
||||||
// we end at the passed target
|
// we end at the passed target
|
||||||
memcpy(&(dda->endpoint), target, sizeof(TARGET));
|
memcpy(&(dda->endpoint), target, sizeof(TARGET));
|
||||||
|
|
@ -158,20 +158,7 @@ void dda_create(TARGET *target, DDA *dda) {
|
||||||
serwrite_uint32(dda->y_delta); serial_writechar(',');
|
serwrite_uint32(dda->y_delta); serial_writechar(',');
|
||||||
serwrite_uint32(dda->z_delta); serial_writechar(',');
|
serwrite_uint32(dda->z_delta); serial_writechar(',');
|
||||||
serwrite_uint32(dda->e_delta); serial_writechar(',');
|
serwrite_uint32(dda->e_delta); serial_writechar(',');
|
||||||
serwrite_uint32(dda->f_delta); serial_writestr_P("] [");
|
serwrite_uint32(dda->f_delta); serial_writestr_P(PSTR("] ["));
|
||||||
|
|
||||||
// since it's unusual to combine X, Y and Z changes in a single move on reprap, check if we can use simpler approximations before trying the full 3d approximation.
|
|
||||||
if (dda->z_delta == 0)
|
|
||||||
distance = approx_distance(dda->x_delta, dda->y_delta);
|
|
||||||
else if (dda->x_delta == 0 && dda->y_delta == 0)
|
|
||||||
distance = dda->z_delta;
|
|
||||||
else
|
|
||||||
distance = approx_distance_3(dda->x_delta, dda->y_delta, dda->z_delta);
|
|
||||||
|
|
||||||
if (distance < 2)
|
|
||||||
distance = dda->e_delta;
|
|
||||||
if (distance < 2)
|
|
||||||
distance = dda->f_delta;
|
|
||||||
|
|
||||||
dda->total_steps = dda->x_delta;
|
dda->total_steps = dda->x_delta;
|
||||||
if (dda->y_delta > dda->total_steps)
|
if (dda->y_delta > dda->total_steps)
|
||||||
|
|
@ -212,19 +199,35 @@ void dda_create(TARGET *target, DDA *dda) {
|
||||||
dda->x_counter = dda->y_counter = dda->z_counter = dda->e_counter = dda->f_counter =
|
dda->x_counter = dda->y_counter = dda->z_counter = dda->e_counter = dda->f_counter =
|
||||||
-(dda->total_steps >> 1);
|
-(dda->total_steps >> 1);
|
||||||
|
|
||||||
|
// since it's unusual to combine X, Y and Z changes in a single move on reprap, check if we can use simpler approximations before trying the full 3d approximation.
|
||||||
|
if (dda->z_delta == 0)
|
||||||
|
distance = approx_distance(dda->x_delta * 1000, dda->y_delta * 1000) / STEPS_PER_MM_X;
|
||||||
|
else if (dda->x_delta == 0 && dda->y_delta == 0)
|
||||||
|
distance = dda->z_delta * 1000 / STEPS_PER_MM_Z;
|
||||||
|
else
|
||||||
|
distance = approx_distance_3(dda->x_delta * 1000 * STEPS_PER_MM_Z / STEPS_PER_MM_X, dda->y_delta * 1000 * STEPS_PER_MM_Z / STEPS_PER_MM_Y, dda->z_delta * 1000) / STEPS_PER_MM_Z;
|
||||||
|
|
||||||
|
if (distance < 2)
|
||||||
|
distance = dda->e_delta * 1000 / STEPS_PER_MM_E;
|
||||||
|
if (distance < 2)
|
||||||
|
distance = dda->f_delta;
|
||||||
|
|
||||||
// pre-calculate move speed in millimeter microseconds per step minute for less math in interrupt context
|
// pre-calculate move speed in millimeter microseconds per step minute for less math in interrupt context
|
||||||
// mm (distance) * 60000000 us/min / step (total_steps) = mm.us per step.min
|
// mm (distance) * 1000 us/ms * 60000000 us/min / step (total_steps) = mm.us per step.min
|
||||||
// so in the interrupt we must simply calculate
|
// so in the interrupt we must simply calculate
|
||||||
// mm.us per step.min / mm per min (F) = us per step
|
// mm.us per step.min / mm per min (F) = us per step
|
||||||
dda->move_duration = distance * 60000000 / dda->total_steps;
|
if (dda->total_steps > 0)
|
||||||
|
dda->move_duration = distance * 60000 / dda->total_steps;
|
||||||
|
else
|
||||||
|
dda->move_duration = 0;
|
||||||
|
|
||||||
serwrite_uint32(dda->move_duration); serial_writestr_P("] }\n");
|
serwrite_uint32(dda->move_duration); serial_writestr_P(PSTR("] }\n"));
|
||||||
|
|
||||||
// next dda starts where we finish
|
// next dda starts where we finish
|
||||||
memcpy(&startpoint, target, sizeof(TARGET));
|
memcpy(&startpoint, target, sizeof(TARGET));
|
||||||
|
|
||||||
// make sure we can run
|
// not running yet, we fire up in dda_start()
|
||||||
dda->live = 1;
|
dda->live = 0;
|
||||||
|
|
||||||
// fire up
|
// fire up
|
||||||
enableTimerInterrupt();
|
enableTimerInterrupt();
|
||||||
|
|
@ -236,8 +239,11 @@ void dda_create(TARGET *target, DDA *dda) {
|
||||||
|
|
||||||
void dda_start(DDA *dda) {
|
void dda_start(DDA *dda) {
|
||||||
// called from interrupt context: keep it simple!
|
// called from interrupt context: keep it simple!
|
||||||
if (dda->nullmove)
|
if (dda->nullmove) {
|
||||||
|
// just change speed?
|
||||||
|
current_position.F = dda->endpoint.F;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
x_direction(dda->x_direction);
|
x_direction(dda->x_direction);
|
||||||
y_direction(dda->y_direction);
|
y_direction(dda->y_direction);
|
||||||
|
|
@ -246,6 +252,8 @@ void dda_start(DDA *dda) {
|
||||||
|
|
||||||
enable_steppers();
|
enable_steppers();
|
||||||
|
|
||||||
|
dda->firstep = 1;
|
||||||
|
|
||||||
dda->live = 1;
|
dda->live = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -403,8 +411,10 @@ void dda_step(DDA *dda) {
|
||||||
unstep();
|
unstep();
|
||||||
|
|
||||||
// we have stepped in speed and now need to recalculate our delay
|
// we have stepped in speed and now need to recalculate our delay
|
||||||
if ((step_option & REAL_MOVE) && (step_option & F_REAL_STEP))
|
if ((step_option & REAL_MOVE) && ((step_option & F_REAL_STEP) || (dda->firstep))) {
|
||||||
setTimer(dda->move_duration / current_position.F);
|
setTimer(dda->move_duration / current_position.F);
|
||||||
|
dda->firstep = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// if we could step, we're still running
|
// if we could step, we're still running
|
||||||
dda->live = (step_option & (X_CAN_STEP | Y_CAN_STEP | Z_CAN_STEP | E_CAN_STEP | F_CAN_STEP))?1:0;
|
dda->live = (step_option & (X_CAN_STEP | Y_CAN_STEP | Z_CAN_STEP | E_CAN_STEP | F_CAN_STEP))?1:0;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ typedef struct {
|
||||||
uint8_t f_direction :1;
|
uint8_t f_direction :1;
|
||||||
uint8_t nullmove :1;
|
uint8_t nullmove :1;
|
||||||
uint8_t live :1;
|
uint8_t live :1;
|
||||||
|
uint8_t firstep :1;
|
||||||
|
|
||||||
uint32_t x_delta;
|
uint32_t x_delta;
|
||||||
uint32_t y_delta;
|
uint32_t y_delta;
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,6 @@ uint8_t option_bitfield;
|
||||||
|
|
||||||
decfloat read_digit;
|
decfloat read_digit;
|
||||||
|
|
||||||
#define PI 3.1415926535
|
|
||||||
|
|
||||||
const char alphabet[] = "GMXYZEFSP";
|
const char alphabet[] = "GMXYZEFSP";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,9 @@
|
||||||
#define E_STARTSTOP_STEPS 20
|
#define E_STARTSTOP_STEPS 20
|
||||||
#define FEEDRATE_FAST_E 1200
|
#define FEEDRATE_FAST_E 1200
|
||||||
|
|
||||||
|
/*
|
||||||
|
should be the same for all machines ;)
|
||||||
|
*/
|
||||||
|
#define PI 3.1415926535
|
||||||
|
|
||||||
#endif /* _MACHINE_H */
|
#endif /* _MACHINE_H */
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#include "ringbuffer.h"
|
#include "ringbuffer.h"
|
||||||
|
|
||||||
#define BUFSIZE 64 + sizeof(ringbuffer)
|
#define BUFSIZE 64 + sizeof(ringbuffer)
|
||||||
#define BAUD 19200
|
#define BAUD 57600
|
||||||
|
|
||||||
volatile uint8_t _rx_buffer[BUFSIZE];
|
volatile uint8_t _rx_buffer[BUFSIZE];
|
||||||
volatile uint8_t _tx_buffer[BUFSIZE];
|
volatile uint8_t _tx_buffer[BUFSIZE];
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
|
|
||||||
void serwrite_hex4(uint8_t v) {
|
void serwrite_hex4(uint8_t v) {
|
||||||
|
v &= 0xF;
|
||||||
if (v < 10)
|
if (v < 10)
|
||||||
serial_writechar('0' + v);
|
serial_writechar('0' + v);
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,9 @@ ISR(TIMER1_COMPA_vect) {
|
||||||
disableTimerInterrupt();
|
disableTimerInterrupt();
|
||||||
sei();
|
sei();
|
||||||
|
|
||||||
dda_step(&movebuffer[mb_tail]);
|
dda_step(&(movebuffer[mb_tail]));
|
||||||
|
|
||||||
|
cli();
|
||||||
enableTimerInterrupt();
|
enableTimerInterrupt();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue