Skip to content

Commit

Permalink
Get retroactive pose script working
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Gleason committed Oct 18, 2017
1 parent 6d2a972 commit a46261c
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions R scripts/poseEstimationChecker.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ calcWheelbase <- function(left, right, angle){
return((left-right)/angle);
}

smoothValue <- function(value, timeMillis, n){
smoothed <- (value[(n+1):length(value)] - value[1:(length(value)-n)])/(timeMillis[(n+1):length(timeMillis)] - timeMillis[1:(length(timeMillis)-n)])*1000;
return(c(rep(0, floor(n/2)), smoothed, rep(0, ceiling(n/2))));
smoothDerivative <- function(value, timeMillis, n){
smoothed <- (value[(n+1):length(value)] - value[1:(length(value)-n)])/((timeMillis[(n+1):length(timeMillis)] - timeMillis[1:(length(timeMillis)-n)])/1000);
return(c(rep(0, ceiling(n/2)), smoothed, rep(0, floor(n/2))));
}

plotWheelVsVel <- function(leftPos, rightPos, rawAngleDegrees, timeMillis, angularVelThreshRad, smoothingConst){
rawAngle <- deg2rad(rawAngleDegrees)

#Smooth values
angular <- deg2rad(smoothValue(rawAngleDegrees, timeMillis, smoothingConst))
left <- smoothValue(leftPos, timeMillis, smoothingConst)
right <- smoothValue(rightPos, timeMillis, smoothingConst)
angular <- smoothDerivative(rawAngle, timeMillis, smoothingConst)
left <- smoothDerivative(leftPos, timeMillis, smoothingConst)
right <- smoothDerivative(rightPos, timeMillis, smoothingConst)

#find effective wheelbase
wheelbase <- calcWheelbase(left, right, angular)
Expand All @@ -37,7 +39,29 @@ plotWheelVsVel <- function(leftPos, rightPos, rawAngleDegrees, timeMillis, angul
#Plot turn radius
plot(x=combinedAngular[,3]/combinedAngular[,1], y=combinedAngular[,2]-2.0833, xlab="Turn Radius (feet)", ylab="Error in wheelbase diameter (feet)", main="Error in Wheelbase Diameter vs. Turn Radius")
abline(a=avgWheelbase-2.0833, b=0, col='green')


return(angular)
sumLeft <- 0
out <- array(dim=c(length(angular),7))
colnames(out)<-c("X","Y","leftX","leftY","rightX","rightY","time")
out[1,] <- c(leftPos[1],rightPos[1],NA,NA,NA,NA,timeMillis[1])
for(i in 2:length(angular)){
deltaTime <- (timeMillis[i] - out[i-1,7])/1000
deltaLeft <- leftPos[i]-leftPos[i-1]
deltaRight <- rightPos[i]-rightPos[i-1]
deltaTheta <- rawAngle[i]-rawAngle[i-1]
avgMoved <- (deltaLeft+deltaRight)/2

sumLeft <- sumLeft + deltaLeft
if (deltaTheta == 0){
out[i,] <- c(out[i-1,1]+avgMoved*cos(rawAngle[i]),out[i-1,2]+avgMoved*sin(rawAngle[i]), NA, NA, NA, NA, timeMillis[i])
} else {
angle <- rawAngle[i-1]-(deltaTheta/2)
mag <- 2*(avgMoved/deltaTheta)*sin(deltaTheta/2)
out[i,] <- c(out[i-1,1]+mag*cos(angle), out[i-1,2]+mag*sin(angle), NA, NA, NA, NA, timeMillis[i])
}
}

plot(out[,1], out[,2], t="l")

return(sumLeft)
}

0 comments on commit a46261c

Please sign in to comment.