-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Noah Gleason
committed
Oct 17, 2017
1 parent
3187eff
commit 6d2a972
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
rad2deg <- function(rad) {(rad * 180) / (pi)} | ||
deg2rad <- function(deg) {(deg * pi) / (180)} | ||
|
||
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)))); | ||
} | ||
|
||
plotWheelVsVel <- function(leftPos, rightPos, rawAngleDegrees, timeMillis, angularVelThreshRad, smoothingConst){ | ||
#Smooth values | ||
angular <- deg2rad(smoothValue(rawAngleDegrees, timeMillis, smoothingConst)) | ||
left <- smoothValue(leftPos, timeMillis, smoothingConst) | ||
right <- smoothValue(rightPos, timeMillis, smoothingConst) | ||
|
||
#find effective wheelbase | ||
wheelbase <- calcWheelbase(left, right, angular) | ||
|
||
#Filter out low angular vel points | ||
combined <- cbind(angular, wheelbase, (left+right)/2) | ||
combinedAngular <- subset(combined, combined[,1] > angularVelThreshRad) | ||
|
||
#Find the mean wheelbase, weighted by angular vel | ||
avgWheelbase = weighted.mean(x=combinedAngular[,2], w=combinedAngular[,1], na.rm=TRUE) | ||
|
||
#plot angular | ||
plot(x=combinedAngular[,1], y=combinedAngular[,2], xlab="Angular Velocity (rad/sec)", ylab="Effective wheelbase diameter (feet)", main="Effective Wheelbase Diameter vs. Angular Velocity") | ||
abline(a=avgWheelbase, b=0, col='green') | ||
|
||
#plot linear | ||
plot(x=combinedAngular[,3], y=combinedAngular[,2], xlab="Linear Velocity (feet/sec)", ylab="Effective wheelbase diameter (feet)", main="Effective Wheelbase Diameter vs. Linear Velocity") | ||
abline(a=avgWheelbase, b=0, col='green') | ||
|
||
#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) | ||
} |