Skip to content

Commit

Permalink
Add hwy long tuning (commaai#226)
Browse files Browse the repository at this point in the history
* Add highway braking DELTA values for live tuner

* Add Highway braking delta values to kegman_conf.py

* Add highway delta braking to live tuner

* Update README.md

* Update README.md
  • Loading branch information
kegman committed Oct 1, 2019
1 parent a86c0d1 commit d8b0364
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 32 deletions.
58 changes: 30 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
This is a fork of comma's openpilot: https://github.com/commaai/openpilot, and contains tweaks for Hondas and GM vehicles. It is open source and inherits MIT license. By installing this software you accept all responsibility for anything that might occur while you use it. All contributors to this fork are not liable. <b>Use at your own risk.</b>

<b>NOTE: If you upgrade to 0.6 you cannot go back to 0.5.xx without reflashing your NEOS!</b>
Here's how to flash back to v9 NEOS if you want to downgrade (it's not that bad)

<b>Manual Instructions to flash back to v9 NEOS for downgrading back to 0.5.xx:</b>
- the boot and system image files for v9 NEOS - are in #hw-unofficial - look for the 0.5.13 - they are pinned messages (click pin icon at top)
- download android fastboot
- press and hold UP vol and Power to go into Fastboot mode (Eon Gold is hold DOWN and Power)
- connect to PC with USB cord
- put the system and boot img files in the same directory as fastboot.exe
- type in these commands (only the ones that start with fastboot): https://github.com/commaai/eon-neos/blob/master/flash.sh#L8-L19
- restart the Eon, on the setup screen enter your wifi password and SSID and SSH in - after you successfully SSH in reboot
- when your Eon boots it will ask you to enter install URL: enter https://openpilot.comma.ai
- when the Eon reboots it will ask you to upgrade NEOS - STOP - do not say yes
- SSH into the Eon
- cd /data
- rm -rf ./openpilot
- git clone https://github.com/kegman/openpilot
- cd openpilot
- git checkout (one of the non-0.6 branches)
- reboot
- enjoy

<b>NOTE:</b> If you have upgraded at any time to v0.5.10, v0.6.x and you want to go back to a branch with v0.5.9 or v0.5.8, then you have to SSH into the Eon and edit the file /data/params/d/ControlsParams and rename "angle_model_bias" to "angle_offset" or your car will have Dash Errors and you'll be scratching your head for hours!

<b>Pedal Users:</b> Also note that you need to flash your Pedal to go to v0.5.10. If you want to go back to 0.5.9 or 0.5.8 you need to flash your pedal back to 0.5.9. Instructions are here: https://medium.com/@jfrux/comma-pedal-updating-the-firmware-over-can-fa438a3cf910. Also. After you flash your Pedal.. All hell will break loose on your dash. Traction control error, Power Steering Error, Trailer Error, OMFG the sky is falling error etc. DON'T PANIC. Just drive around a bit and it will disappear after about 2-3 restarts of the car. Don't rush it I believe it's time dependent as well. Just drive as normal. They'll go away.


<b>IMPORTANT:</b> I have added the stopping of services for Nidec vehicles, which always have power from the panda. See feature list below for details.
Here's how to flash back to v9 NEOS if you want to downgrade (it's not that bad) - scroll to bottom of readme for instructions on downgrading

<b>ALSO IMPORTANT:</b> /data/kegman.json is a file that holds parameters and is used on various branches / forks. When switching between forks (like @arne182 and @gernby), or between branches within this repo (like non-gernby and gernby), it is best to delete or rename the existing file so there are no parameter conflicts. _Do this before rebooting the EON to compile on the new fork/branch._

Expand All @@ -41,7 +15,7 @@ I will attempt to detail the changes in each of the branches here:

<b>kegman</b> - this is the default branch which does not include Gernby's resonant feed forward steering (i.e. it's comma's default steering)

<b>kegman-noAEB</b> - since 0.6.4 comma has reintroduced Honda stock emergency braking. It has had some unexpected results especially on tight curves on 2 lane roads. This disables honda stock AEB on nidec vehicles
<b>kegman-noAEB</b> - this branch disables the Honda Nidec AEB passthrough introduced in 0.6.4 as it gives problems and unexpectedly brakes on tight curves and oncoming traffic.

<b>kegman-stockUI</b> - for 0.6 some people were having trouble with devUI so I separated the branches out.

Expand All @@ -61,6 +35,8 @@ I will attempt to detail the changes in each of the branches here:


List of changes and tweaks (latest changes at the top):
- <b> New! Added highway speed braking profile tweaks</b>. Note that 1barHwy, 2barHwy and 3barHwy are DELTAS. For example if One bar distance is 0.9 seconds, 1barHwy of 0.3 will add 3 seconds to the distance during braking making you brake harder.

- <b> New! Added kF feedforward param to live tuner.</b>

- <b> New! Enable / Disable Model based Slowdowns on turns: On tight turns, the model will slow down the car so that you can make the turn. Some like this, some people don't. Set slowOnCurve = "1" to enable slowdowns on curves, or "0" (default) to disable.
Expand Down Expand Up @@ -175,3 +151,29 @@ For Bosch vehicles, the Eon will just simply shutdown as usual when battery fall


Enjoy everyone.


<b>Manual Instructions to flash back to v9 NEOS for downgrading back to 0.5.xx:</b>
- the boot and system image files for v9 NEOS - are in #hw-unofficial - look for the 0.5.13 - they are pinned messages (click pin icon at top)
- download android fastboot
- press and hold UP vol and Power to go into Fastboot mode (Eon Gold is hold DOWN and Power)
- connect to PC with USB cord
- put the system and boot img files in the same directory as fastboot.exe
- type in these commands (only the ones that start with fastboot): https://github.com/commaai/eon-neos/blob/master/flash.sh#L8-L19
- restart the Eon, on the setup screen enter your wifi password and SSID and SSH in - after you successfully SSH in reboot
- when your Eon boots it will ask you to enter install URL: enter https://openpilot.comma.ai
- when the Eon reboots it will ask you to upgrade NEOS - STOP - do not say yes
- SSH into the Eon
- cd /data
- rm -rf ./openpilot
- git clone https://github.com/kegman/openpilot
- cd openpilot
- git checkout (one of the non-0.6 branches)
- reboot
- enjoy

<b>NOTE:</b> If you have upgraded at any time to v0.5.10, v0.6.x and you want to go back to a branch with v0.5.9 or v0.5.8, then you have to SSH into the Eon and edit the file /data/params/d/ControlsParams and rename "angle_model_bias" to "angle_offset" or your car will have Dash Errors and you'll be scratching your head for hours!

<b>Pedal Users:</b> Also note that you need to flash your Pedal to go to v0.5.10. If you want to go back to 0.5.9 or 0.5.8 you need to flash your pedal back to 0.5.9. Instructions are here: https://medium.com/@jfrux/comma-pedal-updating-the-firmware-over-can-fa438a3cf910. Also. After you flash your Pedal.. All hell will break loose on your dash. Traction control error, Power Steering Error, Trailer Error, OMFG the sky is falling error etc. DON'T PANIC. Just drive around a bit and it will disappear after about 2-3 restarts of the car. Don't rush it I believe it's time dependent as well. Just drive as normal. They'll go away.


12 changes: 9 additions & 3 deletions selfdrive/controls/lib/long_mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def __init__(self, mpc_id):
self.oneBarProfile = [ONE_BAR_DISTANCE, float(kegman.conf['1barMax'])]
self.twoBarProfile = [TWO_BAR_DISTANCE, float(kegman.conf['2barMax'])]
self.threeBarProfile = [THREE_BAR_DISTANCE, float(kegman.conf['3barMax'])]
self.oneBarHwy = [ONE_BAR_DISTANCE, ONE_BAR_DISTANCE+float(kegman.conf['1barHwy'])]
self.twoBarHwy = [TWO_BAR_DISTANCE, TWO_BAR_DISTANCE+float(kegman.conf['2barHwy'])]
self.threeBarHwy = [THREE_BAR_DISTANCE, THREE_BAR_DISTANCE+float(kegman.conf['3barHwy'])]

def send_mpc_solution(self, pm, qp_iterations, calculation_time):
qp_iterations = max(0, qp_iterations)
Expand Down Expand Up @@ -168,6 +171,9 @@ def update(self, pm, CS, lead, v_cruise_setpoint):
self.oneBarProfile = [ONE_BAR_DISTANCE, float(kegman.conf['1barMax'])]
self.twoBarProfile = [TWO_BAR_DISTANCE, float(kegman.conf['2barMax'])]
self.threeBarProfile = [THREE_BAR_DISTANCE, float(kegman.conf['3barMax'])]
self.oneBarHwy = [ONE_BAR_DISTANCE, ONE_BAR_DISTANCE+float(kegman.conf['1barHwy'])]
self.twoBarHwy = [TWO_BAR_DISTANCE, TWO_BAR_DISTANCE+float(kegman.conf['2barHwy'])]
self.threeBarHwy = [THREE_BAR_DISTANCE, THREE_BAR_DISTANCE+float(kegman.conf['3barHwy'])]
self.bp_counter = 0


Expand All @@ -178,7 +184,7 @@ def update(self, pm, CS, lead, v_cruise_setpoint):
if self.street_speed:
TR = interp(-self.v_rel, self.oneBarBP, self.oneBarProfile)
else:
TR = interp(-self.v_rel, H_ONE_BAR_PROFILE_BP, H_ONE_BAR_PROFILE)
TR = interp(-self.v_rel, H_ONE_BAR_PROFILE_BP, self.oneBarHwy)
if CS.readdistancelines != self.lastTR:
self.libmpc.init(MPC_COST_LONG.TTC, 1.0, MPC_COST_LONG.ACCELERATION, MPC_COST_LONG.JERK)
self.lastTR = CS.readdistancelines
Expand All @@ -188,7 +194,7 @@ def update(self, pm, CS, lead, v_cruise_setpoint):
if self.street_speed:
TR = interp(-self.v_rel, self.twoBarBP, self.twoBarProfile)
else:
TR = interp(-self.v_rel, H_TWO_BAR_PROFILE_BP, H_TWO_BAR_PROFILE)
TR = interp(-self.v_rel, H_TWO_BAR_PROFILE_BP, self.twoBarHwy)
if CS.readdistancelines != self.lastTR:
self.libmpc.init(MPC_COST_LONG.TTC, MPC_COST_LONG.DISTANCE, MPC_COST_LONG.ACCELERATION, MPC_COST_LONG.JERK)
self.lastTR = CS.readdistancelines
Expand All @@ -198,7 +204,7 @@ def update(self, pm, CS, lead, v_cruise_setpoint):
#if self.street_speed and (self.lead_car_gap_shrinking or self.tailgating):
TR = interp(-self.v_rel, self.threeBarBP, self.threeBarProfile)
else:
TR = interp(-self.v_rel, H_THREE_BAR_PROFILE_BP, H_THREE_BAR_PROFILE)
TR = interp(-self.v_rel, H_THREE_BAR_PROFILE_BP, self.threeBarHwy)
if CS.readdistancelines != self.lastTR:
self.libmpc.init(MPC_COST_LONG.TTC, MPC_COST_LONG.DISTANCE, MPC_COST_LONG.ACCELERATION, MPC_COST_LONG.JERK)
self.lastTR = CS.readdistancelines
Expand Down
7 changes: 7 additions & 0 deletions selfdrive/kegman_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def read_config(self):
self.config.update({"3barMax":"2.5"})
self.element_updated = True

if "1barHwy" not in self.config:
self.config.update({"1barHwy":"0.3"})
self.config.update({"2barHwy":"0.2"})
self.config.update({"3barHwy":"0.1"})
self.element_updated = True

if "slowOnCurves" not in self.config:
self.config.update({"slowOnCurves":"0"})
self.element_updated = True
Expand All @@ -102,6 +108,7 @@ def read_config(self):
"Kp":"-1", "Ki":"-1", "liveParams":"1", "leadDistance":"5", "deadzone":"0.0", \
"1barBP0":"-0.25", "1barBP1":"2.75", "2barBP0":"-0.25", "2barBP1":"3.0", "3barBP0":"0.0", \
"3barBP1":"4.0", "1barMax":"2.5", "2barMax":"2.5", "3barMax":"2.5", \
"1barHwy":"0.3", "2barHwy":"0.2", "3barHwy":"0.1", \
"steerRatio":"-1", "steerRateCost":"-1", "slowOnCurves":"0", "Kf":"-1"}

self.write_config(self.config)
Expand Down
22 changes: 21 additions & 1 deletion tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def getch():
#kegman.write_config(kegman.conf)
param = ["Kp", "Ki", "Kf", "steerRatio", "steerRateCost", "deadzone", \
"1barBP0", "1barBP1", "1barMax", "2barBP0", "2barBP1", \
"2barMax", "3barBP0", "3barBP1", "3barMax"]
"2barMax", "3barBP0", "3barBP1", "3barMax", \
"1barHwy", "2barHwy", "3barHwy"]

j = 0
while True:
Expand Down Expand Up @@ -206,6 +207,25 @@ def getch():
if float(kegman.conf['3barMax']) > 2.5:
kegman.conf['3barMax'] = "2.5"

if float(kegman.conf['1barHwy']) < 0:
kegman.conf['1barHwy'] = "0"

if float(kegman.conf['2barHwy']) < 0:
kegman.conf['2barHwy'] = "0"

if float(kegman.conf['3barHwy']) < 0:
kegman.conf['3barHwy'] = "0"

if float(kegman.conf['1barHwy']) > 2:
kegman.conf['1barHwy'] = "2"

if float(kegman.conf['2barHwy']) > 2:
kegman.conf['2barHwy'] = "2"

if float(kegman.conf['3barHwy']) > 2:
kegman.conf['3barHwy'] = "2"


if float(kegman.conf['Kf']) > 0.01:
kegman.conf['Kf'] = "0.01"

Expand Down

0 comments on commit d8b0364

Please sign in to comment.