Now that the machine itself can navigate autonomously, it's time to get the weeding mechanism doing the same.
In the last log, I got the machine to recognise a barcode, which can be used to stop the machine and allow a weeding routine to be carried out.
First task is to get the X,Y and Z axis's to 'index' or 'register' on limit switches so that it knows exactly where it is before it starts trying to do a task.
The code to achieve this fairly simple and no special libraries are used. The only deviation from my normal procedure was using a 30 ms delay at one point, which will probably be replaced with a 'millis' or 'micros' command which will then allow all the axes to be registered simultaneously.
void CNC_SETUP()
{
unsigned long currentMicros = micros();
//////////////////////////////////////////////////////////////////////////////////////////
speedCNCX = 1600; // 1 = one Hz.
XZeroingStepsTotal = 5000;
dirStateCNCX = LOW; // LOW is Forwards.
// controlState==HIGH is autonomous mode.
// Initial movement forward for zeroing:
if((controlState==HIGH)&&(XZeroingState==LOW)) // Forwards and backwards switch open.
{
XZeroingStep=0;
intervalCNCX = 1000000/speedCNCX; // interval is smaller for faster speed.
if ((currentMicros - previousMicrosCNCX) >= intervalCNCX)
{
LSFX = Fast_digitalRead(49); // Limit switch X forwards
if (stepStateCNCX == LOW)
{
stepStateCNCX = HIGH;
}
else
{
stepStateCNCX = LOW;
}
//DEBUG_PORT.print("XZeroingState = ");DEBUG_PORT.println(XZeroingState);
digitalWrite(53,dirStateCNCX);
digitalWrite(35,stepStateCNCX);
digitalWrite(39,stepStateCNCX); // Orange LED
previousMicrosCNCX = currentMicros;
}
}
else
{
digitalWrite(35,LOW);
} // Initial movement forward for zeroing ends
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if((LSFX==HIGH)&&(controlState==HIGH)) // Either x switches closed autonomous(HGH)
{
delay(30); // Need this delay for reliable operation of switch for some reason.
XZeroingState=HIGH;
}
if(controlState==LOW)
{
XZeroingState=LOW;
}
if((XZeroingState==HIGH)&&(XZeroingStepsTotal > XZeroingStep))
{
dirStateCNCX = HIGH; // LOW is Forwards.
if((LSBX==HIGH)&&(controlState==HIGH)) // backwards switch open.
{
intervalCNCX = 1000000/speedCNCX; // interval is smaller for faster speed.
if ((currentMicros - previousMicrosCNCX) >= intervalCNCX)
{
XZeroingStep++;
LSFX = Fast_digitalRead(49); // Limit switch X forwards
if (stepStateCNCX == LOW)
{
stepStateCNCX = HIGH;
}
else
{
stepStateCNCX = LOW;
}
//DEBUG_PORT.print("XZeroingState = ");DEBUG_PORT.println(XZeroingState);
//DEBUG_PORT.print("XZeroingStep = ");DEBUG_PORT.println(XZeroingStep);
digitalWrite(53,dirStateCNCX);
digitalWrite(35,stepStateCNCX);
digitalWrite(39,stepStateCNCX); // Orange LED
previousMicrosCNCX = currentMicros;
}
}
else
{
digitalWrite(35,LOW);
}
} // if(XZeroing == HIGH)
////////////////////////////////////////////////////////////////////////////////////////
} // CNC
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.