Skip to content

Commit

Permalink
Merge branch '077-clean' into patch-7
Browse files Browse the repository at this point in the history
  • Loading branch information
arne182 authored Sep 7, 2020
2 parents 1273f40 + 1cbd778 commit 946fe8c
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 62 deletions.
2 changes: 2 additions & 0 deletions cereal/car.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ struct CarParams {
kf @4 :Float32;
kfV @5 :List(Float32);
kfBP @6 :List(Float32);
kdBP @7 :List(Float32);
kdV @8 :List(Float32);
}

struct LongitudinalPIDTuning {
Expand Down
4 changes: 3 additions & 1 deletion common/op_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self):
'rsa_max_speed': Param(24.5, VT.number, 'Speed limit to ignore RSA in m/s'),
'smart_speed': Param(True, bool, 'Whether to use Smart Speed for drives above smart_speed_max_vego'),
'smart_speed_max_vego': Param(26.8, VT.number, 'Speed limit to ignore Smartspeed in m/s'),
'spairrowtuning': Param(False, bool, 'Better Tuning for Corolla'),
'spairrowtuning': Param(False, bool, 'INDI Tuning for Corolla'),
'speed_offset': Param(0, VT.number, 'Speed limit offset in m/s', live=True),
'traffic_light_alerts': Param(False, bool, "Switch off the traffic light alerts"),
'traffic_lights': Param(False, bool, "Should Openpilot stop for traffic lights"),
Expand All @@ -95,6 +95,8 @@ def __init__(self):
'use_virtual_middle_line': Param(False, bool, 'For roads over 4m wide, hug right. For roads under 2m wide, hug left.'),
'uniqueID': Param(None, [type(None), str], 'User\'s unique ID'),
'autoUpdate': Param(True, bool, 'Whether to auto-update'),
'corolla_tss2_d_tuning': Param(True, bool, 'lateral spairrowtuning using PID w/ true derivative'),
'lat_d': Param(9.0, VT.number, 'The lateral derivative gain, default is 9.0 for TSS2 Corolla. This is active at all speeds', live=True),
'ludicrous_mode': Param(False, bool, 'Double overall acceleration!')}

self._params_file = '/data/op_params.json'
Expand Down
1 change: 1 addition & 0 deletions selfdrive/car/chrysler/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def get_params(candidate, fingerprint=None, has_relay=False, car_fw=None):
ret.mass = 2858. + STD_CARGO_KG # kg curb weight Pacifica Hybrid 2017
ret.lateralTuning.pid.kpBP, ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kfBP = [[9., 20.], [9., 20.], [0.]]
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV, ret.lateralTuning.pid.kfV = [[0.15,0.30], [0.03,0.05], [0.00006]] # full torque for 10 deg at 80mph means 0.00007818594
ret.lateralTuning.pid.kdBP, ret.lateralTuning.pid.kdV = [[0.], [0.]]
ret.steerActuatorDelay = 0.1
ret.steerRateCost = 0.7
ret.steerLimitTimer = 0.4
Expand Down
1 change: 1 addition & 0 deletions selfdrive/car/ford/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,
ret.mass = 3045. * CV.LB_TO_KG + STD_CARGO_KG
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP, ret.lateralTuning.pid.kfBP = [[0.], [0.], [0.]]
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV, ret.lateralTuning.pid.kfV = [[0.01], [0.005], [1. / MAX_ANGLE]] # TODO: tune this # MAX Steer angle to normalize FF
ret.lateralTuning.pid.kdBP, ret.lateralTuning.pid.kdV = [[0.], [0.]]
ret.steerActuatorDelay = 0.1 # Default delay, not measured yet
ret.steerLimitTimer = 0.8
ret.steerRateCost = 1.0
Expand Down
1 change: 1 addition & 0 deletions selfdrive/car/gm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,
ret.minSteerSpeed = 7 * CV.MPH_TO_MS
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2], [0.00]]
ret.lateralTuning.pid.kdBP, ret.lateralTuning.pid.kdV = [[0.], [0.]]
ret.lateralTuning.pid.kf = 0.00004 # full torque for 20 deg at 80mph means 0.00007818594
ret.steerRateCost = 1.0
ret.steerActuatorDelay = 0.1 # Default delay, not measured yet
Expand Down
1 change: 1 addition & 0 deletions selfdrive/car/honda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,
# For modeling details, see p.198-200 in "The Science of Vehicle Dynamics (2014), M. Guiggiani"
ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0], [0]]
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP, ret.lateralTuning.pid.kfBP = [[0.], [0.], [0.]]
ret.lateralTuning.pid.kdBP, ret.lateralTuning.pid.kdV = [[0.], [0.]]
ret.lateralTuning.pid.kfV = [0.00006] # conservative feed-forward

eps_modified = False
Expand Down
1 change: 1 addition & 0 deletions selfdrive/car/hyundai/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,
ret.lateralTuning.pid.kiV = [0.001, 0.003, 0.005]
ret.lateralTuning.pid.kfBP = [0., 10., 30.]
ret.lateralTuning.pid.kfV = [0.00002, 0.00003, 0.00005]
ret.lateralTuning.pid.kdBP, ret.lateralTuning.pid.kdV = [[0.], [0.]]

if candidate == CAR.SANTA_FE:
ret.mass = 3982. * CV.LB_TO_KG + STD_CARGO_KG
Expand Down
1 change: 1 addition & 0 deletions selfdrive/car/mazda/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,
ret.steerRateCost = 1.0
ret.steerLimitTimer = 0.8
tire_stiffness_factor = 0.70 # not optimized yet
ret.lateralTuning.pid.kdBP, ret.lateralTuning.pid.kdV = [[0.], [0.]]

if candidate in [CAR.CX5]:
ret.mass = 3655 * CV.LB_TO_KG + STD_CARGO_KG
Expand Down
1 change: 1 addition & 0 deletions selfdrive/car/nissan/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,
ret.lateralTuning.pid.kf = 0.00006
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.0], [0.0]]
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.01], [0.005]]
ret.lateralTuning.pid.kdBP, ret.lateralTuning.pid.kdV = [[0.], [0.]]
ret.steerMaxBP = [0.] # m/s
ret.steerMaxV = [1.]

Expand Down
1 change: 1 addition & 0 deletions selfdrive/car/subaru/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,

ret.steerRateCost = 0.7
ret.steerLimitTimer = 0.4
ret.lateralTuning.pid.kdBP, ret.lateralTuning.pid.kdV = [[0.], [0.]]

if candidate == CAR.ASCENT:
ret.mass = 2031. + STD_CARGO_KG
Expand Down
21 changes: 15 additions & 6 deletions selfdrive/car/toyota/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

op_params = opParams()
spairrowtuning = op_params.get('spairrowtuning')
corolla_tss2_D_tuning = op_params.get('corolla_tss2_D_tuning')

GearShifter = car.CarState.GearShifter

Expand Down Expand Up @@ -48,6 +49,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,
if candidate not in [CAR.PRIUS_2019, CAR.PRIUS, CAR.RAV4, CAR.RAV4H, CAR.COROLLA]: # These cars use LQR/INDI
ret.lateralTuning.init('pid')
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP, ret.lateralTuning.pid.kfBP = [[0.], [0.], [0.]]
ret.lateralTuning.pid.kdBP, ret.lateralTuning.pid.kdV = [[0.], [0.]]

if candidate in [CAR.PRIUS, CAR.PRIUS_2019]:
stop_and_go = True
Expand Down Expand Up @@ -258,24 +260,31 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,
ret.mass = 3060. * CV.LB_TO_KG + STD_CARGO_KG
ret.lateralTuning.pid.kfV = [0.00007818594]
if spairrowtuning:
ret.steerActuatorDelay = 0.60
ret.steerActuatorDelay = 0.40
ret.steerRatio = 15.33
ret.steerLimitTimer = 5.0
tire_stiffness_factor = 0.996 # not optimized yet
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]]
ret.lateralTuning.pid.kdBP = [0.]
ret.lateralTuning.pid.kdV = [9.0]
ret.lateralTuning.pid.kf = 0.00007818594
#ret.lateralTuning.pid.kpBP, ret.lateralTuning.pid.kpV = [[0.0, 15.5, 21.0, 29.0], [0.13, 0.39, 0.39, 0.6]]
#ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kiV = [[0.0, 15.5, 21.0, 29.0], [0.005, 0.015, 0.015, 0.1]]
#ret.lateralTuning.pid.kfBP, ret.lateralTuning.pid.kfV = [[0.0, 15.5, 21.0, 29.0], [0.00009, 0.00015, 0.00015, 0.00007818594]]
ret.lateralTuning.init('indi')
ret.lateralTuning.indi.innerLoopGain = 6
ret.lateralTuning.indi.outerLoopGain = 15.0
ret.lateralTuning.indi.timeConstant = 5.5
ret.lateralTuning.indi.actuatorEffectiveness = 6.0

if corolla_tss2_d_tuning:
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]]
ret.lateralTuning.pid.kdBP = [0.]
ret.lateralTuning.pid.kdV = [9.0]
ret.lateralTuning.pid.kf = 0.00007818594

#ret.lateralTuning.init('indi')
#ret.lateralTuning.indi.innerLoopGain = 6
#ret.lateralTuning.indi.outerLoopGain = 15.0
#ret.lateralTuning.indi.timeConstant = 5.5
#ret.lateralTuning.indi.actuatorEffectiveness = 6.0


elif candidate in [CAR.LEXUS_ES_TSS2, CAR.LEXUS_ESH_TSS2]:
stop_and_go = True
ret.safetyParam = 73
Expand Down
1 change: 1 addition & 0 deletions selfdrive/car/volkswagen/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False,

# VW port is a community feature, since we don't own one to test
ret.communityFeature = True
ret.lateralTuning.pid.kdBP, ret.lateralTuning.pid.kdV = [[0.], [0.]]

if candidate == CAR.GOLF:
# Set common MQB parameters that will apply globally
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/controls/lib/dynamic_follow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _send_cur_state(self):

def _change_cost(self, libmpc):
TRs = [0.9, 1.8, 2.7]
costs = [1.10, 0.21, 0.05]
costs = [1.10, 0.12, 0.05]
cost = interp(self.TR, TRs, costs)
if self.last_cost != cost:
libmpc.change_tr(MPC_COST_LONG.TTC, cost, MPC_COST_LONG.ACCELERATION, MPC_COST_LONG.JERK)
Expand Down
5 changes: 3 additions & 2 deletions selfdrive/controls/lib/latcontrol_pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
class LatControlPID():
def __init__(self, CP):
self.pid = PIControllerk_f((CP.lateralTuning.pid.kpBP, CP.lateralTuning.pid.kpV),
(CP.lateralTuning.pid.kiBP, CP.lateralTuning.pid.kiV),
(CP.lateralTuning.pid.kfBP, CP.lateralTuning.pid.kfV), pos_limit=1.0, sat_limit=CP.steerLimitTimer)
(CP.lateralTuning.pid.kiBP, CP.lateralTuning.pid.kiV),
(CP.lateralTuning.pid.kdBP, CP.lateralTuning.pid.kdV),
(CP.lateralTuning.pid.kfBP, CP.lateralTuning.pid.kfV), pos_limit=1.0, sat_limit=CP.steerLimitTimer)
self.angle_steers_des = 0.

def reset(self):
Expand Down
14 changes: 11 additions & 3 deletions selfdrive/controls/lib/pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ def update(self, setpoint, measurement, speed=0.0, check_saturation=True, overri
return self.control

class PIControllerk_f:
def __init__(self, k_p, k_i, k_f, pos_limit=None, neg_limit=None, rate=100, sat_limit=0.8, convert=None):
def __init__(self, k_p, k_i, k_d, k_f, pos_limit=None, neg_limit=None, rate=100, sat_limit=0.8, convert=None):
self._k_p = k_p # proportional gain
self._k_i = k_i # integral gain
self._k_d = k_d # integral gain
self._k_f = k_f # feedforward gain

self.pos_limit = pos_limit
Expand All @@ -216,7 +217,11 @@ def k_p(self):
@property
def k_i(self):
return interp(self.speed, self._k_i[0], self._k_i[1])


@property
def k_d(self):
return interp(self.speed, self._k_d[0], self._k_d[1])

@property
def k_f(self):
return interp(self.speed, self._k_f[0], self._k_f[1])
Expand All @@ -240,12 +245,14 @@ def reset(self):
self.sat_count = 0.0
self.saturated = False
self.control = 0
self.last_error = 0

def update(self, setpoint, measurement, speed=0.0, check_saturation=True, override=False, feedforward=0., deadzone=0., freeze_integrator=False):
self.speed = speed

error = float(apply_deadzone(setpoint - measurement, deadzone))
self.p = error * self.k_p
d = self.k_d * (error - self.last_error)
self.f = feedforward * self.k_f

if override:
Expand All @@ -264,11 +271,12 @@ def update(self, setpoint, measurement, speed=0.0, check_saturation=True, overri
not freeze_integrator:
self.i = i

control = self.p + self.f + self.i
control = self.p + self.f + self.i + d
if self.convert is not None:
control = self.convert(control, speed=self.speed)

self.saturated = self._check_saturation(control, check_saturation, error)
self.last_error = float(error)

self.control = clip(control, self.neg_limit, self.pos_limit)
return self.control
16 changes: 11 additions & 5 deletions selfdrive/data_collection/gps_uploader.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import ftplib
import os
import json
import gzip
import ftplib
import string
import random
import os
import datetime
from common.params import Params
from common.op_params import opParams
Expand Down Expand Up @@ -32,17 +33,22 @@ def upload_data():
username+="-{}".format(car[0])

filename = "gps-data.{}".format(random.randint(1,99999))

fp = open(filepath,"rb")
data = fp.read()
bindata = bytearray(data)
with gzip.open("/data/" + filename + ".gz", "wb") as f:
f.write(bindata)
ftp = ftplib.FTP("arneschwarck.dyndns.org")
ftp.login("openpilot", "communitypilot")
with open(filepath, "rb") as f:
with open("/data/" + filename + ".gz", "rb") as f:
try:
ftp.mkd("/{}".format(username))
except:
pass
ftp.storbinary("STOR /{}/{}".format(username, filename), f)
ftp.storbinary("STOR /{}/{}".format(username, filename + ".gz"), f)
ftp.quit()
os.remove(filepath)
os.remove("/data/" + filename + ".gz")
t = datetime.datetime.utcnow().isoformat()
params.put("LastUpdateTime", t.encode('utf8'))
return True
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/ui/dashcam.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void start_capture() {
struct tm tm = get_time_struct();
snprintf(filename,sizeof(filename),"%04d%02d%02d-%02d%02d%02d.mp4", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
//snprintf(cmd,sizeof(cmd),"screenrecord --size 1280x720 --bit-rate 10000000 %s/%s&",videos_dir,filename);
snprintf(cmd,sizeof(cmd),"screenrecord --size 960x540 --bit-rate 5000000 %s/%s&",videos_dir,filename);
snprintf(cmd,sizeof(cmd),"screenrecord --size 1920x1080 --bit-rate 5000000 %s/%s&",videos_dir,filename);
strcpy(filenames[captureNum],filename);

printf("Capturing to file: %s\n",cmd);
Expand Down
Binary file modified selfdrive/ui/spinner/spinner
Binary file not shown.
58 changes: 15 additions & 43 deletions selfdrive/ui/uiview.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,24 @@
import time
import signal
import subprocess
import multiprocessing
import cereal.messaging as messaging

from common.basedir import BASEDIR

KILL_TIMEOUT = 15


def send_controls_packet(pm):
while True:
dat = messaging.new_message('controlsState')
dat.controlsState.rearViewCam = False
pm.send('controlsState', dat)
time.sleep(1 / 100.)
services = ['controlsState', 'thermal', 'radarState'] # the services needed to be spoofed to start ui offroad
procs = {'camerad': 'selfdrive/camerad/camerad', 'ui': 'selfdrive/ui/ui',
'modeld': 'selfdrive/modeld/modeld', 'calibrationd': 'selfdrive/locationd/calibrationd.py'}
started_procs = [subprocess.Popen(os.path.join(BASEDIR, procs[p]), cwd=os.path.join(BASEDIR, os.path.dirname(procs[p]))) for p in procs] # start needed processes
pm = messaging.PubMaster(services)

dat_cs, dat_thermal, dat_radar = [messaging.new_message(s) for s in services]
dat_cs.controlsState.rearViewCam = False # ui checks for these two messages
dat_thermal.thermal.started = True

def send_thermal_packet(pm):
try:
while True:
dat = messaging.new_message('thermal')
dat.thermal.started = True
pm.send('thermal', dat)
time.sleep(1 / 2.) # 2 hz


def main():
pm = messaging.PubMaster(['controlsState', 'thermal'])
controls_sender = multiprocessing.Process(target=send_controls_packet, args=[pm])
controls_sender.start()
thermal_sender = multiprocessing.Process(target=send_thermal_packet, args=[pm])
thermal_sender.start()

# TODO: refactor with manager start/kill
proc_cam = subprocess.Popen(os.path.join(BASEDIR, "selfdrive/camerad/camerad"), cwd=os.path.join(BASEDIR, "selfdrive/camerad"))
proc_ui = subprocess.Popen(os.path.join(BASEDIR, "selfdrive/ui/ui"), cwd=os.path.join(BASEDIR, "selfdrive/ui"))

def terminate(signalNumber, frame):
print('got SIGTERM, exiting..')
proc_cam.send_signal(signal.SIGINT)
proc_ui.send_signal(signal.SIGINT)
thermal_sender.terminate()
controls_sender.terminate()
exit()

signal.signal(signal.SIGTERM, terminate)
signal.signal(signal.SIGINT, terminate) # catch ctrl-c as well


if __name__ == '__main__':
main()
pm.send('controlsState', dat_cs)
pm.send('thermal', dat_thermal)
pm.send('radarState', dat_radar)
time.sleep(1 / 100) # continually send, rate doesn't matter
except KeyboardInterrupt:
[p.send_signal(signal.SIGINT) for p in started_procs]

0 comments on commit 946fe8c

Please sign in to comment.