mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-26 07:32:06 +08:00
14ff1fb436
version: sunnypilot v2026.002.000 (dev)
date: 2026-06-09T06:39:10
master commit: 01a843e0ac
26 lines
976 B
Python
26 lines
976 B
Python
from cereal import car
|
|
from openpilot.selfdrive.locationd.torqued import TorqueEstimator
|
|
|
|
|
|
def test_cal_percent():
|
|
est = TorqueEstimator(car.CarParams())
|
|
msg = est.get_msg()
|
|
assert msg.liveTorqueParameters.calPerc == 0
|
|
|
|
for (low, high), min_pts in zip(est.filtered_points.buckets.keys(),
|
|
est.filtered_points.buckets_min_points.values(), strict=True):
|
|
for _ in range(int(min_pts)):
|
|
est.filtered_points.add_point((low + high) / 2.0, 0.0)
|
|
|
|
# enough bucket points, but not enough total points
|
|
msg = est.get_msg()
|
|
assert msg.liveTorqueParameters.calPerc == (len(est.filtered_points) / est.min_points_total * 100 + 100) / 2
|
|
|
|
# add enough points to bucket with most capacity
|
|
key = list(est.filtered_points.buckets)[0]
|
|
for _ in range(est.min_points_total - len(est.filtered_points)):
|
|
est.filtered_points.add_point((key[0] + key[1]) / 2.0, 0.0)
|
|
|
|
msg = est.get_msg()
|
|
assert msg.liveTorqueParameters.calPerc == 100
|