Skip to content

Commit

Permalink
Merge pull request #2 from commaai/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
pjlao307 authored Jul 3, 2017
2 parents 7fe46f1 + 70be4ce commit 721ed4e
Show file tree
Hide file tree
Showing 46 changed files with 652 additions and 2,029 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
.ipynb_checkpoints
model2.png

*.d
*.pyc
*.pyo
.*.swp
.*.swo
.*.un~
*.o
*.d
*.so
*.a
*.clb
*.class
*.pyxbldc
*.vcd
config.json
clcache

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "panda"]
path = panda
url = https://github.com/commaai/panda.git
[submodule "opendbc"]
path = opendbc
url = https://github.com/commaai/opendbc.git
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Currently it performs the functions of Adaptive Cruise Control (ACC) and Lane Ke

The openpilot codebase has been written to be concise and enable rapid prototyping. We look forward to your contributions - improving real vehicle automation has never been easier.

Here are [some](https://www.youtube.com/watch?v=9OwTJFuDI7g) [videos](https://www.youtube.com/watch?v=64Wvt5pYQmE) [of](https://www.youtube.com/watch?v=6IW7Nejsr3A) [it](https://www.youtube.com/watch?v=-VN1YcC83nA) [running](https://www.youtube.com/watch?v=EQJZvVeihZk). And a really cool [tutorial](https://www.youtube.com/watch?v=PwOnsT2UW5o).

Hardware
------

Expand All @@ -18,17 +20,20 @@ Supported Cars
------

- Acura ILX 2016 with AcuraWatch Plus
- Limitations: Due to use of the cruise control for gas, it can only be enabled above 25 mph
- Due to use of the cruise control for gas, it can only be enabled above 25 mph

- Honda Civic 2016 with Honda Sensing
- Limitations: Due to limitations in steering firmware, steering is disabled below 18 mph
- Due to limitations in steering firmware, steering is disabled below 12 mph

- Honda CR-V Touring 2015-2016 (very alpha!)
- Can only be enabled above 25 mph

Directory structure
------

- cereal -- The messaging spec used for all logs on the phone
- common -- Library like functionality we've developed here
- dbcs -- Files showing how to interpret data from cars
- opendbc -- Files showing how to interpret data from cars
- panda -- Code used to communicate on CAN and LIN
- phonelibs -- Libraries used on the phone
- selfdrive -- Code needed to drive the car
Expand Down Expand Up @@ -66,11 +71,9 @@ More extensive testing infrastructure and simulation environments are coming soo
Adding Car Support
------

It should be relatively easy to add support for the Honda CR-V Touring. The brake message is the same. Steering has a slightly different message with a different message id. Sniff CAN while using LKAS to find it.

The Honda Accord uses different signaling for the steering and probably requires new hardware.
comma.ai offers [bounties](http://comma.ai/bounties.html) for adding additional car support.

Adding other manufacturers besides Honda/Acura is doable but will be more of an undertaking.
CR-V Touring support came in through this program. Chevy Volt is close. Accord is close as well.

User Data / chffr Account / Crash Reporting
------
Expand All @@ -91,7 +94,7 @@ We welcome both pull requests and issues on
[github](http://github.com/commaai/openpilot). See the TODO file for a list of
good places to start.

Want to get paid to work on openpilot? [comma.ai is hiring](http://comma.ai/hiring.html)
Want to get paid to work on openpilot? [comma.ai is hiring](http://comma.ai/positions.html)

Licensing
------
Expand Down
10 changes: 10 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Version 0.3.3 (2017-06-28)
===========================
* Improved model trained on more data
* Alpha CR-V support thanks to energee and johnnwvs!
* Using the opendbc project for DBC files
* Minor performance improvements
* UI update thanks to pjlao307
* Power off button
* 6% more torque on the Civic

Version 0.3.2 (2017-05-22)
===========================
* Minor stability bugfixes
Expand Down
Binary file modified apk/com.baseui.apk
Binary file not shown.
5 changes: 3 additions & 2 deletions cereal/log.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ struct SensorEventData {
magnetic @5 :SensorVec;
orientation @6 :SensorVec;
gyro @7 :SensorVec;
pressure @9 :SensorVec;
}
source @8 :SensorSource;

Expand Down Expand Up @@ -297,8 +298,8 @@ struct LiveTracks {
struct Live100Data {
canMonoTime @16 :UInt64;
canMonoTimes @21 :List(UInt64);
l20MonoTime @17 :UInt64;
mdMonoTime @18 :UInt64;
l20MonoTimeDEPRECATED @17 :UInt64;
mdMonoTimeDEPRECATED @18 :UInt64;

vEgo @0 :Float32;
aEgoDEPRECATED @1 :Float32;
Expand Down
6 changes: 4 additions & 2 deletions common/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import requests

from selfdrive.version import version

def api_get(endpoint, method='GET', timeout=None, access_token=None, **params):
backend = "https://api.commadotai.com/"

params['_version'] = "OPENPILOTv0.3"

headers = {}
if access_token is not None:
headers['Authorization'] = "JWT "+access_token

headers['User-Agent'] = "openpilot-" + version

return requests.request(method, backend+endpoint, timeout=timeout, headers = headers, params=params)

22 changes: 13 additions & 9 deletions common/dbc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
import bitstring
from binascii import hexlify
import struct
from collections import namedtuple

def int_or_float(s):
Expand Down Expand Up @@ -36,6 +36,7 @@ def __init__(self, fn):
for i in range(0, 64, 8):
for j in range(7, -1, -1):
self.bits.append(i+j)
self.bits_index = dict(zip(self.bits, range(64)))

for l in self.txt:
l = l.strip()
Expand Down Expand Up @@ -102,7 +103,7 @@ def encode(self, msg_id, dd):
if s.is_little_endian:
ss = s.start_bit
else:
ss = self.bits.index(s.start_bit)
ss = self.bits_index[s.start_bit]


if s.is_signed:
Expand Down Expand Up @@ -135,9 +136,6 @@ def decode(self, x, arr=None, debug=False):
Returns (None, None) if the message could not be decoded.
"""

def swap_order(d, wsz=4, gsz=2 ):
return "".join(["".join([m[i:i+gsz] for i in range(wsz-gsz,-gsz,-gsz)]) for m in [d[i:i+wsz] for i in range(0,len(d),wsz)]])

if arr is None:
out = {}
else:
Expand All @@ -156,22 +154,28 @@ def swap_order(d, wsz=4, gsz=2 ):

blen = 8*len(x[2])

st = x[2].rjust(8, '\x00')
le, be = None, None

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

# big or little endian?
# see http://vi-firmware.openxcplatform.com/en/master/config/bit-numbering.html
if s[3] is False:
ss = self.bits.index(s[1])
x2_int = int(hexlify(x[2]), 16)
ss = self.bits_index[s[1]]
if be is None:
be = struct.unpack(">Q", st)[0]
x2_int = be
data_bit_pos = (blen - (ss + s[2]))
else:
x2_int = int(swap_order(hexlify(x[2]), 16, 2), 16)
if le is None:
le = struct.unpack("<Q", st)[0]
x2_int = le
ss = s[1]
data_bit_pos = ss


if data_bit_pos < 0:
continue
ival = (x2_int >> data_bit_pos) & ((1 << (s[2])) - 1)
Expand Down
8 changes: 7 additions & 1 deletion common/fingerprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
},
"HONDA ACCORD 2016 TOURING": {
1024L: 5, 929L: 8, 1027L: 5, 773L: 7, 1601L: 8, 777L: 8, 1036L: 8, 398L: 3, 1039L: 8, 401L: 8, 145L: 8, 1424L: 5, 660L: 8, 661L: 4, 918L: 7, 985L: 3, 923L: 2, 542L: 7, 927L: 8, 800L: 8, 545L: 4, 420L: 8, 422L: 8, 808L: 8, 426L: 8, 1029L: 8, 432L: 7, 57L: 3, 316L: 8, 829L: 5, 1600L: 5, 1089L: 8, 1057L: 5, 780L: 8, 1088L: 8, 464L: 8, 1108L: 8, 597L: 8, 342L: 6, 983L: 8, 344L: 8, 804L: 8, 476L: 4, 1296L: 3, 891L: 8, 1125L: 8, 487L: 4, 892L: 8, 490L: 8, 871L: 8, 1064L: 7, 882L: 2, 884L: 8, 506L: 8, 507L: 1, 380L: 8, 1365L: 5
},
"HONDA CR-V 2016 TOURING": {
57L: 3, 145L: 8, 316L: 8, 340L: 8, 342L: 6, 344L: 8, 380L: 8, 398L: 3, 399L: 6, 401L: 8, 420L: 8, 422L: 8, 426L: 8, 432L: 7, 464L: 8, 474L: 5, 476L: 4, 487L: 4, 490L: 8, 493L: 3, 507L: 1, 542L: 7, 545L: 4, 597L: 8, 660L: 8, 661L: 4, 773L: 7, 777L: 8, 800L: 8, 804L: 8, 808L: 8, 882L: 2, 884L: 7, 888L: 8, 891L: 8, 892L: 8, 923L: 2, 929L: 8, 983L: 8, 985L: 3, 1024L: 5, 1027L: 5, 1029L: 8, 1033L: 5, 1036L: 8, 1039L: 8, 1057L: 5, 1064L: 7, 1108L: 8, 1125L: 8, 1296L: 8, 1365L: 5, 1424L: 5, 1600L: 5, 1601L: 8,
# sent messages
0x194: 4, 0x1fa: 8, 0x30c: 8, 0x33d: 5,
}
}

Expand Down Expand Up @@ -121,8 +126,9 @@ def fingerprint(logcan):
ret.steerKp, ret.steerKi = 12.0, 1.0
elif candidate_cars[0] == "HONDA ACCORD 2016 TOURING":
ret.steerKp, ret.steerKi = 12.0, 1.0
elif candidate_cars[0] == "HONDA CR-V 2016 TOURING":
ret.steerKp, ret.steerKi = 6.0, 0.5
else:
raise ValueError("unsupported car %s" % candidate_cars[0])

return ret

20 changes: 12 additions & 8 deletions common/logging_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@
from collections import OrderedDict
from contextlib import contextmanager

def json_handler(obj):
# if isinstance(obj, (datetime.date, datetime.time)):
# return obj.isoformat()
return repr(obj)

def json_robust_dumps(obj):
return json.dumps(obj, default=json_handler)

class SwagFormatter(logging.Formatter):
def __init__(self, swaglogger):
logging.Formatter.__init__(self, None, '%a %b %d %H:%M:%S %Z %Y')

self.swaglogger = swaglogger
self.host = socket.gethostname()

def json_handler(self, obj):
# if isinstance(obj, (datetime.date, datetime.time)):
# return obj.isoformat()
return repr(obj)

def format(self, record):
def format_dict(self, record):
record_dict = OrderedDict()

if isinstance(record.msg, dict):
Expand Down Expand Up @@ -50,9 +53,10 @@ def format(self, record):
record_dict['threadName'] = record.threadName
record_dict['created'] = record.created

# asctime = self.formatTime(record, self.datefmt)
return record_dict

return json.dumps(record_dict, default=self.json_handler)
def format(self, record):
return json_robust_dumps(self.format_dict(record))

_tmpfunc = lambda: 0
_srcfile = os.path.normcase(_tmpfunc.__code__.co_filename)
Expand Down
61 changes: 37 additions & 24 deletions common/realtime.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
"""Utilities for reading real time clocks and keeping soft real time constraints."""
import os
import time
import ctypes
import platform
import threading
import subprocess
import multiprocessing
import os

from ctypes.util import find_library
from cffi import FFI
ffi = FFI()
ffi.cdef("""
typedef int clockid_t;
struct timespec {
long tv_sec; /* Seconds. */
long tv_nsec; /* Nanoseconds. */
};
int clock_gettime (clockid_t clk_id, struct timespec *tp);
CLOCK_MONOTONIC_RAW = 4 # see <linux/time.h>
CLOCK_BOOTTIME = 7
long syscall(long number, ...);
class timespec(ctypes.Structure):
_fields_ = [
('tv_sec', ctypes.c_long),
('tv_nsec', ctypes.c_long),
]
"""
)
libc = ffi.dlopen(None)

libc_name = find_library('c')
libc = ctypes.CDLL(libc_name, use_errno=True)

# see <linux/time.h>
CLOCK_MONOTONIC_RAW = 4
CLOCK_BOOTTIME = 7

if hasattr(libc, 'clock_gettime'):
libc.clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
has_clock_gettime = True
else:
has_clock_gettime = False
c_clock_gettime = libc.clock_gettime

def clock_gettime(clk_id):
if not has_clock_gettime:
# hack. only for OS X < 10.12
return time.time()
tlocal = threading.local()
def clock_gettime(clk_id):
if not hasattr(tlocal, 'ts'):
tlocal.ts = ffi.new('struct timespec *')

t = timespec()
if libc.clock_gettime(clk_id, ctypes.pointer(t)) != 0:
errno_ = ctypes.get_errno()
raise OSError(errno_, os.strerror(errno_))
return t.tv_sec + t.tv_nsec * 1e-9
ts = tlocal.ts

r = c_clock_gettime(clk_id, ts)
if r != 0:
raise OSError("clock_gettime")
return ts.tv_sec + ts.tv_nsec * 1e-9
else:
# hack. only for OS X < 10.12
def clock_gettime(clk_id):
return time.time()

def monotonic_time():
return clock_gettime(CLOCK_MONOTONIC_RAW)
Expand Down Expand Up @@ -96,3 +106,6 @@ def monitor_time(self):
self._frame += 1
self._remaining = remaining
return lagged

if __name__ == "__main__":
print sec_since_boot()
9 changes: 9 additions & 0 deletions common/testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import os
from nose.tools import nottest

def phone_only(x):
if os.path.isfile("/init.qcom.rc"):
return x
else:
return nottest(x)

2 changes: 0 additions & 2 deletions dbcs/__init__.py

This file was deleted.

Loading

0 comments on commit 721ed4e

Please sign in to comment.