openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.4 KiB

import math
import matplotlib.pyplot as plt
1 month ago
from openpilot.common.filter_simple import JerkEstimator1, JerkEstimator2, JerkEstimator3
from tools.lib.logreader import LogReader
from openpilot.selfdrive.locationd.helpers import PoseCalibrator, Pose
from opendbc.car import ACCELERATION_DUE_TO_GRAVITY
plt.ion()
lr = LogReader("https://connect.comma.ai/8011d605be1cbb77/000001c6--130f915e07/130/138")
calibrator = PoseCalibrator()
sm = {}
j1 = JerkEstimator1(1/20)
1 month ago
j2 = JerkEstimator2(1/100)
j3 = JerkEstimator3(1/100)
1 month ago
# j4 = JerkEstimator4(1/20)
1 month ago
j5 = JerkEstimator1(1/100)
accels = []
1 month ago
kf_accels = []
1 month ago
jerks1, jerks2, jerks3, jerks4, jerks5 = [], [], [], [], []
1 month ago
lp_updated = False
for msg in lr:
if msg.which() == 'livePose':
sm['livePose'] = msg.livePose
1 month ago
lp_updated = True
elif msg.which() == 'liveParameters':
sm['liveParameters'] = msg.liveParameters
elif msg.which() == 'carState':
if len(sm) < 2:
continue
CS = msg.carState
device_pose = Pose.from_live_pose(sm['livePose'])
calibrated_pose = calibrator.build_calibrated_pose(device_pose)
yaw_rate = calibrated_pose.angular_velocity.yaw
roll = sm['liveParameters'].roll
roll_compensated_lateral_accel = (CS.vEgo * yaw_rate) - (math.sin(roll) * ACCELERATION_DUE_TO_GRAVITY)
1 month ago
_j2 = j2.update(roll_compensated_lateral_accel)
_j3 = j3.update(roll_compensated_lateral_accel)
1 month ago
_j5 = j5.update(roll_compensated_lateral_accel)
1 month ago
if lp_updated:
_j1 = j1.update(roll_compensated_lateral_accel)
1 month ago
# _j4 = j4.update(roll_compensated_lateral_accel)
1 month ago
lp_updated = False
else:
_j1 = j1.x
_j2 = j2.x
1 month ago
_j3 = j3.x
1 month ago
# _j4 = j4.x
1 month ago
_j5 = j5.x
1 month ago
jerks1.append(_j1)
jerks2.append(_j2)
jerks3.append(_j3)
1 month ago
# jerks4.append(_j4)
1 month ago
jerks5.append(_j5)
1 month ago
kf_accels.append(j2.kf.x[0][0])
accels.append(roll_compensated_lateral_accel)
print(roll_compensated_lateral_accel)
fig, axs = plt.subplots(2, sharex=True)
axs[0].plot(accels, label='Lateral Accel')
1 month ago
axs[0].plot(kf_accels, label='Kalman filter accel')
axs[0].set_ylabel('Lateral Acceleration (m/s²)')
axs[0].legend()
1 month ago
axs[1].plot(jerks1, label='Low pass filter at 20 Hz (1)')
axs[1].plot(jerks2, label='Kalman filter (2)')
axs[1].plot(jerks3, label='Windowed (3)')
# axs[1].plot(jerks4, label='Jerk Estimator 4')
# axs[1].plot(jerks5, label='Low pass filter at 100 Hz (5)')
axs[1].set_ylabel('Lateral Jerk (m/s³)')
axs[1].legend()