Skip to content

Commit

Permalink
Send future accel to car (eliminate jerking) (commaai#408)
Browse files Browse the repository at this point in the history
* send future accel (0.45 seconds) to car as feedforward, not changing velocity

* add comment for future me

* add comment for future me

* Revert "Disable long derivative if eager accel is enabled (same thing)"

This reverts commit dc785ce.

* Disable long deriv

* Revert "Experimental feature: eager accel (commaai#382)"

This reverts commit 58ee449.

* rename back

* offset but keep gas so car can release brakes easier

* just offset

* Update version

* Update README.md

* Update README.md

* Update README.md

* don't change tuning

* add CP for accel delay

* clip

* always get that confused

* notes

* Update date

* Add param to tune

* Add param to tune
  • Loading branch information
sshane authored and Aragon7777 committed May 8, 2021
1 parent 36d7861 commit 6b0a0fd
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 219 deletions.
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Stock Additions v0.6.6 (0.8.2)
# Stock Additions [Update 3](/SA_RELEASES.md) (0.8.2)

Stock Additions is a fork of openpilot designed to be minimal in design while boasting various feature additions and behavior improvements over stock. I have a 2017 Toyota Corolla with comma pedal, so most of my changes are designed to improve the longitudinal performance.

Expand All @@ -12,13 +12,14 @@ Want to request a feature or create a bug report? [Open an issue here!](https://
### Behavior Changes
* [**Dynamic follow (now with profiles!)**](#dynamic-follow-3-profiles) - 3 + auto profiles to control distance
* [**`auto-df` model for automatic distance profile switching**](#Automatic-DF-profile-switching)
* **Lane Speed** [***❗ALL LANE SPEED FEATURES REMOVED TEMPORARILY❗***](https://github.com/ShaneSmiskol/openpilot/blob/stock_additions/SA_RELEASES.md#stock-additions-v066---2020-02-27-082)
* **Lane Speed** [***❗ALL LANE SPEED FEATURES REMOVED TEMPORARILY❗***](https://github.com/ShaneSmiskol/openpilot/blob/stock_additions/SA_RELEASES.md#stock-additions-v066---2021-02-27-082)
* [**Lane Speed Alerts**](#Lane-Speed-alerts) - alerts for when an adjacent lane is faster
* [**Dynamic camera offsetting**](#Dynamic-camera-offset-based-on-oncoming-traffic) - moves you over if adjacent lane has oncoming traffic
* [**Dynamic gas**](#dynamic-gas) - smoother gas control
* [**Adding derivative to PI for better control**](#pi---pid-controller-for-long-and-lat) - lat: smoother control in turns; long: fix for comma pedal overshoot

### General Features
* [**NEW❗ Smoother long control using delay**](#new-compensate-for-longitudinal-delay-for-earlier-braking) - using an accel delay, just like for lateral
* [**Customize this fork**](#Customize-this-fork-opEdit) - easily edit fork parameters with support for live tuning
* [**Automatic updates**](#Automatic-updates)
* [**ZSS Support**](#ZSS-support) - takes advantage of your high-precision Zorrobyte Steering Sensor
Expand All @@ -34,6 +35,7 @@ Want to request a feature or create a bug report? [Open an issue here!](https://
* [**Videos**](#Videos)

---
## Behavior changes

### Dynamic follow (3 profiles)
Dynamic follow aims to provide the stock (Toyota) experience of having three different distance settings. Dynamic follow works by dynamically changing the distance in seconds which is sent to the long MPC to predict a speed to travel at. Basically, if the lead is decelerating or might soon, increase distance to prepare. And if the lead is accelerating, reduce distance to get up to speed quicker.
Expand All @@ -50,6 +52,7 @@ Just use the button on the button right of the screen while driving to change be
<img src=".media/df_profiles.jpg?raw=true">
</p>

---
### Automatic DF profile switching
I've trained a custom model with Keras that takes in the past 35 seconds of your speed, the lead's speed and the lead's distance. With these inputs, it tries to correctly predict which profile is the best for your current situation.

Expand Down Expand Up @@ -111,10 +114,12 @@ If you have a car without a pedal, or you do have one but I haven't created a pr
Long derivative is disabled by default due to only one tune for all cars, but can be enabled by using [opEdit](#Customize-this-fork-opEdit) and setting the `enable_long_derivative` parameter to `True`. It works well on my '17 Corolla with pedal.

---
### ZSS Support
If you have a Prius with a ZSS ([Zorrobyte](https://github.com/zorrobyte) Steer Sensor), you can use this fork to take full advantage of your high-precision angle sensor! Added support for ZSS with [PR #198](https://github.com/ShaneSmiskol/openpilot/pull/198), there's nothing you need to do. Special thanks to [Trae](https://github.com/d412k5t412) for helping testing the addition!
## General Features

If you have a ZSS but not a Prius, let me know and I can add support for your car.
### NEW❗ Compensate for longitudinal delay for earlier braking
This just simply uses desired future acceleration for feedforward rather than current desired acceleration. openpilot already compensates for steering delay, but not longitudinal. This adds that, replacing the previous ***experimental*** feature called eager accel which tried to fix the same issues; jerky and late braking. Now we more correctly compensate for delay.

By default, we assume a 0.4 second delay from sending acceleration to seeing it realized, which is tunable with the opEdit param `long_accel_delay`. Raise if braking too late, lower if braking too early. Stock openpilot is 0.0 (no delay).

---
### Customize this fork (opEdit)
Expand Down Expand Up @@ -159,6 +164,7 @@ An archive of opParams [lives here.](https://github.com/ShaneSmiskol/op_params)

Parameters are stored at `/data/op_params.json`

---
### opEdit Demo
<img src=".media/op_edit.gif?raw=true" width="1000">

Expand All @@ -170,6 +176,12 @@ When a new update is available on GitHub for Stock Additions, your EON/C2 will p

Therefore, if your device sees an update while you're driving it will reboot approximately 5 to 10 minutes after you finish your drive, it resets the timer if you start driving again before the time is up.

---
### ZSS Support
If you have a Prius with a ZSS ([Zorrobyte](https://github.com/zorrobyte) Steer Sensor), you can use this fork to take full advantage of your high-precision angle sensor! Added support for ZSS with [PR #198](https://github.com/ShaneSmiskol/openpilot/pull/198), there's nothing you need to do. Special thanks to [Trae](https://github.com/d412k5t412) for helping testing the addition!

If you have a ZSS but not a Prius, let me know and I can add support for your car.

---
### Offline crash logging
If you experience a crash or exception while driving with this fork, and you're not on internet for the error to be uploaded to Sentry, you should be able to check out the directory `/data/community/crashes` to see any and all logs of exceptions caught in openpilot. Simply view the logs with `ls -lah` and then `cat` the file you wish to view by date. This does not catch all errors, for example scons compilation errors or some Python syntax errors will not be caught, `tmux a` is usually best to view these (if openpilot didn't start).
Expand All @@ -195,11 +207,15 @@ The `--depth 1` flag shallow clones the fork, it ends up being about 90 Mb so yo

*Or use the [emu CLI](https://github.com/emu-sh/.oh-my-comma) to easily switch to this fork's default branch: `emu fork switch ShaneSmiskol`. The initial setup may take longer than the above command, but you gain the ability to switch to any fork you want.*

*Or (last or, I promise!) you can use my handy fork installation link during NEOS setup after a factory reset: **https://smiskol.com/fork/shane***

---
### Branches
Most of the branches on this fork are development branches I use as various openpilot tests. The few that more permanent are the following:
* [`stock_additions`](https://github.com/ShaneSmiskol/openpilot/tree/stock_additions): This is similar to stock openpilot's release branch. Will receive occasional and tested updates to Stock Additions.
* `stock_additions-devel` or `SA-staging`: My development branch of Stock Additions I use to test new features or changes; similar to the master branch. Not recommendeded as a daily driver.

---
### Archive Stock Additions branches
* [Stock Additions 0.7](https://github.com/ShaneSmiskol/openpilot-archive/tree/stock_additions-07)
* [Stock Additions 0.7.1](https://github.com/ShaneSmiskol/openpilot-archive/tree/stock_additions-071)
Expand Down
23 changes: 22 additions & 1 deletion SA_RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
Stock Additions v0.6.6 - 2020-02-27 (0.8.2)
Stock Additions Update 3 - 2021-05-03 (0.8.2)
===
* Remove eager accel and instead send future desired accel
* Much simpler and better/smoother results (tunable with `long_accel_delay`)

Stock Additions Update 2 - 2021-04-21 (0.8.2)
===
* Update versioning sceme to *Updates*, which reset on each new openpilot version
* For pedal users: convert acceleration to correct gas percentage for smooth gas control (dynamic gas isn't needed anymore!)
* Offroad apk with color correction option from ihsakashi
* opParams and opEdit: Make more params live! Any param not marked `static` can be adjusted while onroad! The non-static non-live params update within 10 seconds.
* New param to change at which speed lane changes become nudgeless above (`alca_no_nudge_speed`)
* Experimental feature: eager acceleration (read the README under general features)
* More accurate LDW warning
* Features ported from 0.8.3:
* The newest KL model, and a param to enable laneless
* (0.8.4) The laneless MPC retune fix from Harald
* A few car firmware updates
* GPS malfunction fix

Stock Additions v0.6.6 - 2021-02-27 (0.8.2)
===
* Continued grey panda support (white panda not guaranteed)
* Temporary removal of LaneSpeed and DynamicCameraOffset features
Expand All @@ -9,6 +29,7 @@ Stock Additions v0.6.6 - 2020-02-27 (0.8.2)
* Add color corrections button, PR by ihsakashi
* More parameters now update while driving.
* If the param isn't marked with "static" you no longer have to reboot
* Parameter `alca_no_nudge_speed` controls the speed at which lane changes go from needing a nudge to "nudgeless"

Stock Additions v0.6.5 - 2020-12-07 (0.8)
===
Expand Down
1 change: 1 addition & 0 deletions cereal/car.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ struct CarParams {
startingBrakeRate @53 :Float32; # brake_travel/s while releasing on restart

steerActuatorDelay @36 :Float32; # Steering wheel actuator delay in seconds
longAccelDelay @39 :Float32; # Acceleration delay in seconds
openpilotLongitudinalControl @37 :Bool; # is openpilot doing the longitudinal control?
carVin @38 :Text; # VIN number queried during fingerprinting
dashcamOnly @41: Bool;
Expand Down
19 changes: 4 additions & 15 deletions common/op_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,8 @@ def __init__(self):

self.fork_params = {'camera_offset': Param(0.06, NUMBER, 'Your camera offset to use in lane_planner.py', live=True),
'dynamic_follow': Param('auto', str, static=True, hidden=True),
'eager_accel': Param(False, [bool, int], 'Experimental❗ Combats hysteresis in the cruise control system, braking sooner to eliminate jerking\n'
'Set the param to `1` to use the first method: uses the smoothened derivative of desired accel\n'
'Setting the param to `2` uses the smoothened jerk of acceleration (tighter control/modification)\n'
'Try out both and see which is smoother. False disables this feature (so does True)', live=True),
'accel_eagerness': Param(1.0, NUMBER, 'Multiplier for the acceleration modifier. 1 is full eagerness (default), 0.8 is 80%, etc.', live=True),

'accel_time_constant_0_mph': Param(0.01, NUMBER, 'Time constant for eager accel at 0 mph in seconds\n' # todo: tune using these then remove
'Approaching 0 is no change, the higher it is the more the response\n'
'The defaults are generally okay', live=True),
'accel_time_constant_10_mph': Param(0.1, NUMBER, 'Time constant for eager accel at 10 mph in seconds', live=True),
'accel_time_constant_80_mph': Param(1.0, NUMBER, 'Time constant for eager accel at 80 mph in seconds', live=True),

# 'replay_accel': Param(False, bool, 'Set param to True while engaged at 20 mph', live=True),
'long_accel_delay': Param(0.4, NUMBER, 'The delay in seconds from requesting acceleration to seeing it\n'
'Raise if braking late, lower if braking early. Stock openpilot uses 0.0', live=True),
'global_df_mod': Param(1.0, NUMBER, 'The multiplier for the current distance used by dynamic follow. The range is limited from 0.85 to 2.5\n'
'Smaller values will get you closer, larger will get you farther\n'
'This is multiplied by any profile that\'s active. Set to 1. to disable', live=True),
Expand All @@ -123,8 +112,8 @@ def __init__(self):
# 'lane_speed_alerts': Param('silent', str, 'Can be: (\'off\', \'silent\', \'audible\')\n'
# 'Whether you want openpilot to alert you of faster-traveling adjacent lanes'),
'upload_on_hotspot': Param(False, bool, 'If False, openpilot will not upload driving data while connected to your phone\'s hotspot'),
'enable_long_derivative': Param(False, bool, 'If you have longitudinal overshooting, enable this! This enables derivative-based\n'
'integral wind-down to help reduce overshooting within the long PID loop'),
# 'enable_long_derivative': Param(False, bool, 'If you have longitudinal overshooting, enable this! This enables derivative-based\n'
# 'integral wind-down to help reduce overshooting within the long PID loop'),
'disengage_on_gas': Param(False, bool, 'Whether you want openpilot to disengage on gas input or not'),
'update_behavior': Param('auto', str, 'Can be: (\'off\', \'alert\', \'auto\') without quotes\n'
'off will never update, alert shows an alert on-screen\n'
Expand Down
159 changes: 0 additions & 159 deletions misc_scripts/debug/explore_eager.py

This file was deleted.

2 changes: 2 additions & 0 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def get_std_params(candidate, fingerprint, has_relay):
ret.minSteerSpeed = 0.

# stock ACC by default
ret.longAccelDelay = 0.4

ret.enableCruise = True
ret.minEnableSpeed = -1. # enable is done by stock ACC, so ignore this
ret.steerRatioRear = 0. # no rear steering, at least on the listed cars aboveA
Expand Down
Loading

0 comments on commit 6b0a0fd

Please sign in to comment.