added code with merge conflict as note to self, accelleration will just have to wait

This commit is contained in:
Simen Svale Skogsrud 2010-12-20 14:01:38 +01:00
parent 703d812b85
commit 48b596c2fe
7 changed files with 158 additions and 5 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.hex
*.o
*.elf
.DS_Store

View File

@ -31,7 +31,7 @@ DEVICE = atmega328p
CLOCK = 16000000
PROGRAMMER = -c avrisp2 -P usb
OBJECTS = main.o motion_control.o gcode.o spindle_control.o wiring_serial.o serial_protocol.o stepper.o \
eeprom.o config.o
eeprom.o config.o accelleration.o
# FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m
FUSES = -U hfuse:w:0xd2:m -U lfuse:w:0xff:m

51
accelleration.h Normal file
View File

@ -0,0 +1,51 @@
/*
accelleration.h - accelleration management support
Part of Grbl
Copyright (c) 2009 Simen Svale Skogsrud
Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef accelleration_h
#define accelleration_h
// Unless someone else defined AC_TICKS_PER_SECOND, we define a sensible default
#ifndef AC_TICKS_PER_SECOND
#define AC_TICKS_PER_SECOND 10
#endif
struct AccellerationProfile {
float initial_scaler;
float final_scaler;
float accelleration_delta;
float decelleration_delta;
uint32_t accellerate_ticks;
uint32_t plateau_ticks;
};
struct AccellerationProfileSegment {
float v_entry[3];
float v_ideal[3];
float v_exit[3];
float distance;
float f_entry, f_exit;
};
struct AccellerationProfileBuilder {
AccellerationProfileSegment segment[3];
uint8_t current;
};
#endif

View File

@ -32,11 +32,19 @@ void reset_settings() {
settings.steps_per_mm[2] = Z_STEPS_PER_MM;
settings.pulse_microseconds = STEP_PULSE_MICROSECONDS;
settings.default_feed_rate = DEFAULT_FEEDRATE;
<<<<<<< Updated upstream
settings.default_seek_rate = RAPID_FEEDRATE;
settings.dead_feed_rate = DEFAULT_FEEDRATE/5;
settings.acceleration = DEFAULT_FEEDRATE/100;
settings.mm_per_arc_segment = MM_PER_ARC_SEGMENT;
settings.invert_mask = STEPPING_INVERT_MASK;
=======
settings.seek_rate = DEFAULT_SEEKRATE;
settings.mm_per_arc_segment = DEFAULT_MM_PER_ARC_SEGMENT;
settings.invert_mask = 0;
settings.max_jerk = DEFAULT_MAX_JERK;
settings.accelleration = DEFAULT_ACCELLERATION;
>>>>>>> Stashed changes
}
void dump_settings() {
@ -51,7 +59,10 @@ void dump_settings() {
printPgmString(PSTR(" (mm/sec^2 max acceleration)\r\n$9 = ")); printFloat(settings.acceleration);
printPgmString(PSTR(" (mm/arc segment)\r\n$10 = ")); printInteger(settings.invert_mask);
printPgmString(PSTR(" (step port invert mask. binary = ")); printIntegerInBase(settings.invert_mask, 2);
printPgmString(PSTR(")\r\n\r\n'$x=value' to set parameter or just '$' to dump current settings\r\n"));
printPgmString(PSTR(")\n\r$8 = ")); printFloat(settings.max_jerk);
printPgmString(PSTR(" (max jerk in delta mm/second)\r\n$9 = ")); printFloat(settings.accelleration);
printPgmString(PSTR(" (accelleration in mm/second^2)"));
printPgmString(PSTR("\r\n'$x=value' to set parameter or just '$' to dump current settings\r\n"));
}
int read_settings() {
@ -77,11 +88,19 @@ void store_setting(int parameter, double value) {
settings.steps_per_mm[parameter] = value; break;
case 3: settings.pulse_microseconds = round(value); break;
case 4: settings.default_feed_rate = value; break;
<<<<<<< Updated upstream
case 5: settings.default_seek_rate = value; break;
case 6: settings.dead_feed_rate = value; break;
case 8: settings.mm_per_arc_segment = value; break;
case 9: settings.acceleration = value; break;
case 10: settings.invert_mask = trunc(value); break;
=======
case 5: settings.seek_rate = value; break;
case 6: settings.mm_per_arc_segment = value; break;
case 7: settings.invert_mask = trunc(value); break;
case 8: settings.max_jerk = value; break;
case 9: settings.accelleration = fabs(value); break;
>>>>>>> Stashed changes
default:
printPgmString(PSTR("Unknown parameter\r\n"));
return;

View File

@ -22,6 +22,8 @@
#define config_h
#define VERSION "0.51"
#include <math.h>
#include <inttypes.h>
// Settings that can only be set at compile-time:
@ -69,6 +71,10 @@ struct Settings {
double default_seek_rate;
uint8_t invert_mask;
double mm_per_arc_segment;
<<<<<<< Updated upstream
=======
double max_jerk;
>>>>>>> Stashed changes
double accelleration;
};
struct Settings settings;
@ -94,6 +100,8 @@ void store_setting(int parameter, double value);
#define RAPID_FEEDRATE 480.0 // in millimeters per minute
#define DEFAULT_FEEDRATE 480.0
#define DEFAULT_MAX_JERK 10.0
#define DEFAULT_ACCELLERATION 0.1
// Use this line for default operation (step-pulses high)
#define STEPPING_INVERT_MASK 0

View File

@ -41,4 +41,10 @@
#define Y_AXIS 1
#define Z_AXIS 2
void scale_vector(float *target, float *source, float multiplier) {
target[0] = source[0]*multiplier;
target[1] = source[1]*multiplier;
target[2] = source[2]*multiplier;
}
#endif

View File

@ -40,6 +40,7 @@
#define LINE_BUFFER_SIZE 10
#endif
<<<<<<< Updated upstream
struct Line {
uint32_t steps_x, steps_y, steps_z;
int32_t maximum_steps;
@ -75,6 +76,41 @@ void update_accelleration_plan() {
int initial_buffer_tail = line_buffer_tail;
}
=======
#define ENABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 |= (1<<OCIE1A)
#define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
#define CYCLES_PER_ACCELLERATION_TICK (F_CPU)
// This record is used to buffer the setup for each linear movement
struct Block {
uint32_t steps_x, steps_y, steps_z; // Step count along each axis
double rate_x, rate_y, rate_z; // Nominal steps/minute for each axis
int32_t maximum_steps; // The largest stepcount of any axis for this block
uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
uint32_t rate; // The nominal step rate for this block in microseconds/step
};
struct Block block_buffer[BLOCK_BUFFER_SIZE]; // A buffer for motion instructions
volatile int block_buffer_head = 0; // Index of the next block to be pushed
volatile int block_buffer_tail = 0; // Index of the block to process now
// Variables used by The Stepper Driver Interrupt
uint8_t out_bits; // The next stepping-bits to be output
struct Block *current_block; // A pointer to the block currently being traced
int32_t counter_x,
counter_y,
counter_z; // counter variables for the bresenham line tracer
uint32_t iterations; // The number of iterations left to complete the current_block
volatile int busy; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler.
// Variables used by the accelleration manager
float rate_multiplier; // The current rate multiplier. at 1.0 nominal rates equals actual rates
float rate_change_rate; // The amount the rate_multiplier changes each
uint32_t rate_ramp_iterations; // The accelleration iterations for which the current rate ramp is valid
void config_step_timer(uint32_t microseconds);
>>>>>>> Stashed changes
// Add a new linear movement to the buffer. steps_x, _y and _z is the signed, relative motion in
// steps. Microseconds specify how many microseconds the move should take to perform. To aid accelleration
@ -83,6 +119,7 @@ void st_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_t
// Calculate the buffer head after we push this byte
int next_buffer_head = (line_buffer_head + 1) % LINE_BUFFER_SIZE;
// If the buffer is full: good! That means we are well ahead of the robot.
<<<<<<< Updated upstream
// Nap until there is room in the buffer.
while(line_buffer_tail == next_buffer_head) { sleep_mode(); }
// Setup line record
@ -94,6 +131,26 @@ void st_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_t
// Bail if this is a zero-length line
if (line->maximum_steps == 0) { return; };
line->rate = (TICKS_PER_MICROSECOND*microseconds)/line->maximum_steps;
=======
// Rest here until there is room in the buffer.
while(block_buffer_tail == next_buffer_head) { sleep_mode(); }
// Prepare to set up new block
struct Block *block = &block_buffer[block_buffer_head];
// Number of steps for each axis
block->steps_x = labs(steps_x);
block->steps_y = labs(steps_y);
block->steps_z = labs(steps_z);
block->maximum_steps = max(block->steps_x, max(block->steps_y, block->steps_z));
// Bail if this is a zero-length block
if (block->maximum_steps == 0) { return; };
// Rate in steps/second for each axis
double rate_multiplier = 60.0*1000000.0/microseconds;
block->rate_x = round(block->steps_x*rate_multiplier);
block->rate_y = round(block->steps_y*rate_multiplier);
block->rate_z = round(block->steps_z*rate_multiplier);
block->rate = microseconds/block->maximum_steps;
// Compute direction bits for this block
>>>>>>> Stashed changes
uint8_t direction_bits = 0;
if (steps_x < 0) { direction_bits |= (1<<X_DIRECTION_BIT); }
if (steps_y < 0) { direction_bits |= (1<<Y_DIRECTION_BIT); }
@ -101,6 +158,7 @@ void st_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_t
line->direction_bits = direction_bits;
line->average_millimeters_per_step_event = millimeters/line->maximum_steps
// Move buffer head
<<<<<<< Updated upstream
line_buffer_head = next_buffer_head;
// enable stepper interrupt
TIMSK1 |= (1<<OCIE1A);
@ -110,6 +168,16 @@ void st_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_t
// This timer interrupt is executed at the rate set with config_step_timer. It pops one instruction from
// the line_buffer, executes it. Then it starts timer2 in order to reset the motor port after
// five microseconds.
=======
block_buffer_head = next_buffer_head;
// Ensure that block processing is running by enabling The Stepper Driver Interrupt
ENABLE_STEPPER_DRIVER_INTERRUPT();
}
// "The Stepper Driver Interrupt" - This timer interrupt is the workhorse of Grbl. It is executed at the rate set with
// config_step_timer. It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
// It is supported by The Stepper Port Reset Interrupt which it uses to reset the stepper port after each pulse.
>>>>>>> Stashed changes
#ifdef TIMER1_COMPA_vect
SIGNAL(TIMER1_COMPA_vect)
#else
@ -123,7 +191,7 @@ SIGNAL(SIG_OUTPUT_COMPARE1A)
STEPPING_PORT = (STEPPING_PORT & ~DIRECTION_MASK) | (out_bits & DIRECTION_MASK);
// Then pulse the stepping pins
STEPPING_PORT = (STEPPING_PORT & ~STEP_MASK) | out_bits;
// Reset step pulse reset timer so that SIG_OVERFLOW2 can reset the signal after
// Reset step pulse reset timer so that The Stepper Port Reset Interrupt can reset the signal after
// exactly settings.pulse_microseconds microseconds.
TCNT2 = -(((settings.pulse_microseconds-2)*TICKS_PER_MICROSECOND)/8);
@ -222,7 +290,7 @@ void st_init()
TCCR2B = (1<<CS21); // Full speed, 1/8 prescaler
TIMSK2 |= (1<<TOIE2);
// Just ste the step_timer to something serviceably lazy
// Just set the step_timer to something serviceably lazy
config_step_timer(20000);
// set enable pin
STEPPERS_ENABLE_PORT |= 1<<STEPPERS_ENABLE_BIT;