Skip to content

Commit

Permalink
Support resolution less than 1 nm.
Browse files Browse the repository at this point in the history
  • Loading branch information
tnakamot committed Aug 19, 2022
1 parent 27ef1e6 commit 7e90fa9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions QSBLinearEncoderReader/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace QSBLinearEncoderReader
public partial class MainForm : Form
{
private QSB_D _qsb;
private double _resolution_mm = 0.000005;
private double _resolution_nm = 5.0 / 4;
private int _zeroCount = 0;
private int _latestCount = 0;
private bool _connected = false;
Expand Down Expand Up @@ -72,8 +72,8 @@ private void updateEncoderReadingDisplay()
try
{
_latestCount = (int)_qsb.GetCount();
double displacement = (_latestCount - _zeroCount) * _resolution_mm;
labelEncoderReading.Text = displacement.ToString("000.000000");
double displacement_mm = (_latestCount - _zeroCount) * _resolution_nm * 1e-6;
labelEncoderReading.Text = displacement_mm.ToString("0.00000000");
}
catch (Exception ex)
{
Expand Down Expand Up @@ -125,11 +125,11 @@ private void connect(String portName)
_qsb.SetDirection(EncoderDirection.CountingUp);
appendOneLineLogMessage("Direction: positive");

_resolution_mm = 0.000005;
appendOneLineLogMessage("Encoder resolution: " + _resolution_mm.ToString("0.000000") + " mm/count");
_resolution_nm = 5.0 / 4;
appendOneLineLogMessage("Encoder resolution: " + _resolution_nm.ToString("0.00") + " nm/count");

_zeroCount = 0;
appendOneLineLogMessage("Encoder count for zero position: " + _zeroCount);
appendOneLineLogMessage("Set the encoder zero position count to " + _zeroCount);

// Update the encoder reading display.
updateEncoderReadingDisplay();
Expand Down Expand Up @@ -209,8 +209,8 @@ private void recordCurrentEncoderReading()
try
{
int count = (int)_qsb.GetCount();
double displacement = (count - _zeroCount) * _resolution_mm;
_recordingStream.WriteLineAsync(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.fff") + "," + count + "," + displacement.ToString("000.000000"));
double displacement = (count - _zeroCount) * _resolution_nm * 1e-6;
_recordingStream.WriteLineAsync(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.fff") + "," + count + "," + displacement.ToString("0.00000000"));
}
catch (Exception ex)
{
Expand Down

0 comments on commit 7e90fa9

Please sign in to comment.