Skip to content

Ford: Initial support for LCA vehicles - #23331

Merged
adeebshihadeh merged 9 commits into
commaai:masterfrom
incognitojam:ford-port
Apr 14, 2022
Merged

adeebshihadeh merged 9 commits into
commaai:masterfrom
incognitojam:ford-port

Conversation

@incognitojam

@incognitojam incognitojam commented Dec 28, 2021

Copy link
Copy Markdown
Contributor

This PR adds support for the Focus Mk4 (EU) and Escape Mk4 using the Lane Centering function.

I am using a manual-transmission Ford Focus 2018 with stock CC and LKA (retrofitted ACC - radar seems to be factory fitted in the UK, perhaps for pre-collision assist, but ACC can be enabled using Forscan).

Thanks to Rikka, Desta, 360a and everyone else in the #ford channel for providing code, ideas and help with this. Thanks to @jyoung8607 for review and help getting this to work!

Checklist

  • added to docs/CARS.md
  • test route added to routes.py
  • route with openpilot:
  • route with stock system:
  • car harness used (if comma doesn't sell it, put N/A): I think it is the same camera connector as the Mazda harness, but a different pinout (Molex WM10326-ND)

Related PRs:

Documentation

Steering commands

We can command the Power Steering Control Module (PSCM) to steer the car using the LateralMotionControl message, from Ford's Lane Centering Assist (LCA) / Traffic Jam Assist (TJA) feature. This gives us curvature-based control.

All cars which have LCA/TJA as an option should have a compatible PSCM fitted, and vehicles owners who didn't buy the optio from Ford should be able to enable it by changing the LCA/TJA enable bit in the PSCM As-Built Data.

From short testing so far, the Lane_Assist_Data1 message must be sent alongside the LCA message for the PSCM to behave. This command is used by the stock system for the "Lane Keep Aid/Assist" (LKA) feature, which corrects the steering wheel when the car drifts out of the lane, but does not keep the car centered. This was the old method of commanding steering, but was subject to the 10s lockout on almost all vehicles.

Initially it was believed that LateralMotionControl2 was used for LCA, as it has some interesting signals and checksums and counters, but then we found that we could use LateralMotionControl. As of yet, we don't know what LateralMotionControl2 is used for. It is not sent on the vehicles we have tested so far. Perhaps it is used for Blue Cruise.

We can steer down to 0mph (it is not linked to the cruise control state), although the cruise control min engage speed and disengage speed varies depending on transmission and stop-and-go.

Method Min Steer Speed Lockout
LKA 35mph Yes, 200-300ms every 10 seconds
LCA 0mph No
Transmission Stop and Go Min Engage Speed Disengage Speed
Manual - 20mph 20mph
Automatic No 20mph 12mph
Automatic Yes 0mph -

Curvature Control

LCA is a "curvature" based control method. The Image Processing Module A (IPMA) in the vehicle writes a message describing the vehicle's current position in a lane and the lane's properties (e.g. curvature) to the CAN bus, and then the PSCM integrates this information with other data (e.g. vehicle yaw) to actuate the steering wheel to the correct position.

To achieve Lateral Control with openpilot, we can take some values from the lateral plan to estimate the lane curvature and path offset. Doing this gives adequate results, even without writing path angle and curvature rate. However, I think lane angle and curvature rate might be able to get us even better control out of the PSCM.

The signals for ramp speed and precision may be worth experimenting with when considering tuning/rate limits.

Screenshot from 2022-03-13 13-59-10

Longitudinal Control

Although not approached in this PR, I believe we will be able to implement longitudinal control quite easily in the future. As the Cruise Control Module (C-CM, the radar) is on a private bus with the IPMA, it is the IPMA which is responsible for calculating and sending ACC commands. We can also intercept these with the same harness. We may even be able to provide ACC for vehicles without a radar, with a few coding changes.

@incognitojam

incognitojam commented Dec 28, 2021

Copy link
Copy Markdown
Contributor Author

I don't have stock LCA in my Ford since it's a manual-transmission and I haven't found a workaround to make it work using the As-Built Data yet (the LCA and TJA features are set with the same bit flag, which makes the IPMA fault when I enable it).

My IPMA does output the LateralMotionControl messages, but does not set the mode signal, so the PSCM does not act on it. It only sends LKA actions. I could record a route so that you could still compare this data to OP but I would be steering 🤦‍♂️.

Alternatively, another community member has an Escape with LCA (who provided me with a route so that I could see the CAN data). Perhaps we could port the Escape too as both a stock LCA and OP route could be provided and compared.

@pd0wm pd0wm added the car port label Dec 29, 2021
@incognitojam incognitojam changed the title Ford support for LCA vehicles Ford: Support for LCA vehicles Dec 29, 2021
@incognitojam
incognitojam force-pushed the ford-port branch 5 times, most recently from 1d4009d to 95dae6c Compare January 4, 2022 20:12
@incognitojam
incognitojam force-pushed the ford-port branch 2 times, most recently from f8c863c to 979692e Compare January 11, 2022 17:06
@incognitojam

Copy link
Copy Markdown
Contributor Author

I've just rebased this branch on the latest master commit. I will continue to look at tuning when I next have free time, just it is hard to record a "drive" because the tuning is so poor at the moment I cannot let it steer for long periods, I don't know if there would be much value in sharing more drives yet. Guidances for next steps would be appreciated!

@incognitojam
incognitojam force-pushed the ford-port branch 2 times, most recently from cd4c00d to 0e06b79 Compare January 11, 2022 19:54
@adeebshihadeh

Copy link
Copy Markdown
Contributor

Guidances for next steps would be appreciated!

What kind of guidance are you looking for exactly? Tuning, getting this merged?

@incognitojam

incognitojam commented Jan 12, 2022

Copy link
Copy Markdown
Contributor Author

I should have been more specific 😅 I'm just racking my brains trying to figure out why this isn't steering as expected. Got some help in the #tuning channel though, and I'm going to experiment to see if the car is actually torque based and not angle based... Will be testing on another branch later!

image

I thought it would have been angle based because the LKA method (and I've been told the park assist method too) are angle based. It would be odd that the leaked DBC would be wrong about this... But the plotjuggler chart seems to show that the desired steering angle/sendcan angle is almost the derivative of the actual steering angle.

@incognitojam
incognitojam force-pushed the ford-port branch 10 times, most recently from f4fd9de to e227d34 Compare January 15, 2022 20:42
@incognitojam

Copy link
Copy Markdown
Contributor Author

Screenshot from 2022-01-15 21-36-30
Currently I'm seeing the steerRatio increasing constantly over the length of a drive... OP steers quite strongly when only small adjustments to the steering angle are required. Will try adjusting steerRateCost and disabling the params learner for steer ratio.

@incognitojam

Copy link
Copy Markdown
Contributor Author

Pinning the steerRatio to 1 seems to give better results with less ping pong. Current theory is that the Ford LCA command accepts the wheels steering angle rather than the steering wheel angle.

@incognitojam
incognitojam force-pushed the ford-port branch 2 times, most recently from f0213c1 to 6e45589 Compare March 17, 2022 22:41
@incognitojam

Copy link
Copy Markdown
Contributor Author

Just created a separate PR for the "try Panda bus for FPv2 queries" stuff ^^

@incognitojam
incognitojam force-pushed the ford-port branch 6 times, most recently from c61b828 to b536c00 Compare March 19, 2022 20:04
@incognitojam

Copy link
Copy Markdown
Contributor Author

Added some signals for yawRate, brake (although it's brake torque? not pedal pct) and I think I've found a better signal for steeringPressed, too

@EasternPA

Copy link
Copy Markdown
Contributor

Following with great excitement. Any reason why the suggested documentation update in the first post indicates that Automatics with Stop and Go will disengage at 10 MPH? What am I missing?

@incognitojam

Copy link
Copy Markdown
Contributor Author

Following with great excitement. Any reason why the suggested documentation update in the first post indicates that Automatics with Stop and Go will disengage at 10 MPH? What am I missing?

I think I might've made a mistake with that actually, was just from memory, it doesn't make sense actually!

@EasternPA

EasternPA commented Mar 25, 2022

Copy link
Copy Markdown
Contributor

Following with great excitement. Any reason why the suggested documentation update in the first post indicates that Automatics with Stop and Go will disengage at 10 MPH? What am I missing?

I think I might've made a mistake with that actually, was just from memory, it doesn't make sense actually!

Thank you for making that update so quickly. I have about 8 months before I must pick up my next OP ride, and I'm not sure what to get next. You're doing great work here, keep it up!

@scripty29

scripty29 commented Mar 31, 2022

Copy link
Copy Markdown

Hey @incognitojam i have been following you for a little while. I have a 2019 F150 with ACC stop and go and LKA. Any chance your code will work with my truck and or do you need additional testers? Also willing to learn how to tune etc.. but I don’t have a lot of coding experience. Cheers on the work you have done so far!

@incognitojam

incognitojam commented Apr 3, 2022

Copy link
Copy Markdown
Contributor Author

I have a 2019 F150 with ACC stop and go and LKA. Any chance your code will work with my truck

Hi @scripty29 , I'm not sure it will work on your F150... Do you know if Ford offered "traffic jam assist" or lane centering option from the factory? You might not have a compatible power steering module

You'd be able to check if you get an OBD adapter and the Forscan software (or another scan tool if you have access to that) Look at the PSCM configuration and see what options there are. If you want you could share the As-Built Data and the firmware if you can see that too

@scripty29

Copy link
Copy Markdown

I have Forscan and can check this afternoon! I will report back with my findings 🤞

@incognitojam

Copy link
Copy Markdown
Contributor Author

Just rebased this onto the latest master, using the new FW query stuff so that there isn't a hack for choosing the panda bus anymore

@adeebshihadeh adeebshihadeh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd like to get this merged as it seems very similar to the current F150 platform. Here's some quick comments after going through the PR - I'll do a thorough review sometime this week.

Let's start by whittling this down to a subset of this PR that can be merged right away:

  • fordcan changes to build the new messages
  • carState
  • carController
  • new car models + fusion removal
  • possibly the FW query
  • re-enable dashcamOnly

Feel free to do that in this PR or break out into a new one.

Comment thread selfdrive/car/ford/carstate.py Outdated
Comment thread selfdrive/car/ford/interface.py Outdated
# civic and scaling by mass and wheelbase
ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)
# Auto Transmission: Gear_Shift_by_Wire_FD1
if 0x5A in fingerprint[0]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CAN fingerprint detection can be unreliable, switch to checking ECU fw versions if possible

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there an example of how to do this somewhere else?

@incognitojam incognitojam Apr 13, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

actually, I found how to do it by reading car_fw, but I guess you can only use this after the FPv2 stuff is added

@incognitojam incognitojam Apr 14, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From memory, the transmission ECU never appeared in the car_fw... Only saw the eps, esp, radar, camera and engine responses. I tried looking at 360a's routes on useradmin but for some reason I can't see the car params?

EDIT: 0x7E1 should be the TCM. I was also thinking we could add the blindspot modules as well, which are 0x7C4 (SODL) and 0x7C6 (SODR), but maybe it's not possible to speak to those from this bus...

from selfdrive.car.ford.values import DBC
from selfdrive.car.interfaces import RadarInterfaceBase

RADAR_MSGS = list(range(0x500, 0x540))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

doesn't work on your car?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll have to test this again... I can't remember what the problem was

Comment thread selfdrive/car/ford/values.py Outdated
@adeebshihadeh

Copy link
Copy Markdown
Contributor

Nice job @incognitojam! Seems we'll be able to support quite a few existing Fords as well as the new Blue Cruise platform with this port. LateralMotionControl2 is present on the F-150 with Blue Cruise, but we never saw it steer due to the faults.

Here's the next steps:

  • break out FW query into a new PR
  • finish & merge the matching panda safety
  • good quality steering with the curvature message

We can also review and merge the matching panda safety #812 once it's ready, though it'll stay behind the debug panda flag until we get a Ford again and verify it. We'll be ready to invest more time into this once the whole port is working well on a car from the factory.

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.

7 participants