In [1]:
data.frame(R.Version())
When creating a CSV file from OpenRocket, take the "kitchen sink" approach. If it gives you an option to include something, include it. Missing data may cause this script to break or give misleading/unexpected output.
The comment character should be an octothorpe (#
). The CSV should include commented lines for when certain events occur, such as the apogee.
In [2]:
# CSV file you want to look at
#csvName <- 'simData/LV3_L13_O3400_2018-02-06.csv'
csvName <- 'simData/LV3_L13_N2501_2018-02-06.csv'
cat('This cell DOES auto-complete parens and quotes. (awful!)')
In [ ]:
cat('This cell doesn\'t auto-complete my parens or quotes. (nice!)')
cat('And, now that I\'ve restarted the server and the kernel, it DOES!)
In [ ]:
cat('This cell was created after the kernel was started, and it doesn\'t.')
cat('After re-opening the cell, it still behaves correctly.')
In [3]:
#### parse the CSV file ####
simStringLines <- readLines(csvName)#read the CSV as a vector of the lines
dat <- read.csv(#load the simulation from a CSV into a data frame
csvName,
comment.char= "#",#ignore commented lines
nrows= grep("APOGEE", simStringLines)#stop reading [slightly] after apogee
)
if (!exists("dat")) stop("Couldn't find ", csvName) # check that we sucessfully read the CSV
datNames <- simStringLines[grep("Time", simStringLines)] # extract the column names
datNames <- sub(pattern= "# ", replacement= "", x= datNames) # remove comment char
datNames <- strsplit(datNames, split= ",")[[1]] # break apart into a vector
datNames <- gsub("[^[:alnum:]///' ]", "", datNames)#regex black magic (remove weird chars)
datNames <- sub(pattern= " ", replacement= "_", datNames)#replace spaces with underscores
datNames <- sub(pattern= " ", replacement= "_", datNames)#nonbreaking spaces?
datNames <- sub(pattern= " ", replacement= "_", datNames)#other magical spaces?!
colnames(dat) <- datNames # name the columns
head(dat)
In [4]:
flightMaximums <- sapply(1:ncol(dat), function(i) max(dat[,i], na.rm = T))
names(flightMaximums) <- names(dat)
In [5]:
cat('Maximum values:\n')
flightMaximums
In [6]:
par.old <- par()
layout(matrix(c(1,2), nrow=2), heights = c(1,1))
par(mar=c(0,5,2,2))
plot(
dat$Time_s, dat$Stability_margin_calibers_,
type='l', ylim=c(0, max(dat$Stab, na.rm=T)),
xlab='time (s)', ylab=NA, xaxt='n',
main='Characterizing Plots'
)
lines(dat$Time_s, dat$Angle_of_attack_, col='gray')
grid(col='darkgray')
legend(
'center',
legend=c(
'stability margin calibers',
'angle of attack (degrees)',
paste('SMC off rail = ', na.omit(dat$Stability)[1])
),
col=c('black', 'gray', NA),
lty=1
)
par(mar=c(5,5,0,2))
plot(
dat$Time, dat$Vertical_orientation_zenith_,
xlab='time (s)', ylab= 'vertical orientation\n(degrees)',
type='l'
)
grid(col='gray')
suppressWarnings(par(par.old))