Browse Source

加液同时进行

master
sige 1 year ago
parent
commit
7b0074aeae
  1. 49
      src/main/java/com/iflytop/digester/deviceinstance/LiquidAdditionInstance.java

49
src/main/java/com/iflytop/digester/deviceinstance/LiquidAdditionInstance.java

@ -13,6 +13,11 @@ import java.util.List;
import java.util.Map;
@Component
public class LiquidAdditionInstance {
// finish callback
public interface ExecuteCallback {
void callback();
}
// list of liquids
private List<LiquidAdditionLiquid> liquids;
// lock for bucket empty
@ -93,12 +98,14 @@ public class LiquidAdditionInstance {
Boolean hasGoutTin = this.checkTubeExists("GOUT", batchIndex, "TIN", tubes);
if ( hasGoutTout || hasGoutTin ) {
UfCmdSnippetExecutor.execute("LiquidAdditionPrepare.Out." + batchIndex);
var pumpExecOut = new ArrayList<ExecuteCallback>();
if ( hasGoutTout ) {
this.pump(pumpGroupOutIndex, volume);
pumpExecOut.add(() -> this.pump(pumpGroupOutIndex, volume));
}
if ( hasGoutTin ) {
this.pump(pumpGroupInIndex, volume);
pumpExecOut.add(() -> this.pump(pumpGroupInIndex, volume));
}
this.pumpGroupExecute(pumpExecOut);
}
// 内圈
@ -106,27 +113,55 @@ public class LiquidAdditionInstance {
Boolean hasGinTin = this.checkTubeExists("GIN", batchIndex, "TIN", tubes);
if ( hasGinTout || hasGinTin ) {
UfCmdSnippetExecutor.execute("LiquidAdditionPrepare.In." + batchIndex);
var pumpExecIn = new ArrayList<ExecuteCallback>();
if ( hasGinTout ) {
this.pump(pumpGroupOutIndex, volume);
pumpExecIn.add(() -> this.pump(pumpGroupOutIndex, volume));
}
if ( hasGinTin ) {
this.pump(pumpGroupInIndex, volume);
pumpExecIn.add(() -> this.pump(pumpGroupInIndex, volume));
}
this.pumpGroupExecute(pumpExecIn);
}
}
UfCmdSnippetExecutor.execute("LiquidAdditionReset");
}
// pump group execute
private void pumpGroupExecute( List<ExecuteCallback> actions ) {
List<Thread> threads = new ArrayList<>();
for (ExecuteCallback action : actions) {
Thread thread = new Thread(action::callback);
threads.add(thread);
thread.start();
}
for (Thread thread : threads) {
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
// add liquid to tubes by given pump indexes
private void pump( Integer pumpIndex, Integer volume ) {
var liquid = liquids.get((0==pumpIndex%2) ? pumpIndex/2 : (pumpIndex-1)/2);
var type = liquid.type;
var snippetKey = "LiquidAdditionPump." + pumpIndex;
var rotateDistance = this.convertVolumeToPumpRotationDistance(type, volume);
Map<String,Object> snippetParams = Map.of("volume", rotateDistance);
UfCmdSnippetExecutor.execute(snippetKey, snippetParams);
String pumpKey = String.format("LiquidPeristalticPump_%d_%d", pumpIndex/2, pumpIndex%2);
UfActuatorCmdExecutor.execute(pumpKey,"motor_easy_move_by_nb", rotateDistance.toString());
do {
String status = UfActuatorCmdExecutor.execute(pumpKey, "module_get_status");
if ( "0".equals(status) ) {
break ;
}
UfCommon.delay(100);
} while( true );
UfActuatorCmdExecutor.execute(pumpKey, "motor_easy_move_by", "-500");
// update liquid volume
liquid.setVolumeByConsumed(volume);

Loading…
Cancel
Save