{"record":{"id":"9b4d113d57359ddd","repo":"commaai/openpilot","slug":"too-few-samples-found-in-route","errorCode":null,"errorMessage":"too few samples found in route","messagePattern":"too few samples found in route","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/scripts/car/toyota_eps_factor.py","lineNumber":46,"sourceCode":"\n    for m in msg.can:\n      if m.address == 0x2e4 and m.src == 128:\n        engaged = bool(m.dat[0] & 1)\n        torque_cmd = to_signed((m.dat[1] << 8) | m.dat[2], 16)\n      elif m.address == 0x260 and m.src == 0:\n        eps_torque = to_signed((m.dat[5] << 8) | m.dat[6], 16)\n        steering_pressed = abs(to_signed((m.dat[1] << 8) | m.dat[2], 16)) > STEER_THRESHOLD\n\n    if engaged and torque_cmd is not None and eps_torque is not None and not steering_pressed:\n      cmds.append(torque_cmd)\n      eps.append(eps_torque)\n    else:\n      if len(cmds) > MIN_SAMPLES:\n        break\n      cmds, eps = [], []\n\n  if len(cmds) < MIN_SAMPLES:\n    raise Exception(\"too few samples found in route\")\n\n  lm = linear_model.LinearRegression(fit_intercept=False)\n  lm.fit(np.array(cmds).reshape(-1, 1), eps)\n  scale_factor = 1. / lm.coef_[0]\n\n  if plot:\n    plt.plot(np.array(eps) * scale_factor)\n    plt.plot(cmds)\n    plt.show()\n  return scale_factor\n\n\nif __name__ == \"__main__\":\n  lr = LogReader(sys.argv[1])\n  n = get_eps_factor(lr, plot=\"--plot\" in sys.argv)\n  print(\"EPS torque factor: \", n)\n","sourceCodeStart":28,"sourceCodeEnd":63,"githubUrl":"https://github.com/commaai/openpilot/blob/516ec1e68203439a73f340f1d0b3b91eabc626ee/tools/scripts/car/toyota_eps_factor.py#L28-L63","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"# before\n# short 30s drive, driver hands on -> too few samples\npython tools/scripts/car/toyota_eps_factor.py <route>\n\n# after\n# record several minutes engaged, hands off, gentle curves, then:\npython tools/scripts/car/toyota_eps_factor.py <long_engaged_route>","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    factor = toyota_eps_factor(route, MIN_SAMPLES=512)\nexcept Exception as e:\n    if 'too few samples' in str(e):\n        # collect a longer engaged, hands-off route before retrying\n        sys.exit('need a longer engaged drive (>512 samples)')\n    raise","preventionTips":["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."],"tags":["car-porting","toyota","eps","can","data-quality","openpilot"],"backgroundTag":null,"analyzedSha":"516ec1e68203439a73f340f1d0b3b91eabc626ee","analyzedAt":"2026-08-15T00:17:37.461Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}