[chronojump] Force sensor: adding tare and calibrate. Fixing with current arduino code
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Force sensor: adding tare and calibrate. Fixing with current arduino code
- Date: Mon, 18 Sep 2017 18:41:42 +0000 (UTC)
commit e47a9162ee088099f0d8ce02d980a28f42370826
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Sep 18 20:40:53 2017 +0200
Force sensor: adding tare and calibrate. Fixing with current arduino code
glade/app1.glade | 133 +++++++++++++++++++++++++++++++++++++++++++++++-
src/gui/chronojump.cs | 2 +
src/gui/forceSensor.cs | 119 ++++++++++++++++++++++++++++++++++++++++--
3 files changed, 246 insertions(+), 8 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index fbf3176..9d3f02c 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -1366,6 +1366,12 @@
<placeholder/>
</child>
<child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
<widget class="GtkLabel"
id="label_start_selector_jumps">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -4453,6 +4459,36 @@ EncoderInertialCapture</property>
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <widget class="GtkButton"
id="button_force_sensor_connect">
+ <property name="label"
translatable="yes">Connect</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked"
handler="on_button_force_sensor_connect_clicked" swapped="no"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">20</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkButton"
id="button_force_sensor_disconnect1">
+ <property name="label"
translatable="yes">Disconnect</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked"
handler="on_button_force_sensor_disconnect_clicked" swapped="no"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">20</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
</widget>
</child>
</widget>
@@ -6110,10 +6146,97 @@ after time</property>
<property name="xscale">0</property>
<property name="top_padding">8</property>
<child>
- <widget class="GtkLabel" id="label51">
+ <widget class="GtkHBox" id="hbox231">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">20</property>
+ <child>
+ <widget class="GtkButton"
id="button_force_sensor_tare">
+ <property name="label"
translatable="yes">Tare</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked"
handler="on_button_force_sensor_tare_clicked" swapped="no"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">20</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkHBox" id="hbox230">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">10</property>
+ <child>
+ <widget class="GtkHBox"
id="hbox_spin_force_sensor">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">4</property>
+ <child>
+ <widget class="GtkSpinButton"
id="spin_force_sensor_calibration_kg_value">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ <property
name="invisible_char_set">True</property>
+ <property
name="primary_icon_activatable">False</property>
+ <property
name="secondary_icon_activatable">False</property>
+ <property
name="primary_icon_sensitive">True</property>
+ <property
name="secondary_icon_sensitive">True</property>
+ <property name="adjustment">20 0 500 1 10
0</property>
+ <property name="climb_rate">1</property>
+ <property name="digits">2</property>
+ <property name="numeric">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel"
id="calibration_factor_kg_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="label">force sensor</property>
+ <property name="xalign">0</property>
+ <property name="label">Kg</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkButton"
id="button_force_sensor_calibrate">
+ <property name="label"
translatable="yes">Calibrate</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <signal name="clicked"
handler="on_button_force_sensor_calibrate_clicked" swapped="no"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
</widget>
</child>
</widget>
@@ -21083,6 +21206,12 @@ then click this button.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 0afd830..15ff060 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2153,6 +2153,8 @@ public partial class ChronoJumpWindow
LogB.Information("cancelling force capture");
forceProcessCancel = true;
}
+ if(portFSOpened)
+ portFS.Close();
LogB.Information("Bye3!");
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index c8191a1..056feb1 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -35,6 +35,7 @@ public partial class ChronoJumpWindow
[Widget] Gtk.VScale vscale_force_sensor;
[Widget] Gtk.Viewport viewport_force_sensor_graph;
[Widget] Gtk.Image image_force_sensor_graph;
+ [Widget] Gtk.SpinButton spin_force_sensor_calibration_kg_value;
Thread forceThread;
static bool forceProcessFinish;
@@ -54,14 +55,109 @@ public partial class ChronoJumpWindow
static double forceSensorLast; //Needed to display value and move vscale
string forceSensorPortName;
+ SerialPort portFS;
+ bool portFSOpened;
+
+ //TODO: don't reopen port because arduino makes reset and tare, calibration... is lost
+
+ private void on_button_force_sensor_connect_clicked(object o, EventArgs args)
+ {
+ LogB.Information(" FS connect 0 ");
+ if(chronopicRegister.ConnectedOfType(ChronopicRegisterPort.Types.ARDUINO_FORCE) == null)
+ {
+ new DialogMessage(Constants.MessageTypes.WARNING, "Force sensor is not connected!");
+ return;
+ }
+
+ LogB.Information(" FS connect 1 ");
+ forceSensorPortName =
chronopicRegister.ConnectedOfType(ChronopicRegisterPort.Types.ARDUINO_FORCE).Port;
+ LogB.Information(" FS connect 2 ");
+ if(forceSensorPortName == null || forceSensorPortName == "")
+ {
+ new DialogMessage(Constants.MessageTypes.WARNING, "Please, select port");
+ return;
+ }
+ LogB.Information(" FS connect 3 ");
+
+ portFS = new SerialPort(forceSensorPortName, 115200); //forceSensor
+ LogB.Information(" FS connect 4 ");
+ portFS.Open();
+ portFSOpened = true;
+ Thread.Sleep(2500); //sleep to let arduino start reading
+ event_execute_label_message.Text = "Connected!";
+ LogB.Information(" FS connect 5 ");
+ }
+ private void on_button_force_sensor_disconnect_clicked(object o, EventArgs args)
+ {
+ portFS.Close();
+ portFSOpened = false;
+ event_execute_label_message.Text = "Disconnected!";
+ }
+
+ private void on_button_force_sensor_tare_clicked(object o, EventArgs args)
+ {
+ if(! portFSOpened) //TODO: better check is connected!
+ {
+ new DialogMessage(Constants.MessageTypes.WARNING, "Please, connect!");
+ return;
+ }
+
+ event_execute_label_message.Text = "Taring ...";
+ portFS.WriteLine("tare:");
+
+ string str = "";
+ do {
+ Thread.Sleep(100); //sleep to let arduino start reading
+ str = portFS.ReadLine();
+ LogB.Information("init string: " + str);
+ }
+ while(! str.Contains("Taring OK"));
+
+ event_execute_label_message.Text = "Tared!";
+ }
+
+ private void on_button_force_sensor_calibrate_clicked(object o, EventArgs args)
+ {
+ if(! portFSOpened) //TODO: better check is connected!
+ {
+ new DialogMessage(Constants.MessageTypes.WARNING, "Please, connect!");
+ return;
+ }
+
+ event_execute_label_message.Text = "Calibrating ...";
+ LogB.Information("calibrate:" + spin_force_sensor_calibration_kg_value.Value.ToString() +
";");
+ portFS.WriteLine("calibrate:" + spin_force_sensor_calibration_kg_value.Value.ToString() +
";");
+
+ string str = "";
+ do {
+ Thread.Sleep(100); //sleep to let arduino start reading
+ str = portFS.ReadLine();
+ LogB.Information("init string: " + str);
+ }
+ while(! str.Contains("Calibrating OK"));
+
+ event_execute_label_message.Text = "Calibrated!";
+ }
+
+
private void forceSensorCapture()
{
+ //TODO: check is connected!
+ //
+ /*
forceSensorPortName =
chronopicRegister.ConnectedOfType(ChronopicRegisterPort.Types.ARDUINO_FORCE).Port;
if(forceSensorPortName == null || forceSensorPortName == "")
{
new DialogMessage(Constants.MessageTypes.WARNING, "Please, select port");
return;
}
+ */
+ if(! portFSOpened) //TODO: better check is connected!
+ {
+ new DialogMessage(Constants.MessageTypes.WARNING, "Please, connect!");
+ return;
+ }
+
button_execute_test.Sensitive = false;
event_execute_button_finish.Sensitive = true;
@@ -95,18 +191,21 @@ public partial class ChronoJumpWindow
private void forceSensorCaptureDo()
{
lastChangedTime = 0;
+ /*
SerialPort port = new SerialPort(forceSensorPortName, 115200); //forceSensor
port.Open();
Thread.Sleep(2500); //sleep to let arduino start reading
+ */
- port.WriteLine("Start:-920.80:"); //Imp: note decimal is point
+ //port.WriteLine("Start:-920.80:"); //Imp: note decimal is point
+ portFS.WriteLine("start_capture:"); //Imp: note decimal is point
string str = "";
do {
Thread.Sleep(100); //sleep to let arduino start reading
- str = port.ReadLine();
+ str = portFS.ReadLine();
LogB.Information("init string: " + str);
}
- while(! str.StartsWith("StartedOk"));
+ while(! str.Contains("Starting capture"));
forceCaptureStartMark = true;
capturingForce = forceStatus.CAPTURING;
@@ -121,7 +220,7 @@ public partial class ChronoJumpWindow
double firstTime = 0;
while(! forceProcessFinish && ! forceProcessCancel)
{
- str = port.ReadLine();
+ str = portFS.ReadLine();
//check if there is one and only one ';'
if( ! (str.Contains(";") && str.IndexOf(";") == str.LastIndexOf(";")) )
@@ -130,6 +229,14 @@ public partial class ChronoJumpWindow
string [] strFull = str.Split(new char[] {';'});
//LogB.Information("str: " + str);
+ LogB.Information("time: " + strFull[0]);
+ if(! Util.IsNumber(Util.ChangeDecimalSeparator(strFull[0]), true))
+ continue;
+
+ LogB.Information("force: " + strFull[1]);
+ if(! Util.IsNumber(Util.ChangeDecimalSeparator(strFull[1]), true))
+ continue;
+
//needed to store double in user locale
double time = Convert.ToDouble(Util.ChangeDecimalSeparator(strFull[0]));
@@ -147,14 +254,14 @@ public partial class ChronoJumpWindow
//changeSlideIfNeeded(time, force);
}
- port.WriteLine("Stop");
+ portFS.WriteLine("end_capture:");
writer.Flush();
writer.Close();
((IDisposable)writer).Dispose();
capturingForce = forceStatus.STOP;
- port.Close();
+ //port.Close();
if(forceProcessCancel)
Util.FileDelete(fileName);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]