diff --git a/lib/maincontroller/homing.cpp b/lib/maincontroller/homing.cpp index e45a40f..d307feb 100644 --- a/lib/maincontroller/homing.cpp +++ b/lib/maincontroller/homing.cpp @@ -32,12 +32,15 @@ void homingController::start() { } bool homingController::nextAxis() { - homingSequenceIndex++; - return selectAxis(); + if (homingSequenceIndex < theMachineProperties.nmbrHomingAxis) { + homingSequenceIndex++; + return selectAxis(); + } + return false; } bool homingController::selectAxis() { - while (homingSequenceIndex < nmbrAxis) { + while (homingSequenceIndex < theMachineProperties.nmbrHomingAxis) { currentHomingAxis = theMachineProperties.homingSequence[homingSequenceIndex]; currentHomingAxisIndex = static_cast(currentHomingAxis); if (static_cast(currentHomingAxis) < nmbrAxis) { diff --git a/lib/maincontroller/homing.md b/lib/maincontroller/homing.md index ff982b7..e6b7050 100644 --- a/lib/maincontroller/homing.md +++ b/lib/maincontroller/homing.md @@ -1,17 +1,10 @@ Next Steps : -* nextAxis should skip axis which can't home - - - - - +* add timeouts in case motors are not running Todo : think about how to handle errors * not reaching the closing or opening of a switch (in time / in space) * receiving events on other switches than the one monitoring - -Todo : homing uses gcode to generate motions, however, it should not change the modal state of the machine. So we must save the modal state and afterwards restore it.. -ToDo : we need to capture the position on the opening of the switch as the ZERO +TODO : we need to capture the position on the opening of the switch as the ZERO diff --git a/lib_target/cnc3axis/general/machineproperties.h b/lib_target/cnc3axis/general/machineproperties.h index 3c0c66e..692b2e9 100644 --- a/lib_target/cnc3axis/general/machineproperties.h +++ b/lib_target/cnc3axis/general/machineproperties.h @@ -47,9 +47,9 @@ class machineProperties { } motors; struct Limits { - bool hasLimitsMax[nmbrAxis]{true, false, true}; // limit switches towards the positive direction of the Axis + bool hasLimitsMax[nmbrAxis]{true, true, true}; // limit switches towards the positive direction of the Axis uint32_t limitMaxIndex[nmbrAxis]{1, 2, 0}; // index into myInputs[] telling which input is the matching limit switch - bool hasLimitsMin[nmbrAxis]{false, true, false}; // limit switches towards the negative direction of the Axis + bool hasLimitsMin[nmbrAxis]{false, false, false}; // limit switches towards the negative direction of the Axis uint32_t limitMinIndex[nmbrAxis]{0, 2, 4}; // index into myInputs[] telling which input is the matching limit switch float maxLimitswitchTravel{2.0F}; // [mm] } limits; @@ -71,8 +71,9 @@ class machineProperties { float vHoming{10}; // faster homing speed, towards switch closing float vHomingSlow{1}; // slower homing, towards opening limitswitch - axis homingSequence[nmbrAxis]{axis::Z, axis::X, axis::Y}; // in which sequence do we want to home axis. - bool homingDirection[nmbrAxis]{true, false, true}; // in which direction do we want to home : true = positive, false = negative + static constexpr uint32_t nmbrHomingAxis{3U}; // how many axis do have homing + axis homingSequence[nmbrHomingAxis]{axis::Z, axis::X, axis::Y}; // in which sequence do we want to home axis. + bool homingDirection[nmbrAxis]{true, true, true}; // in which direction do we want to home : true = positive, false = negative double homingOffset[nmbrAxis]{3.0, 3.0, 3.0}; // after homing, what distance from the limitswitches do we set the machine zero. Needs to be positive // static constexpr float t = limits.maxLimitswitchTravel * 6.0 / motors.jMax; diff --git a/src/cnc3axis/main.cpp b/src/cnc3axis/main.cpp index 19a909c..3fb57f6 100644 --- a/src/cnc3axis/main.cpp +++ b/src/cnc3axis/main.cpp @@ -70,8 +70,8 @@ inputs allSwitchAndButtons; debouncedInput myInputs[nmbrInputs] = { debouncedInput(event::limitSwitchZMaxClosed, event::limitSwitchZMaxOpened), debouncedInput(event::limitSwitchXMaxClosed, event::limitSwitchXMaxOpened), - debouncedInput(event::limitSwitchYMinClosed, event::limitSwitchYMinOpened), debouncedInput(event::limitSwitchYMaxClosed, event::limitSwitchYMaxOpened), + debouncedInput(event::limitSwitchYMinClosed, event::limitSwitchYMinOpened), debouncedInput(event::limitSwitchZMinClosed, event::limitSwitchZMinOpened), debouncedInput(event::limitSwitchXMinClosed, event::limitSwitchXMinOpened), debouncedInput(event::emergencyStopButtonPressed, event::emergencyStopButtonReleased),