Skip to content
Browse files

Fix for edge cases, and add EEPROM setting for Z hold

Edge cases:
* The last step before turning around triggered the endstop switch
* The endstop switch "bounced" and traveling was set early, causing the endstop orientation to get flipped.
  • Loading branch information...
1 parent 29815db commit ad6995b03bd385aa81411472b3caa6af2efc4cce @giseburt giseburt committed Oct 3, 2011
View
1 v2/src/Motherboard/EepromMap.hh
@@ -32,6 +32,7 @@ const static uint16_t VERSION_HIGH = 0x0001;
/// Axis inversion flags: 1 byte.
/// Axis N (where X=0, Y=1, etc.) is inverted if the Nth bit is set.
+/// Bit 7 is used for HoldZ OFF: 1 = off, 0 = on
const static uint16_t AXIS_INVERSION = 0x0002;
/// Endstop inversion flags: 1 byte.
View
9 v2/src/Motherboard/boards/mb24/Motherboard.cc
@@ -26,6 +26,7 @@
#include "Interface.hh"
#include "Tool.hh"
#include "Commands.hh"
+#include "Eeprom.hh"
#include "EepromMap.hh"
@@ -98,8 +99,12 @@ void Motherboard::reset() {
indicateError(0); // turn off blinker
// Init steppers
- // NB: for now, we are turning on Z hold for these boards!
- //steppers::setHoldZ(true);
+
+ uint8_t axis_invert = eeprom::getEeprom8(eeprom::AXIS_INVERSION, 0);
+ bool dont_hold_z = (axis_invert & (1<<7)) != 0;
+ if (dont_hold_z)
+ steppers::setHoldZ(true);
+
for (int i = 0; i < STEPPER_COUNT; i++) {
stepper[i].init(i);
}
View
6 v2/src/Motherboard/boards/rrmbv12/Motherboard.cc
@@ -23,6 +23,7 @@
#include "Configuration.hh"
#include "Steppers.hh"
#include "Command.hh"
+#include "Eeprom.hh"
#include "EepromMap.hh"
/// Instantiate static motherboard instance
@@ -86,6 +87,11 @@ void Motherboard::reset() {
psu.turnOn(true);
// Init steppers
+ uint8_t axis_invert = eeprom::getEeprom8(eeprom::AXIS_INVERSION, 0);
+ bool dont_hold_z = (axis_invert & (1<<7)) != 0;
+ if (dont_hold_z)
+ steppers::setHoldZ(true);
+
for (int i = 0; i < STEPPER_COUNT; i++) {
stepper[i].init(i);
}
View
67 v2/src/shared/StepperAxis.cc
@@ -61,24 +61,35 @@ void StepperAxis::doInterrupt(const int32_t intervals) {
counter -= intervals;
bool hit_endstop = direction ? interface->isAtMaximum() : interface->isAtMinimum();
#if defined(SINGLE_SWITCH_ENDSTOPS) && (SINGLE_SWITCH_ENDSTOPS == 1)
- if (hit_endstop) {
+ // We must move at least ENDSTOP_DEBOUNCE from where we hit the endstop before we declare traveling
+ if (hit_endstop || ((endstop_play < ENDSTOP_DEFAULT_PLAY - ENDSTOP_DEBOUNCE) && endstop_status != ESS_TRAVELING)) {
// Did we *just* hit the endstop?
- if (endstop_status == ESS_TRAVELING || endstop_status == ESS_UNKNOWN) {
- if (endstop_status != ESS_UNKNOWN)
- endstop_status = direction ? ESS_AT_MAXIMUM : ESS_AT_MINIMUM;
- hit_endstop = false; // pretend this never happened... :-)
+ if (endstop_status == ESS_TRAVELING) {
+ endstop_play = ENDSTOP_DEFAULT_PLAY;
+ if (prev_direction)
+ endstop_status = ESS_AT_MAXIMUM;
+ else
+ endstop_status = ESS_AT_MINIMUM;
// OR, are we traveling away from the endstop we just hit and still have play...
- } else if (endstop_play > 0 && (endstop_status != (direction ? ESS_AT_MAXIMUM : ESS_AT_MINIMUM))) {
- --endstop_play;
- hit_endstop = false; // pretend this never happened... :-)
+ } else if ((direction && endstop_status != ESS_AT_MAXIMUM) || (!direction && endstop_status != ESS_AT_MINIMUM)) {
+ if (endstop_play > 0) {
+ --endstop_play;
+ hit_endstop = false; // pretend this never happened...
+ } else {
+ // we ran out of play, so we must be ramming into the side, switch directions
+ // endstop_status = !direction ? ESS_AT_MAXIMUM : ESS_AT_MINIMUM;
+ // endstop_play = ENDSTOP_DEFAULT_PLAY;
+ }
}
// otherwise we hit the endstop
// but if we didn't hit an endstop, clear the status
} else {
endstop_status = ESS_TRAVELING;
+ endstop_play = ENDSTOP_DEFAULT_PLAY;
}
+ prev_direction = direction;
#endif //SINGLE_SWITCH_ENDSTOPS
if (direction) {
if (!hit_endstop) interface->step(true);
@@ -100,29 +111,35 @@ bool StepperAxis::doHoming(const int32_t intervals) {
counter -= intervals;
bool hit_endstop = direction ? interface->isAtMaximum() : interface->isAtMinimum();
#if defined(SINGLE_SWITCH_ENDSTOPS) && (SINGLE_SWITCH_ENDSTOPS == 1)
-// For homing we act a little different .. we assume we are there if we start out hitting the endstop
- if (hit_endstop) {
- // Did we *just* hit the endstop?
- if (endstop_status == ESS_UNKNOWN) {
- // we "hit" the endstop, so we'll record this direction as the one we hit
- endstop_status = direction ? ESS_AT_MAXIMUM : ESS_AT_MINIMUM;
- } else if (endstop_status == ESS_TRAVELING) {
- endstop_play = ENDSTOP_DEFAULT_PLAY;
- if (endstop_status != ESS_UNKNOWN)
- endstop_status = direction ? ESS_AT_MAXIMUM : ESS_AT_MINIMUM;
- hit_endstop = false; // pretend this never happened... :-)
+ // For homing we act a little different .. we assume we are there if we start out hitting the endstop
+ if (hit_endstop|| ((endstop_play < ENDSTOP_DEFAULT_PLAY - ENDSTOP_DEBOUNCE) && endstop_status != ESS_TRAVELING)) {
+ // Did we *just* hit the endstop?
+ if (endstop_status == ESS_TRAVELING || endstop_status == ESS_UNKNOWN) {
+ // we "hit" the endstop, so we'll record this direction as the one we hit
+ endstop_play = ENDSTOP_DEFAULT_PLAY;
+ if (direction)
+ endstop_status = ESS_AT_MAXIMUM;
+ else
+ endstop_status = ESS_AT_MINIMUM;
- // OR, are we traveling away from the endstop we just hit and still have play...
- } else if (endstop_play > 0 && (endstop_status != (direction ? ESS_AT_MAXIMUM : ESS_AT_MINIMUM))) {
- --endstop_play;
- hit_endstop = false; // pretend this never happened... :-)
+ // OR, are we traveling away from the endstop we just hit
+ } else if ((direction && endstop_status != ESS_AT_MAXIMUM) || (!direction && endstop_status != ESS_AT_MINIMUM)) {
+ if (endstop_play > 0) {
+ --endstop_play;
+ hit_endstop = false; // pretend this never happened... :-)
+ } else {
+ // we ran out of play, so we must be ramming into the side, switch directions
+ // endstop_status = direction ? ESS_AT_MINIMUM : ESS_AT_MAXIMUM;
+ // endstop_play = ENDSTOP_DEFAULT_PLAY;
+ }
}
- // otherwise we hit the endstop
+ // otherwise we hit the endstop
// but if we didn't hit an endstop, clear the status
} else {
- endstop_status = ESS_TRAVELING;
+ endstop_status = ESS_TRAVELING;
}
+ prev_direction = direction;
#endif //SINGLE_SWITCH_ENDSTOPS
if (direction) {
View
5 v2/src/shared/StepperAxis.hh
@@ -6,7 +6,9 @@
// If we started with an endstop triggered, then we don't know where we are
// So we can go this many steps either way until we find out...
+// TODO: These should be in EEPROM, most likely, and per-axis
#define ENDSTOP_DEFAULT_PLAY 10000
+#define ENDSTOP_DEBOUNCE 20
/// The stepper axis module implmeents a driver for a single stepper axis. It is designed
/// to be accessed via the Steppers namespace, and uses a StepperInterface to talk to the
@@ -26,9 +28,10 @@ public:
volatile int32_t delta; ///< Amount to increment counter per tick
volatile bool direction; ///< True for positive, false for negative
#if defined(SINGLE_SWITCH_ENDSTOPS) && (SINGLE_SWITCH_ENDSTOPS == 1)
+ volatile bool prev_direction; ///< Record the previous direction for endstop detection
volatile int32_t endstop_play; ///< Amount to move while endstop triggered, to see which way to move
- enum endstop_status_t {///< State of the endstop
+ enum endstop_status_t { ///< State of the endstop
ESS_UNKNOWN,
ESS_TRAVELING,
ESS_AT_MAXIMUM,

0 comments on commit ad6995b

Please sign in to comment.
Something went wrong with that request. Please try again.