This commit is contained in:
gac-S_Changer
2018-08-29 17:47:32 +02:00
parent 1229efe275
commit b84b745a49
4 changed files with 62 additions and 42 deletions

View File

@@ -8,6 +8,7 @@ import ch.psi.utils.State;
import ch.psi.utils.swing.SwingUtils;
import java.awt.Color;
import java.util.List;
import javax.swing.SwingUtilities;
/**
*
@@ -16,7 +17,7 @@ public class Recovery extends Panel {
public Recovery() {
initComponents();
startTimer(1000, 200);
startTimer(5000, 200);
}
//Overridable callbacks
@@ -27,6 +28,12 @@ public class Recovery extends Panel {
@Override
public void onStateChange(State state, State former) {
if (state==State.Ready){
SwingUtilities.invokeLater(()->{onTimer();});
}
textSegment.setEnabled(state == State.Ready);
textDistance.setEnabled(state == State.Ready);
textPosition.setEnabled(state == State.Ready);
updateButton();
}
@@ -40,42 +47,50 @@ public class Recovery extends Panel {
@Override
public void onExecutedFile(String fileName, Object result) {
}
@Override
protected void onTimer() {
Device robot = getContext().getDevicePool().getByName("robot", Device.class);
if (!robot.getState().isNormal()){
if ((robot==null) || (!robot.getState().isNormal())){
ledValidSegment.setColor(Color.BLACK);
textSegment.setText("");
ledKnownPosition.setColor(Color.BLACK);
textPosition.setText("");
} else {
try{
List segment = (List) eval("get_current_segment()", true);
ledValidSegment.setColor((segment == null) ? Color.RED : Color.GREEN);
textSegment.setText((segment == null) ? "": segment.get(0) + "->" + segment.get(1) + " [" + segment.get(2) + "mm]");
if (getState()==State.Ready){
String point = null;
try{
Object distance = eval("get_current_distance()", true);
textDistance.setText((distance == null) ? "" : String.format("%1.2f",((Number)distance).doubleValue()));
point = (String) eval("robot.get_current_point()", true);
ledKnownPosition.setColor((point == null) ? Color.RED : Color.GREEN);
textPosition.setText((point == null) ? "": point);
} catch (Exception ex) {
System.out.println(ex);
ledKnownPosition.setColor(Color.BLACK);
textPosition.setText("");
}
try{
List segment = (List) eval("get_current_segment()", true);
ledValidSegment.setColor((segment == null) ? Color.RED : Color.GREEN);
textSegment.setText((segment == null) ? "": segment.get(0) + "->" + segment.get(1) + " [" + segment.get(2) + "mm]");
if ((segment == null)||(point!=null)){
textDistance.setText("");
} else {
try{
Object distance = eval("get_current_distance()", true);
textDistance.setText((distance == null) ? "" : String.format("%1.2f",((Number)distance).doubleValue()));
} catch (Exception ex) {
textDistance.setText("");
}
}
} catch (Exception ex) {
System.out.println(ex);
ledValidSegment.setColor(Color.BLACK);
textSegment.setText("");
textDistance.setText("");
}
} catch (Exception ex) {
System.out.println(ex);
ledValidSegment.setColor(Color.BLACK);
textSegment.setText("");
textDistance.setText("");
}
try{
String point = (String) eval("robot.get_current_point()", true);
ledKnownPosition.setColor((point == null) ? Color.RED : Color.GREEN);
textPosition.setText((point == null) ? "": point);
} catch (Exception ex) {
System.out.println(ex);
ledKnownPosition.setColor(Color.BLACK);
textPosition.setText("");
}
}
}
}
updateButton();
}