Skip to content

Slimming down carState #2499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed

Slimming down carState #2499

wants to merge 4 commits into from

Conversation

adeebshihadeh
Copy link
Contributor

The current car port backlog is untenable. While this isn't a magic bullet, I think the first step is to strip out anything that's not strictly necessary for openpilot. These fields may have become luxuries we can no longer afford.

Our API to the car is essentially carstate.py and carcontroller.py, and the more we reduce that surface area, the easier porting, fingerprinting, and maintenance will be.

@sshane @jyoung8607 Any thoughts? This is a fairly aggressive pass at carState. As a side benefit, the smaller carState means we can throw more of them in qlogs.

Comment on lines -229 to -231
# clutch (manual transmission only)
clutchPressed @28 :Bool;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used for USER_DISABLE?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently not

(openpilot)  1 batman@workstation-adeeb2:~/fourpilot$ rg -i clutchpress selfdrive/
(openpilot)  1 batman@workstation-adeeb2:~/fourpilot$

@@ -108,7 +108,7 @@ def update(self, CC, CS, now_nanos):
apply_curvature = actuators.curvature

# apply rate limits, curvature error limit, and clip to signal range
current_curvature = -CS.out.yawRate / max(CS.out.vEgoRaw, 0.1)
current_curvature = 0 # TODO: calculate from alternative source, yawRate deprecated
Copy link
Contributor

@sshane sshane Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for the safety. just pull it from CS.yaw_rate

@@ -34,15 +34,13 @@ def update(self, can_parsers) -> structs.CarState:
# car speed
ret.vEgoRaw = cp.vl["BrakeSysFeatures"]["Veh_V_ActlBrk"] * CV.KPH_TO_MS
ret.vEgo, ret.aEgo = self.update_speed_kf(ret.vEgoRaw)
ret.yawRate = cp.vl["Yaw_Data_FD1"]["VehYaw_W_Actl"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.yaw_rate = cp.vl["Yaw_Data_FD1"]["VehYaw_W_Actl"]

Comment on lines +106 to +107
# >100 degree/sec steering fault prevention (steeringRateDeg deprecated, disabling check)
self.steer_rate_counter, apply_steer_req = common_fault_avoidance(False, lat_active,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a huge downgrade...

@sshane
Copy link
Contributor

sshane commented Jul 21, 2025

I think it makes sense to start to remove unnecessary fields

@github-actions github-actions bot added the body label Jul 21, 2025
@jyoung8607
Copy link
Collaborator

jyoung8607 commented Jul 21, 2025

  gasDEPRECATED @3 :Float32;        # this is user pedal only
  brakeDEPRECATED @5 :Float32;      # this is user pedal only
  engineRpmDEPRECATED @46 :Float32;
  genericToggleDEPRECATED @23 :Bool;
  cumLagMsDEPRECATED @50 :Float32;
  wheelSpeedsDEPRECATED @2 :WheelSpeeds;

I'm good with these. Wheel speeds are obviously safety relevant, but we keep the important outcomes in the form of vEgoRaw and standstill. Likewise for gasPressed and brakePressed.

  clutchPressedDEPRECATED @28 :Bool;

Weak preference to keep this. It's just a bool, and it'll be necessary later for a good OP long experience. Cars with ACC and MT tend to stay engaged for a few seconds while shifting, but we want to reject initial entry, and we'll want to freeze or even reset the gas/accel integrator. We're not doing these things yet, but I don't want to lose the prerequisite signals.

  steeringRateDegDEPRECATED @15 :Float32;
  yawRateDEPRECATED @22 :Float32;   # best estimate of yaw rate

Not stoked about losing convenient views of these, given their active use in safety/fault-mitigation in a few ports, but life would go on.

Other fields

  • At a glance, canErrorCounter is recorded by card but doesn't seem like it's doing anything useful
  • steeringAngleOffsetDeg is Toyota only and could just live there, but also safety relevant, hmm
  • Can we consolidate vCruise and cruiseState.speed?
  • Likewise vCruiseCluster and cruiseState.speedCluster
  • cruiseState.speedOffset appears to be unused

Other ideas

  • Some of our Float32s might be represented sufficiently with Float16s
  • Perhaps consider a new carSensors type of object for nice-but-optional data, exclude it from qlogs

@adeebshihadeh
Copy link
Contributor Author

  clutchPressedDEPRECATED @28 :Bool;

Weak preference to keep this.

Removed for now. Easy enough to add back if necessary.

  • Can we consolidate vCruise and cruiseState.speed?
  • Likewise vCruiseCluster and cruiseState.speedCluster

Potentially. There is a meaningful difference in that cruiseState is the car's own state. Regardless of whether we decide to keep it, this difference is not at all clear, and that should be fixed.

  • Some of our Float32s might be represented sufficiently with Float16s

float32 is the smallest type in capnproto.

  • Perhaps consider a new carSensors type of object for nice-but-optional data, exclude it from qlogs

So the qlogs were really just a bonus. It's more about separating the necessary vs the nice-to-haves, and at the very least, I think we need a different file if we want to bring back the nice-to-haves.

@adeebshihadeh
Copy link
Contributor Author

Alright, pretty much done with the first pass at this.

It's clear that there's lot more to do here on a per-port basis. Some examples:

  • do we really need this weighting?
    # blend in transmission speed at low speed, since it has more low speed accuracy
  • can we remove carState.standstill or just define it as vEgoRaw < 0.1?
  • carState.wheelSpeeds can go once the body doesn't use it for closed loop control on the joystick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants