Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
Display telemetry data for different laps
if 'google.colab' in str(get_ipython()):
from google.colab import drive
drive.mount('/content/drive')
path = '/content/drive/MyDrive/SA'
else:
path = '../data'
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).
try:
import rosbag
except ModuleNotFoundError:
!pip3 install rosbag --extra-index-url https://rospypi.github.io/simple/
import rosbag
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import json
import os
from scipy.spatial import distance
import matplotlib.animation as animation
from matplotlib import rc
import PIL
from PIL import Image
from matplotlib.pyplot import cm
from datetime import datetime as dt
from matplotlib.dates import date2num
Failed to load Python extension for LZ4 support. LZ4 compression will not be available.
Plot track layout from json file
"""
1. plot the track layout from json file
2. return the position of the yellow/blue cones and the center line
"""
def plot_track_layout(json_file):
track_path = os.path.join(path, json_file)
cone_y_x, cone_y_y = [], [] # yellow cones
cone_b_x, cone_b_y = [], [] # blue cones
center_x, center_y = [], [] # center points between yellow and blue cones
with open(track_path) as f:
track = json.load(f)
for id in range(len(track['yellow_cones'])):
cone_y_x.append(track['yellow_cones'][id]['x'])
cone_y_y.append(track['yellow_cones'][id]['y'])
cone_b_x.append(track['blue_cones'][id]['x'])
cone_b_y.append(track['blue_cones'][id]['y'])
center_x.append((track['yellow_cones'][id]['x']+track['blue_cones'][id]['x'])/2)
center_y.append((track['yellow_cones'][id]['y']+track['blue_cones'][id]['y'])/2)
cone_y = {'x' : cone_y_x, 'y' : cone_y_y}
cone_b = {'x' : cone_b_x, 'y' : cone_b_y}
center = {'x' : center_x, 'y' : center_y}
plt.plot(cone_y_x, cone_y_y, color='y')
plt.plot(cone_b_x, cone_b_y, color='b')
plt.plot(center_x, center_y, color='r')
return cone_y, cone_b, center