R/calc_vsp.R

Defines functions calc_vsp

Documented in calc_vsp

#' Calculate VSP
#'
#' This function simply calculates VSP using the methods outlined in the Davison 2020 STOTEN paper.
#' This is useful for remote sensing datasets in conjuction with, for example, dplyr::mutate().
#'
#'
#' @param mass Vehicle mass in kg or tonnes
#' @param speed Vehicle speed in m/s, mph or km/h.
#' @param accel Vehicle acceleration in m/s/s, mph/s or km/h/s.
#' @param R0 Rolling coefficient. Defaults to generic diesel car value 157.
#' @param R1 Rolling coefficient. Defaults to generic diesel car value 0.95.
#' @param CdA Air resistance coefficient. Defaults to generic diesel car value 0.660.
#' @param aux Auxiliary power demand in W. Defaults to 2500.
#' @param mass_unit The unit of the vehicle mass provided. Can be "kg" or "t". Defaults to "kg".
#' @param speed_unit The unit of the vehicle speed provided. Can be "ms", "mph" or "kmh". Defaults to "ms".
#' @param accel_unit The unit of the vehicle acceleration provided. Can be "mss", "mphs" or "kmhs". Defaults to "mss".
#' @param grad_unit The unit of the road gradient provided. Can be "rr" (rise over run), "perc" or "deg". Defaults to "rr".
#' @param vehicle_specific Logical. If true (default), returns vehicle specific power in kW/t. If false, returns vehicle power in W.
#' @return A value of vehicle (specific) power.
#' @export

calc_vsp = function(mass = 1750, speed, accel, grad = 0,
                    R0 = 157, R1 = 0.95, CdA = 0.660, aux = 2500,
                    mass_unit = "kg",
                    speed_unit = "ms",
                    accel_unit = "mss",
                    grad_unit = "rr",
                    vehicle_specific = T){

  if(!mass_unit %in% c("kg", "t")){warning("Supported mass units: kg, t")}
  if(!speed_unit %in% c("ms", "mph", "kmh")){warning("Supported speed units: ms, mph, kmh")}
  if(!accel_unit %in% c("mss", "mphs", "kmhs")){warning("Supported accel units: mss, mphs, kmhs")}
  if(!grad_unit %in% c("rr", "perc", "deg")){warning("Supported mass units: rr (rise/run), perc, deg")}

  mass = dplyr::case_when(mass_unit == "kg" ~ mass,
                          mass_unit == "t" ~ mass*1000)

  speed = dplyr::case_when(speed_unit == "ms" ~ speed,
                           speed_unit == "mph" ~ speed / 2.237,
                           speed_unit == "kmh" ~ speed / 3.6)

  accel = dplyr::case_when(accel_unit == "mss" ~ accel,
                           accel_unit == "mphs" ~ accel / 2.237,
                           accel_unit == "kmhs" ~ accel / 3.6)

  grad = dplyr::case_when(grad_unit == "rr" ~ grad,
                          grad_unit == "perc" ~ grad/100,
                          grad_unit == "deg" ~ tan(grad * pi/180))

  P = ((mass * accel * 1.04) + #F = ma (acceleration)
         (R0 + R1 * (speed)) + # F = R0 * R1 v (road resistance)
         (0.5 * CdA * 1.2 * (speed)^2) + # F = 1/2 p v2 Cd A (wind)
         (mass * 9.81 * (grad/100))) * # F = mgh (gradient)
    1.08 * (speed) + # (tramission losses)
    aux # (aux power)

  if(vehicle_specific){P = P / mass}

  return(P)

}

calc_vsp(speed = 1, accel = 1, vehicle_specific = F)
jack-davison/jdavisonmisc documentation built on Jan. 1, 2021, 4:26 a.m.