[chronojump] Encoder: capture with only one graphical window
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Encoder: capture with only one graphical window
- Date: Tue, 20 Nov 2012 18:22:59 +0000 (UTC)
commit a86ec89c1cc335045907ac6ee33cee7f826b10c2
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Nov 20 19:21:36 2012 +0100
Encoder: capture with only one graphical window
encoder/graph.R | 16 ++++++++++---
encoder/pyserial_pyper.py | 53 ++++++++++++++++++++++++++++++++++-----------
src/util.cs | 17 ++++++++++----
3 files changed, 64 insertions(+), 22 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index d4494b8..0e7e6a6 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -189,7 +189,9 @@ paint <- function(rawdata, eccon, xmin, xmax, yrange, knRanges, superpose, highl
#eccons ec and ec-rep is the same here (only show one curve)
#receive data as cumulative sum
lty=c(1,1,1)
-
+
+#xmin=xmin-500
+
rawdata=rawdata[xmin:xmax]
a=cumsum(rawdata)
a=a+startH
@@ -217,6 +219,7 @@ paint <- function(rawdata, eccon, xmin, xmax, yrange, knRanges, superpose, highl
axis(1) #can be added xmin
axis(2)
}
+
par(new=T)
colNormal="black"
if(superpose)
@@ -250,6 +253,7 @@ paint <- function(rawdata, eccon, xmin, xmax, yrange, knRanges, superpose, highl
axis(4, col=cols[1], lty=lty[1], line=0, padj=-.5)
abline(h=0,lty=3,col="black")
}
+ #mtext(text=paste("max speed:",round(max(speed$y),3)),side=3,at=which(speed$y == max(speed$y)),cex=.8,col=cols[1])
}
#show extrema values in speed
@@ -290,15 +294,15 @@ paint <- function(rawdata, eccon, xmin, xmax, yrange, knRanges, superpose, highl
abline(v=max(crossDownToUp),col=cols[1])
mtext(text=min(crossDownToUp),side=1,at=min(crossDownToUp),cex=.8,col=cols[1])
mtext(text=max(crossDownToUp),side=1,at=max(crossDownToUp),cex=.8,col=cols[1])
- mtext(text="eccentric ",side=3,at=min(crossDownToUp),cex=.8,adj=1,col=cols[1])
- mtext(text=" concentric ",side=3,at=max(crossDownToUp),cex=.8,adj=0,col=cols[1])
+ mtext(text="eccentric ",side=3,at=min(crossDownToUp),cex=.8,adj=1,col=cols[1],line=.5)
+ mtext(text=" concentric ",side=3,at=max(crossDownToUp),cex=.8,adj=0,col=cols[1],line=.5)
}
}
accel <- predict( speed, deriv=1 )
#speed comes in mm/ms when derivate to accel its mm/ms^2 to convert it to m/s^2 need to *1000 because it's quadratic
accel$y <- accel$y * 1000
-
+
#print(accel$y)
#alternative R method (same result)
#accel2 <- D1ss( 1:length(speed$y), speed$y )
@@ -345,6 +349,7 @@ paint <- function(rawdata, eccon, xmin, xmax, yrange, knRanges, superpose, highl
if(axesAndTitle)
axis(4, col="magenta", lty=lty[1], line=2, padj=-.5)
+ #mtext(text=paste("max accel:",round(max(accel$y),3)),side=3,at=which(accel$y == max(accel$y)),cex=.8,col=cols[1],line=2)
}
#print(c(knRanges$accely, max(accel$y), min(accel$y)))
@@ -497,6 +502,9 @@ paintPowerPeakPowerBars <- function(paf, myEccons, height) {
par(new=T, xpd=T)
plot(bp[2,],height,type="l",lwd=2,xlim=c(1,n*3+.5),ylim=c(0,max(height)),axes=F,xlab="",ylab="",col="green")
legend("bottom",col=c(pafColors,"green"), lty=c(0,0,1,1), lwd=c(1,1,2,2), pch=c(15,15,NA,NA), legend=c("Power","Peak Power", "Time at Peak Power ", "Height"), ncol=4, inset=-.2)
+ abline(h=max(height),lty=2, col="green")
+ abline(h=min(height),lty=2, col="green")
+# text(max(bp[,2]),max(height),max(height),adj=c(0,.5),cex=0.8)
axis(4, col="green", line=3, padj=-.5)
mtext("Height (cm)", side=4, line=2)
}
diff --git a/encoder/pyserial_pyper.py b/encoder/pyserial_pyper.py
index ad329b3..61f46ff 100644
--- a/encoder/pyserial_pyper.py
+++ b/encoder/pyserial_pyper.py
@@ -141,6 +141,7 @@ def assignColor(found, conditionHigher, conditionLower):
else:
return BLACK
+rangeList = list()
meanPowerList = list()
def calculate_all_in_r(temp, top_values, bottom_values, direction_now, smoothingOne, eccon, minHeight, isJump):
if (len(top_values)>0 and len(bottom_values)>0):
@@ -241,8 +242,9 @@ def calculate_all_in_r(temp, top_values, bottom_values, direction_now, smoothing
if play:
playsound(soundFile)
+ rangeList.append(height)
meanPowerList.append(meanPower)
- update_graph(meanPowerList)
+ update_graph(rangeList,meanPowerList)
else:
print chr(27) + "[0;47m" + phase + "%6i," % height + " " + "Discarded" + chr(27)+"[0m"
@@ -260,12 +262,15 @@ def calculate_range(temp_cumsum, top_values, bottom_values, direction_now):
# print(text,rmax-rmin)
return(rmax-rmin)
-def update_graph(meanPowerList):
+#range: Range of movement (height in some parts of the code)
+def update_graph(rangeList, meanPowerList):
s=pygame.Surface((surface_width,surface_height))
horiz_margin = 10
vert_margin = 20
+ max_range = max(rangeList)
+
max_power = max(meanPowerList)
if powerLowerCondition > max_power:
max_power = powerLowerCondition
@@ -278,22 +283,38 @@ def update_graph(meanPowerList):
s.fill((30,30,30)) #color the surface
screen.fill((0,0,0)) #make redraw background black
- sep=4
+ sep=20 #between reps
+ sep_small=2 #between bars
count = 0
- font = pygame.font.Font(None, 22)
+ fontBig = pygame.font.Font(None, 22)
+ fontSmall = pygame.font.Font(None, 18)
+ colorRange = (200,200,200)
+ colorPower = (255,255,255)
for meanPower in meanPowerList:
- bar_height = surface_height - ((surface_height * meanPower / max_power) - 2*vert_margin)
+ if count > 10:
+ sep = 10
+ range_height = surface_height - ((surface_height * (rangeList[count]) / max_range ) - 2*vert_margin)
+ power_height = surface_height - ((surface_height * meanPower / max_power) - 2*vert_margin)
if len(meanPowerList) == 1:
width = (surface_width - 2*horiz_margin) / 2 #do not fill all the screen with only one bar
else:
width = (surface_width - 2*horiz_margin) / len(meanPowerList)
left = horiz_margin + width*count
- #pygame.draw.rect(s, (255,255,255), (left, bar_height, width-sep, surface_height-bar_height), 2)
- pygame.draw.rect(s, (255,255,255), (left, bar_height, width-sep, surface_height-bar_height), 0) #0: filled
+ range_width = width/4
+ #pygame.draw.rect(s, (255,255,255), (left, power_height, width-sep, surface_height-power_height), 2)
+ pygame.draw.rect(s, colorRange, (left, range_height, range_width, surface_height-range_height), 0) #0: filled
+ power_width = width - range_width - sep_small - sep
+ pygame.draw.rect(s, colorPower, (left+range_width+sep_small, power_height, power_width, surface_height-power_height), 0) #0: filled
- string = "%.2f" % meanPower
- text = font.render(string,1,(255,255,255))
- textpos = text.get_rect(centerx=left+width/2, centery=bar_height-vert_margin)
+ string = "%.0f" % rangeList[count]
+ text = fontSmall.render(string,1,colorRange)
+ textpos = text.get_rect(centerx=left+(range_width/2), centery=range_height-vert_margin)
+ s.blit(text,textpos)
+
+ #string = "%.2f" % meanPower
+ string = "%.0f" % meanPower
+ text = fontBig.render(string,1,colorPower)
+ textpos = text.get_rect(centerx=left+range_width+sep_small+(power_width/2), centery=power_height-vert_margin)
s.blit(text,textpos)
count = count +1
@@ -361,9 +382,12 @@ if __name__ == '__main__':
pygame.font.init
pygame.init()
- screen = pygame.display.set_mode((640,480)) #make window
- surface_width=640
- surface_height=440
+ #screen = pygame.display.set_mode((640,480)) #make window
+ #surface_width=640
+ #surface_height=440
+ screen = pygame.display.set_mode((800,600)) #make window
+ surface_width=800
+ surface_height=540
for i in xrange(record_time):
@@ -482,6 +506,9 @@ if __name__ == '__main__':
print "\nDone! Please, close this window."
while 1:
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT: sys.exit()
+
pygame.time.delay(30)
pygame.display.flip() #update the screen
#TODO: http://stackoverflow.com/questions/10466590/hiding-pygame-display
diff --git a/src/util.cs b/src/util.cs
index c5dc180..a38e672 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -995,7 +995,7 @@ public class Util
}
//python program
- public static void RunPythonEncoder(string pythonScript, EncoderStruct es, bool useTerminal) {
+ public static void RunPythonEncoder(string pythonScript, EncoderStruct es, bool capture) {
CancelRScript = false;
ProcessStartInfo pinfo;
@@ -1004,9 +1004,11 @@ public class Util
//in which we may haven't got permissions
string pBin="python";
- if(useTerminal) {
+
+ //currently we are not using useTerminal. It was originally to encoder capture with text and graph
+ useTerminal = false;
+ if(useTerminal)
pBin="xterm";
- }
// if (IsWindows())
// pBin=System.IO.Path.Combine(GetPrefixDir(), "bin/python.exe");
@@ -1015,9 +1017,14 @@ public class Util
pinfo.FileName=pBin;
string outputFileCheck = "";
- if(useTerminal) {
- pinfo.Arguments = "-bg white -fg black -hold -geometry 72x34+100+40 -fn *-fixed-*-*-*-20-* -e \"python " +
+ if(capture) {
+ if(useTerminal) {
+ //currentl we are not using this
+ pinfo.Arguments = "-bg white -fg black -hold -geometry 72x34+100+40 -fn *-fixed-*-*-*-20-* -e \"python " +
pythonScript + " " + es.OutputData1 + " " + es.Ep.ToString1() + "\"";
+ } else
+ pinfo.Arguments = pythonScript + " " + es.OutputData1 + " " + es.Ep.ToString1();
+
outputFileCheck = es.OutputData1;
} else {
pinfo.Arguments = pythonScript + " " + es.InputData + " " +
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]