Startup
This commit is contained in:
26
devices/AthosCamera.properties
Normal file
26
devices/AthosCamera.properties
Normal file
@@ -0,0 +1,26 @@
|
||||
#Mon Aug 26 09:42:13 CEST 2019
|
||||
colormap=Flame
|
||||
colormapAutomatic=true
|
||||
colormapLogarithmic=false
|
||||
colormapMax=NaN
|
||||
colormapMin=NaN
|
||||
flipHorizontally=false
|
||||
flipVertically=false
|
||||
grayscale=false
|
||||
invert=false
|
||||
rescaleFactor=1.0
|
||||
rescaleOffset=0.0
|
||||
roiHeight=-1
|
||||
roiWidth=-1
|
||||
roiX=0
|
||||
roiY=0
|
||||
rotation=0.0
|
||||
rotationCrop=false
|
||||
scale=1.0
|
||||
serverURL=localhost\:8889
|
||||
spatialCalOffsetX=-637.4980411378614
|
||||
spatialCalOffsetY=-483.5036425564949
|
||||
spatialCalScaleX=-35.21126887460907
|
||||
spatialCalScaleY=-48.38709552593848
|
||||
spatialCalUnits=mm
|
||||
transpose=false
|
||||
@@ -16,18 +16,28 @@
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace pref="503" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="edit_y_center_of_mass" min="-2" pref="124" max="-2" attributes="0"/>
|
||||
<Component id="edit_x_center_of_mass" min="-2" pref="124" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="edit_y_center_of_mass" min="-2" pref="124" max="-2" attributes="0"/>
|
||||
<Component id="edit_x_center_of_mass" min="-2" pref="124" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="72" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="buttonRec" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="buttonStop" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="92" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="72" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
@@ -51,7 +61,12 @@
|
||||
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="edit_y_center_of_mass" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="303" max="32767" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="123" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="buttonRec" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="buttonStop" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="151" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
@@ -79,12 +94,36 @@
|
||||
<Component class="javax.swing.JTextField" name="edit_y_center_of_mass">
|
||||
<Properties>
|
||||
<Property name="editable" type="boolean" value="false"/>
|
||||
<Property name="horizontalAlignment" type="int" value="11"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="edit_x_center_of_mass">
|
||||
<Properties>
|
||||
<Property name="editable" type="boolean" value="false"/>
|
||||
<Property name="horizontalAlignment" type="int" value="11"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JToggleButton" name="buttonRec">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="getIcon("Rec")" type="code"/>
|
||||
</Property>
|
||||
<Property name="toolTipText" type="java.lang.String" value="Start Data Recording"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonRecActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonStop">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="getIcon("Stop")" type="code"/>
|
||||
</Property>
|
||||
<Property name="enabled" type="boolean" value="false"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonStopActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
||||
@@ -1,34 +1,54 @@
|
||||
import ch.psi.pshell.bs.PipelineServer;
|
||||
import ch.psi.pshell.bs.StreamValue;
|
||||
import ch.psi.pshell.device.Device;
|
||||
import ch.psi.pshell.device.DeviceAdapter;
|
||||
import ch.psi.pshell.device.DeviceListener;
|
||||
import ch.psi.pshell.imaging.ColormapSource;
|
||||
import ch.psi.pshell.imaging.Overlay;
|
||||
import ch.psi.pshell.imaging.Overlays;
|
||||
import ch.psi.pshell.scan.MonitorScan;
|
||||
import ch.psi.pshell.ui.App;
|
||||
import ch.psi.pshell.ui.Panel;
|
||||
import ch.psi.utils.State;
|
||||
import ch.psi.utils.Threading;
|
||||
import ch.psi.utils.swing.MainFrame;
|
||||
import java.awt.Font;
|
||||
import java.awt.Point;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AthosCameras extends Panel {
|
||||
|
||||
PipelineServer server;
|
||||
ColormapSource camera;
|
||||
PipelineServer imagePipeline;
|
||||
PipelineServer dataPipeline;
|
||||
String serverUrl;
|
||||
Overlay errorOverlay;
|
||||
String instanceName;
|
||||
String imageInstanceName;
|
||||
String dataInstanceName;
|
||||
String cameraName;
|
||||
String persistFile = "{context}/AthosCameras";
|
||||
|
||||
final String CAMERA_DEVICE_NAME = "AthosCamera";
|
||||
String pipelineSuffix = "_sp";
|
||||
String pipelineSuffixData = "_acd";
|
||||
String pipelineSuffixImage = "_aci";
|
||||
|
||||
boolean persisting;
|
||||
|
||||
public AthosCameras() {
|
||||
initComponents();
|
||||
|
||||
}
|
||||
|
||||
ImageIcon getIcon(String name){
|
||||
return new ImageIcon(ch.psi.pshell.ui.App.class.getResource("/ch/psi/pshell/ui/" + (MainFrame.isDark() ? "dark/": "") + name + ".png"));
|
||||
}
|
||||
|
||||
//Overridable callbacks
|
||||
@@ -41,6 +61,7 @@ public class AthosCameras extends Panel {
|
||||
Logger.getLogger(AthosCameras.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
renderer.setPersistenceFile(Paths.get(getContext().getSetup().expandPath(persistFile)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,12 +83,12 @@ public class AthosCameras extends Panel {
|
||||
PipelineServer newServer() throws IOException {
|
||||
if (serverUrl != null) {
|
||||
System.out.println("Connecting to server: " + serverUrl);
|
||||
server = new PipelineServer(CAMERA_DEVICE_NAME, serverUrl);
|
||||
imagePipeline = new PipelineServer(CAMERA_DEVICE_NAME, serverUrl);
|
||||
} else {
|
||||
System.out.println("Connecting to server");
|
||||
server = new PipelineServer(CAMERA_DEVICE_NAME);
|
||||
imagePipeline = new PipelineServer(CAMERA_DEVICE_NAME);
|
||||
}
|
||||
return server;
|
||||
return imagePipeline;
|
||||
}
|
||||
|
||||
void setCamera(String cameraName) throws IOException, InterruptedException {
|
||||
@@ -87,33 +108,60 @@ public class AthosCameras extends Panel {
|
||||
|
||||
System.out.println("Setting camera: " + cameraName );
|
||||
try{
|
||||
camera = newServer();
|
||||
camera.getConfig().flipHorizontally = false;
|
||||
camera.getConfig().flipVertically = false;
|
||||
camera.getConfig().rotation = 0.0;
|
||||
camera.getConfig().roiX = 0;
|
||||
camera.getConfig().roiY = 0;
|
||||
camera.getConfig().roiWidth = -1;
|
||||
camera.getConfig().roiHeight = -1;
|
||||
camera.initialize();
|
||||
camera.assertInitialized();
|
||||
System.out.println("Camera initialization OK");
|
||||
imagePipeline = newServer();
|
||||
imagePipeline.getConfig().flipHorizontally = false;
|
||||
imagePipeline.getConfig().flipVertically = false;
|
||||
imagePipeline.getConfig().rotation = 0.0;
|
||||
imagePipeline.getConfig().roiX = 0;
|
||||
imagePipeline.getConfig().roiY = 0;
|
||||
imagePipeline.getConfig().roiWidth = -1;
|
||||
imagePipeline.getConfig().roiHeight = -1;
|
||||
imagePipeline.getConfig().save();
|
||||
imagePipeline.initialize();
|
||||
imagePipeline.assertInitialized();
|
||||
System.out.println("Image pipeline initialization OK");
|
||||
|
||||
String pipelineName = cameraName + pipelineSuffix;
|
||||
instanceName = cameraName + pipelineSuffix + "1";
|
||||
if (!server.getPipelines().contains(pipelineName)) {
|
||||
String pipelineName = cameraName + pipelineSuffixImage;
|
||||
imageInstanceName = cameraName + pipelineSuffixImage + "1";
|
||||
if (!imagePipeline.getPipelines().contains(pipelineSuffixImage)) {
|
||||
System.out.println("Creating pipeline: " + pipelineName);
|
||||
HashMap<String, Object> config = new HashMap<>();
|
||||
config.put("camera_name", cameraName);
|
||||
//config.put("include", new String[]{"image", "width", "height"});
|
||||
config.put("function", "transparent");
|
||||
config.put("max_frame_rate" , 2.1);
|
||||
//server.createFromConfig(config, pipelineName);
|
||||
server.savePipelineConfig(pipelineName, config);
|
||||
imagePipeline.savePipelineConfig(pipelineName, config);
|
||||
}
|
||||
server.start(pipelineName, instanceName);
|
||||
|
||||
camera.getConfig().save();
|
||||
renderer.setDevice(camera);
|
||||
renderer.setAutoScroll(true);
|
||||
renderer.setSource(camera);
|
||||
imagePipeline.start(pipelineName, imageInstanceName);
|
||||
renderer.setDevice(imagePipeline);
|
||||
|
||||
|
||||
dataPipeline = newServer();
|
||||
//dataPipeline.getConfig().copyFrom(imagePipeline.getConfig());
|
||||
dataPipeline.initialize();
|
||||
dataPipeline.assertInitialized();
|
||||
System.out.println("Data pipeline initialization OK");
|
||||
|
||||
pipelineName = cameraName + pipelineSuffixData;
|
||||
dataInstanceName = cameraName + pipelineSuffixData + "1";
|
||||
if (!dataPipeline.getPipelines().contains(pipelineSuffixData)) {
|
||||
System.out.println("Creating pipeline: " + pipelineName);
|
||||
HashMap<String, Object> config = new HashMap<>();
|
||||
config.put("camera_name", cameraName);
|
||||
config.put("include", new String[]{"x_center_of_mass", "y_center_of_mass"});
|
||||
//server.createFromConfig(config, pipelineName);
|
||||
dataPipeline.savePipelineConfig(pipelineName, config);
|
||||
}
|
||||
dataPipeline.start(pipelineName, dataInstanceName);
|
||||
|
||||
dataPipeline.getStream().addListener(new DeviceAdapter() {
|
||||
@Override
|
||||
public void onCacheChanged(Device device, Object value, Object former, long timestamp, boolean arg4) {
|
||||
updateData((StreamValue)value);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
renderer.clearOverlays();
|
||||
@@ -131,6 +179,37 @@ public class AthosCameras extends Panel {
|
||||
}
|
||||
}
|
||||
|
||||
String getDoubleStr(StreamValue sv, String id){
|
||||
return String.format("%1.4f", sv.getValue(id));
|
||||
}
|
||||
|
||||
void updateData(StreamValue value){
|
||||
//System.exit(0);
|
||||
try{
|
||||
edit_x_center_of_mass.setText(getDoubleStr(value, "x_center_of_mass"));
|
||||
} catch (Exception ex){
|
||||
edit_x_center_of_mass.setText("");
|
||||
}
|
||||
try{
|
||||
edit_y_center_of_mass.setText(getDoubleStr(value, "y_center_of_mass"));
|
||||
} catch (Exception ex){
|
||||
edit_y_center_of_mass.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
MonitorScan scan;
|
||||
|
||||
void startRecording() throws IOException, InterruptedException{
|
||||
System.out.println("startRecording");
|
||||
scan= new MonitorScan(dataPipeline.getStream(), dataPipeline.getStream().getReadables().toArray(new ch.psi.pshell.device.Readable[0]), -1, -1);
|
||||
Threading.getFuture(() ->scan.start());
|
||||
}
|
||||
|
||||
void stopRecording() throws InterruptedException{
|
||||
System.out.println("stopRecording");
|
||||
scan.abort();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -142,29 +221,56 @@ public class AthosCameras extends Panel {
|
||||
jLabel2 = new javax.swing.JLabel();
|
||||
edit_y_center_of_mass = new javax.swing.JTextField();
|
||||
edit_x_center_of_mass = new javax.swing.JTextField();
|
||||
buttonRec = new javax.swing.JToggleButton();
|
||||
buttonStop = new javax.swing.JButton();
|
||||
|
||||
jLabel1.setText("x_center_of_mass:");
|
||||
|
||||
jLabel2.setText("y_center_of_mass:");
|
||||
|
||||
edit_y_center_of_mass.setEditable(false);
|
||||
edit_y_center_of_mass.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
|
||||
|
||||
edit_x_center_of_mass.setEditable(false);
|
||||
edit_x_center_of_mass.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
|
||||
|
||||
buttonRec.setIcon(getIcon("Rec"));
|
||||
buttonRec.setToolTipText("Start Data Recording");
|
||||
buttonRec.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonRecActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonStop.setIcon(getIcon("Stop"));
|
||||
buttonStop.setEnabled(false);
|
||||
buttonStop.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonStopActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap(503, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(jLabel2)
|
||||
.addComponent(jLabel1))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(edit_y_center_of_mass, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(edit_x_center_of_mass, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(72, 72, 72))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(jLabel2)
|
||||
.addComponent(jLabel1))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(edit_y_center_of_mass, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(edit_x_center_of_mass, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGap(72, 72, 72))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(buttonRec)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonStop)
|
||||
.addGap(92, 92, 92))))
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
@@ -182,7 +288,11 @@ public class AthosCameras extends Panel {
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel2)
|
||||
.addComponent(edit_y_center_of_mass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addContainerGap(303, Short.MAX_VALUE))
|
||||
.addGap(123, 123, 123)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(buttonRec)
|
||||
.addComponent(buttonStop))
|
||||
.addContainerGap(151, Short.MAX_VALUE))
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
@@ -191,7 +301,27 @@ public class AthosCameras extends Panel {
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void buttonRecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRecActionPerformed
|
||||
try{
|
||||
buttonStop.setEnabled(buttonRec.isSelected());
|
||||
if (buttonRec.isSelected()){
|
||||
startRecording();
|
||||
} else {
|
||||
stopRecording();
|
||||
}
|
||||
} catch (Exception ex){
|
||||
this.showException(ex);
|
||||
}
|
||||
}//GEN-LAST:event_buttonRecActionPerformed
|
||||
|
||||
private void buttonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopActionPerformed
|
||||
buttonRec.setSelected(false);
|
||||
buttonRecActionPerformed(null);
|
||||
}//GEN-LAST:event_buttonStopActionPerformed
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JToggleButton buttonRec;
|
||||
private javax.swing.JButton buttonStop;
|
||||
private javax.swing.JTextField edit_x_center_of_mass;
|
||||
private javax.swing.JTextField edit_y_center_of_mass;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
|
||||
Reference in New Issue
Block a user