Merge branch 'master' of https://github.com/FarmBot/farmbot-arduino-firmware
commit
720d66ea78
16
README.md
16
README.md
|
@ -139,12 +139,12 @@ _F_ | | |_Farm commands, commands specially added for FarmBot
|
|||
F |01 |T |Dose amount of water using time in millisecond (not implemented)
|
||||
F |02 |N |Dose amount of water using flow meter that measures pulses (not implemented)
|
||||
F |09 | |Reset emergency stop
|
||||
F |11 | |Home X axis
|
||||
F |12 | |Home Y axis
|
||||
F |13 | |Home Z axis
|
||||
F |14 | |Calibrate X axis
|
||||
F |15 | |Calibrate Y axis
|
||||
F |16 | |Calibrate Z axis
|
||||
F |11 | |Home X axis (find 0) __*__
|
||||
F |12 | |Home Y axis (find 0) __*__
|
||||
F |13 | |Home Z axis (find 0) __*__
|
||||
F |14 | |Calibrate X axis (measure length + find 0) __*__
|
||||
F |15 | |Calibrate Y axis (measure length + find 0) __*__
|
||||
F |16 | |Calibrate Z axis (measure length + find 0) __*__
|
||||
F |20 | |List all parameters and value
|
||||
F |21 |P |Read parameter
|
||||
F |22 |P V |Write parameter
|
||||
|
@ -161,9 +161,11 @@ F |61 |P V |Set the servo on the pin P (only pin 4 and 5) to the
|
|||
F |81 | |Report end stop
|
||||
F |82 | |Report current position
|
||||
F |83 | |Report software version
|
||||
F |84 |X Y Z |Set axis current position to zero (yes=1/no=0)
|
||||
F |84 |X Y Z |Set axis current position to zero (yes=1/no=0)
|
||||
E | | |Emergency stop
|
||||
|
||||
__*__ Requires the use of encoders or end stops.
|
||||
|
||||
### Codes received from the arduino
|
||||
|
||||
Code type|Number|Parameters |Function
|
||||
|
|
|
@ -29,6 +29,7 @@ Command::Command(char *commandChar)
|
|||
else
|
||||
{
|
||||
invalidCommand = true;
|
||||
commandCodeEnum = CODE_UNDEFINED;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
12
src/Config.h
12
src/Config.h
|
@ -149,10 +149,10 @@
|
|||
const long ENCODER_TYPE_Y_DEFAULT = 0;
|
||||
const long ENCODER_TYPE_Z_DEFAULT = 0;
|
||||
|
||||
// Position = encoder position * scaling / 100
|
||||
const long ENCODER_SCALING_X_DEFAULT = 56;
|
||||
const long ENCODER_SCALING_Y_DEFAULT = 56;
|
||||
const long ENCODER_SCALING_Z_DEFAULT = 56;
|
||||
// Position = encoder position * scaling / 10000
|
||||
const long ENCODER_SCALING_X_DEFAULT = 5556;
|
||||
const long ENCODER_SCALING_Y_DEFAULT = 5556;
|
||||
const long ENCODER_SCALING_Z_DEFAULT = 5556;
|
||||
|
||||
// Number of steps missed before motor is seen as not moving
|
||||
const long ENCODER_MISSED_STEPS_MAX_X_DEFAULT = 5;
|
||||
|
@ -208,9 +208,9 @@
|
|||
#endif /* CONFIG_H_ */
|
||||
|
||||
#if defined(RAMPS_V14) && !defined(SOFTWARE_VERSION)
|
||||
#define SOFTWARE_VERSION "6.0.0.R\0"
|
||||
#define SOFTWARE_VERSION "6.0.1.R\0"
|
||||
#endif
|
||||
|
||||
#if defined(FARMDUINO_V10) && !defined(SOFTWARE_VERSION)
|
||||
#define SOFTWARE_VERSION "6.0.0.F\0"
|
||||
#define SOFTWARE_VERSION "6.0.1.F\0"
|
||||
#endif
|
||||
|
|
|
@ -29,6 +29,9 @@ int GCodeProcessor::execute(Command *command)
|
|||
int execution = 0;
|
||||
bool isMovement = false;
|
||||
|
||||
bool emergencyStop = false;
|
||||
emergencyStop = CurrentState::getInstance()->isEmergencyStop();
|
||||
|
||||
int attempt = 0;
|
||||
int maximumAttempts = ParameterList::getInstance()->getValue(PARAM_MOV_NR_RETRY);
|
||||
|
||||
|
@ -54,7 +57,7 @@ int GCodeProcessor::execute(Command *command)
|
|||
|
||||
//Only allow reset of emergency stop when emergency stop is engaged
|
||||
|
||||
if (CurrentState::getInstance()->isEmergencyStop())
|
||||
if (emergencyStop)
|
||||
{
|
||||
if (!(
|
||||
command->getCodeEnum() == F09 ||
|
||||
|
@ -143,7 +146,8 @@ int GCodeProcessor::execute(Command *command)
|
|||
|
||||
// Execute command with retry
|
||||
CurrentState::getInstance()->setLastError(0);
|
||||
while (attempt < 1 || (attempt < maximumAttempts && execution != 0))
|
||||
while (attempt < 1 || (!emergencyStop && attempt < maximumAttempts && execution != 0 && execution != 2))
|
||||
// error 2 is timeout error: stop movement retries
|
||||
{
|
||||
|
||||
if (LOGGING || debugMessages)
|
||||
|
@ -164,6 +168,7 @@ int GCodeProcessor::execute(Command *command)
|
|||
|
||||
handler->execute(command);
|
||||
execution = CurrentState::getInstance()->getLastError();
|
||||
emergencyStop = CurrentState::getInstance()->isEmergencyStop();
|
||||
|
||||
if (LOGGING || debugMessages)
|
||||
{
|
||||
|
|
|
@ -161,22 +161,30 @@ long ParameterList::readValueEeprom(int id)
|
|||
long three = 0;
|
||||
long four = 0;
|
||||
|
||||
// Process 2-byte or 4-byte EEPROM value
|
||||
// Return -1 for negative values (1 in highest bit) to indicate value should be set to default.
|
||||
if (id == 141 || id == 142 || id == 143)
|
||||
{
|
||||
// 4-byte EEPROM value
|
||||
three = EEPROM.read(address + 20);
|
||||
four = EEPROM.read(address + 21);
|
||||
if ((three == 255 && four == 255) && !(one == 255 && two == 255))
|
||||
{
|
||||
// Value may have been recently increased to 4 bytes. Keep only the first two.
|
||||
three = 0;
|
||||
four = 0;
|
||||
if (two > 127) { return -1; }
|
||||
}
|
||||
if (four > 127) { return -1; }
|
||||
}
|
||||
|
||||
// just in case there are non uninitialized EEPROM bytes
|
||||
// put them both to zero
|
||||
if (three == -1 && four == -1)
|
||||
else
|
||||
{
|
||||
three = 0;
|
||||
four = 0;
|
||||
// 2-byte EEPROM value
|
||||
if (two > 127) { return -1; }
|
||||
}
|
||||
|
||||
//Return the recomposed long by using bitshift.
|
||||
return ((one << 0) & 0xFF) + ((two << 8) & 0xFF00) + ((three << 16) & 0xFF0000) + ((four << 24) & 0xFF000000);
|
||||
// Return the recomposed long by using bitshift.
|
||||
return ((one & 0xFFl) << 0) + ((two & 0xFFl) << 8) + ((three & 0xFFl) << 16) + ((four & 0xFFl) << 24);
|
||||
}
|
||||
|
||||
int ParameterList::writeValueEeprom(int id, long value)
|
||||
|
|
|
@ -538,23 +538,26 @@ int StepperControl::moveToCoords(double xDestScaled, double yDestScaled, double
|
|||
serialBuffer += "\r\n";
|
||||
serialBuffer += "R99 timeout X axis\r\n";
|
||||
//Serial.print("R99 timeout X axis\r\n");
|
||||
error = 1;
|
||||
// error 2 is timeout error: stop movement retries
|
||||
error = 2;
|
||||
}
|
||||
if (axisActive[1] == true && ((millis() >= timeStart && millis() - timeStart > timeOut[0] * 1000) || (millis() < timeStart && millis() > timeOut[0] * 1000)))
|
||||
if (axisActive[1] == true && ((millis() >= timeStart && millis() - timeStart > timeOut[1] * 1000) || (millis() < timeStart && millis() > timeOut[1] * 1000)))
|
||||
{
|
||||
serialBuffer += COMM_REPORT_TIMEOUT_Y;
|
||||
serialBuffer += "\r\n";
|
||||
serialBuffer += "R99 timeout Y axis\r\n";
|
||||
//Serial.print("R99 timeout Y axis\r\n");
|
||||
error = 1;
|
||||
// error 2 is timeout error: stop movement retries
|
||||
error = 2;
|
||||
}
|
||||
if (axisActive[2] == true && ((millis() >= timeStart && millis() - timeStart > timeOut[0] * 1000) || (millis() < timeStart && millis() > timeOut[0] * 1000)))
|
||||
if (axisActive[2] == true && ((millis() >= timeStart && millis() - timeStart > timeOut[2] * 1000) || (millis() < timeStart && millis() > timeOut[2] * 1000)))
|
||||
{
|
||||
serialBuffer += COMM_REPORT_TIMEOUT_Z;
|
||||
serialBuffer += "\r\n";
|
||||
serialBuffer += "R99 timeout Z axis\r\n";
|
||||
//Serial.print("R99 timeout Z axis\r\n");
|
||||
error = 1;
|
||||
// error 2 is timeout error: stop movement retries
|
||||
error = 2;
|
||||
}
|
||||
|
||||
// Check if there is an emergency stop command
|
||||
|
@ -584,7 +587,7 @@ int StepperControl::moveToCoords(double xDestScaled, double yDestScaled, double
|
|||
}
|
||||
}
|
||||
|
||||
if (error == 1)
|
||||
if (error != 0)
|
||||
{
|
||||
serialBuffer += "R99 error\r\n";
|
||||
//Serial.print("R99 error\r\n");
|
||||
|
@ -849,7 +852,9 @@ int StepperControl::calibrateAxis(int axis)
|
|||
break;
|
||||
default:
|
||||
Serial.print("R99 Calibration error: invalid axis selected\r\n");
|
||||
return 1;
|
||||
error = 1;
|
||||
CurrentState::getInstance()->setLastError(error);
|
||||
return error;
|
||||
}
|
||||
|
||||
// Preliminary checks
|
||||
|
@ -857,7 +862,9 @@ int StepperControl::calibrateAxis(int axis)
|
|||
if (calibAxis->endStopMin() || calibAxis->endStopMax())
|
||||
{
|
||||
Serial.print("R99 Calibration error: end stop active before start\r\n");
|
||||
return 1;
|
||||
error = 1;
|
||||
CurrentState::getInstance()->setLastError(error);
|
||||
return error;
|
||||
}
|
||||
|
||||
Serial.print("R99");
|
||||
|
@ -867,7 +874,7 @@ int StepperControl::calibrateAxis(int axis)
|
|||
Serial.print("\r\n");
|
||||
|
||||
*axisStatus = COMM_REPORT_MOVE_STATUS_START_MOTOR;
|
||||
reportStatus(calibAxis, axisSubStep[0]);
|
||||
reportStatus(calibAxis, axisStatus[0]);
|
||||
|
||||
// Move towards home
|
||||
calibAxis->enableMotor();
|
||||
|
@ -883,7 +890,7 @@ int StepperControl::calibrateAxis(int axis)
|
|||
motorConsMissedSteps[2] = 0;
|
||||
|
||||
*axisStatus = COMM_REPORT_MOVE_STATUS_CRAWLING;
|
||||
reportStatus(calibAxis, axisSubStep[0]);
|
||||
reportStatus(calibAxis, axisStatus[0]);
|
||||
|
||||
reportCalib(calibAxis, COMM_REPORT_CALIBRATE_STATUS_TO_HOME);
|
||||
|
||||
|
@ -900,11 +907,14 @@ int StepperControl::calibrateAxis(int axis)
|
|||
{
|
||||
Serial.print("R99 emergency stop\r\n");
|
||||
movementDone = true;
|
||||
CurrentState::getInstance()->setEmergencyStop();
|
||||
Serial.print(COMM_REPORT_EMERGENCY_STOP);
|
||||
CurrentState::getInstance()->printQAndNewLine();
|
||||
error = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Move until the end stop for home position is reached, either by end stop or motot skipping
|
||||
// Move until the end stop for home position is reached, either by end stop or motor skipping
|
||||
if ((!calibAxis->endStopMin() && !calibAxis->endStopMax()) && !movementDone && (*missedSteps < *missedStepsMax))
|
||||
{
|
||||
|
||||
|
@ -922,20 +932,23 @@ int StepperControl::calibrateAxis(int axis)
|
|||
CurrentState::getInstance()->printQAndNewLine();
|
||||
}
|
||||
|
||||
if (stepsCount % (speedHome[axis] / 6) == 0 /*|| *missedSteps > 3*/)
|
||||
if (debugMessages)
|
||||
{
|
||||
Serial.print("R99");
|
||||
Serial.print(" step count ");
|
||||
Serial.print(stepsCount);
|
||||
Serial.print(" missed steps ");
|
||||
Serial.print(*missedSteps);
|
||||
Serial.print(" max steps ");
|
||||
Serial.print(*missedStepsMax);
|
||||
Serial.print(" cur pos mtr ");
|
||||
Serial.print(calibAxis->currentPosition());
|
||||
Serial.print(" cur pos enc ");
|
||||
Serial.print(calibEncoder->currentPosition());
|
||||
Serial.print("\r\n");
|
||||
if (stepsCount % (speedHome[axis] / 6) == 0 /*|| *missedSteps > 3*/)
|
||||
{
|
||||
Serial.print("R99");
|
||||
Serial.print(" step count ");
|
||||
Serial.print(stepsCount);
|
||||
Serial.print(" missed steps ");
|
||||
Serial.print(*missedSteps);
|
||||
Serial.print(" max steps ");
|
||||
Serial.print(*missedStepsMax);
|
||||
Serial.print(" cur pos mtr ");
|
||||
Serial.print(calibAxis->currentPosition());
|
||||
Serial.print(" cur pos enc ");
|
||||
Serial.print(calibEncoder->currentPosition());
|
||||
Serial.print("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
calibAxis->resetMotorStep();
|
||||
|
@ -1025,6 +1038,9 @@ int StepperControl::calibrateAxis(int axis)
|
|||
{
|
||||
Serial.print("R99 emergency stop\r\n");
|
||||
movementDone = true;
|
||||
CurrentState::getInstance()->setEmergencyStop();
|
||||
Serial.print(COMM_REPORT_EMERGENCY_STOP);
|
||||
CurrentState::getInstance()->printQAndNewLine();
|
||||
error = 1;
|
||||
}
|
||||
}
|
||||
|
@ -1052,6 +1068,11 @@ int StepperControl::calibrateAxis(int axis)
|
|||
Serial.print(COMM_REPORT_CMD_BUSY);
|
||||
//Serial.print("\r\n");
|
||||
CurrentState::getInstance()->printQAndNewLine();
|
||||
|
||||
Serial.print("R99");
|
||||
Serial.print(" step count: ");
|
||||
Serial.print(stepsCount);
|
||||
Serial.print("\r\n");
|
||||
}
|
||||
|
||||
calibAxis->resetMotorStep();
|
||||
|
@ -1094,7 +1115,7 @@ int StepperControl::calibrateAxis(int axis)
|
|||
}
|
||||
|
||||
*axisStatus = COMM_REPORT_MOVE_STATUS_STOP_MOTOR;
|
||||
reportStatus(calibAxis, axisSubStep[0]);
|
||||
reportStatus(calibAxis, axisStatus[0]);
|
||||
|
||||
calibAxis->disableMotor();
|
||||
|
||||
|
@ -1117,10 +1138,11 @@ int StepperControl::calibrateAxis(int axis)
|
|||
reportPosition();
|
||||
|
||||
*axisStatus = COMM_REPORT_MOVE_STATUS_IDLE;
|
||||
reportStatus(calibAxis, axisSubStep[0]);
|
||||
reportStatus(calibAxis, axisStatus[0]);
|
||||
|
||||
reportCalib(calibAxis, COMM_REPORT_CALIBRATE_STATUS_IDLE);
|
||||
|
||||
CurrentState::getInstance()->setLastError(error);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -1238,8 +1260,8 @@ void StepperControl::loadMotorSettings()
|
|||
endStEnbl[2] = intToBool(ParameterList::getInstance()->getValue(MOVEMENT_ENABLE_ENDPOINTS_Z));
|
||||
|
||||
timeOut[0] = ParameterList::getInstance()->getValue(MOVEMENT_TIMEOUT_X);
|
||||
timeOut[1] = ParameterList::getInstance()->getValue(MOVEMENT_TIMEOUT_X);
|
||||
timeOut[2] = ParameterList::getInstance()->getValue(MOVEMENT_TIMEOUT_X);
|
||||
timeOut[1] = ParameterList::getInstance()->getValue(MOVEMENT_TIMEOUT_Y);
|
||||
timeOut[2] = ParameterList::getInstance()->getValue(MOVEMENT_TIMEOUT_Z);
|
||||
|
||||
motorKeepActive[0] = ParameterList::getInstance()->getValue(MOVEMENT_KEEP_ACTIVE_X);
|
||||
motorKeepActive[1] = ParameterList::getInstance()->getValue(MOVEMENT_KEEP_ACTIVE_Y);
|
||||
|
|
|
@ -9,7 +9,7 @@ StepperControlEncoder::StepperControlEncoder()
|
|||
|
||||
position = 0;
|
||||
encoderType = 0; // default type
|
||||
scalingFactor = 100;
|
||||
scalingFactor = 10000;
|
||||
|
||||
curValChannelA = false;
|
||||
curValChannelA = false;
|
||||
|
@ -75,13 +75,13 @@ void StepperControlEncoder::setPosition(long newPosition)
|
|||
long StepperControlEncoder::currentPosition()
|
||||
{
|
||||
// Apply scaling to the output of the encoder, except when scaling is zero or lower
|
||||
if (scalingFactor == 100 || scalingFactor <= 0)
|
||||
if (scalingFactor == 10000 || scalingFactor <= 0)
|
||||
{
|
||||
return position * encoderInvert;
|
||||
}
|
||||
else
|
||||
{
|
||||
return position * scalingFactor / 100 * encoderInvert;
|
||||
return position * scalingFactor / 10000 * encoderInvert;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue