Improve puck loading management
This commit is contained in:
@@ -25,6 +25,7 @@ import ch.psi.pshell.swing.SwingUtils;
|
||||
import ch.psi.pshell.utils.State.StateException;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
@@ -463,25 +464,83 @@ public class Controller {
|
||||
}
|
||||
|
||||
|
||||
public Boolean isDoorClosed() {
|
||||
//Non-blocking
|
||||
public boolean isDoorOpen() {
|
||||
try {
|
||||
return doorsOpened;
|
||||
//if (getMainFrame().getState().isInitialized()){
|
||||
// return getMainFrame().eval("is_door_closed()", true).equals(false);
|
||||
// }
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//Non-blocking
|
||||
public boolean isRobotParked() {
|
||||
try {
|
||||
if (getMainFrame().getState().isInitialized()){
|
||||
return getMainFrame().eval("is_door_closed()", true).equals(true);
|
||||
return getMainFrame().eval("'pPark' in robot.get_current_points_cached()", true).equals(true);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Point fmm;
|
||||
public void onCoverDetection(Point fmm ){
|
||||
this.fmm = fmm;
|
||||
checkPuckLoading();
|
||||
}
|
||||
|
||||
public boolean isCoverDetected() {
|
||||
return fmm!=null;
|
||||
}
|
||||
|
||||
boolean doorsOpened;
|
||||
boolean doorsHaveOpened;
|
||||
public void onDoorsOpenChange(boolean value){
|
||||
doorsOpened = value;
|
||||
doorsHaveOpened =value;
|
||||
checkPuckLoading();
|
||||
}
|
||||
|
||||
public void setServiceMode(boolean value){
|
||||
try{
|
||||
String state = value ? "True" : "False";
|
||||
getMainFrame().evalAsync("set_service_mode(" + state + ")");
|
||||
getMainFrame().eval("set_service_mode(" + state + ")", true);
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
checkPuckLoading();
|
||||
}
|
||||
|
||||
public boolean canSetPuckLoading(){
|
||||
if (isServiceMode()){
|
||||
return true;
|
||||
}
|
||||
return !isCoverDetected() && isDoorOpen() && isRobotParked() && getState().isInitialized();
|
||||
}
|
||||
|
||||
private void checkPuckLoading(){
|
||||
try{
|
||||
if (isServiceMode()){
|
||||
//Open/close manually in service mode
|
||||
} else {
|
||||
if (!canSetPuckLoading()){
|
||||
setPuckLoading(false);
|
||||
} else {
|
||||
//Opens automatically once after door is oppen
|
||||
if (doorsHaveOpened){
|
||||
doorsHaveOpened=false;
|
||||
//setPuckLoading(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean isBarcodeReaderScanPucks() {
|
||||
try {
|
||||
@@ -700,14 +759,12 @@ public class Controller {
|
||||
boolean puckReaderOk = true;
|
||||
String insertedPuckDatamatrix;
|
||||
Puck removedPuck;
|
||||
|
||||
//true->load
|
||||
//false->unload
|
||||
//null->finish transfer mode
|
||||
|
||||
void setPuckLoading(boolean load) {
|
||||
if (load != puckLoading) {
|
||||
if (load){
|
||||
if (isDoorClosed()){
|
||||
if (load){
|
||||
if (!canSetPuckLoading()){
|
||||
Logger.getLogger(Controller.class.getName()).warning("Cannot set puck loading");
|
||||
return;
|
||||
}
|
||||
insertedPuckDatamatrix = null;
|
||||
@@ -752,7 +809,16 @@ public class Controller {
|
||||
} catch (Exception ex) {
|
||||
errorHandler.apply(null, ex);
|
||||
}
|
||||
onPuckLoadingModeChange(puckLoading);
|
||||
|
||||
if ( hasLoadDialog()) {
|
||||
if (puckLoading) {
|
||||
showDialogPuckLoading();
|
||||
mainFrame.setViewDesign();
|
||||
} else {
|
||||
hideDialogPuckLoading();
|
||||
mainFrame.setViewCamera();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -772,8 +838,10 @@ public class Controller {
|
||||
return puckLoading;
|
||||
}
|
||||
|
||||
String laserPos;
|
||||
public void setLaserPos(String pos){
|
||||
try {
|
||||
laserPos = pos;
|
||||
getMainFrame().evalAsync("set_laser_pos(" + ((pos==null) ? "" : ("'" + pos + "'") ) + ")" ,true);
|
||||
getMainFrame().basePlatePanel.pointPuck((pos==null) ? null : basePlate.getPuckByName(pos));
|
||||
} catch (StateException ex) {
|
||||
@@ -790,6 +858,10 @@ public class Controller {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getLaserPos(){
|
||||
return laserPos;
|
||||
}
|
||||
|
||||
void playSound(String name) {
|
||||
try {
|
||||
@@ -1007,11 +1079,11 @@ public class Controller {
|
||||
}
|
||||
|
||||
|
||||
void showDialogPuckLoading(boolean load) {
|
||||
void showDialogPuckLoading() {
|
||||
if ((dialogPuckLoading != null) && (dialogPuckLoading.isVisible())) {
|
||||
return;
|
||||
}
|
||||
dialogPuckLoading = new PuckLoadingDialog(mainFrame.getTopLevel(), load, false);
|
||||
dialogPuckLoading = new PuckLoadingDialog(mainFrame.getTopLevel(), false);
|
||||
dialogPuckLoading.setLocationRelativeTo(mainFrame);
|
||||
dialogPuckLoading.setVisible(true);
|
||||
checkPuckDetectionEnabling();
|
||||
@@ -1048,23 +1120,13 @@ public class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public void onPuckLoadingModeChange(boolean puckLoadMode) {
|
||||
if ( hasLoadDialog()) {
|
||||
if (puckLoadMode) {
|
||||
showDialogPuckLoading(puckLoadMode);
|
||||
mainFrame.setViewDesign();
|
||||
} else {
|
||||
hideDialogPuckLoading();
|
||||
mainFrame.setViewCamera();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onPuckScanned(String datamatrix) {
|
||||
Logger.getLogger(Controller.class.getName()).info("Scanned puck: " + datamatrix);
|
||||
if (isPuckLoading()) {
|
||||
getMainFrame().setPuckDatamatrix(datamatrix);
|
||||
if ( hasLoadDialog()) {
|
||||
showDialogPuckLoading(puckLoading);
|
||||
showDialogPuckLoading();
|
||||
dialogPuckLoading.onPuckScanned(datamatrix);
|
||||
}
|
||||
} else {
|
||||
@@ -1093,7 +1155,7 @@ public class Controller {
|
||||
}
|
||||
|
||||
if (hasLoadDialog()) {
|
||||
showDialogPuckLoading(puckLoading);
|
||||
showDialogPuckLoading();
|
||||
dialogPuckLoading.onPuckMounted(puck, datamatrix);
|
||||
} else {
|
||||
if ((datamatrix == null) || (datamatrix.isEmpty())){
|
||||
@@ -1110,11 +1172,11 @@ public class Controller {
|
||||
clearPuckMountedSample(puck);
|
||||
Controller.getInstance().linkPuckDatamatrix(puck, null, !hasLoadDialog());
|
||||
if ( hasLoadDialog()) {
|
||||
showDialogPuckLoading(puckLoading);
|
||||
showDialogPuckLoading();
|
||||
dialogPuckLoading.onPuckUnmounted(puck);
|
||||
}
|
||||
removedPuck = puck;
|
||||
}
|
||||
}
|
||||
|
||||
void clearPuckMountedSample(Puck puck){
|
||||
try{
|
||||
|
||||
Reference in New Issue
Block a user