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{
|
||||
|
||||
@@ -79,8 +79,7 @@ public class MainPanel extends Panel {
|
||||
StatusBar statusBar;
|
||||
JPopupMenu samplePopupMenu;
|
||||
JMenuItem menuMountSample;
|
||||
JMenuItem menuUnmoountSample;
|
||||
boolean doorsHaveOpened;
|
||||
JMenuItem menuUnmoountSample;
|
||||
|
||||
|
||||
public enum BasePlateLayout {
|
||||
@@ -412,12 +411,14 @@ public class MainPanel extends Panel {
|
||||
feedback_psys_safety.addListener(new DeviceListener() {
|
||||
@Override
|
||||
public void onValueChanged(Device device, Object value, Object former) {
|
||||
doorsHaveOpened = Boolean.FALSE.equals(value);
|
||||
Controller.getInstance().onDoorsOpenChange(Boolean.FALSE.equals(value));
|
||||
updatePsysSafety(value);
|
||||
}
|
||||
});
|
||||
feedback_psys_safety.request();
|
||||
updatePsysSafety(((Device) getDevice("feedback_psys_safety")).take());
|
||||
Object psys_safety=((Device) getDevice("feedback_psys_safety")).take();
|
||||
Controller.getInstance().onDoorsOpenChange(Boolean.FALSE.equals(psys_safety));
|
||||
updatePsysSafety(psys_safety);
|
||||
((Device) getDevice("robot")).addListener(new DeviceListener() {
|
||||
@Override
|
||||
public void onValueChanged(Device device, Object value, Object former) {
|
||||
@@ -642,9 +643,7 @@ public class MainPanel extends Panel {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean doors_open = !Boolean.TRUE.equals(Controller.getInstance().isDoorClosed());
|
||||
boolean cover_pos_detected = isCoverPosDetected();
|
||||
buttonSampleLoad.setEnabled(doors_open && !cover_pos_detected && getState().isInitialized());
|
||||
buttonSampleLoad.setEnabled(Controller.getInstance().canSetPuckLoading() || Controller.getInstance().isServiceMode());
|
||||
buttonCamera.setEnabled(getState().isInitialized());
|
||||
buttonDrawing.setEnabled(getState().isInitialized());
|
||||
}
|
||||
@@ -655,8 +654,7 @@ public class MainPanel extends Panel {
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ((value == null) || !(value instanceof Boolean)) {
|
||||
ledPsysSafety.setColor(Color.BLACK);
|
||||
} else if (Boolean.TRUE.equals(manualMode)) {
|
||||
@@ -666,13 +664,6 @@ public class MainPanel extends Panel {
|
||||
} else {
|
||||
ledPsysSafety.setColor(Color.RED);
|
||||
}
|
||||
if (!Boolean.TRUE.equals(value)){
|
||||
try {
|
||||
Controller.getInstance().setPuckLoading(false);
|
||||
} catch (Exception ex) {
|
||||
getLogger().log(Level.WARNING, null, ex);
|
||||
}
|
||||
}
|
||||
updateButtonState();
|
||||
}
|
||||
|
||||
@@ -848,7 +839,9 @@ public class MainPanel extends Panel {
|
||||
|
||||
|
||||
if (expert == false) {
|
||||
Controller.getInstance().setServiceMode(false);
|
||||
if (getState().isInitialized()){
|
||||
Controller.getInstance().setServiceMode(false);
|
||||
}
|
||||
// buttonCamera.setSelected(true);
|
||||
// buttonDrawing.setSelected(false);
|
||||
// updateViewType();
|
||||
@@ -1132,21 +1125,8 @@ public class MainPanel extends Panel {
|
||||
textCoverDet.setText("No Cover");
|
||||
} else {
|
||||
textCoverDet.setText((fmm==null) ? "" :fmm.x + ", " + fmm.y);
|
||||
if ( getState().isReady() &&
|
||||
!checkExpert.isSelected() &&
|
||||
Boolean.FALSE.equals(Controller.getInstance().isDoorClosed())){
|
||||
try{
|
||||
if ((fmm!=null)){
|
||||
Controller.getInstance().setPuckLoading(false);
|
||||
} else {
|
||||
if (doorsHaveOpened){
|
||||
doorsHaveOpened=false;
|
||||
Controller.getInstance().setPuckLoading(true);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
getLogger().log(Level.WARNING, null, e);
|
||||
}
|
||||
if ( getState().isReady()){
|
||||
Controller.getInstance().onCoverDetection(fmm);
|
||||
}
|
||||
}
|
||||
updateButtonState();
|
||||
@@ -2266,6 +2246,7 @@ public class MainPanel extends Panel {
|
||||
|
||||
private void buttonSampleLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSampleLoadActionPerformed
|
||||
try {
|
||||
getLogger().info("Button Sample Load");
|
||||
Controller.getInstance().setPuckLoading(true);
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
|
||||
@@ -133,6 +133,9 @@
|
||||
<TableHeader reorderingAllowed="false" resizingAllowed="true"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="tableMouseReleased"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
|
||||
</AuxValues>
|
||||
|
||||
@@ -22,7 +22,6 @@ import javax.swing.table.DefaultTableModel;
|
||||
public class PuckLoadingDialog extends JDialog {
|
||||
Path dialogPersistPath;
|
||||
DefaultTableModel model;
|
||||
final boolean load;
|
||||
|
||||
final int INDEX_USER = 0;
|
||||
final int INDEX_DEWAR = 1;
|
||||
@@ -31,10 +30,9 @@ public class PuckLoadingDialog extends JDialog {
|
||||
/**
|
||||
* Creates new form PuckLoadingDialog
|
||||
*/
|
||||
public PuckLoadingDialog(java.awt.Frame parent, boolean load, boolean modal) {
|
||||
super(parent, load ? "Puck Loading" : "Puck Unloading", modal);
|
||||
public PuckLoadingDialog(java.awt.Frame parent, boolean modal) {
|
||||
super(parent, "Puck Loading", modal);
|
||||
initComponents();
|
||||
this.load = load;
|
||||
this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
|
||||
this.setName("PuckLoadingDialog");
|
||||
dialogPersistPath = Paths.get(Setup.getContextPath(), getClass().getSimpleName());
|
||||
@@ -282,6 +280,11 @@ public class PuckLoadingDialog extends JDialog {
|
||||
table.setRowHeight(40);
|
||||
table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
|
||||
table.getTableHeader().setReorderingAllowed(false);
|
||||
table.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mouseReleased(java.awt.event.MouseEvent evt) {
|
||||
tableMouseReleased(evt);
|
||||
}
|
||||
});
|
||||
panelTable.setViewportView(table);
|
||||
|
||||
buttonSet.setFont(new java.awt.Font("Lucida Grande", 0, 24)); // NOI18N
|
||||
@@ -397,6 +400,23 @@ public class PuckLoadingDialog extends JDialog {
|
||||
}
|
||||
}//GEN-LAST:event_buttonClearDatamatrixActionPerformed
|
||||
|
||||
private void tableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseReleased
|
||||
try {
|
||||
int row = table.getSelectedRow();
|
||||
String position = (row >= 0) ? String.valueOf(table.getValueAt(row, INDEX_POSITION)) : null;
|
||||
if ((position!=null) && (!position.isBlank())){
|
||||
Puck puck = Controller.getInstance().getPuck(position);
|
||||
if (puck!=null) {
|
||||
Controller.getInstance().setLaserPos(puck);
|
||||
} else {
|
||||
Controller.getInstance().setLaserPos((Puck)null);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
SwingUtils.showException(this, ex);
|
||||
}
|
||||
}//GEN-LAST:event_tableMouseReleased
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
@@ -427,7 +447,7 @@ public class PuckLoadingDialog extends JDialog {
|
||||
/* Create and display the dialog */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
PuckLoadingDialog dialog = new PuckLoadingDialog(new javax.swing.JFrame(), true, true);
|
||||
PuckLoadingDialog dialog = new PuckLoadingDialog(new javax.swing.JFrame(), true);
|
||||
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(java.awt.event.WindowEvent e) {
|
||||
|
||||
Reference in New Issue
Block a user