general clean up after refactoring
This commit is contained in:
parent
49ca861dc0
commit
7e152851cc
2
config.h
2
config.h
@ -21,7 +21,7 @@
|
|||||||
#ifndef config_h
|
#ifndef config_h
|
||||||
#define config_h
|
#define config_h
|
||||||
|
|
||||||
#define VERSION "0.0"
|
#define VERSION "0.5"
|
||||||
|
|
||||||
#define X_STEPS_PER_MM (94.488188976378*16)
|
#define X_STEPS_PER_MM (94.488188976378*16)
|
||||||
#define Y_STEPS_PER_MM (94.488188976378*16)
|
#define Y_STEPS_PER_MM (94.488188976378*16)
|
||||||
|
2
main.c
2
main.c
@ -39,8 +39,6 @@ int main(void)
|
|||||||
gc_init(); // initialize gcode-parser
|
gc_init(); // initialize gcode-parser
|
||||||
sp_init(); // initialize the serial protocol
|
sp_init(); // initialize the serial protocol
|
||||||
|
|
||||||
st_start(); // start the stepper subsystem
|
|
||||||
|
|
||||||
DDRD |= (1<<3)|(1<<4)|(1<<5);
|
DDRD |= (1<<3)|(1<<4)|(1<<5);
|
||||||
|
|
||||||
for(;;){
|
for(;;){
|
||||||
|
@ -40,27 +40,20 @@
|
|||||||
|
|
||||||
#define ONE_MINUTE_OF_MICROSECONDS 60000000.0
|
#define ONE_MINUTE_OF_MICROSECONDS 60000000.0
|
||||||
|
|
||||||
volatile int8_t mode; // The current operation mode
|
|
||||||
int32_t position[3]; // The current position of the tool in absolute steps
|
int32_t position[3]; // The current position of the tool in absolute steps
|
||||||
uint8_t direction_bits; // The direction bits to be used with any upcoming step-instruction
|
|
||||||
|
|
||||||
void set_stepper_directions(int8_t *direction);
|
|
||||||
inline void step_steppers(uint8_t bits);
|
inline void step_steppers(uint8_t bits);
|
||||||
inline void step_axis(uint8_t axis);
|
inline void step_axis(uint8_t axis);
|
||||||
void prepare_linear_motion(uint32_t x, uint32_t y, uint32_t z, float feed_rate, int invert_feed_rate);
|
void prepare_linear_motion(uint32_t x, uint32_t y, uint32_t z, float feed_rate, int invert_feed_rate);
|
||||||
|
|
||||||
void mc_init()
|
void mc_init()
|
||||||
{
|
{
|
||||||
mode = MC_MODE_AT_REST;
|
|
||||||
clear_vector(position);
|
clear_vector(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mc_dwell(uint32_t milliseconds)
|
void mc_dwell(uint32_t milliseconds)
|
||||||
{
|
{
|
||||||
mode = MC_MODE_DWELL;
|
st_buffer_line(0, 0, 0, milliseconds*1000);
|
||||||
st_synchronize();
|
|
||||||
_delay_ms(milliseconds);
|
|
||||||
mode = MC_MODE_AT_REST;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second
|
// Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second
|
||||||
@ -128,30 +121,6 @@ void mc_arc(double theta, double angular_travel, double radius, double linear_tr
|
|||||||
|
|
||||||
void mc_go_home()
|
void mc_go_home()
|
||||||
{
|
{
|
||||||
mode = MC_MODE_HOME;
|
|
||||||
st_go_home();
|
st_go_home();
|
||||||
st_synchronize();
|
|
||||||
clear_vector(position); // By definition this is location [0, 0, 0]
|
clear_vector(position); // By definition this is location [0, 0, 0]
|
||||||
mode = MC_MODE_AT_REST;
|
|
||||||
}
|
|
||||||
|
|
||||||
int mc_status()
|
|
||||||
{
|
|
||||||
return(mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the direction bits for the stepper motors according to the provided vector.
|
|
||||||
// direction is an array of three 8 bit integers representing the direction of
|
|
||||||
// each motor. The values should be negative (reverse), 0 or positive (forward).
|
|
||||||
void set_stepper_directions(int8_t *direction)
|
|
||||||
{
|
|
||||||
/* Sorry about this convoluted code! It uses the fact that bit 7 of each direction
|
|
||||||
int is set when the direction == -1, but is 0 when direction is forward. This
|
|
||||||
way we can generate the whole direction bit-mask without doing any comparisions
|
|
||||||
or branching. Fast and compact, yet practically unreadable. Sorry sorry sorry.
|
|
||||||
*/
|
|
||||||
direction_bits = (
|
|
||||||
((direction[X_AXIS]&0x80)>>(7-X_DIRECTION_BIT)) |
|
|
||||||
((direction[Y_AXIS]&0x80)>>(7-Y_DIRECTION_BIT)) |
|
|
||||||
((direction[Z_AXIS]&0x80)>>(7-Z_DIRECTION_BIT)));
|
|
||||||
}
|
}
|
||||||
|
@ -26,40 +26,13 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "nuts_bolts.h"
|
#include "nuts_bolts.h"
|
||||||
|
|
||||||
#define LINE_BUFFER_SIZE 128
|
#define LINE_BUFFER_SIZE 60
|
||||||
|
|
||||||
char line[LINE_BUFFER_SIZE];
|
char line[LINE_BUFFER_SIZE];
|
||||||
uint8_t line_counter;
|
uint8_t char_counter;
|
||||||
|
|
||||||
void prompt() {
|
void prompt() {
|
||||||
printString("ok\r\n");
|
printString("ok\r\n");
|
||||||
line_counter = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_result() {
|
|
||||||
double position[3];
|
|
||||||
int inches_mode;
|
|
||||||
uint8_t status_code;
|
|
||||||
uint32_t line_number;
|
|
||||||
int i; // loop variable
|
|
||||||
gc_get_status(position, &status_code, &inches_mode, &line_number);
|
|
||||||
printString("\r\n[ ");
|
|
||||||
for(i=X_AXIS; i<=Z_AXIS; i++) {
|
|
||||||
printInteger(trunc(position[i]*100));
|
|
||||||
printByte(' ');
|
|
||||||
}
|
|
||||||
printByte(']');
|
|
||||||
printByte('@');
|
|
||||||
printInteger(line_number);
|
|
||||||
printByte(':');
|
|
||||||
switch(status_code) {
|
|
||||||
case GCSTATUS_OK: printString("0 OK\r\n"); break;
|
|
||||||
case GCSTATUS_BAD_NUMBER_FORMAT: printString("1 Bad number format\r\n"); break;
|
|
||||||
case GCSTATUS_EXPECTED_COMMAND_LETTER: printString("2 Expected command letter\r\n"); break;
|
|
||||||
case GCSTATUS_UNSUPPORTED_STATEMENT: printString("3 Unsupported statement\r\n"); break;
|
|
||||||
case GCSTATUS_MOTION_CONTROL_ERROR: printString("4 Motion control error\r\n"); break;
|
|
||||||
case GCSTATUS_FLOATING_POINT_ERROR: printString("5 Floating point error\r\n"); break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sp_init()
|
void sp_init()
|
||||||
@ -78,19 +51,15 @@ void sp_process()
|
|||||||
while((c = serialRead()) != -1)
|
while((c = serialRead()) != -1)
|
||||||
{
|
{
|
||||||
if((c == '\n')) { // Line is complete. Then execute!
|
if((c == '\n')) { // Line is complete. Then execute!
|
||||||
line[line_counter] = 0;
|
line[char_counter] = 0;
|
||||||
// printString("->");
|
|
||||||
// printString(line);
|
|
||||||
// printString("<-\r\n");
|
|
||||||
gc_execute_line(line);
|
gc_execute_line(line);
|
||||||
line_counter = 0;
|
char_counter = 0;
|
||||||
prompt();
|
prompt();
|
||||||
} else if (c <= ' ') { // Throw away whitepace and control characters
|
} else if (c <= ' ') { // Throw away whitepace and control characters
|
||||||
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
|
} else if (c >= 'a' && c <= 'z') { // Upcase lowercase
|
||||||
line[line_counter++] = c-'a'+'A';
|
line[char_counter++] = c-'a'+'A';
|
||||||
} else {
|
} else {
|
||||||
line[line_counter++] = c;
|
line[char_counter++] = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,8 +27,6 @@
|
|||||||
|
|
||||||
// Initialize the serial protocol
|
// Initialize the serial protocol
|
||||||
void sp_init();
|
void sp_init();
|
||||||
// Called by motion control just before the motion starts
|
|
||||||
void sp_send_execution_marker();
|
|
||||||
// Read command lines from the serial port and execute them as they
|
// Read command lines from the serial port and execute them as they
|
||||||
// come in. Blocks until the serial buffer is emptied.
|
// come in. Blocks until the serial buffer is emptied.
|
||||||
void sp_process();
|
void sp_process();
|
||||||
|
86
stepper.c
86
stepper.c
@ -33,7 +33,7 @@
|
|||||||
#include "wiring_serial.h"
|
#include "wiring_serial.h"
|
||||||
|
|
||||||
#define TICKS_PER_MICROSECOND (F_CPU/1000000)
|
#define TICKS_PER_MICROSECOND (F_CPU/1000000)
|
||||||
#define LINE_BUFFER_SIZE 8
|
#define LINE_BUFFER_SIZE 10
|
||||||
|
|
||||||
struct Line {
|
struct Line {
|
||||||
uint32_t steps_x, steps_y, steps_z;
|
uint32_t steps_x, steps_y, steps_z;
|
||||||
@ -52,15 +52,11 @@ struct Line *current_line;
|
|||||||
volatile int32_t counter_x, counter_y, counter_z;
|
volatile int32_t counter_x, counter_y, counter_z;
|
||||||
uint32_t iterations;
|
uint32_t iterations;
|
||||||
|
|
||||||
uint8_t stepper_mode = STEPPER_MODE_STOPPED;
|
void config_step_timer(uint32_t microseconds);
|
||||||
|
|
||||||
void config_pace_timer(uint32_t microseconds);
|
|
||||||
|
|
||||||
// Add a new linear movement to the buffer. steps_x, _y and _z is the signed, relative motion in
|
// 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.
|
// steps. Microseconds specify how many microseconds the move should take to perform.
|
||||||
void st_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_t microseconds) {
|
void st_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_t microseconds) {
|
||||||
// Buffer nothing unless stepping subsystem is running
|
|
||||||
if (stepper_mode != STEPPER_MODE_RUNNING) { return; }
|
|
||||||
// Calculate the buffer head after we push this byte
|
// Calculate the buffer head after we push this byte
|
||||||
int next_buffer_head = (line_buffer_head + 1) % LINE_BUFFER_SIZE;
|
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.
|
// If the buffer is full: good! That means we are well ahead of the robot.
|
||||||
@ -108,7 +104,7 @@ SIGNAL(SIG_OUTPUT_COMPARE1A)
|
|||||||
PORTD ^= (1<<5);
|
PORTD ^= (1<<5);
|
||||||
// Retrieve a new line and get ready to step it
|
// Retrieve a new line and get ready to step it
|
||||||
current_line = &line_buffer[line_buffer_tail];
|
current_line = &line_buffer[line_buffer_tail];
|
||||||
config_pace_timer(current_line->rate);
|
config_step_timer(current_line->rate);
|
||||||
counter_x = -(current_line->maximum_steps/2);
|
counter_x = -(current_line->maximum_steps/2);
|
||||||
counter_y = counter_x;
|
counter_y = counter_x;
|
||||||
counter_z = counter_x;
|
counter_z = counter_x;
|
||||||
@ -183,23 +179,20 @@ void st_init()
|
|||||||
TCCR2B = (1<<CS21); // Full speed, 1/8 prescaler
|
TCCR2B = (1<<CS21); // Full speed, 1/8 prescaler
|
||||||
TIMSK2 = 0; // All interrupts disabled
|
TIMSK2 = 0; // All interrupts disabled
|
||||||
|
|
||||||
sei();
|
TIMSK2 |= (1<<TOIE2);
|
||||||
|
// set enable pin
|
||||||
|
STEPPERS_ENABLE_PORT |= 1<<STEPPERS_ENABLE_BIT;
|
||||||
|
|
||||||
// start off with a mellow pace
|
sei();
|
||||||
config_pace_timer(20000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block until all buffered steps are executed
|
// Block until all buffered steps are executed
|
||||||
void st_synchronize()
|
void st_synchronize()
|
||||||
{
|
{
|
||||||
if (stepper_mode == STEPPER_MODE_RUNNING) {
|
|
||||||
while(line_buffer_tail != line_buffer_head) { sleep_mode(); }
|
while(line_buffer_tail != line_buffer_head) { sleep_mode(); }
|
||||||
} else {
|
|
||||||
st_flush();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cancel all pending steps
|
// Cancel all buffered steps
|
||||||
void st_flush()
|
void st_flush()
|
||||||
{
|
{
|
||||||
cli();
|
cli();
|
||||||
@ -208,42 +201,8 @@ void st_flush()
|
|||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the stepper subsystem
|
|
||||||
void st_start()
|
|
||||||
{
|
|
||||||
// Enable timer interrupts
|
|
||||||
TIMSK1 |= (1<<OCIE1A);
|
|
||||||
TIMSK2 |= (1<<TOIE2);
|
|
||||||
// set enable pin
|
|
||||||
STEPPERS_ENABLE_PORT |= 1<<STEPPERS_ENABLE_BIT;
|
|
||||||
stepper_mode = STEPPER_MODE_RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute all buffered steps, then stop the stepper subsystem
|
|
||||||
inline void st_stop()
|
|
||||||
{
|
|
||||||
// flush pending operations
|
|
||||||
st_synchronize();
|
|
||||||
// disable timer interrupts
|
|
||||||
TIMSK1 &= ~(1<<OCIE1A);
|
|
||||||
TIMSK2 &= ~(1<<TOIE2);
|
|
||||||
// reset enable pin
|
|
||||||
STEPPERS_ENABLE_PORT &= ~(1<<STEPPERS_ENABLE_BIT);
|
|
||||||
stepper_mode = STEPPER_MODE_STOPPED;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a bitmask with the stepper bit for the given axis set
|
|
||||||
uint8_t st_bit_for_stepper(int axis) {
|
|
||||||
switch(axis) {
|
|
||||||
case X_AXIS: return(1<<X_STEP_BIT);
|
|
||||||
case Y_AXIS: return(1<<Y_STEP_BIT);
|
|
||||||
case Z_AXIS: return(1<<Z_STEP_BIT);
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configures the prescaler and ceiling of timer 1 to produce the given pace as accurately as possible.
|
// Configures the prescaler and ceiling of timer 1 to produce the given pace as accurately as possible.
|
||||||
void config_pace_timer(uint32_t microseconds)
|
void config_step_timer(uint32_t microseconds)
|
||||||
{
|
{
|
||||||
uint32_t ticks = microseconds*TICKS_PER_MICROSECOND;
|
uint32_t ticks = microseconds*TICKS_PER_MICROSECOND;
|
||||||
uint16_t ceiling;
|
uint16_t ceiling;
|
||||||
@ -274,34 +233,7 @@ void config_pace_timer(uint32_t microseconds)
|
|||||||
OCR1A = ceiling;
|
OCR1A = ceiling;
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_limit_switches()
|
|
||||||
{
|
|
||||||
// Dual read as crude debounce
|
|
||||||
return((LIMIT_PORT & LIMIT_MASK) | (LIMIT_PORT & LIMIT_MASK));
|
|
||||||
}
|
|
||||||
|
|
||||||
int check_limit_switch(int axis)
|
|
||||||
{
|
|
||||||
uint8_t mask = 0;
|
|
||||||
switch (axis) {
|
|
||||||
case X_AXIS: mask = 1<<X_LIMIT_BIT; break;
|
|
||||||
case Y_AXIS: mask = 1<<Y_LIMIT_BIT; break;
|
|
||||||
case Z_AXIS: mask = 1<<Z_LIMIT_BIT; break;
|
|
||||||
}
|
|
||||||
return((LIMIT_PORT&mask) || (LIMIT_PORT&mask));
|
|
||||||
}
|
|
||||||
|
|
||||||
void st_go_home()
|
void st_go_home()
|
||||||
{
|
{
|
||||||
// Todo: Perform the homing cycle
|
// Todo: Perform the homing cycle
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert from millimeters to step-counts along the designated axis
|
|
||||||
int32_t st_millimeters_to_steps(double millimeters, int axis) {
|
|
||||||
switch(axis) {
|
|
||||||
case X_AXIS: return(round(millimeters*X_STEPS_PER_MM));
|
|
||||||
case Y_AXIS: return(round(millimeters*Y_STEPS_PER_MM));
|
|
||||||
case Z_AXIS: return(round(millimeters*Z_STEPS_PER_MM));
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
15
stepper.h
15
stepper.h
@ -32,9 +32,6 @@
|
|||||||
// Initialize and start the stepper motor subsystem
|
// Initialize and start the stepper motor subsystem
|
||||||
void st_init();
|
void st_init();
|
||||||
|
|
||||||
// Returns a bitmask with the stepper bit for the given axis set
|
|
||||||
uint8_t st_bit_for_stepper(int axis);
|
|
||||||
|
|
||||||
// Add a new linear movement to the buffer. steps_x, _y and _z is the signed, relative motion in
|
// 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.
|
// steps. Microseconds specify how many microseconds the move should take to perform.
|
||||||
void st_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_t rate);
|
void st_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_t rate);
|
||||||
@ -45,19 +42,7 @@ void st_synchronize();
|
|||||||
// Cancel all pending steps
|
// Cancel all pending steps
|
||||||
void st_flush();
|
void st_flush();
|
||||||
|
|
||||||
// Start the stepper subsystem
|
|
||||||
void st_start();
|
|
||||||
|
|
||||||
// Execute all buffered steps, then stop the stepper subsystem
|
|
||||||
inline void st_stop();
|
|
||||||
|
|
||||||
// Execute the homing cycle
|
// Execute the homing cycle
|
||||||
void st_go_home();
|
void st_go_home();
|
||||||
|
|
||||||
// Echo steps to serial port? (true/false)
|
|
||||||
void st_set_echo(int value);
|
|
||||||
|
|
||||||
// Convert from millimeters to step-counts along the designated axis
|
|
||||||
int32_t st_millimeters_to_steps(double millimeters, int axis);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
13
todo.txt
13
todo.txt
@ -1,19 +1,6 @@
|
|||||||
* Use errno to detect fp-errors
|
* Use errno to detect fp-errors
|
||||||
* Optimize arc target detection code utilizing the primary axis of travel
|
|
||||||
* Arcs might be a step or two off because of FP gotchas. Must add a little nudge in the end there?
|
|
||||||
* Implement homing cycle in stepper.c
|
* Implement homing cycle in stepper.c
|
||||||
* Implement limit switch support in stepper.c (use port-triggered interrupts?)
|
* Implement limit switch support in stepper.c (use port-triggered interrupts?)
|
||||||
* How on earth am I going to deal with arcs in setups that have different steps/mm on each axis? Must
|
|
||||||
support elipses?! Oh no.
|
|
||||||
* Eliminate need for x and y in step_arc_along_
|
|
||||||
* Tool table
|
|
||||||
* Tool length offsets
|
|
||||||
* Tool change M6
|
* Tool change M6
|
||||||
* Path Control Modes
|
* Path Control Modes
|
||||||
* Spindle speed support
|
* Spindle speed support
|
||||||
|
|
||||||
Bugs to fix:
|
|
||||||
|
|
||||||
This generates an infinite sequence of non-steppings
|
|
||||||
G01 X152.730364 Y331.534522
|
|
||||||
G03 X152.30001 Y331.959998 I-1.959917 J-1.552007
|
|
||||||
|
Loading…
Reference in New Issue
Block a user