-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCharacterizationScript.R
More file actions
37 lines (32 loc) · 2.04 KB
/
CharacterizationScript.R
File metadata and controls
37 lines (32 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#Provided by team 449
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))));
}
characterize <- function(smoothing = 2){
vel <- read.csv(file="c:\vel", header=TRUE, sep=",")
accel <- read.csv(file="c:\accel", header=TRUE, sep=",")
goodVel <- subset(vel, abs(Drive.left_vel) > 0.1 & Drive.left_voltage!=0 & abs(Drive.right_vel) > 0.1 & Drive.right_voltage!=0)
goodVel$left_accel <- smoothDerivative(goodVel$Drive.left_vel, goodVel$time, smoothing)
goodVel$right_accel <- smoothDerivative(goodVel$Drive.right_vel, goodVel$time, smoothing)
accel$left_accel <- smoothDerivative(accel$Drive.left_vel, accel$time, smoothing)
accel$right_accel <- smoothDerivative(accel$Drive.right_vel, accel$time, smoothing)
goodAccel <- subset(accel, Drive.left_voltage != 0 & Drive.right_voltage != 0)
goodAccelLeft <- goodAccel[(which.max(abs(goodAccel$left_accel))+1):length(goodAccel$time),]
goodAccelRight <- goodAccel[(which.max(abs(goodAccel$right_accel))+1):length(goodAccel$time),]
combinedLeftVoltage <- c(goodVel$Drive.left_voltage, goodAccelLeft$Drive.left_voltage)
combinedRightVoltage <- c(goodVel$Drive.right_voltage, goodAccelRight$Drive.right_voltage)
combinedLeftVel <- c(goodVel$Drive.left_vel, goodAccelLeft$Drive.left_vel)
combinedRightVel <- c(goodVel$Drive.right_vel, goodAccelRight$Drive.right_vel)
combinedLeftAccel <- c(goodVel$left_accel, goodAccelLeft$left_accel)
combinedRightAccel <- c(goodVel$right_accel, goodAccelRight$right_accel)
plot(goodAccelLeft$time, goodAccelLeft$left_accel)
plot(goodVel$time, goodVel$Drive.left_voltage)
plot(goodVel$Drive.left_voltage, goodVel$Drive.left_vel)
leftModel <- lm(combinedLeftVoltage~combinedLeftVel+combinedLeftAccel)
rightModel <- lm(combinedRightVoltage~combinedRightVel+combinedRightAccel)
print(summary(leftModel))
print(summary(rightModel))
}
f <- characterize()
f