commaai/openpilot · error
too few samples found in route
Error message
too few samples found in route
What it means
Raised at the end of sample collection in toyota_eps_factor.py when fewer than MIN_SAMPLES (512) paired (torque_cmd, eps_torque) samples were gathered from the route's CAN data. The script needs a continuous engaged run with LKA torque commands and matching EPS motor torque readings while the driver is not overriding; if the route never accumulates that many valid pairs, the linear regression cannot be fitted reliably.
Source
Thrown at tools/scripts/car/toyota_eps_factor.py:46
for m in msg.can:
if m.address == 0x2e4 and m.src == 128:
engaged = bool(m.dat[0] & 1)
torque_cmd = to_signed((m.dat[1] << 8) | m.dat[2], 16)
elif m.address == 0x260 and m.src == 0:
eps_torque = to_signed((m.dat[5] << 8) | m.dat[6], 16)
steering_pressed = abs(to_signed((m.dat[1] << 8) | m.dat[2], 16)) > STEER_THRESHOLD
if engaged and torque_cmd is not None and eps_torque is not None and not steering_pressed:
cmds.append(torque_cmd)
eps.append(eps_torque)
else:
if len(cmds) > MIN_SAMPLES:
break
cmds, eps = [], []
if len(cmds) < MIN_SAMPLES:
raise Exception("too few samples found in route")
lm = linear_model.LinearRegression(fit_intercept=False)
lm.fit(np.array(cmds).reshape(-1, 1), eps)
scale_factor = 1. / lm.coef_[0]
if plot:
plt.plot(np.array(eps) * scale_factor)
plt.plot(cmds)
plt.show()
return scale_factor
if __name__ == "__main__":
lr = LogReader(sys.argv[1])
n = get_eps_factor(lr, plot="--plot" in sys.argv)
print("EPS torque factor: ", n)
View on GitHub (pinned to 516ec1e682)
Solutions
- Record a longer route with openpilot engaged and hands off (no driver torque) so >512 consecutive valid samples accumulate.
- Verify the car actually sends the torque messages this script decodes (check the CAN IDs at the top of toyota_eps_factor.py against your car's bus logs).
- Lower MIN_SAMPLES in the script only as a last resort — the fitted EPS factor will be noisier and affect steer accuracy.
- Make sure you're passing a route with steering engaged segments, not just a drive with openpilot passive.
Example fix
# before # short 30s drive, driver hands on -> too few samples python tools/scripts/car/toyota_eps_factor.py <route> # after # record several minutes engaged, hands off, gentle curves, then: python tools/scripts/car/toyota_eps_factor.py <long_engaged_route>
Defensive patterns
Strategy: validation
Try / catch
try:
factor = toyota_eps_factor(route, MIN_SAMPLES=512)
except Exception as e:
if 'too few samples' in str(e):
# collect a longer engaged, hands-off route before retrying
sys.exit('need a longer engaged drive (>512 samples)')
raise Prevention
- Record multi-minute routes with openpilot engaged and no driver torque on the wheel.
- Confirm the car emits the Toyota torque CAN IDs the script decodes before collecting data.
- Don't lower MIN_SAMPLES without increasing the measurement noise budget for the EPS factor.
When it happens
Trigger: Processing a route where the car was never openpilot-engaged long enough, where STEER_THRESHOLD-qualifying driver torque kept resetting the sample buffer (any steering_pressed event clears cmds/eps), or where the expected Toyota CAN IDs for torque_cmd/eps_torque never appeared (wrong car or DBC).
Common situations: Short test drives, routes where the driver kept touching the wheel, wrong car model (no TOYOTA torque messages on those IDs), or a segment with gaps in CAN data. Users frequently hit this on a first quick recording before doing a proper engaged drive.
Related errors
- invalid speed group, see help
- signal %s out of bounds.start_bit: %d size: %d
- bundled firmware is {expected_product!r}, expected version {
- cannot recover from the ROM bootloader without a config back
- invalid config backup: {backup}
AI-assisted analysis of commaai/openpilot@516ec1e682 (2026-08-15).
Data as JSON: /api/errors/9b4d113d57359ddd.
Report an issue: GitHub.