[chronojump] On raceAnalyzer capture shown speed in real time with a radial Cairo graph
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] On raceAnalyzer capture shown speed in real time with a radial Cairo graph
- Date: Tue, 15 Dec 2020 16:47:04 +0000 (UTC)
commit 4ac9058d53798079e96f06cd203f9c96fade32b3
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Dec 15 17:45:20 2020 +0100
On raceAnalyzer capture shown speed in real time with a radial Cairo graph
src/gui/app1/runEncoder.cs | 30 ++++++++++++++++++++++++++----
src/gui/cairo/radial.cs | 34 ++++++++++++++++------------------
2 files changed, 42 insertions(+), 22 deletions(-)
---
diff --git a/src/gui/app1/runEncoder.cs b/src/gui/app1/runEncoder.cs
index c0612000..c234ab22 100644
--- a/src/gui/app1/runEncoder.cs
+++ b/src/gui/app1/runEncoder.cs
@@ -29,6 +29,7 @@ using System.Text; //StringBuilder
using System.Collections;
using System.Collections.Generic; //List<T>
using System.Text.RegularExpressions; //Regex
+using System.Diagnostics; //Stopwatch
using Mono.Unix;
@@ -237,6 +238,7 @@ public partial class ChronoJumpWindow
runEncoderPulseMessage = "";
runEncoderButtonsSensitive(false);
sensitiveLastTestButtons(false);
+ runEncoderCaptureSpeed = 0;
if(chronopicRegister.NumConnectedOfType(ChronopicRegisterPort.Types.ARDUINO_RUN_ENCODER) == 0)
{
@@ -385,7 +387,6 @@ public partial class ChronoJumpWindow
event_execute_ButtonCancel.Clicked -= new EventHandler(on_cancel_clicked);
event_execute_ButtonCancel.Clicked += new EventHandler(on_cancel_clicked);
- runEncoderCaptureSpeed = 0;
runEncoderCaptureThread = new Thread(new ThreadStart(runEncoderCaptureDo));
GLib.Idle.Add (new GLib.IdleHandler (pulseGTKRunEncoderCapture));
@@ -466,6 +467,7 @@ public partial class ChronoJumpWindow
str = "";
int firstTime = 0;
int timePre = 0;
+ Stopwatch sw = new Stopwatch();
int rowsCount = 0;
while(! runEncoderProcessFinish && ! runEncoderProcessCancel && ! runEncoderProcessError)
@@ -485,7 +487,16 @@ public partial class ChronoJumpWindow
*/
if (portRE.BytesToRead == 0)
+ {
+ //runEncoder sends changes. If there is no movement in certain time, just
show a 0 on screen and capture graph
+ if(sw.ElapsedMilliseconds > 500)
+ {
+ runEncoderCaptureSpeed = 0;
+ sw.Stop();
+ }
+
continue;
+ }
//time (4 bytes: long at Arduino, uint at c-sharp), force (2 bytes: uint)
List<int> binaryReaded = readBinaryRunEncoderValues();
@@ -494,9 +505,17 @@ public partial class ChronoJumpWindow
int force = binaryReaded[2];
int encoderOrRCA = binaryReaded[3];
- runEncoderCaptureSpeed = UtilAll.DivideSafe(Math.Abs(encoderDisplacement) * 1000000 *
0.003003, (time - timePre)); //hardcoded: same as sprintEncoder.R
- //LogB.Information("runEncoderCaptureSpeed: " +
UtilAll.DivideSafe(Math.Abs(encoderDisplacement) * 1000000 * 0.003003, (time - timePre)).ToString());
//hardcoded: same as sprintEncoder.R
- timePre = time;
+ if(time > timePre)
+ {
+ if(timePre > 0)
+ {
+ runEncoderCaptureSpeed =
UtilAll.DivideSafe(Math.Abs(encoderDisplacement) * 1000000 * 0.003003, (time - timePre)); //hardcoded: same
as sprintEncoder.R
+ LogB.Information(string.Format("encoderDisplacement: {0};
runEncoderCaptureSpeed: {1}; time: {2}; timePre: {3}",
+ encoderDisplacement, runEncoderCaptureSpeed,
time, timePre));
+ }
+ timePre = time;
+ sw.Restart();
+ }
LogB.Information(string.Format("{0};{1};{2};{3};{4}", pps, encoderDisplacement, time,
force, encoderOrRCA));
writer.WriteLine(string.Format("{0};{1};{2}", encoderDisplacement, time, force));
@@ -514,6 +533,7 @@ public partial class ChronoJumpWindow
triggerListRunEncoder.Add(trigger);
}
}
+ sw.Stop();
LogB.Information(string.Format("FINISHED WITH conditions: {0}-{1}-{2}",
runEncoderProcessFinish, runEncoderProcessCancel,
runEncoderProcessError));
@@ -1302,6 +1322,8 @@ public partial class ChronoJumpWindow
event_execute_label_message.Text = runEncoderPulseMessage;
label_race_analyzer_capture_speed.Text = Util.TrimDecimals(runEncoderCaptureSpeed,3)
+ " m/s";
+ cairoRadial.GraphSpeed(runEncoderCaptureSpeed);
+
if(runEncoderPulseMessage == capturingMessage)
event_execute_button_finish.Sensitive = true;
}
diff --git a/src/gui/cairo/radial.cs b/src/gui/cairo/radial.cs
index c7c73a86..fa2ca45d 100644
--- a/src/gui/cairo/radial.cs
+++ b/src/gui/cairo/radial.cs
@@ -55,9 +55,8 @@ public class CairoRadial
g.SetSourceRGB(1,1,1);
g.Paint();
- //graphWidth = Convert.ToInt32(area.Allocation.Width *.8);
- graphWidth = area.Allocation.Width;
- graphHeight = area.Allocation.Height;
+ graphWidth = area.Allocation.Width - 2*margin;
+ graphHeight = area.Allocation.Height - 2*margin;
g.SetSourceRGB(0,0,0);
g.LineWidth = 2;
@@ -73,17 +72,17 @@ public class CairoRadial
//blue = colorFromRGB(178, 223, 238); //lightblue
//bluePlots = colorFromRGB(0, 0, 200);
- g.MoveTo(5,10);
- g.LineTo(20,30);
- g.Color = red;
- g.Stroke();
-
g.Color = black;
- //TODO: correctly operate with the margins
- printText(graphWidth/2 -margin, margin, 0, textHeight, "0", g, alignTypes.CENTER);
- printText(graphWidth -margin, graphHeight/2 -margin, 0, textHeight, "5", g,
alignTypes.CENTER);
- printText(graphWidth/2 -margin, graphHeight-margin, 0, textHeight, "10", g,
alignTypes.CENTER);
- printText(margin, graphHeight/2-margin, 0, textHeight, "15", g, alignTypes.CENTER);
+ double minSide = graphWidth;
+ if(graphHeight < minSide)
+ minSide = graphHeight;
+ for(int i = 0; i < 20; i ++)
+ {
+ double iArc = (2*Math.PI / maxValue) * i;
+ printText(Convert.ToInt32(margin + graphWidth/2 + (minSide/2) * 1 * Math.Cos(iArc -
Math.PI/2)),
+ Convert.ToInt32(margin + graphHeight/2 + (minSide/2) * 1 *
Math.Sin(iArc - Math.PI/2)),
+ 0, textHeight, i.ToString(), g, alignTypes.CENTER);
+ }
}
//TODO: currently max is 20
@@ -95,21 +94,20 @@ public class CairoRadial
double speedArc = (2*Math.PI / maxValue) * speed;
- g.SetSourceRGB(0.5, 0.5, 0.5);
- g.MoveTo(graphWidth/2, graphHeight/2);
+ //g.SetSourceRGB(0.5, 0.5, 0.5);
+ g.MoveTo(margin + graphWidth/2, margin + graphHeight/2);
double minSide = graphWidth;
if(graphHeight < minSide)
minSide = graphHeight;
//thanks to: http://ralph-glass.homepage.t-online.de/clock/readme.html
- g.LineTo(graphWidth/2 + (minSide/2 -2*margin) * 0.9 * Math.Cos(speedArc - Math.PI/2),
- graphHeight/2 + (minSide/2 -2*margin) * 0.9 * Math.Sin(speedArc - Math.PI/2));
+ g.LineTo(margin + graphWidth/2 + (minSide/2) * .9 * Math.Cos(speedArc - Math.PI/2),
+ margin + graphHeight/2 + (minSide/2) * .9 * Math.Sin(speedArc - Math.PI/2));
g.Color = red;
g.Stroke();
endGraphDisposing();
- LogB.Information("Graph speed done!");
}
//TODO: all this methods have to be shared with xy.cs
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]