Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
Fix probing on Grbl
Browse files Browse the repository at this point in the history
  • Loading branch information
cncgoko committed Nov 3, 2017
1 parent d0c685b commit b061897
Show file tree
Hide file tree
Showing 23 changed files with 419 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public abstract class AbstractGrblControllerService <M extends MachineState,
/** Jog runnable */
private J jogger;
public AtomicInteger pendingCommandsCount;
public Integer plannerBufferCapacity;

/**
* Constructor
Expand Down Expand Up @@ -485,7 +486,7 @@ public void startMotion() throws GkException{
communicator.send( startResumeCommand, false );
if(executionService.getExecutionState() == ExecutionState.PAUSED){
executionService.resumeQueueExecution();
}else{
}else if(executionService.getExecutionState() == ExecutionState.RUNNING){
executionService.beginQueueExecution(ExecutionQueueType.DEFAULT);
}
}
Expand Down Expand Up @@ -550,6 +551,14 @@ public int getAvailablePlannerBuffer() throws GkException {
return grblState.getAvailablePlannerBuffer();
}

/** (inheritDoc)
* @see org.goko.controller.grbl.commons.IGrblControllerService#isPlannerBufferEmpty()
*/
@Override
public boolean isPlannerBufferEmpty() throws GkException {
return getAvailablePlannerBuffer() >= plannerBufferCapacity;
}

/**
* @return
* @return the configuration
Expand Down Expand Up @@ -715,7 +724,29 @@ public void resetCurrentCoordinateSystem() throws GkException {
*/
@Override
public void updateCoordinateSystemPosition(ICoordinateSystem cs, Tuple6b position) throws GkException {
throw new GkTechnicalException("TO DO"); // FIXME
String cmd = "G10";
switch (cs.getCode()) {
case "G54": cmd +="P1";
break;
case "G55": cmd +="P2";
break;
case "G56": cmd +="P3";
break;
case "G57": cmd +="P4";
break;
case "G58": cmd +="P5";
break;
case "G59": cmd +="P6";
break;
default: throw new GkFunctionalException("GRBL-002", cs.getCode());
}
Tuple6b mPos = new Tuple6b(position);
cmd += "L2";
cmd += "X"+getPositionAsString(mPos.getX());
cmd += "Y"+getPositionAsString(mPos.getY());
cmd += "Z"+getPositionAsString(mPos.getZ());
communicator.send(cmd, true);
communicator.send(Grbl.VIEW_PARAMETERS, true );
}

/**
Expand Down Expand Up @@ -770,6 +801,10 @@ public IExecutionService<ExecutionTokenState, IExecutionToken<ExecutionTokenStat
public void setExecutionService(IExecutionService<ExecutionTokenState, IExecutionToken<ExecutionTokenState>> executionService) throws GkException {
this.executionService = executionService;
this.executor.setExecutionService(executionService);
this.executionService.addExecutionListener(ExecutionQueueType.DEFAULT, getExecutor());
this.executionService.addExecutionListener(ExecutionQueueType.SYSTEM, getExecutor());
this.executionService.addExecutionListener(ExecutionQueueType.DEFAULT, this);
this.executionService.addExecutionListener(ExecutionQueueType.SYSTEM, this);
this.executionService.setExecutor(executor);//new GrblDebugExecutor(gcodeService));
}

Expand Down Expand Up @@ -959,6 +994,7 @@ public void onConnected() throws GkException {
@Override
public void onDisconnected() throws GkException {
getStatusPoller().stop();
plannerBufferCapacity = null;
}

/**
Expand Down Expand Up @@ -1059,4 +1095,18 @@ public void turnSpindleOnCcw() throws GkException{
public void turnSpindleOff() throws GkException{
getCommunicator().turnSpindleOff();
}

/**
* @return the plannerBufferCapacity
*/
public Integer getPlannerBufferCapacity() {
return plannerBufferCapacity;
}

/**
* @param plannerBufferCapacity the plannerBufferCapacity to set
*/
public void setPlannerBufferCapacity(Integer plannerBufferCapacity) {
this.plannerBufferCapacity = plannerBufferCapacity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public void confirmNextLineExecution() throws GkException{
}
}

/** (inheritDoc)
* @see org.goko.core.execution.monitor.executor.AbstractStreamingExecutor#isTokenComplete()
*/
@Override
public boolean isTokenComplete() throws GkException {
return super.isTokenComplete() && grblService.isPlannerBufferEmpty();
}
/**
* Notify the parent executor if the conditions are met
* @throws GkException GkException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,11 @@ public void setMachinePosition(Tuple6b position) throws GkException {
}

public Tuple6b getCoordinateSystemOffset(ICoordinateSystem cs) throws GkException {
return offsets.get(cs);
return offsets.get(cs) == null ? new Tuple6b() : new Tuple6b( offsets.get(cs) );
}

public void setCoordinateSystemOffset(ICoordinateSystem cs, Tuple6b offset) throws GkException {
offsets.put(cs, offset);
offsets.put(cs, new Tuple6b( offset ));
if(gcodeContext != null){
gcodeContext.setCoordinateSystemData(cs, offset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ public interface IGrblControllerService<C extends AbstractGrblConfiguration<C>,
* @throws GkException GkException
*/
int getAvailablePlannerBuffer() throws GkException;

/**
* Returns <code>true</code> if the planner buffer is completely empty (no motion running)
* @return an integer
* @throws GkException GkException
*/
boolean isPlannerBufferEmpty() throws GkException;

/**
* Sends the given GCode line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void prepare(List<ProbeRequest> lstProbeRequest) throws GkException {
for (int i = 0; i < lstProbeRequest.size(); i++) {
ProbeCallable probeCallable = new ProbeCallable();
this.lstProbeCallable.add(probeCallable);
completionService.submit(probeCallable);
this.completionService.submit(probeCallable);
}

probeGCodeProvider = getProbingCode(lstProbeRequest, gcodeContextProvider.getGCodeContext());
Expand Down Expand Up @@ -92,14 +92,14 @@ public boolean isProbingInProgress(){
* @throws GkException GkException
*/
public void handleProbeResult(boolean probed, Tuple6b position) throws GkException{
if(CollectionUtils.isNotEmpty(lstProbeCallable)){
if(isProbingInProgress()){
ProbeResult probeResult = new ProbeResult();
probeResult.setProbed(probed);
probeResult.setProbedPosition(position);

ProbeCallable callable = lstProbeCallable.remove(0);
callable.setProbeResult(probeResult);
}
}
}

public void cancelActiveProbing() throws GkException{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,31 @@ public void resetCurrentCoordinateSystem() throws GkException {
*/
@Override
public void updateCoordinateSystemPosition(ICoordinateSystem cs, Tuple6b position) throws GkException {
throw new GkTechnicalException("TO DO"); // FIXME
String cmd = "G10";
switch (cs.getCode()) {
case "G54": cmd +="P1";
break;
case "G55": cmd +="P2";
break;
case "G56": cmd +="P3";
break;
case "G57": cmd +="P4";
break;
case "G58": cmd +="P5";
break;
case "G59": cmd +="P6";
break;
default: throw new GkFunctionalException("GRBL-002", cs.getCode());
}
Tuple6b offsets = getCoordinateSystemOffset(getCurrentCoordinateSystem());
Tuple6b mPos = new Tuple6b(getPosition());
mPos = mPos.add(offsets);
cmd += "L2";
cmd += "X"+getPositionAsString(mPos.getX());
cmd += "Y"+getPositionAsString(mPos.getY());
cmd += "Z"+getPositionAsString(mPos.getZ());
communicator.send(GkUtils.toBytesList(cmd));
communicator.send(GkUtils.toBytesList(Grbl.VIEW_PARAMETERS));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,31 @@ public void resetCurrentCoordinateSystem() throws GkException {
*/
@Override
public void updateCoordinateSystemPosition(ICoordinateSystem cs, Tuple6b position) throws GkException {
throw new GkTechnicalException("TO DO"); // FIXME
String cmd = "G10";
switch (cs.getCode()) {
case "G54": cmd +="P1";
break;
case "G55": cmd +="P2";
break;
case "G56": cmd +="P3";
break;
case "G57": cmd +="P4";
break;
case "G58": cmd +="P5";
break;
case "G59": cmd +="P6";
break;
default: throw new GkFunctionalException("GRBL-002", cs.getCode());
}
Tuple6b offsets = getCoordinateSystemOffset(getCurrentCoordinateSystem());
Tuple6b mPos = new Tuple6b(getPosition());
mPos = mPos.add(offsets);
cmd += "L2";
cmd += "X"+getPositionAsString(mPos.getX());
cmd += "Y"+getPositionAsString(mPos.getY());
cmd += "Z"+getPositionAsString(mPos.getZ());
communicator.send(GkUtils.toBytesList(cmd));
communicator.send(GkUtils.toBytesList(Grbl.VIEW_PARAMETERS));
}

/**
Expand Down Expand Up @@ -1030,11 +1054,12 @@ public CompletionService<ProbeResult> probe(List<ProbeRequest> lstProbeRequest)
}

probeGCodeProvider = getZProbingCode(lstProbeRequest, getGCodeContext());
probeGCodeProvider.setCode("TinyG probing");
probeGCodeProvider.setCode("Grbl probing");
gcodeService.addGCodeProvider(probeGCodeProvider);
probeGCodeProvider = gcodeService.getGCodeProvider(probeGCodeProvider.getId());// Required since internally the provider is a new one
executionService.addToExecutionQueue(probeGCodeProvider);
executionService.beginQueueExecution(ExecutionQueueType.DEFAULT);
executionService.clearExecutionQueue(ExecutionQueueType.SYSTEM);
executionService.addToExecutionQueue(ExecutionQueueType.SYSTEM, probeGCodeProvider);
executionService.beginQueueExecution(ExecutionQueueType.SYSTEM);

return completionService;
}
Expand Down
Loading

0 comments on commit b061897

Please sign in to comment.