12 Generating a trajr Route From the Telemetry Data
With a large number of points available, we can cast the dataset directly to a trajr route.
The trajr R package was originally developed for use analysing animal tracks, but it’s also really handy for analysing rally routes…
telemetry_full_trajectory = function(telem_df_full){
utm_telem_full = st_transform(telem_df_full,
crs=utm_proj4_string) %>%
mutate(lat = st_coordinates(.)[,1],
lon = st_coordinates(.)[,2])
trj <- TrajFromCoords(utm_telem_full %>% select(lon, lat, utc),
xCol="lon", yCol="lat", timeCol="utc")
# We assume that the first location is the first location on the route
trj$distance = Mod(trj$displacement)
trj$cum_dist = cumsum(trj$distance)
trj$speed = telem_df_full$speed
trj$brk = telem_df_full$brk
trj$throttle = telem_df_full$throttle
trj$rpm = telem_df_full$rpm
trj$lon = telem_df_full$lon
trj$lat = telem_df_full$lat
trj$accx = telem_df_full$accx
trj$accy = telem_df_full$accy
trj$driver = telem_df_full$driver
trj$stage = telem_df_full$stage
trj
}The data includes:
lat/loncoordinates;- a sample timestamp;
speedin km/h;throttleandbrk(brake) as percentage values;rpmrevs;accxandaccyacceleration forces.
If we plot these values against the distance into stage, generated from the location data and cross-referenced to the nearest point on the official stage route, we can generate an idealised basis for comparison between different drivers. However, given that drivers typically follow a very similar line, and hence complete a similar distance over the stage, using their actual distance into the route should provide a reasonable, if approximate, basis for comparison most of the time.
The trajr route actually calculates a distance into the route assuming an origin based on the first point in the route.
evans_fn="df_telemetrymergeddata_SS7_Evans.csv"
trj_evans = telemetry_full_trajectory(get_full_telem(file.path(path, evans_fn)))
ogier_fn="df_telemetrymergeddata_SS7_Ogier.csv"
trj_ogier = telemetry_full_trajectory(get_full_telem(file.path(path, ogier_fn)))
breen_fn="df_telemetrymergeddata_SS7_Breen.csv"
trj_breen = telemetry_full_trajectory(get_full_telem(file.path(path, breen_fn)))