Skip to content

Commit

Permalink
Fix bugs, improve backlash calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocipriani01 committed Dec 16, 2020
1 parent 9b30e01 commit 7e158c4
Show file tree
Hide file tree
Showing 21 changed files with 359 additions and 109 deletions.
8 changes: 6 additions & 2 deletions InnoSetup.iss
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[Setup]
AppId={{863670cf-a7a6-4314-9479-c99e1c6fce06}
AppName=ThunderFocus
AppVersion=2.2
AppVerName=ThunderFocus v2.2
AppVersion=2.3
AppVerName=ThunderFocus v2.3
AppPublisher=marcocipriani01
AppPublisherURL=https://marcocipriani01.github.io/
AppSupportURL=https://marcocipriani01.github.io/
Expand All @@ -21,11 +21,15 @@ OutputDir=Installers
WizardImageFile="D:\ThunderFocus\WizardImage.bmp"
SetupIconFile="D:\ThunderFocus\ThunderFocusASCOM\Resources\icon.ico"
UninstallDisplayIcon="D:\ThunderFocus\ThunderFocusASCOM\Resources\icon.ico"
ChangesEnvironment=yes

[Languages]
;Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl"

[Registry]
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName: "thunderfok"; ValueData: "{app}"; Flags: preservestringtype

[Dirs]
Name: "{app}"

Expand Down
Binary file modified Installers/ThunderFocus_Win_64bit.exe
Binary file not shown.
Binary file modified JRE-bundle/ThunderFocus.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions ThunderFocus-GUI/.idea/statistic.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ThunderFocus-GUI/deb-builder/ThunderFocus/DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Maintainer: marcocipriani01
Depends:
Suggests: openjdk-14-jre
Priority: optional
Version: 2.2
Version: 2.3
Description: ThunderFocus for Debian.
Binary file not shown.
Binary file modified ThunderFocus-GUI/out/artifacts/ThunderFocus_jar/ThunderFocus.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion ThunderFocus-GUI/src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Specification-Vendor: marcocipriani01
Main-Class: marcocipriani01.thunderfocus.Main
Name: marcocipriani01/thunder/focus
Specification-Title: ThunderFocus
Specification-Version: 2.2
Specification-Version: 2.3
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="marcocipriani01.thunderfocus.BacklashCalibrationWindow">
<grid id="cbd77" binding="parent" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="16" bottom="16" right="16"/>
<margin top="0" left="16" bottom="16" right="16"/>
<constraints>
<xy x="90" y="54" width="397" height="539"/>
</constraints>
Expand Down Expand Up @@ -35,7 +35,7 @@
</constraints>
</hspacer>
<grid id="8b5b7" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="8" left="0" bottom="16" right="0"/>
<margin top="8" left="0" bottom="8" right="0"/>
<constraints>
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<maximum-size width="420" height="-1"/>
Expand Down Expand Up @@ -92,6 +92,14 @@
<toolTipText value="Caricamento..."/>
</properties>
</component>
<component id="f582e" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="&lt;html&gt;&#10;&lt;h2&gt;Calibrazione backlash&lt;/h2&gt;&#10;Il motore verrà inizialmente mosso tutto in una direzione. Per effettuare la calibrazione, muovere il focheggiatore di un passo alla volta (o fare spostamenti più grandi se ne si è sicuri) e salvare non appena si vede il focheggiatore muoversi. Evitare di superare il punto giusto, in quanto potrebbe alterare la precisione del sistema. Si consiglia di arrotondare sempre per difetto il risultato ed eventualmente aggiustarlo nel pannello di configurazione.&#10;&lt;/html&gt;"/>
</properties>
</component>
<component id="95b87" class="javax.swing.JLabel" binding="counterLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false">
Expand All @@ -104,14 +112,7 @@
<horizontalTextPosition value="0"/>
<text value="0"/>
<toolTipText value="Numero di passi di backlash."/>
</properties>
</component>
<component id="f582e" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="&lt;html&gt;&#10;&lt;h2&gt;Calibrazione backlash&lt;/h2&gt;&#10;Il motore verrà inizialmente mosso tutto in una direzione. Per iniziare, muovere il focheggiatore un passo alla volta nella direzione opposta (o fare piccoli spostamenti più grandi se si è sicuri). Accettare non appena si vede il focheggiatore effettivamente muoversi.&lt;br&gt;&#10;Evitare di superare il punto giusto, in quanto potrebbe alterare la precisione del sistema. Si consiglia di arrotondare per difetto il risultato e aggiustarlo successivamente nelle impostazioni. Eventualmente, si può tornare indietro con un movimento negativo.&#10;&lt;/html&gt;"/>
<visible value="false"/>
</properties>
</component>
</children>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package marcocipriani01.thunderfocus;

import marcocipriani01.thunderfocus.board.ThunderFocuser;
import marcocipriani01.simplesocket.ConnectionException;
import marcocipriani01.thunderfocus.board.ThunderFocuser;

import javax.swing.*;
import java.awt.*;
Expand All @@ -19,8 +19,9 @@ public class BacklashCalibrationWindow extends JDialog implements ThunderFocuser
private JButton relMovButton;
private JSpinner relMovSpinner;
private JLabel loading;
private int count;
private boolean initialMoveDone = false;
private volatile int count = 0;
private volatile int phase = 0;
private boolean wasPowerSaveOn;

public BacklashCalibrationWindow(Frame owner) {
super(owner, Main.APP_NAME, true);
Expand All @@ -43,19 +44,19 @@ public BacklashCalibrationWindow(Frame owner) {
dispose();
});
oneStepButton.addActionListener(e -> {
SwingUtilities.invokeLater(() -> setControlsEnabled(false));
try {
Main.focuser.run(ThunderFocuser.Commands.FOK1_REL_MOVE, this, 1);
setControlsEnabled(false);
} catch (ConnectionException ex) {
connectionErr(ex);
} catch (ThunderFocuser.InvalidParamException | NumberFormatException ex) {
valueOutOfLimits(ex);
}
});
relMovButton.addActionListener(e -> {
SwingUtilities.invokeLater(() -> setControlsEnabled(false));
try {
Main.focuser.run(ThunderFocuser.Commands.FOK1_REL_MOVE, this, (int) relMovSpinner.getValue());
setControlsEnabled(false);
} catch (ConnectionException ex) {
connectionErr(ex);
} catch (ThunderFocuser.InvalidParamException | NumberFormatException ex) {
Expand All @@ -66,19 +67,31 @@ public BacklashCalibrationWindow(Frame owner) {
Main.focuser.addListener(this);
Main.focuser.clearRequestedPositions();
try {
wasPowerSaveOn = Main.focuser.isPowerSaverOn();
Main.focuser.run(ThunderFocuser.Commands.FOK1_POWER_SAVER, this, 0);
Main.focuser.run(ThunderFocuser.Commands.FOK1_SET_BACKLASH, this, 0);
Main.focuser.run(ThunderFocuser.Commands.FOK1_ABS_MOVE, this, Main.settings.getFokMaxTravel() / 2);
int target = Main.settings.getFokMaxTravel() / 4;
if (target == Main.focuser.getCurrentPos()) {
phase = 1;
Main.focuser.run(ThunderFocuser.Commands.FOK1_ABS_MOVE, this, 20);
} else {
Main.focuser.run(ThunderFocuser.Commands.FOK1_ABS_MOVE, this, target);
}
} catch (ConnectionException e) {
connectionErr(e);
dispose();
} catch (ThunderFocuser.InvalidParamException e) {
e.printStackTrace();
}
setBounds(450, 250, 420, 510);
setBounds(450, 250, 420, 520);
setResizable(false);
setVisible(true);
}

private void createUIComponents() {
relMovSpinner = new JSpinner(new SpinnerNumberModel(5, -500, 500, 1));
}

private void valueOutOfLimits(Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Valore fuori dai limiti o non valido.", Main.APP_NAME, JOptionPane.ERROR_MESSAGE);
Expand All @@ -93,6 +106,7 @@ private void connectionErr(ConnectionException e) {
public void dispose() {
super.dispose();
try {
Main.focuser.run(ThunderFocuser.Commands.FOK1_POWER_SAVER, this, wasPowerSaveOn ? 1 : 0);
Main.focuser.run(ThunderFocuser.Commands.FOK1_STOP, this);
} catch (ConnectionException e) {
connectionErr(e);
Expand All @@ -104,7 +118,7 @@ public void dispose() {
Main.focuser.removeListener(this);
}

private void setControlsEnabled(boolean b) {
private synchronized void setControlsEnabled(final boolean b) {
loading.setVisible(!b);
counterLabel.setVisible(b);
acceptButton.setEnabled(b);
Expand All @@ -114,20 +128,29 @@ private void setControlsEnabled(boolean b) {
}

@Override
public void onReachedPos() {
setControlsEnabled(true);
if (initialMoveDone) {
count += Main.focuser.getRequestedRelPos();
counterLabel.setText(String.valueOf(count));
} else {
try {
Main.focuser.run(ThunderFocuser.Commands.FOK1_ABS_MOVE, this, 20);
initialMoveDone = true;
} catch (ConnectionException e) {
connectionErr(e);
e.printStackTrace();
} catch (ThunderFocuser.InvalidParamException e) {
e.printStackTrace();
public synchronized void onReachedPos() {
switch (phase) {
case 0 -> {
try {
Main.focuser.run(ThunderFocuser.Commands.FOK1_ABS_MOVE, this, 20);
phase = 1;
} catch (ConnectionException e) {
connectionErr(e);
e.printStackTrace();
} catch (ThunderFocuser.InvalidParamException e) {
e.printStackTrace();
}
}
case 1 -> {
phase = 2;
SwingUtilities.invokeLater(() -> setControlsEnabled(true));
}
case 2 -> {
count += Main.focuser.getRequestedRelPos();
SwingUtilities.invokeLater(() -> {
counterLabel.setText(String.valueOf(count));
setControlsEnabled(true);
});
}
}
}
Expand All @@ -151,8 +174,4 @@ public void updateFocuserState(ThunderFocuser.FocuserState focuserState) {
public void updateConnSate(ThunderFocuser.ConnState connState) {

}

private void createUIComponents() {
relMovSpinner = new JSpinner(new SpinnerNumberModel(5, -500, 500, 1));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@
<enabled value="false"/>
<horizontalTextPosition value="0"/>
<icon value="marcocipriani01/thunderfocus/res/launch.png"/>
<text value="Controlli voltanti"/>
<text value="Controlli volanti"/>
<toolTipText value="Apre la finestra dei contrlli volanti."/>
<verticalTextPosition value="3"/>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private void createUIComponents() {
fokMaxTravelSpinner = new JSpinner(new SpinnerNumberModel(
Main.settings.getFokMaxTravel(), 1, 2147483647, 1));
fokBacklashSpinner = new JSpinner(new SpinnerNumberModel(
Main.focuser.getBacklash(), 0, 200, 1));
Main.focuser.getBacklash(), 0, 1000, 1));
powerBoxTable = new JPowerBoxTable();
powerBoxAutoModeBox = new JComboBox<>();
powerBoxLatSpinner = new JSpinner(new SpinnerNumberModel(0.0, -180.0, 180.0, 0.001));
Expand Down Expand Up @@ -855,7 +855,7 @@ public void updateParam(ThunderFocuser.Parameters p) {
}
case BACKLASH -> fokBacklashSpinner.setValue(Main.focuser.getBacklash());
case REVERSE_DIR -> fokReverseDirBox.setSelected(Main.focuser.isReverseDir());
case ENABLE_POWER_SAVE -> fokPowerSaverBox.setSelected(Main.focuser.isPowerSaver());
case ENABLE_POWER_SAVE -> fokPowerSaverBox.setSelected(Main.focuser.isPowerSaverOn());
case POWERBOX_PINS -> powerBoxTable.refresh();
case POWERBOX_AUTO_MODE -> powerBoxAutoModeBox.setSelectedItem(Main.focuser.getPowerBox().getAutoMode());
case POWERBOX_AMBIENT_DATA -> {
Expand Down Expand Up @@ -926,7 +926,7 @@ public void updateConnSate(ThunderFocuser.ConnState connState) {
}
fokSpeedSlider.setValue(Main.focuser.getSpeed());
fokReverseDirBox.setSelected(Main.focuser.isReverseDir());
fokPowerSaverBox.setSelected(Main.focuser.isPowerSaver());
fokPowerSaverBox.setSelected(Main.focuser.isPowerSaverOn());
int currentPos = Main.focuser.getCurrentPos();
posSlider.removeChangeListener(MainWindow.this);
posSlider.setValue(currentPos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public class ThunderFocuser implements SerialMessageListener {
private final ArrayList<Listener> listeners = new ArrayList<>();
private String version = "<?>";
private PowerBox powerBox = null;
private int timerCount = 0;
private volatile int timerCount = 0;
private Listener exclusiveCaller = null;
private ConnState connState = ConnState.DISCONNECTED;
private FocuserState focuserState = FocuserState.NONE;
private boolean ready = false;
private volatile boolean ready = false;
private int requestedPos = 0;
private int requestedRelPos = 10;
private int currentPos = 0;
Expand All @@ -45,14 +45,14 @@ public boolean isReady() {
return ready;
}

public void connect(String port) throws ConnectionException {
public synchronized void connect(String port) throws ConnectionException {
updConnSate(ConnState.TIMEOUT);
serialPort.connect(port);
timerCount = 1;
new Timer("SendSettingsRequestTask #" + timerCount).schedule(new SendSettingsRequestTask(), 500);
}

public void disconnect() {
public synchronized void disconnect() {
updConnSate(ConnState.TIMEOUT);
updFocuserState(FocuserState.NONE);
ready = false;
Expand Down Expand Up @@ -136,7 +136,7 @@ public boolean isReverseDir() {
return reverseDir;
}

public boolean isPowerSaver() {
public boolean isPowerSaverOn() {
return powerSaver;
}

Expand All @@ -149,7 +149,7 @@ public int stepsToTicks(int steps) {
}

@Override
public void onPortMessage(String msg) {
public synchronized void onPortMessage(String msg) {
char c;
String param;
try {
Expand Down Expand Up @@ -498,7 +498,7 @@ public InvalidParamException(String s) {

private class SendSettingsRequestTask extends TimerTask {
@Override
public void run() {
public synchronized void run() {
if (!ready && serialPort.isConnected()) {
try {
System.err.println("Sending focuser settings request");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Locale;

/**
* Simple serial port manager with listeners.
Expand Down
Loading

0 comments on commit 7e158c4

Please sign in to comment.