Skip to content

Commit a422246

Browse files
author
Vehicle Researcher
committed
openpilot v0.5.4 release
1 parent e5b2ec4 commit a422246

File tree

123 files changed

+927
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+927
-395
lines changed

Dockerfile.openpilot

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ COPY ./phonelibs /tmp/openpilot/phonelibs
1717
COPY ./pyextra /tmp/openpilot/pyextra
1818

1919
RUN mkdir -p /tmp/openpilot/selfdrive/test/out
20+
RUN make -C /tmp/openpilot/selfdrive/controls/lib/longitudinal_mpc clean
21+
RUN make -C /tmp/openpilot/selfdrive/controls/lib/lateral_mpc clean

RELEASES.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
Version 0.5.4 (2018-09-25)
2+
========================
3+
* New Driving Model
4+
* New Driver Monitoring Model
5+
* Improve longitudinal mpc in mid-low speed braking
6+
* Honda Accord hybrid support thanks to energee!
7+
* Ship mpc binaries and sensibly reduce build time
8+
* Calibration more stable
9+
* More Hyundai and Kia cars supported thanks to emmertex!
10+
* Various GM Volt improvements thanks to vntarasov!
11+
112
Version 0.5.3 (2018-09-03)
213
========================
314
* Hyundai Santa Fe support!

cereal/car.capnp

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct CarEvent @0x9b1657f34caf3ad3 {
4242
speedTooLow @17;
4343
outOfSpace @18;
4444
overheat @19;
45-
calibrationInProgress @20;
45+
calibrationIncomplete @20;
4646
calibrationInvalid @21;
4747
controlsMismatch @22;
4848
pcmEnable @23;
@@ -69,6 +69,8 @@ struct CarEvent @0x9b1657f34caf3ad3 {
6969
promptDriverUnresponsive @44;
7070
driverUnresponsive @45;
7171
belowSteerSpeed @46;
72+
calibrationProgress @47;
73+
lowBattery @48;
7274
}
7375
}
7476

cereal/log.capnp

+1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ struct ThermalData {
276276
startedTs @13 :UInt64;
277277

278278
thermalStatus @14 :ThermalStatus;
279+
chargerDisabled @17 :Bool;
279280

280281
enum ThermalStatus {
281282
green @0; # all processes run

common/dbc.py

+81-44
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import re
22
import os
33
import struct
4-
import bitstring
54
import sys
65
import numbers
76
from collections import namedtuple, defaultdict
@@ -17,6 +16,7 @@ def int_or_float(s):
1716
"DBCSignal", ["name", "start_bit", "size", "is_little_endian", "is_signed",
1817
"factor", "offset", "tmin", "tmax", "units"])
1918

19+
2020
class dbc(object):
2121
def __init__(self, fn):
2222
self.name, _ = os.path.splitext(os.path.basename(fn))
@@ -122,6 +122,16 @@ def lookup_msg_id(self, msg_id):
122122
msg_id = self.msg_name_to_address[msg_id]
123123
return msg_id
124124

125+
def reverse_bytes(self, x):
126+
return ((x & 0xff00000000000000) >> 56) | \
127+
((x & 0x00ff000000000000) >> 40) | \
128+
((x & 0x0000ff0000000000) >> 24) | \
129+
((x & 0x000000ff00000000) >> 8) | \
130+
((x & 0x00000000ff000000) << 8) | \
131+
((x & 0x0000000000ff0000) << 24) | \
132+
((x & 0x000000000000ff00) << 40) | \
133+
((x & 0x00000000000000ff) << 56)
134+
125135
def encode(self, msg_id, dd):
126136
"""Encode a CAN message using the dbc.
127137
@@ -131,35 +141,40 @@ def encode(self, msg_id, dd):
131141
"""
132142
msg_id = self.lookup_msg_id(msg_id)
133143

134-
# TODO: Stop using bitstring, which is super slow.
135144
msg_def = self.msgs[msg_id]
136145
size = msg_def[0][1]
137146

138-
bsf = bitstring.Bits(hex="00"*size)
147+
result = 0
139148
for s in msg_def[1]:
140149
ival = dd.get(s.name)
141150
if ival is not None:
142-
ival = (ival / s.factor) - s.offset
143-
ival = int(round(ival))
144151

145-
# should pack this
152+
b2 = s.size
146153
if s.is_little_endian:
147-
ss = s.start_bit
154+
b1 = s.start_bit
148155
else:
149-
ss = self.bits_index[s.start_bit]
156+
b1 = (s.start_bit // 8) * 8 + (-s.start_bit - 1) % 8
157+
bo = 64 - (b1 + s.size)
158+
159+
ival = (ival / s.factor) - s.offset
160+
ival = int(round(ival))
150161

162+
if s.is_signed and ival < 0:
163+
ival = (1 << b2) + ival
151164

152-
if s.is_signed:
153-
tbs = bitstring.Bits(int=ival, length=s.size)
154-
else:
155-
tbs = bitstring.Bits(uint=ival, length=s.size)
165+
shift = b1 if s.is_little_endian else bo
166+
mask = ((1 << b2) - 1) << shift
167+
dat = (ival & ((1 << b2) - 1)) << shift
168+
169+
if s.is_little_endian:
170+
mask = self.reverse_bytes(mask)
171+
dat = self.reverse_bytes(dat)
156172

157-
lpad = bitstring.Bits(bin="0b"+"0"*ss)
158-
rpad = bitstring.Bits(bin="0b"+"0"*(8*size-(ss+s.size)))
159-
tbs = lpad+tbs+rpad
173+
result &= ~mask
174+
result |= dat
160175

161-
bsf |= tbs
162-
return bsf.tobytes()
176+
result = struct.pack('>Q', result)
177+
return result[:size]
163178

164179
def decode(self, x, arr=None, debug=False):
165180
"""Decode a CAN message using the dbc.
@@ -195,55 +210,77 @@ def decode(self, x, arr=None, debug=False):
195210
if debug:
196211
print name
197212

198-
blen = 8*len(x[2])
199-
200-
st = x[2].rjust(8, '\x00')
213+
st = x[2].ljust(8, '\x00')
201214
le, be = None, None
202-
size = msg[0][1]
203215

204216
for s in msg[1]:
205217
if arr is not None and s[0] not in arr:
206218
continue
207219

208-
# big or little endian?
209-
# see http://vi-firmware.openxcplatform.com/en/master/config/bit-numbering.html
210-
if s[3] is False:
211-
ss = self.bits_index[s[1]]
212-
if be is None:
213-
be = struct.unpack(">Q", st)[0]
214-
x2_int = be
215-
data_bit_pos = (blen - (ss + s[2]))
220+
start_bit = s[1]
221+
signal_size = s[2]
222+
little_endian = s[3]
223+
signed = s[4]
224+
factor = s[5]
225+
offset = s[6]
226+
227+
b2 = signal_size
228+
if little_endian:
229+
b1 = start_bit
216230
else:
231+
b1 = (start_bit // 8) * 8 + (-start_bit - 1) % 8
232+
bo = 64 - (b1 + signal_size)
233+
234+
if little_endian:
217235
if le is None:
218236
le = struct.unpack("<Q", st)[0]
219-
x2_int = le >> (64 - 8 * size)
220-
ss = s[1]
221-
data_bit_pos = ss
237+
shift_amount = b1
238+
tmp = le
239+
else:
240+
if be is None:
241+
be = struct.unpack(">Q", st)[0]
242+
shift_amount = bo
243+
tmp = be
222244

223-
if data_bit_pos < 0:
245+
if shift_amount < 0:
224246
continue
225-
ival = (x2_int >> data_bit_pos) & ((1 << (s[2])) - 1)
226247

227-
if s[4] and (ival & (1<<(s[2]-1))): # signed
228-
ival -= (1<<s[2])
248+
tmp = (tmp >> shift_amount) & ((1 << b2) - 1)
249+
if signed and (tmp >> (b2 - 1)):
250+
tmp -= (1 << b2)
229251

230-
# control the offset
231-
ival = (ival * s[5]) + s[6]
232-
#if debug:
233-
# print "%40s %2d %2d %7.2f %s" % (s[0], s[1], s[2], ival, s[-1])
252+
tmp = tmp * factor + offset
253+
254+
# if debug:
255+
# print "%40s %2d %2d %7.2f %s" % (s[0], s[1], s[2], tmp, s[-1])
234256

235257
if arr is None:
236-
out[s[0]] = ival
258+
out[s[0]] = tmp
237259
else:
238-
out[arr.index(s[0])] = ival
260+
out[arr.index(s[0])] = tmp
239261
return name, out
240262

241263
def get_signals(self, msg):
242264
msg = self.lookup_msg_id(msg)
243265
return [sgs.name for sgs in self.msgs[msg][1]]
244266

267+
245268
if __name__ == "__main__":
246269
from opendbc import DBC_PATH
270+
import numpy as np
271+
272+
dbc_test = dbc(os.path.join(DBC_PATH, 'toyota_prius_2017_pt_generated.dbc'))
273+
msg = ('STEER_ANGLE_SENSOR', {'STEER_ANGLE': -6.0, 'STEER_RATE': 4, 'STEER_FRACTION': -0.2})
274+
encoded = dbc_test.encode(*msg)
275+
decoded = dbc_test.decode((0x25, 0, encoded))
276+
assert decoded == msg
277+
278+
dbc_test = dbc(os.path.join(DBC_PATH, 'hyundai_santa_fe_2019_ccan.dbc'))
279+
decoded = dbc_test.decode((0x2b0, 0, "\xfa\xfe\x00\x07\x12"))
280+
assert np.isclose(decoded[1]['SAS_Angle'], -26.2)
281+
282+
msg = ('SAS11', {'SAS_Stat': 7.0, 'MsgCount': 0.0, 'SAS_Angle': -26.200000000000003, 'SAS_Speed': 0.0, 'CheckSum': 0.0})
283+
encoded = dbc_test.encode(*msg)
284+
decoded = dbc_test.decode((0x2b0, 0, encoded))
247285

248-
dbc_test = dbc(os.path.join(DBC_PATH, sys.argv[1]))
249-
print dbc_test.get_signals(0xe4)
286+
assert decoded == msg

common/filter_simple.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class FirstOrderFilter():
2+
# first order filter
3+
def __init__(self, x0, ts, dt):
4+
self.k = (dt / ts) / (1. + dt / ts)
5+
self.x = x0
6+
7+
def update(self, x):
8+
self.x = (1. - self.k) * self.x + self.k * x
9+
10+

common/transformations/model.py

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
bigmodel_frame_from_road_frame = np.dot(bigmodel_intrinsics,
5858
get_view_frame_from_road_frame(0, 0, 0, model_height))
5959

60+
model_frame_from_bigmodel_frame = np.dot(model_intrinsics, np.linalg.inv(bigmodel_intrinsics))
61+
6062
# 'camera from model camera'
6163
def get_model_height_transform(camera_frame_from_road_frame, height):
6264
camera_frame_from_road_ground = np.dot(camera_frame_from_road_frame, np.array([

selfdrive/boardd/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ WARN_FLAGS = -Werror=implicit-function-declaration \
1313
-Werror=return-type \
1414
-Werror=format-extra-args
1515

16-
CFLAGS = -std=gnu11 -g -fPIC -I../../ -O2 $(WARN_FLAGS)
17-
CXXFLAGS = -std=c++11 -g -fPIC -I../../ -O2 $(WARN_FLAGS)
16+
CFLAGS = -std=gnu11 -g -fPIC -I../ -I../../ -O2 $(WARN_FLAGS)
17+
CXXFLAGS = -std=c++11 -g -fPIC -I../ -I../../ -O2 $(WARN_FLAGS)
1818

1919
ZMQ_FLAGS = -I$(PHONELIBS)/zmq/aarch64/include
2020
ZMQ_LIBS = -L$(PHONELIBS)/zmq/aarch64/lib \

selfdrive/car/gm/carcontroller.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from selfdrive.boardd.boardd import can_list_to_can_capnp
55
from selfdrive.car import apply_std_steer_torque_limits
66
from selfdrive.car.gm import gmcan
7-
from selfdrive.car.gm.values import CAR, DBC
7+
from selfdrive.car.gm.values import CAR, DBC, AccState
88
from selfdrive.can.packer import CANPacker
99

1010

@@ -29,11 +29,11 @@ def __init__(self, car_fingerprint):
2929
self.ADAS_KEEPALIVE_STEP = 10
3030
# pedal lookups, only for Volt
3131
MAX_GAS = 3072 # Only a safety limit
32-
ZERO_GAS = 2048
32+
self.ZERO_GAS = 2048
3333
MAX_BRAKE = 350 # Should be around 3.5m/s^2, including regen
3434
self.MAX_ACC_REGEN = 1404 # ACC Regen braking is slightly less powerful than max regen paddle
3535
self.GAS_LOOKUP_BP = [-0.25, 0., 0.5]
36-
self.GAS_LOOKUP_V = [self.MAX_ACC_REGEN, ZERO_GAS, MAX_GAS]
36+
self.GAS_LOOKUP_V = [self.MAX_ACC_REGEN, self.ZERO_GAS, MAX_GAS]
3737
self.BRAKE_LOOKUP_BP = [-1., -0.25]
3838
self.BRAKE_LOOKUP_V = [MAX_BRAKE, 0]
3939

@@ -83,7 +83,6 @@ def update(self, sendcan, enabled, CS, frame, actuators, \
8383
return
8484

8585
P = self.params
86-
8786
# Send CAN commands.
8887
can_sends = []
8988
canbus = self.canbus
@@ -131,12 +130,18 @@ def update(self, sendcan, enabled, CS, frame, actuators, \
131130
if (frame % 4) == 0:
132131
idx = (frame / 4) % 4
133132

134-
at_full_stop = enabled and CS.standstill
135-
near_stop = enabled and (CS.v_ego < P.NEAR_STOP_BRAKE_PHASE)
133+
car_stopping = apply_gas < P.ZERO_GAS
134+
standstill = CS.pcm_acc_status == AccState.STANDSTILL
135+
at_full_stop = enabled and standstill and car_stopping
136+
near_stop = enabled and (CS.v_ego < P.NEAR_STOP_BRAKE_PHASE) and car_stopping
136137
can_sends.append(gmcan.create_friction_brake_command(self.packer_ch, canbus.chassis, apply_brake, idx, near_stop, at_full_stop))
137138

138-
at_full_stop = enabled and CS.standstill
139-
can_sends.append(gmcan.create_gas_regen_command(self.packer_pt, canbus.powertrain, apply_gas, idx, enabled, at_full_stop))
139+
# Auto-resume from full stop by resetting ACC control
140+
acc_enabled = enabled
141+
if standstill and not car_stopping:
142+
acc_enabled = False
143+
144+
can_sends.append(gmcan.create_gas_regen_command(self.packer_pt, canbus.powertrain, apply_gas, idx, acc_enabled, at_full_stop))
140145

141146
# Send dashboard UI commands (ACC status), 25hz
142147
if (frame % 4) == 0:

selfdrive/car/gm/gmcan.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,15 @@ def create_gas_regen_command(packer, bus, throttle, idx, acc_engaged, at_full_st
6060

6161
def create_friction_brake_command(packer, bus, apply_brake, idx, near_stop, at_full_stop):
6262

63-
if apply_brake == 0:
64-
mode = 0x1
65-
else:
63+
mode = 0x1
64+
if apply_brake > 0:
6665
mode = 0xa
6766

68-
if at_full_stop:
69-
mode = 0xd
70-
# TODO: this is to have GM bringing the car to complete stop,
71-
# but currently it conflicts with OP controls, so turned off.
72-
#elif near_stop:
73-
# mode = 0xb
67+
if near_stop:
68+
mode = 0xb
69+
70+
if at_full_stop:
71+
mode = 0xd
7472

7573
brake = (0x1000 - apply_brake) & 0xfff
7674
checksum = (0x10000 - (mode << 12) - brake - idx) & 0xffff

0 commit comments

Comments
 (0)