adding axis sub status functions
parent
3d59c0b8ff
commit
0250dccb66
Binary file not shown.
22
src/Config.h
22
src/Config.h
|
@ -22,6 +22,28 @@ const int LOGGING = 0;
|
|||
//const bool AXIS_HOME_UP_Y = false;
|
||||
//const bool AXIS_HOME_UP_Z = true;
|
||||
|
||||
const String COMM_REPORT_CMD_START = "R01";
|
||||
const String COMM_REPORT_CMD_DONE = "R02";
|
||||
const String COMM_REPORT_CMD_ERROR = "R03";
|
||||
const String COMM_REPORT_CMD_BUSY = "R04";
|
||||
const String COMM_REPORT_CMD_STATUS = "R05";
|
||||
const String COMM_REPORT_COMMENT = "R99";
|
||||
|
||||
const int COMM_REPORT_MOVE_STATUS_IDLE = 0;
|
||||
const int COMM_REPORT_MOVE_STATUS_START_MOTOR = 1;
|
||||
const int COMM_REPORT_MOVE_STATUS_ACCELERATING = 2;
|
||||
const int COMM_REPORT_MOVE_STATUS_CRUISING = 3;
|
||||
const int COMM_REPORT_MOVE_STATUS_DECELERATING = 4;
|
||||
const int COMM_REPORT_MOVE_STATUS_STOP_MOTOR = 5;
|
||||
const int COMM_REPORT_MOVE_STATUS_CRAWLING = 6;
|
||||
const int COMM_REPORT_MOVE_STATUS_ERROR = -1;
|
||||
|
||||
const int COMM_REPORT_CALIBRATE_STATUS_IDLE = 0;
|
||||
const int COMM_REPORT_CALIBRATE_STATUS_TO_HOME = 1;
|
||||
const int COMM_REPORT_CALIBRATE_STATUS_TO_END = 2;
|
||||
const int COMM_REPORT_CALIBRATE_STATUS_ERROR = -1;
|
||||
|
||||
|
||||
const int MOVEMENT_INTERRUPT_SPEED = 100; // Interrupt cycle in micro seconds
|
||||
|
||||
const unsigned int MOVEMENT_SPEED_BASE_TIME = 2000;
|
||||
|
|
|
@ -34,12 +34,12 @@ int GCodeProcessor::execute(Command* command) {
|
|||
Serial.println("This is false: handler == NULL");
|
||||
return -1;
|
||||
}
|
||||
Serial.println("R01");
|
||||
Serial.println(COMM_REPORT_CMD_START);
|
||||
int execution = handler->execute(command);
|
||||
if(execution == 0) {
|
||||
Serial.println("R02");
|
||||
Serial.println(COMM_REPORT_CMD_DONE);
|
||||
} else {
|
||||
Serial.println("R03");
|
||||
Serial.println(COMM_REPORT_CMD_ERROR);
|
||||
}
|
||||
return execution;
|
||||
};
|
||||
|
|
|
@ -296,7 +296,8 @@ int StepperControl::moveToCoords( long xDest, long yDest, long zDest,
|
|||
if (currentMillis % 750 == 0)
|
||||
//if (1 == 1)
|
||||
{
|
||||
Serial.print("R04\n");
|
||||
Serial.print(COMM_REPORT_CMD_BUSY);
|
||||
Serial.print("\n");
|
||||
reportPosition();
|
||||
/*
|
||||
Serial.print("R99");
|
||||
|
@ -488,7 +489,8 @@ int StepperControl::calibrateAxis(int axis) {
|
|||
if (stepsCount % (speedMin[axis] * 3) == 0)
|
||||
{
|
||||
// Periodically send message still active
|
||||
Serial.print("R04\n");
|
||||
Serial.print(COMM_REPORT_CMD_BUSY);
|
||||
Serial.print("\n");
|
||||
}
|
||||
|
||||
if (stepsCount % (speedMin[axis] / 6) == 0 /*|| *missedSteps > 3*/)
|
||||
|
@ -604,7 +606,8 @@ int StepperControl::calibrateAxis(int axis) {
|
|||
if (stepsCount % (speedMin[axis] * 3) == 0)
|
||||
{
|
||||
// Periodically send message still active
|
||||
Serial.print("R04\n");
|
||||
Serial.print(COMM_REPORT_CMD_BUSY);
|
||||
Serial.print("\n");
|
||||
}
|
||||
/*
|
||||
if (stepsCount % (speedMin[axis] / 6) == 0)
|
||||
|
@ -685,6 +688,28 @@ int StepperControl::calibrateAxis(int axis) {
|
|||
}
|
||||
|
||||
|
||||
void checkAxisSubStatus(StepperControlAxis* axis, int* axisSubStatus) {
|
||||
int newStatus = 0;
|
||||
|
||||
if (axis->isAccelerating()) {
|
||||
newStatus = COMM_REPORT_MOVE_STATUS_ACCELERATING;
|
||||
}
|
||||
|
||||
if (axis->isCruising()) {
|
||||
newStatus = COMM_REPORT_MOVE_STATUS_CRUISING;
|
||||
}
|
||||
|
||||
if (axis->isDecelerating()) {
|
||||
newStatus = COMM_REPORT_MOVE_STATUS_DECELERATING;
|
||||
}
|
||||
|
||||
if (axis->isCrawling()) {
|
||||
newStatus = COMM_REPORT_MOVE_STATUS_CRAWLING;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Handle movement by checking each axis
|
||||
void StepperControl::handleMovementInterrupt(void){
|
||||
|
||||
|
|
|
@ -51,8 +51,10 @@ private:
|
|||
StepperControlEncoder encoderZ;
|
||||
|
||||
void checkAxisVsEncoder(StepperControlAxis* axis, StepperControlEncoder* encoder, float* missedSteps, long* lastPosition, float* encoderStepDecay, bool* encoderEnabled);
|
||||
void checkAxisSubStatus(StepperControlAxis* axis, int* axisSubStatus);
|
||||
|
||||
bool axisActive[3];
|
||||
int axisSubStep[3];
|
||||
|
||||
void loadMotorSettings();
|
||||
void loadEncoderSettings();
|
||||
|
|
|
@ -18,6 +18,11 @@ StepperControlAxis::StepperControlAxis() {
|
|||
|
||||
movementUp = false;
|
||||
movementToHome = false;
|
||||
movementAccelerating = false;
|
||||
movementDecelerating = false;
|
||||
movementCruising = false;
|
||||
movementCrawling = false;
|
||||
movementMotorActive = false;
|
||||
}
|
||||
|
||||
void StepperControlAxis::test() {
|
||||
|
@ -41,6 +46,12 @@ unsigned int StepperControlAxis::calculateSpeed(long sourcePosition, long curren
|
|||
long staPos;
|
||||
long endPos;
|
||||
|
||||
|
||||
movementAccelerating = false;
|
||||
movementDecelerating = false;
|
||||
movementCruising = false;
|
||||
movementCrawling = false;
|
||||
|
||||
if (abs(sourcePosition) < abs(destinationPosition)) {
|
||||
staPos = abs(sourcePosition);
|
||||
endPos = abs(destinationPosition);;
|
||||
|
@ -54,24 +65,29 @@ unsigned int StepperControlAxis::calculateSpeed(long sourcePosition, long curren
|
|||
// Set the minimum speed if the position would be out of bounds
|
||||
if (curPos < staPos || curPos > endPos) {
|
||||
newSpeed = minSpeed;
|
||||
movementCrawling = true;
|
||||
} else {
|
||||
if (curPos >= staPos && curPos <= halfway) {
|
||||
// accelerating
|
||||
if (curPos > (staPos + stepsAccDec)) {
|
||||
// now beyond the accelleration point to go full speed
|
||||
newSpeed = maxSpeed + 1;
|
||||
movementCruising = true;
|
||||
} else {
|
||||
// speeding up, increase speed linear within the first period
|
||||
newSpeed = (1.0 * (curPos - staPos) / stepsAccDec * (maxSpeed - minSpeed)) + minSpeed;
|
||||
movementAccelerating = true;
|
||||
}
|
||||
} else {
|
||||
// decelerating
|
||||
if (curPos < (endPos - stepsAccDec)) {
|
||||
// still before the deceleration point so keep going at full speed
|
||||
newSpeed = maxSpeed + 2;
|
||||
movementCruising = true;
|
||||
} else {
|
||||
// speeding up, increase speed linear within the first period
|
||||
newSpeed = (1.0 * (endPos - curPos) / stepsAccDec * (maxSpeed - minSpeed)) + minSpeed;
|
||||
movementDecelerating = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -294,10 +310,12 @@ void StepperControlAxis::loadCoordinates(long sourcePoint, long destinationPoint
|
|||
|
||||
void StepperControlAxis::enableMotor() {
|
||||
digitalWrite(pinEnable, LOW);
|
||||
movementMotorActive = true;
|
||||
}
|
||||
|
||||
void StepperControlAxis::disableMotor() {
|
||||
digitalWrite(pinEnable, HIGH);
|
||||
movementMotorActive = false;
|
||||
}
|
||||
|
||||
void StepperControlAxis::setDirectionUp() {
|
||||
|
@ -418,3 +436,20 @@ bool StepperControlAxis::movingToHome() {
|
|||
bool StepperControlAxis::movingUp() {
|
||||
return movementUp;
|
||||
}
|
||||
|
||||
bool StepperControlAxis::isAccelerating() {
|
||||
return movementAccelerating;
|
||||
}
|
||||
|
||||
bool StepperControlAxis::isDecelerating() {
|
||||
return movementDecelerating;
|
||||
}
|
||||
|
||||
bool StepperControlAxis::isCrawling() {
|
||||
return movementCrawling;
|
||||
}
|
||||
|
||||
bool StepperControlAxis::isMotorActive() {
|
||||
return movementMotorActive;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,11 @@ public:
|
|||
|
||||
bool isAxisActive();
|
||||
void deactivateAxis();
|
||||
bool isAccelerating();
|
||||
bool isDecelerating();
|
||||
bool isCruising();
|
||||
bool isCrawling();
|
||||
bool isMotorActive();
|
||||
|
||||
bool endStopMin();
|
||||
bool endStopMax();
|
||||
|
@ -107,6 +112,11 @@ private:
|
|||
bool movementUp;
|
||||
bool movementToHome;
|
||||
bool movementStepDone;
|
||||
bool movementAccelerating;
|
||||
bool movementDecelerating;
|
||||
bool movementCruising;
|
||||
bool movementCrawling;
|
||||
bool movementMotorActive;
|
||||
|
||||
void step(long ¤tPoint, unsigned long steps, long destinationPoint);
|
||||
bool pointReached(long currentPoint, long destinationPoint);
|
||||
|
|
Loading…
Reference in New Issue