mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-05 00:05:52 +08:00
28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
from cereal import car
|
|
from types import SimpleNamespace
|
|
from openpilot.selfdrive.locationd.torqued import TorqueEstimator
|
|
|
|
|
|
def test_cal_percent():
|
|
est = TorqueEstimator(car.CarParams())
|
|
est.starpilot_toggles = SimpleNamespace(use_custom_latAccelFactor=False, use_custom_friction=False)
|
|
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
|