summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkintel <kintel@cb376a5e-1013-0410-a455-b6b1f9ac8223>2008-11-09 03:35:50 +0000
committerkintel <kintel@cb376a5e-1013-0410-a455-b6b1f9ac8223>2008-11-09 03:35:50 +0000
commit466694d15195762d4fb2bdcb4f07ea7de43e495e (patch)
treef7961534fb7720cc7d96fd3559d0cfdb3d059c72
parent0b4abc28b847849b23d46e5e4a0119134a0a1945 (diff)
downloadreprap-backup-466694d15195762d4fb2bdcb4f07ea7de43e495e.tar.gz
reprap-backup-466694d15195762d4fb2bdcb4f07ea7de43e495e.zip
Tried to temporarily put back Zach's coding style for easier diff
git-svn-id: https://reprap.svn.sourceforge.net/svnroot/reprap@2226 cb376a5e-1013-0410-a455-b6b1f9ac8223
-rw-r--r--trunk/users/metalab/GCode_Interpreter/GCode_Interpreter.pde141
-rw-r--r--trunk/users/metalab/GCode_Interpreter/extruder.pde148
-rw-r--r--trunk/users/metalab/GCode_Interpreter/process_string.pde2
-rw-r--r--trunk/users/metalab/GCode_Interpreter/stepper_control.pde355
-rw-r--r--trunk/users/metalab/GCode_Interpreter/utils.cpp58
5 files changed, 362 insertions, 342 deletions
diff --git a/trunk/users/metalab/GCode_Interpreter/GCode_Interpreter.pde b/trunk/users/metalab/GCode_Interpreter/GCode_Interpreter.pde
index 39ebeca7..34ce65b7 100644
--- a/trunk/users/metalab/GCode_Interpreter/GCode_Interpreter.pde
+++ b/trunk/users/metalab/GCode_Interpreter/GCode_Interpreter.pde
@@ -1,4 +1,4 @@
-// Yep, this is actually -*- c++ -*-
+/* -*- mode: c++; c-basic-offset: 8; indent-tabs-mode: t -*- */
// Arduino G-code Interpreter
// v1.0 by Mike Ellery - initial software (mellery@gmail.com)
@@ -10,9 +10,9 @@
#include "_init.h"
AxisConfig axes[3] = {
- {X_STEP_PIN, X_DIR_PIN, X_MIN_PIN, X_MAX_PIN, X_ENABLE_PIN, INVERT_X_DIR, REFERENCE_X_DIR, ENDSTOP_X_MIN_ENABLED, ENDSTOP_X_MAX_ENABLED, X_STEPS_PER_INCH, X_STEPS_PER_MM, X_MOTOR_STEPS},
- {Y_STEP_PIN, Y_DIR_PIN, Y_MIN_PIN, Y_MAX_PIN, Y_ENABLE_PIN, INVERT_Y_DIR, REFERENCE_Y_DIR, ENDSTOP_Y_MIN_ENABLED, ENDSTOP_Y_MAX_ENABLED, Y_STEPS_PER_INCH, Y_STEPS_PER_MM, Y_MOTOR_STEPS},
- {Z_STEP_PIN, Z_DIR_PIN, Z_MIN_PIN, Z_MAX_PIN, Z_ENABLE_PIN, INVERT_Z_DIR, REFERENCE_Z_DIR, ENDSTOP_Z_MIN_ENABLED, ENDSTOP_Z_MAX_ENABLED, Z_STEPS_PER_INCH, Z_STEPS_PER_MM, Z_MOTOR_STEPS}
+ {X_STEP_PIN, X_DIR_PIN, X_MIN_PIN, X_MAX_PIN, X_ENABLE_PIN, INVERT_X_DIR, REFERENCE_X_DIR, ENDSTOP_X_MIN_ENABLED, ENDSTOP_X_MAX_ENABLED, X_STEPS_PER_INCH, X_STEPS_PER_MM, X_MOTOR_STEPS},
+ {Y_STEP_PIN, Y_DIR_PIN, Y_MIN_PIN, Y_MAX_PIN, Y_ENABLE_PIN, INVERT_Y_DIR, REFERENCE_Y_DIR, ENDSTOP_Y_MIN_ENABLED, ENDSTOP_Y_MAX_ENABLED, Y_STEPS_PER_INCH, Y_STEPS_PER_MM, Y_MOTOR_STEPS},
+ {Z_STEP_PIN, Z_DIR_PIN, Z_MIN_PIN, Z_MAX_PIN, Z_ENABLE_PIN, INVERT_Z_DIR, REFERENCE_Z_DIR, ENDSTOP_Z_MIN_ENABLED, ENDSTOP_Z_MAX_ENABLED, Z_STEPS_PER_INCH, Z_STEPS_PER_MM, Z_MOTOR_STEPS}
};
//our command string
@@ -26,77 +26,84 @@ boolean bytes_received = false;
void setup()
{
- //Do startup stuff here
- Serial.begin(19200);
- Serial.println("start");
+ //Do startup stuff here
+ Serial.begin(19200);
+ Serial.println("start");
- //other initialization.
- init_steppers();
- init_extruder();
- clear_process_string();
+ //other initialization.
+ init_steppers();
+ init_extruder();
+ clear_process_string();
}
void clear_process_string()
{
- //init our command buffer
- for (uint8_t i=0; i<COMMAND_SIZE; i++) word[i] = 0;
- serial_count = 0;
- bytes_received = false;
+ //init our command buffer
+ for (uint8_t i=0; i<COMMAND_SIZE; i++) word[i] = 0;
+ serial_count = 0;
+ bytes_received = false;
- idle_time = millis();
+ idle_time = millis();
}
void loop()
{
- char c;
-
- extruder_manage_temperature(); //keep it hot!
-
- //read in characters if we got them.
- if (Serial.available() > 0) {
- c = Serial.read();
-
- // Reset no_data timer
- no_data = 0;
- idle_time = millis();
-
- // commands end with newlines
- if (c != '\n') {
- // Start of comment - ignore any bytes received from now on
- if (c == '(') comment = true;
-
- // If we're not in comment mode, add it to our array.
- if (!comment) {
- word[serial_count] = c;
- serial_count++;
- }
-
- if (c == ')') comment = false; // End of comment - start listening again
- }
-
- bytes_received = true;
- }
- else {
- // mark no_data if nothing heard for 100 milliseconds
- if ((millis() - idle_time) >= 100) {
- no_data++;
- idle_time = millis();
- }
- }
-
- // if there's a pause or we got a real command, do it
- if (bytes_received && (c == '\n' || no_data)) {
-// if (no_data) Serial.print("NODATA ");
-// Serial.print("debug: ");
-// Serial.println(word);
-
- //process our command!
- process_string(word, serial_count);
-
- //clear command.
- clear_process_string();
- }
-
- //no data for > 1 sec -> turn off steppers
- if (no_data > 10) disable_steppers();
+ char c;
+
+ extruder_manage_temperature(); //keep it hot!
+
+ //read in characters if we got them.
+ if (Serial.available() > 0)
+ {
+ c = Serial.read();
+
+ // Reset no_data timer
+ no_data = 0;
+ idle_time = millis();
+
+ // commands end with newlines
+ if (c != '\n')
+ {
+ // Start of comment - ignore any bytes received from now on
+ if (c == '(') comment = true;
+
+ // If we're not in comment mode, add it to our array.
+ if (!comment)
+ {
+ word[serial_count] = c;
+ serial_count++;
+ }
+
+ if (c == ')') comment = false; // End of comment - start listening again
+ }
+
+ bytes_received = true;
+ }
+ else
+ {
+ // mark no_data if nothing heard for 100 milliseconds
+ if ((millis() - idle_time) >= 100)
+ {
+ no_data++;
+ idle_time = millis();
+ }
+ }
+
+ // if there's a pause or we got a real command, do it
+ if (bytes_received && (c == '\n' || no_data))
+ {
+ // if (no_data) Serial.print("NODATA ");
+ // Serial.print("debug: ");
+ // Serial.println(word);
+
+ //process our command!
+ process_string(word, serial_count);
+
+ //clear command.
+ clear_process_string();
+ }
+
+ //no data for > 1 sec -> turn off steppers
+ if (no_data > 10)
+ disable_steppers();
}
diff --git a/trunk/users/metalab/GCode_Interpreter/extruder.pde b/trunk/users/metalab/GCode_Interpreter/extruder.pde
index ec3591b6..8456b4aa 100644
--- a/trunk/users/metalab/GCode_Interpreter/extruder.pde
+++ b/trunk/users/metalab/GCode_Interpreter/extruder.pde
@@ -1,4 +1,4 @@
-// Yep, this is actually -*- c++ -*-
+/* -*- mode: c++; c-basic-offset: 8; indent-tabs-mode: t -*- */
#include "ThermistorTable.h"
@@ -23,42 +23,42 @@ bool extruder_direction = EXTRUDER_FORWARD;
void init_extruder()
{
- //default to room temp.
- extruder_set_temperature(21);
+ //default to room temp.
+ extruder_set_temperature(21);
- //setup our pins
- pinMode(EXTRUDER_MOTOR_DIR_PIN, OUTPUT);
- pinMode(EXTRUDER_MOTOR_SPEED_PIN, OUTPUT);
- pinMode(EXTRUDER_HEATER_PIN, OUTPUT);
- pinMode(EXTRUDER_FAN_PIN, OUTPUT);
+ //setup our pins
+ pinMode(EXTRUDER_MOTOR_DIR_PIN, OUTPUT);
+ pinMode(EXTRUDER_MOTOR_SPEED_PIN, OUTPUT);
+ pinMode(EXTRUDER_HEATER_PIN, OUTPUT);
+ pinMode(EXTRUDER_FAN_PIN, OUTPUT);
- //initialize values
- digitalWrite(EXTRUDER_MOTOR_DIR_PIN, EXTRUDER_FORWARD);
- analogWrite(EXTRUDER_FAN_PIN, 0);
- analogWrite(EXTRUDER_HEATER_PIN, 0);
- analogWrite(EXTRUDER_MOTOR_SPEED_PIN, 0);
+ //initialize values
+ digitalWrite(EXTRUDER_MOTOR_DIR_PIN, EXTRUDER_FORWARD);
+ analogWrite(EXTRUDER_FAN_PIN, 0);
+ analogWrite(EXTRUDER_HEATER_PIN, 0);
+ analogWrite(EXTRUDER_MOTOR_SPEED_PIN, 0);
}
void extruder_set_direction(bool direction)
{
- extruder_direction = direction;
- digitalWrite(EXTRUDER_MOTOR_DIR_PIN, direction);
+ extruder_direction = direction;
+ digitalWrite(EXTRUDER_MOTOR_DIR_PIN, direction);
}
void extruder_set_speed(byte speed)
{
- analogWrite(EXTRUDER_MOTOR_SPEED_PIN, speed);
+ analogWrite(EXTRUDER_MOTOR_SPEED_PIN, speed);
}
void extruder_set_cooler(byte speed)
{
- analogWrite(EXTRUDER_FAN_PIN, speed);
+ analogWrite(EXTRUDER_FAN_PIN, speed);
}
void extruder_set_temperature(int temp)
{
- extruder_target_celsius = temp;
- extruder_max_celsius = (int)((float)temp * 1.1);
+ extruder_target_celsius = temp;
+ extruder_max_celsius = (int)((float)temp * 1.1);
}
/**
@@ -68,9 +68,9 @@ void extruder_set_temperature(int temp)
int extruder_get_temperature()
{
#if EXTRUDER_THERMISTOR_PIN >= 0
- return extruder_read_thermistor();
+ return extruder_read_thermistor();
#elif EXTRUDER_THERMOCOUPLE_PIN >= 0
- return extruder_read_thermocouple();
+ return extruder_read_thermocouple();
#endif
}
@@ -79,31 +79,31 @@ int extruder_get_temperature()
*/
int extruder_read_thermistor()
{
- int raw = extruder_sample_temperature(EXTRUDER_THERMISTOR_PIN);
-
- int celsius = 0;
- byte i;
-
- for (i=1; i<NUMTEMPS; i++)
- {
- if (temptable[i][0] > raw)
- {
- celsius = temptable[i-1][1] +
- (raw - temptable[i-1][0]) *
- (temptable[i][1] - temptable[i-1][1]) /
- (temptable[i][0] - temptable[i-1][0]);
-
- break;
- }
- }
-
- // Overflow: Set to last value in the table
- if (i == NUMTEMPS) celsius = temptable[i-1][1];
- // Clamp to byte
- if (celsius > 255) celsius = 255;
- else if (celsius < 0) celsius = 0;
-
- return celsius;
+ int raw = extruder_sample_temperature(EXTRUDER_THERMISTOR_PIN);
+
+ int celsius = 0;
+ byte i;
+
+ for (i=1; i<NUMTEMPS; i++)
+ {
+ if (temptable[i][0] > raw)
+ {
+ celsius = temptable[i-1][1] +
+ (raw - temptable[i-1][0]) *
+ (temptable[i][1] - temptable[i-1][1]) /
+ (temptable[i][0] - temptable[i-1][0]);
+
+ break;
+ }
+ }
+
+ // Overflow: Set to last value in the table
+ if (i == NUMTEMPS) celsius = temptable[i-1][1];
+ // Clamp to byte
+ if (celsius > 255) celsius = 255;
+ else if (celsius < 0) celsius = 0;
+
+ return celsius;
}
@@ -113,7 +113,7 @@ int extruder_read_thermistor()
*/
int extruder_read_thermocouple()
{
- return ( 5.0 * extruder_sample_temperature(EXTRUDER_THERMOCOUPLE_PIN) * 100.0) / 1024.0;
+ return ( 5.0 * extruder_sample_temperature(EXTRUDER_THERMOCOUPLE_PIN) * 100.0) / 1024.0;
}
#endif
@@ -122,17 +122,17 @@ int extruder_read_thermocouple()
*/
int extruder_sample_temperature(byte pin)
{
- int raw = 0;
+ int raw = 0;
- //read in a certain number of samples
- for (byte i=0; i<TEMPERATURE_SAMPLES; i++)
- raw += analogRead(pin);
+ //read in a certain number of samples
+ for (byte i=0; i<TEMPERATURE_SAMPLES; i++)
+ raw += analogRead(pin);
- //average the samples
- raw = raw/TEMPERATURE_SAMPLES;
+ //average the samples
+ raw = raw/TEMPERATURE_SAMPLES;
- //send it back.
- return raw;
+ //send it back.
+ return raw;
}
/*!
@@ -142,26 +142,28 @@ int extruder_sample_temperature(byte pin)
*/
void extruder_manage_temperature()
{
- static long lastread = 0;
+ static long lastread = 0;
- if (millis() - lastread > 200) {
- lastread = millis();
+ if (millis() - lastread > 200)
+ {
+ lastread = millis();
- //make sure we know what our temp is.
- int current_celsius = extruder_get_temperature();
- byte newheat = 0;
+ //make sure we know what our temp is.
+ int current_celsius = extruder_get_temperature();
+ byte newheat = 0;
- //put the heater into high mode if we're not at our target.
- if (current_celsius < extruder_target_celsius)
- newheat = extruder_heater_high;
- //put the heater on low if we're at our target.
- else if (current_celsius < extruder_max_celsius)
- newheat = extruder_heater_low;
+ //put the heater into high mode if we're not at our target.
+ if (current_celsius < extruder_target_celsius)
+ newheat = extruder_heater_high;
+ //put the heater on low if we're at our target.
+ else if (current_celsius < extruder_max_celsius)
+ newheat = extruder_heater_low;
- // Only update heat if it changed
- if (extruder_heater_current != newheat) {
- extruder_heater_current = newheat;
- analogWrite(EXTRUDER_HEATER_PIN, extruder_heater_current);
- }
- }
+ // Only update heat if it changed
+ if (extruder_heater_current != newheat)
+ {
+ extruder_heater_current = newheat;
+ analogWrite(EXTRUDER_HEATER_PIN, extruder_heater_current);
+ }
+ }
}
diff --git a/trunk/users/metalab/GCode_Interpreter/process_string.pde b/trunk/users/metalab/GCode_Interpreter/process_string.pde
index c7e4f8a3..66f54c19 100644
--- a/trunk/users/metalab/GCode_Interpreter/process_string.pde
+++ b/trunk/users/metalab/GCode_Interpreter/process_string.pde
@@ -1,4 +1,4 @@
-// Yep, this is actually -*- c++ -*-
+/* -*- mode: c++; c-basic-offset: 8; indent-tabs-mode: t -*- */
// Our point structures to make things nice.
struct LongPoint
diff --git a/trunk/users/metalab/GCode_Interpreter/stepper_control.pde b/trunk/users/metalab/GCode_Interpreter/stepper_control.pde
index b3e7a6f7..4399dc68 100644
--- a/trunk/users/metalab/GCode_Interpreter/stepper_control.pde
+++ b/trunk/users/metalab/GCode_Interpreter/stepper_control.pde
@@ -1,4 +1,4 @@
-// Yep, this is actually -*- c++ -*-
+/* -*- mode: c++; c-basic-offset: 8; indent-tabs-mode: t -*- */
#include "_init.h"
#include "utils.h"
@@ -16,278 +16,287 @@ int milli_delay;
void init_steppers()
{
- //turn them off to start.
- disable_steppers();
-
- for (uint8_t i=0;i<3;i++) {
- current_units.p[i] = 0.0;
- target_units.p[i] = 0.0;
+ //turn them off to start.
+ disable_steppers();
+
+ for (uint8_t i=0;i<3;i++)
+ {
+ current_units.p[i] = 0.0;
+ target_units.p[i] = 0.0;
- const AxisConfig &a = axes[i];
- pinMode(a.step_pin, OUTPUT);
- pinMode(a.dir_pin, OUTPUT);
- pinMode(a.enable_pin, OUTPUT);
+ const AxisConfig &a = axes[i];
+ pinMode(a.step_pin, OUTPUT);
+ pinMode(a.dir_pin, OUTPUT);
+ pinMode(a.enable_pin, OUTPUT);
- if (a.min_endstop_enabled) pinMode(a.min_pin, INPUT);
- if (a.max_endstop_enabled) pinMode(a.max_pin, INPUT);
- }
+ if (a.min_endstop_enabled) pinMode(a.min_pin, INPUT);
+ if (a.max_endstop_enabled) pinMode(a.max_pin, INPUT);
+ }
- //figure our stuff.
- calculate_deltas();
+ //figure our stuff.
+ calculate_deltas();
}
void dda_move(long micro_delay)
{
- //turn on steppers to start moving =)
- enable_steppers();
+ //turn on steppers to start moving =)
+ enable_steppers();
- //figure out our deltas
- max_delta = max(delta_steps.p[X_AXIS], delta_steps.p[Y_AXIS]);
- max_delta = max(delta_steps.p[Z_AXIS], max_delta);
+ //figure out our deltas
+ max_delta = max(delta_steps.p[X_AXIS], delta_steps.p[Y_AXIS]);
+ max_delta = max(delta_steps.p[Z_AXIS], max_delta);
- //init stuff.
- counter[0] = -max_delta/2;
- counter[1] = -max_delta/2;
- counter[2] = -max_delta/2;
+ //init stuff.
+ counter[0] = -max_delta/2;
+ counter[1] = -max_delta/2;
+ counter[2] = -max_delta/2;
- //our step flags
- bool can_step_flags[3] = {false, false, false};
+ //our step flags
+ bool can_step_flags[3] = {false, false, false};
- //how long do we delay for?
- // We subtract the expected overhead of the loop to make the real speed
- // closer to our target feedrate. FIXME: This is just a hack and should
- // be handled properly.
- micro_delay -= 100;
- if (micro_delay >= 16383) milli_delay = micro_delay / 1000;
- else milli_delay = 0;
+ //how long do we delay for?
+ // We subtract the expected overhead of the loop to make the real speed
+ // closer to our target feedrate. FIXME: This is just a hack and should
+ // be handled properly.
+ micro_delay -= 100;
+ if (micro_delay >= 16383) milli_delay = micro_delay / 1000;
+ else milli_delay = 0;
- //do our DDA line!
- do {
- for (uint8_t i=0;i<3;i++) {
- const AxisConfig &a = axes[i];
- can_step_flags[i] = can_step(a.min_endstop_enabled, a.max_endstop_enabled,
- a.min_pin, a.max_pin,
- current_steps.p[i], target_steps.p[i], direction[i]);
+ //do our DDA line!
+ do
+ {
+ for (uint8_t i=0;i<3;i++)
+ {
+ const AxisConfig &a = axes[i];
+ can_step_flags[i] = can_step(a.min_endstop_enabled, a.max_endstop_enabled,
+ a.min_pin, a.max_pin,
+ current_steps.p[i], target_steps.p[i], direction[i]);
- if (can_step_flags[i]) {
- counter[i] += delta_steps.p[i];
+ if (can_step_flags[i])
+ {
+ counter[i] += delta_steps.p[i];
- if (counter[i] > 0) {
- do_step(a.step_pin);
- counter[i] -= max_delta;
+ if (counter[i] > 0)
+ {
+ do_step(a.step_pin);
+ counter[i] -= max_delta;
- if (direction[i]) current_steps.p[i]++;
- else current_steps.p[i]--;
- }
- }
- }
+ if (direction[i]) current_steps.p[i]++;
+ else current_steps.p[i]--;
+ }
+ }
+ }
- //keep it hot =)
- extruder_manage_temperature();
+ //keep it hot =)
+ extruder_manage_temperature();
- //wait for next step.
- if (milli_delay > 0)
- delay(milli_delay);
- else
- delayMicrosecondsInterruptible(micro_delay);
- }
- while (can_step_flags[X_AXIS] || can_step_flags[Y_AXIS] || can_step_flags[Z_AXIS]);
+ //wait for next step.
+ if (milli_delay > 0)
+ delay(milli_delay);
+ else
+ delayMicrosecondsInterruptible(micro_delay);
+ }
+ while (can_step_flags[X_AXIS] || can_step_flags[Y_AXIS] || can_step_flags[Z_AXIS]);
- //set our points to be the same
- current_units.p[X_AXIS] = target_units.p[X_AXIS];
- current_units.p[Y_AXIS] = target_units.p[Y_AXIS];
- current_units.p[Z_AXIS] = target_units.p[Z_AXIS];
- calculate_deltas();
+ //set our points to be the same
+ current_units.p[X_AXIS] = target_units.p[X_AXIS];
+ current_units.p[Y_AXIS] = target_units.p[Y_AXIS];
+ current_units.p[Z_AXIS] = target_units.p[Z_AXIS];
+ calculate_deltas();
}
bool can_step(bool minenabled, bool maxenabled, byte min_pin, byte max_pin,
long current, long target, bool direction)
{
- //stop us if we're on target
- if (target == current) return false;
- //stop us if we're at home and still going
- else if (minenabled && read_switch(min_pin) && !direction) return false;
- //stop us if we're at max and still going
- else if (maxenabled && read_switch(max_pin) && direction) return false;
+ //stop us if we're on target
+ if (target == current) return false;
+ //stop us if we're at home and still going
+ else if (minenabled && read_switch(min_pin) && !direction) return false;
+ //stop us if we're at max and still going
+ else if (maxenabled && read_switch(max_pin) && direction) return false;
- //default to being able to step
- return true;
+ //default to being able to step
+ return true;
}
void do_step(byte step_pin)
{
- digitalWrite(step_pin, HIGH);
- delayMicroseconds(5);
- digitalWrite(step_pin, LOW);
+ digitalWrite(step_pin, HIGH);
+ delayMicroseconds(5);
+ digitalWrite(step_pin, LOW);
}
bool read_switch(byte pin)
{
- //dual read as crude debounce
+ //dual read as crude debounce
#if ENDSTOPS_INVERTING == 1
- return !digitalRead(pin) && !digitalRead(pin);
+ return !digitalRead(pin) && !digitalRead(pin);
#else
- return digitalRead(pin) && digitalRead(pin);
+ return digitalRead(pin) && digitalRead(pin);
#endif
}
long to_steps(float steps_per_unit, float units)
{
- return steps_per_unit * units;
+ return steps_per_unit * units;
}
void set_target(float x, float y, float z)
{
- target_units.p[X_AXIS] = x;
- target_units.p[Y_AXIS] = y;
- target_units.p[Z_AXIS] = z;
+ target_units.p[X_AXIS] = x;
+ target_units.p[Y_AXIS] = y;
+ target_units.p[Z_AXIS] = z;
- calculate_deltas();
+ calculate_deltas();
}
void set_position(float x, float y, float z)
{
- current_units.p[X_AXIS] = x;
- current_units.p[Y_AXIS] = y;
- current_units.p[Z_AXIS] = z;
+ current_units.p[X_AXIS] = x;
+ current_units.p[Y_AXIS] = y;
+ current_units.p[Z_AXIS] = z;
- calculate_deltas();
+ calculate_deltas();
}
void calculate_deltas()
{
- for (uint8_t i=0;i<3;i++) {
- const AxisConfig &a = axes[i];
+ for (uint8_t i=0;i<3;i++)
+ {
+ const AxisConfig &a = axes[i];
- //figure our deltas.
- delta_units.p[i] = abs(target_units.p[i] - current_units.p[i]);
+ //figure our deltas.
+ delta_units.p[i] = abs(target_units.p[i] - current_units.p[i]);
- //set our steps current, target, and delta
- current_steps.p[i] = to_steps(units[i], current_units.p[i]);
+ //set our steps current, target, and delta
+ current_steps.p[i] = to_steps(units[i], current_units.p[i]);
- target_steps.p[i] = to_steps(units[i], target_units.p[i]);
+ target_steps.p[i] = to_steps(units[i], target_units.p[i]);
- delta_steps.p[i] = abs(target_steps.p[i] - current_steps.p[i]);
+ delta_steps.p[i] = abs(target_steps.p[i] - current_steps.p[i]);
- //what is our direction
- direction[i] = (target_units.p[i] >= current_units.p[i]);
+ //what is our direction
+ direction[i] = (target_units.p[i] >= current_units.p[i]);
- //set our direction pins as well
- digitalWrite(a.dir_pin, a.invert_dir ^ direction[i]);
- }
+ //set our direction pins as well
+ digitalWrite(a.dir_pin, a.invert_dir ^ direction[i]);
+ }
}
long calculate_feedrate_delay(float feedrate)
{
- //how long is our line length?
- float distance = sqrt(delta_units.p[X_AXIS]*delta_units.p[X_AXIS] +
- delta_units.p[Y_AXIS]*delta_units.p[Y_AXIS] +
- delta_units.p[Z_AXIS]*delta_units.p[Z_AXIS]);
- long master_steps = 0;
+ //how long is our line length?
+ float distance = sqrt(delta_units.p[X_AXIS]*delta_units.p[X_AXIS] +
+ delta_units.p[Y_AXIS]*delta_units.p[Y_AXIS] +
+ delta_units.p[Z_AXIS]*delta_units.p[Z_AXIS]);
+ long master_steps = 0;
- //find the dominant axis.
- if (delta_steps.p[X_AXIS] > delta_steps.p[Y_AXIS]) {
- if (delta_steps.p[Z_AXIS] > delta_steps.p[X_AXIS])
- master_steps = delta_steps.p[Z_AXIS];
- else
- master_steps = delta_steps.p[X_AXIS];
- }
- else {
- if (delta_steps.p[Z_AXIS] > delta_steps.p[Y_AXIS])
- master_steps = delta_steps.p[Z_AXIS];
- else
- master_steps = delta_steps.p[Y_AXIS];
- }
+ //find the dominant axis.
+ if (delta_steps.p[X_AXIS] > delta_steps.p[Y_AXIS])
+ {
+ if (delta_steps.p[Z_AXIS] > delta_steps.p[X_AXIS])
+ master_steps = delta_steps.p[Z_AXIS];
+ else
+ master_steps = delta_steps.p[X_AXIS];
+ }
+ else
+ {
+ if (delta_steps.p[Z_AXIS] > delta_steps.p[Y_AXIS])
+ master_steps = delta_steps.p[Z_AXIS];
+ else
+ master_steps = delta_steps.p[Y_AXIS];
+ }
- //calculate delay between steps in microseconds. this is sort of tricky, but not too bad.
- //the formula has been condensed to save space. here it is in english:
- // (feedrate is in mm/minute)
- // distance / feedrate * 60000000.0 = move duration in microseconds
- // move duration / master_steps = time between steps for master axis.
+ //calculate delay between steps in microseconds. this is sort of tricky, but not too bad.
+ //the formula has been condensed to save space. here it is in english:
+ // (feedrate is in mm/minute)
+ // distance / feedrate * 60000000.0 = move duration in microseconds
+ // move duration / master_steps = time between steps for master axis.
- return ((distance * 60000000.0) / feedrate) / master_steps;
+ return ((distance * 60000000.0) / feedrate) / master_steps;
}
long getMaxSpeed()
{
- if (delta_steps.p[Z_AXIS] > 0)
- return calculate_feedrate_delay(FAST_Z_FEEDRATE);
- else
- return calculate_feedrate_delay(FAST_XY_FEEDRATE);
+ if (delta_steps.p[Z_AXIS] > 0)
+ return calculate_feedrate_delay(FAST_Z_FEEDRATE);
+ else
+ return calculate_feedrate_delay(FAST_XY_FEEDRATE);
}
void enable_steppers()
{
- // Enable steppers only for axes which are moving
- // taking account of the fact that some or all axes
- // may share an enable line (check using macros at
- // compile time to avoid needless code)
- if (target_units.p[X_AXIS] == current_units.p[X_AXIS]
+ // Enable steppers only for axes which are moving
+ // taking account of the fact that some or all axes
+ // may share an enable line (check using macros at
+ // compile time to avoid needless code)
+ if (target_units.p[X_AXIS] == current_units.p[X_AXIS]
#if X_ENABLE_PIN == Y_ENABLE_PIN
- && target_units.p[Y_AXIS] == current_units.p[Y_AXIS]
+ && target_units.p[Y_AXIS] == current_units.p[Y_AXIS]
#endif
#if X_ENABLE_PIN == Z_ENABLE_PIN
- && target_units.p[Z_AXIS] == current_units.p[Z_AXIS]
+ && target_units.p[Z_AXIS] == current_units.p[Z_AXIS]
#endif
- )
- digitalWrite(X_ENABLE_PIN, !ENABLE_ON);
- else
- digitalWrite(X_ENABLE_PIN, ENABLE_ON);
- if (target_units.p[Y_AXIS] == current_units.p[Y_AXIS]
+ )
+ digitalWrite(X_ENABLE_PIN, !ENABLE_ON);
+ else
+ digitalWrite(X_ENABLE_PIN, ENABLE_ON);
+ if (target_units.p[Y_AXIS] == current_units.p[Y_AXIS]
#if Y_ENABLE_PIN == X_ENABLE_PIN
- && target_units.p[X_AXIS] == current_units.p[X_AXIS]
+ && target_units.p[X_AXIS] == current_units.p[X_AXIS]
#endif
#if Y_ENABLE_PIN == Z_ENABLE_PIN
- && target_units.p[Z_AXIS] == current_units.p[Z_AXIS]
+ && target_units.p[Z_AXIS] == current_units.p[Z_AXIS]
#endif
- )
- digitalWrite(Y_ENABLE_PIN, !ENABLE_ON);
- else
- digitalWrite(Y_ENABLE_PIN, ENABLE_ON);
- if (target_units.p[Z_AXIS] == current_units.p[Z_AXIS]
+ )
+ digitalWrite(Y_ENABLE_PIN, !ENABLE_ON);
+ else
+ digitalWrite(Y_ENABLE_PIN, ENABLE_ON);
+ if (target_units.p[Z_AXIS] == current_units.p[Z_AXIS]
#if Z_ENABLE_PIN == X_ENABLE_PIN
- && target_units.p[X_AXIS] == current_units.p[X_AXIS]
+ && target_units.p[X_AXIS] == current_units.p[X_AXIS]
#endif
#if Z_ENABLE_PIN == Y_ENABLE_PIN
- && target_units.p[Y_AXIS] == current_units.p[Y_AXIS]
+ && target_units.p[Y_AXIS] == current_units.p[Y_AXIS]
#endif
- )
- digitalWrite(Z_ENABLE_PIN, !ENABLE_ON);
- else
- digitalWrite(Z_ENABLE_PIN, ENABLE_ON);
+ )
+ digitalWrite(Z_ENABLE_PIN, !ENABLE_ON);
+ else
+ digitalWrite(Z_ENABLE_PIN, ENABLE_ON);
}
void disable_steppers()
{
- //disable our steppers
- digitalWrite(X_ENABLE_PIN, !ENABLE_ON);
+ //disable our steppers
+ digitalWrite(X_ENABLE_PIN, !ENABLE_ON);
#if Y_ENABLE_PIN != X_ENABLE_PIN
- digitalWrite(Y_ENABLE_PIN, !ENABLE_ON);
+ digitalWrite(Y_ENABLE_PIN, !ENABLE_ON);
#endif
#if (Z_ENABLE_PIN != X_ENABLE_PIN && Z_ENABLE_PIN != Y_ENABLE_PIN)
- digitalWrite(Z_ENABLE_PIN, !ENABLE_ON);
+ digitalWrite(Z_ENABLE_PIN, !ENABLE_ON);
#endif
}
void home_axis(Axis axis)
{
- const AxisConfig &a = axes[axis];
+ const AxisConfig &a = axes[axis];
- // Seek to home
- FloatPoint fp = {current_units.p[X_AXIS], current_units.p[Y_AXIS], current_units.p[Z_AXIS]};
- // Go to a position guaranteed to be outside the axis
- fp.p[axis] = 1000.0*(a.reference_dir?1.0:-1.0);
- set_target(fp.p[X_AXIS], fp.p[Y_AXIS], fp.p[Z_AXIS]);
- feedrate_micros = calculate_feedrate_delay(feedrate);
- dda_move(feedrate_micros);
+ // Seek to home
+ FloatPoint fp = {current_units.p[X_AXIS], current_units.p[Y_AXIS], current_units.p[Z_AXIS]};
+ // Go to a position guaranteed to be outside the axis
+ fp.p[axis] = 1000.0*(a.reference_dir?1.0:-1.0);
+ set_target(fp.p[X_AXIS], fp.p[Y_AXIS], fp.p[Z_AXIS]);
+ feedrate_micros = calculate_feedrate_delay(feedrate);
+ dda_move(feedrate_micros);
- // Move slowly until reference switch is off again, to move to the exact reference
- enable_steppers();
- digitalWrite(a.dir_pin, !(a.reference_dir ^ a.invert_dir));
- while (read_switch(a.reference_dir?a.max_pin:a.min_pin)) {
- do_step(a.step_pin);
- delay(10); // Really slow. FIXME: This machine dependant
- }
+ // Move slowly until reference switch is off again, to move to the exact reference
+ enable_steppers();
+ digitalWrite(a.dir_pin, !(a.reference_dir ^ a.invert_dir));
+ while (read_switch(a.reference_dir?a.max_pin:a.min_pin))
+ {
+ do_step(a.step_pin);
+ delay(10); // Really slow. FIXME: This machine dependant
+ }
}
diff --git a/trunk/users/metalab/GCode_Interpreter/utils.cpp b/trunk/users/metalab/GCode_Interpreter/utils.cpp
index 8008deb0..fab2a552 100644
--- a/trunk/users/metalab/GCode_Interpreter/utils.cpp
+++ b/trunk/users/metalab/GCode_Interpreter/utils.cpp
@@ -1,43 +1,45 @@
+/* -*- mode: c++; c-basic-offset: 8; indent-tabs-mode: t -*- */
+
#include "utils.h"
void delayMicrosecondsInterruptible(unsigned int us)
{
#if F_CPU >= 16000000L
- // for the 16 MHz clock on most Arduino boards
+ // for the 16 MHz clock on most Arduino boards
- // for a one-microsecond delay, simply return. the overhead
- // of the function call yields a delay of approximately 1 1/8 us.
- if (--us == 0) return;
+ // for a one-microsecond delay, simply return. the overhead
+ // of the function call yields a delay of approximately 1 1/8 us.
+ if (--us == 0) return;
- // the following loop takes a quarter of a microsecond (4 cycles)
- // per iteration, so execute it four times for each microsecond of
- // delay requested.
- us <<= 2;
+ // the following loop takes a quarter of a microsecond (4 cycles)
+ // per iteration, so execute it four times for each microsecond of
+ // delay requested.
+ us <<= 2;
- // account for the time taken in the preceeding commands.
- us -= 2;
+ // account for the time taken in the preceeding commands.
+ us -= 2;
#else
- // for the 8 MHz internal clock on the ATmega168
+ // for the 8 MHz internal clock on the ATmega168
- // for a one- or two-microsecond delay, simply return. the overhead of
- // the function calls takes more than two microseconds. can't just
- // subtract two, since us is unsigned; we'd overflow.
- if (--us == 0) return;
- if (--us == 0) return;
+ // for a one- or two-microsecond delay, simply return. the overhead of
+ // the function calls takes more than two microseconds. can't just
+ // subtract two, since us is unsigned; we'd overflow.
+ if (--us == 0) return;
+ if (--us == 0) return;
- // the following loop takes half of a microsecond (4 cycles)
- // per iteration, so execute it twice for each microsecond of
- // delay requested.
- us <<= 1;
+ // the following loop takes half of a microsecond (4 cycles)
+ // per iteration, so execute it twice for each microsecond of
+ // delay requested.
+ us <<= 1;
- // partially compensate for the time taken by the preceeding commands.
- // we can't subtract any more than this or we'd overflow w/ small delays.
- us--;
+ // partially compensate for the time taken by the preceeding commands.
+ // we can't subtract any more than this or we'd overflow w/ small delays.
+ us--;
#endif
- // busy wait
- __asm__ __volatile__ (
- "1: sbiw %0,1" "\n\t" // 2 cycles
- "brne 1b" : "=w" (us) : "0" (us) // 2 cycles
- );
+ // busy wait
+ __asm__ __volatile__ (
+ "1: sbiw %0,1" "\n\t" // 2 cycles
+ "brne 1b" : "=w" (us) : "0" (us) // 2 cycles
+ );
}