[chronojump] 699951 done for non-propulsive stuff
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] 699951 done for non-propulsive stuff
- Date: Thu, 30 May 2013 10:58:02 +0000 (UTC)
commit f8d872ebd7aebf3d7bed3320b9a9ae9fca5accd8
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu May 30 12:57:00 2013 +0200
699951 done for non-propulsive stuff
encoder/graph.R | 56 +++++++++++++++++++++--------
encoder/pyserial_pyper.py | 48 +++++++++----------------
encoder/pyserial_pyper_windows.py | 70 +++++++++++++++++++++---------------
3 files changed, 98 insertions(+), 76 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index e0b8349..47696cd 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -79,11 +79,14 @@ findCurves <- function(rawdata, eccon, min_height, draw, title) {
row=1; i=1; j=1
while(max(c(i,j)) <= min(c(length(b$minindex[,1]),length(b$maxindex[,1])))) {
+ #tempStart at the end of minindexs
+ #tempStart = b$minindex[i,2]
+
#tempStart at the mean of minindexs
- #tempStart = mean(c(b$minindex[i,1],b$minindex[i,2]))
+ #this is better because has more data in order to reduceCurveBySpeed
+ #then we get similar results than pyserial_pyper.py
+ tempStart = mean(c(b$minindex[i,1],b$minindex[i,2]))
- #tempStart at the end of minindexs
- tempStart = b$minindex[i,2]
#end at the mean of maximum values
#tempEnd = mean(c(b$maxindex[j,1],b$maxindex[j,2]))
@@ -162,13 +165,13 @@ findCurves <- function(rawdata, eccon, min_height, draw, title) {
mtext("height (cm) ",side=2,adj=1,line=-1)
abline(v=b$maxindex/1000,lty=3); abline(v=b$minindex/1000,lty=3) #ms -> s
- #plot speed
- speed <- smooth.spline( 1:length(rawdata), rawdata, spar=smoothingAll)
- abline(h=0,lty=2,col="yellow")
- lines((1:length(rawdata))/1000, speed$y*10, col="green")
- print("SPEEEDYYYY")
- print(max(speed$y))
- print(min(speed$y))
+ #plot speed (currently disabled)
+ #speed <- smooth.spline( 1:length(rawdata), rawdata, spar=smoothingAll)
+ #abline(h=0,lty=2,col="yellow")
+ #lines((1:length(rawdata))/1000, speed$y*10, col="green")
+ #print("SPEEEDYYYY")
+ #print(max(speed$y))
+ #print(min(speed$y))
}
return(as.data.frame(cbind(start,end,startH)))
}
@@ -180,6 +183,11 @@ findCurves <- function(rawdata, eccon, min_height, draw, title) {
reduceCurveBySpeed <- function(eccon, row, startT, rawdata, smoothingOneEC, smoothingOneC) {
a=rawdata
+ #debug
+ #print("startT and aaaaaaaaaaaaaaaaaaaaaaa")
+ #print(startT)
+ #print(a)
+
smoothing = 0
if(eccon == "c")
smoothing = smoothingOneC
@@ -187,9 +195,6 @@ reduceCurveBySpeed <- function(eccon, row, startT, rawdata, smoothingOneEC, smoo
speed <- smooth.spline( 1:length(a), a, spar=smoothing)
b=extrema(speed$y)
- #find the b$cross at left of max speed
- x.ini=1
-
#from searchValue, go to the left, searchValue is at max speed on going up
#but is min speed on going down (this happens when not "concentric" and when phase is odd (impar)
searchValue = max(speed$y)
@@ -200,9 +205,28 @@ reduceCurveBySpeed <- function(eccon, row, startT, rawdata, smoothingOneEC, smoo
maxSpeedT <- min(which(speed$y == searchValue))
- for(i in b$cross[,2]) { if(i < maxSpeedT) { x.ini = i } } #left adjust
-
- return(startT+x.ini)
+ #left adjust
+ #find the b$cross at left of max speed
+
+ x.ini = 0 #good to declare here
+ bcrossLen = length(b$cross[,2])
+ if(bcrossLen == 0)
+ x.ini = 0
+ else if(bcrossLen == 1)
+ x.ini = b$cross[,2]
+ else
+ for(i in b$cross[,2])
+ if(i < maxSpeedT)
+ x.ini = i
+
+ #debug
+ #print(b)
+ print(b$cross[,2])
+ #print(bcrossLen)
+ #print(maxSpeedT)
+ print(x.ini)
+
+ return(startT + x.ini)
}
findECPhases <- function(a,speed) {
diff --git a/encoder/pyserial_pyper.py b/encoder/pyserial_pyper.py
index e273bd9..d7ac9c7 100644
--- a/encoder/pyserial_pyper.py
+++ b/encoder/pyserial_pyper.py
@@ -82,13 +82,9 @@ direction_completed = -1 # 1 or -1
#This will be useful to know the start of movement
frames_pull_top1 = list()
-#frames_pull_top2 = list() #unused
frames_push_bottom1 = list()
-#frames_push_bottom2 = list() #unused
previous_frame_change = 0
-lag=20
-
mode = "graph"
#mode = "text"
@@ -165,29 +161,40 @@ def calculate_all_in_r(temp, top_values, bottom_values, direction_now,
myR.assign('a',temp[start:end])
- print("start:" + str(start) + "; end:" + str(end))
+ print("start:" + str(start) + "; end:" + str(end))
if direction_now == -1:
myR.run('speed <- smooth.spline( 1:length(a), a, spar=smoothingOne)')
+
#reduce curve by speed, the same way as graph.R
myR.run('b=extrema(speed$y)')
myR.run('maxSpeedT <- min(which(speed$y == max(speed$y)))')
maxSpeedT = myR.get('maxSpeedT')
bcrossLen = myR.get('length(b$cross[,2])')
bcross = myR.get('b$cross[,2]')
+
+ #debug
+ b = myR.get('b')
+ print("printing bbbbbbbbbbbb")
+ print(b)
+ print("printing bbbbbbbbbbbb cross")
+ print(bcross)
+ print("printing bbbbbbbbbbbb maxSpeedT")
+ print(maxSpeedT)
+
if bcrossLen == 0:
return
if bcrossLen == 1:
- x_ini = bcrossLen
+ x_ini = bcross #if bcross has only one item, then this fails: 'bcross[0]'.
Just do 'bcross'
else:
- x_ini = 0
+ x_ini = bcross[0]
for i in bcross:
if i < maxSpeedT:
x_ini = i #left adjust
myR.assign('a',temp[start+x_ini:end])
- print("start reduced:" + str(start + x_ini) + "; end:" + str(end))
+ print("start reduced (start+x_ini):" + str(start + x_ini) + " (x_ini:" + str(x_ini) +
"); end:" + str(end))
myR.run('speed <- smooth.spline( 1:length(a), a, spar=smoothingOne)')
myR.run('a.cumsum <- cumsum(a)')
@@ -475,9 +482,8 @@ if __name__ == '__main__':
temp = list() #raw values
temp_cumsum = list() #cumulative sums of raw values
temp_cumsum.append(0)
- #temp_speed = list() #unused
w_time = datetime.now().second
- #print "start read data"
+ print "start read data"
# Detecting if serial port is available and Recording the data from Chronopic.
for i in xrange(delete_initial_time):
#if ser.readable(): #commented because don't work on linux
@@ -505,17 +511,11 @@ if __name__ == '__main__':
byte_data = ser.read()
# conver HEX to INT value
signedChar_data = unpack('b' * len(byte_data), byte_data)[0]
-
+
temp.append(signedChar_data)
if(i>0):
temp_cumsum.append(temp_cumsum[i-1]+signedChar_data)
- #unused
- #if(i>lag):
- # temp_speed.append(1.0*(temp_cumsum[i]-temp_cumsum[i-lag])/lag)
- #else:
- # temp_speed.append(0)
-
msCount = msCount +1
if msCount == 1000 :
secondsLeft = secondsLeft -1
@@ -536,9 +536,6 @@ if __name__ == '__main__':
k=list(temp_cumsum[previous_frame_change:i-direction_change_period])
- #phase = 0 #unused
- #speed = 0 #unused
-
if direction_now == 1:
#we are going up, we passed the direction_change_count
#then we can record the bottom moment
@@ -555,11 +552,6 @@ if __name__ == '__main__':
new_frame_change =
previous_frame_change+len(k)-1-k[::-1].index(min(k))
print("NFC 1 2 (end zeros on the bottom) %i" % new_frame_change)
- #frames_push_bottom2.append(new_frame_change) #unused
- #phase = " down" #unused
-
- #if previous_frame_change != 0 and new_frame_change != 0:
- # speed =
min(temp_speed[previous_frame_change:new_frame_change])
else:
new_frame_change = previous_frame_change+k.index(max(k))
print("NFC 2 1 (start zeros on the top) %i" % new_frame_change)
@@ -569,12 +561,6 @@ if __name__ == '__main__':
new_frame_change =
previous_frame_change+len(k)-1-k[::-1].index(max(k))
print("NFC 2 2 (end zeros on the top) %i" % new_frame_change)
- #frames_pull_top2.append(new_frame_change) #unused
- #phase = " up" #unused
-
- #if previous_frame_change != 0 and new_frame_change != 0:
- # speed =
max(temp_speed[previous_frame_change:new_frame_change])
-
if len(frames_pull_top1)>0 and len(frames_push_bottom1)>0:
calculate_all_in_r(temp, frames_pull_top1, frames_push_bottom1,
diff --git a/encoder/pyserial_pyper_windows.py b/encoder/pyserial_pyper_windows.py
index fd01bc9..cf59981 100644
--- a/encoder/pyserial_pyper_windows.py
+++ b/encoder/pyserial_pyper_windows.py
@@ -85,13 +85,9 @@ direction_completed = -1 # 1 or -1
#This will be useful to know the start of movement
frames_pull_top1 = list()
-frames_pull_top2 = list()
frames_push_bottom1 = list()
-frames_push_bottom2 = list()
previous_frame_change = 0
-lag=20
-
mode = "graph"
#mode = "text"
@@ -168,25 +164,40 @@ def calculate_all_in_r(temp, top_values, bottom_values, direction_now,
myR.assign('a',temp[start:end])
+ print("start:" + str(start) + "; end:" + str(end))
+
if direction_now == -1:
myR.run('speed <- smooth.spline( 1:length(a), a, spar=smoothingOne)')
+
#reduce curve by speed, the same way as graph.R
myR.run('b=extrema(speed$y)')
myR.run('maxSpeedT <- min(which(speed$y == max(speed$y)))')
maxSpeedT = myR.get('maxSpeedT')
bcrossLen = myR.get('length(b$cross[,2])')
bcross = myR.get('b$cross[,2]')
+
+ #debug
+ b = myR.get('b')
+ print("printing bbbbbbbbbbbb")
+ print(b)
+ print("printing bbbbbbbbbbbb cross")
+ print(bcross)
+ print("printing bbbbbbbbbbbb maxSpeedT")
+ print(maxSpeedT)
+
if bcrossLen == 0:
return
if bcrossLen == 1:
- x_ini = bcrossLen
+ x_ini = bcross #if bcross has only one item, then this fails: 'bcross[0]'.
Just do 'bcross'
else:
+ x_ini = bcross[0]
for i in bcross:
if i < maxSpeedT:
x_ini = i #left adjust
myR.assign('a',temp[start+x_ini:end])
+ print("start reduced (start+x_ini):" + str(start + x_ini) + " (x_ini:" + str(x_ini) +
"); end:" + str(end))
myR.run('speed <- smooth.spline( 1:length(a), a, spar=smoothingOne)')
myR.run('a.cumsum <- cumsum(a)')
@@ -198,7 +209,12 @@ def calculate_all_in_r(temp, top_values, bottom_values, direction_now,
# else:
# myR.run('force <- mass*accel$y')
myR.run('power <- force*speed$y')
- myR.run('meanPower <- mean(abs(power))')
+
+ if eccon == "c":
+ myR.run('meanPower <- mean(power)')
+ else:
+ myR.run('meanPower <- mean(abs(power))')
+
myR.run('peakPower <- max(power)')
#without the 'min', if there's more than one value it returns a list and this make crash
later in
@@ -477,7 +493,6 @@ if __name__ == '__main__':
temp = list() #raw values
temp_cumsum = list() #cumulative sums of raw values
temp_cumsum.append(0)
- temp_speed = list()
w_time = datetime.now().second
print "start read data"
# Detecting if serial port is available and Recording the data from Chronopic.
@@ -498,12 +513,11 @@ if __name__ == '__main__':
for event in pygame.event.get():
if event.type == pygame.QUIT or (event.type == KEYUP and event.key == K_ESCAPE):
userStops = TRUE
-
+
if userStops:
print "USER BREAKS"
break
-
#if ser.readable(): #commented because don't work on linux
byte_data = ser.read()
@@ -513,11 +527,7 @@ if __name__ == '__main__':
temp.append(signedChar_data)
if(i>0):
temp_cumsum.append(temp_cumsum[i-1]+signedChar_data)
- if(i>lag):
- temp_speed.append(1.0*(temp_cumsum[i]-temp_cumsum[i-lag])/lag)
- else:
- temp_speed.append(0)
-
+
msCount = msCount +1
if msCount == 1000 :
secondsLeft = secondsLeft -1
@@ -538,29 +548,31 @@ if __name__ == '__main__':
k=list(temp_cumsum[previous_frame_change:i-direction_change_period])
- phase = 0
- speed = 0
-
if direction_now == 1:
- #we are going up, we passed the ditection_change_count
+ #we are going up, we passed the direction_change_count
#then we can record the bottom moment
- #and print speed on going down
- new_frame_change = previous_frame_change+k.index(min(k))
+ #and print speed on going down (Not done anymore)
+
+ #this has (maybe) 0,-1,0,0,0,0,0, .... (and -1 can be selected
(min(k)).
+ #Then, do not pass this to frames_push_bottom, pass the next
new_frame_change
+
+ new_frame_change = previous_frame_change+k.index(min(k))
+ print("NFC 1 1 (start zeros on the bottom) %i" % new_frame_change)
+
frames_push_bottom1.append(new_frame_change)
+
new_frame_change =
previous_frame_change+len(k)-1-k[::-1].index(min(k))
- frames_push_bottom2.append(new_frame_change)
- phase = " down"
- if previous_frame_change != 0 and new_frame_change != 0:
- speed =
min(temp_speed[previous_frame_change:new_frame_change])
+ print("NFC 1 2 (end zeros on the bottom) %i" % new_frame_change)
+
else:
new_frame_change = previous_frame_change+k.index(max(k))
+ print("NFC 2 1 (start zeros on the top) %i" % new_frame_change)
+
frames_pull_top1.append(new_frame_change)
+
new_frame_change =
previous_frame_change+len(k)-1-k[::-1].index(max(k))
- frames_pull_top2.append(new_frame_change)
- phase = " up"
- if previous_frame_change != 0 and new_frame_change != 0:
- speed =
max(temp_speed[previous_frame_change:new_frame_change])
-
+ print("NFC 2 2 (end zeros on the top) %i" % new_frame_change)
+
if len(frames_pull_top1)>0 and len(frames_push_bottom1)>0:
calculate_all_in_r(temp, frames_pull_top1, frames_push_bottom1,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]