parent
c7b5fb9116
commit
a77c0a1098
73 changed files with 10311 additions and 2848 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +1,4 @@ |
||||
import os |
||||
BASEDIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../") |
||||
BASEDIR = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../")) |
||||
|
||||
|
||||
|
@ -1,32 +1,47 @@ |
||||
from common.realtime import sec_since_boot |
||||
import time |
||||
|
||||
class Profiler(object): |
||||
def __init__(self, enabled=False): |
||||
self.enabled = enabled |
||||
self.cp = [] |
||||
self.start_time = sec_since_boot() |
||||
self.cp = {} |
||||
self.cp_ignored = [] |
||||
self.iter = 0 |
||||
self.start_time = time.clock() |
||||
self.last_time = self.start_time |
||||
|
||||
def checkpoint(self, name): |
||||
if not self.enabled: |
||||
return |
||||
tt = sec_since_boot() |
||||
self.cp.append((name, tt - self.last_time)) |
||||
self.last_time = tt |
||||
self.tot = 0. |
||||
|
||||
def reset(self, enabled=False): |
||||
self.enabled = enabled |
||||
self.cp = [] |
||||
self.start_time = sec_since_boot() |
||||
self.cp = {} |
||||
self.cp_ignored = [] |
||||
self.iter = 0 |
||||
self.start_time = time.clock() |
||||
self.last_time = self.start_time |
||||
|
||||
def checkpoint(self, name, ignore=False): |
||||
# ignore flag needed when benchmarking threads with ratekeeper |
||||
if not self.enabled: |
||||
return |
||||
tt = time.clock() |
||||
if name not in self.cp: |
||||
self.cp[name] = 0. |
||||
if ignore: |
||||
self.cp_ignored.append(name) |
||||
self.cp[name] += tt - self.last_time |
||||
if not ignore: |
||||
self.tot += tt - self.last_time |
||||
self.last_time = tt |
||||
|
||||
def display(self): |
||||
if not self.enabled: |
||||
return |
||||
self.iter += 1 |
||||
print "******* Profiling *******" |
||||
tot = 0.0 |
||||
for n, ms in self.cp: |
||||
print "%30s: %7.2f" % (n, ms*1000.0) |
||||
tot += ms |
||||
print " TOTAL: %7.2f" % (tot*1000.0) |
||||
for n in self.cp: |
||||
ms = self.cp[n] |
||||
if n in self.cp_ignored: |
||||
print "%30s: %7.2f perc: %1.0f" % (n, ms*1000.0, ms/self.tot*100), " IGNORED" |
||||
else: |
||||
print "%30s: %7.2f perc: %1.0f" % (n, ms*1000.0, ms/self.tot*100) |
||||
print "Iter clock: %2.6f TOTAL: %2.2f" % (self.tot/self.iter, self.tot) |
||||
|
||||
|
@ -0,0 +1,39 @@ |
||||
#!/usr/bin/bash |
||||
|
||||
function launch { |
||||
# apply update |
||||
if [ "$(git rev-parse HEAD)" != "$(git rev-parse @{u})" ]; then |
||||
git reset --hard @{u} && |
||||
git clean -xdf && |
||||
exec "${BASH_SOURCE[0]}" |
||||
fi |
||||
|
||||
# check if NEOS update is required |
||||
while [ "$(cat /VERSION)" -lt 4 ] && [ ! -e /data/media/0/noupdate ]; do |
||||
curl -o /tmp/updater https://neos.comma.ai/updater && chmod +x /tmp/updater && /tmp/updater |
||||
sleep 10 |
||||
done |
||||
|
||||
# no cpu rationing for now |
||||
echo 0-3 > /dev/cpuset/background/cpus |
||||
echo 0-3 > /dev/cpuset/system-background/cpus |
||||
echo 0-3 > /dev/cpuset/foreground/boost/cpus |
||||
echo 0-3 > /dev/cpuset/foreground/cpus |
||||
echo 0-3 > /dev/cpuset/android/cpus |
||||
|
||||
# wait for network |
||||
(cd selfdrive/ui/spinner && exec ./spinner 'waiting for network...') & spin_pid=$! |
||||
until ping -W 1 -c 1 8.8.8.8; do sleep 1; done |
||||
kill $spin_pid |
||||
|
||||
export PYTHONPATH="$PWD" |
||||
|
||||
# start manager |
||||
cd selfdrive |
||||
./manager.py |
||||
|
||||
# if broken, keep on screen error |
||||
while true; do sleep 1; done |
||||
} |
||||
|
||||
launch |
Binary file not shown.
Binary file not shown.
@ -0,0 +1,121 @@ |
||||
#!/usr/bin/env python |
||||
import os |
||||
import time |
||||
import zmq |
||||
from common.realtime import sec_since_boot |
||||
import common.numpy_fast as np |
||||
from cereal import car |
||||
from selfdrive.config import Conversions as CV |
||||
from selfdrive.services import service_list |
||||
import selfdrive.messaging as messaging |
||||
from selfdrive.controls.lib.drive_helpers import EventTypes as ET, create_event |
||||
|
||||
# mocked car interface to work with chffrplus |
||||
TS = 0.01 # 100Hz |
||||
YAW_FR = 0.2 # ~0.8s time constant on yaw rate filter |
||||
# low pass gain |
||||
LPG = 2 * 3.1415 * YAW_FR * TS / (1 + 2 * 3.1415 * YAW_FR * TS) |
||||
|
||||
|
||||
class CarInterface(object): |
||||
def __init__(self, CP, sendcan=None): |
||||
|
||||
self.CP = CP |
||||
|
||||
print "Using Mock Car Interface" |
||||
context = zmq.Context() |
||||
|
||||
# TODO: subscribe to phone sensor |
||||
self.sensor = messaging.sub_sock(context, service_list['sensorEvents'].port) |
||||
self.gps = messaging.sub_sock(context, service_list['gpsLocation'].port) |
||||
|
||||
self.speed = 0. |
||||
self.yaw_rate = 0. |
||||
self.yaw_rate_meas = 0. |
||||
|
||||
@staticmethod |
||||
def compute_gb(accel, speed): |
||||
return accel |
||||
|
||||
@staticmethod |
||||
def calc_accel_override(a_ego, a_target, v_ego, v_target): |
||||
return 1.0 |
||||
|
||||
@staticmethod |
||||
def get_params(candidate, fingerprint): |
||||
|
||||
ret = car.CarParams.new_message() |
||||
|
||||
ret.carName = "mock" |
||||
ret.radarName = "mock" |
||||
ret.carFingerprint = candidate |
||||
|
||||
ret.safetyModel = car.CarParams.SafetyModels.noOutput |
||||
|
||||
# FIXME: hardcoding honda civic 2016 touring params so they can be used to |
||||
# scale unknown params for other cars |
||||
ret.mass = 1700. |
||||
ret.rotationalInertia = 2500. |
||||
ret.wheelbase = 2.70 |
||||
ret.centerToFront = ret.wheelbase * 0.5 |
||||
ret.steerRatio = 13. # reasonable |
||||
ret.longPidDeadzoneBP = [0.] |
||||
ret.longPidDeadzoneV = [0.] |
||||
ret.tireStiffnessFront = 1e6 # very stiff to neglect slip |
||||
ret.tireStiffnessRear = 1e6 # very stiff to neglect slip |
||||
ret.steerRatioRear = 0. |
||||
|
||||
ret.steerMaxBP = [0.] |
||||
ret.steerMaxV = [0.] # 2/3rd torque allowed above 45 kph |
||||
ret.gasMaxBP = [0.] |
||||
ret.gasMaxV = [0.] |
||||
ret.brakeMaxBP = [0.] |
||||
ret.brakeMaxV = [0.] |
||||
|
||||
ret.longitudinalKpBP = [0.] |
||||
ret.longitudinalKpV = [0.] |
||||
ret.longitudinalKiBP = [0.] |
||||
ret.longitudinalKiV = [0.] |
||||
|
||||
return ret |
||||
|
||||
# returns a car.CarState |
||||
def update(self, c): |
||||
|
||||
# get basic data from phone and gps since CAN isn't connected |
||||
sensors = messaging.recv_sock(self.sensor) |
||||
if sensors is not None: |
||||
for sensor in sensors.sensorEvents: |
||||
if sensor.type == 4: # gyro |
||||
self.yaw_rate_meas = -sensor.gyro.v[0] |
||||
|
||||
gps = messaging.recv_sock(self.gps) |
||||
if gps is not None: |
||||
self.speed = gps.gpsLocation.speed |
||||
|
||||
# create message |
||||
ret = car.CarState.new_message() |
||||
|
||||
# speeds |
||||
ret.vEgo = self.speed |
||||
ret.vEgoRaw = self.speed |
||||
ret.aEgo = 0. |
||||
self.yawRate = LPG * self.yaw_rate_meas + (1. - LPG) * self.yaw_rate |
||||
ret.yawRate = self.yaw_rate |
||||
ret.standstill = self.speed < 0.01 |
||||
ret.wheelSpeeds.fl = self.speed |
||||
ret.wheelSpeeds.fr = self.speed |
||||
ret.wheelSpeeds.rl = self.speed |
||||
ret.wheelSpeeds.rr = self.speed |
||||
curvature = self.yaw_rate / max(self.speed, 1.) |
||||
ret.steeringAngle = curvature * self.CP.steerRatio * self.CP.wheelbase * CV.RAD_TO_DEG |
||||
|
||||
events = [] |
||||
#events.append(create_event('passive', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE])) |
||||
ret.events = events |
||||
|
||||
return ret.as_reader() |
||||
|
||||
def apply(self, c): |
||||
# in mock no carcontrols |
||||
return False |
@ -1,8 +1,64 @@ |
||||
class CAR: |
||||
PRIUS = "TOYOTA PRIUS 2017" |
||||
RAV4 = "TOYOTA RAV4 2017" |
||||
|
||||
PRIUS = "TOYOTA PRIUS 2017" |
||||
RAV4H = "TOYOTA RAV4 2017 HYBRID" |
||||
RAV4 = "TOYOTA RAV4 2017" |
||||
|
||||
|
||||
class ECU: |
||||
CAM = 0 # camera |
||||
DSU = 1 # driving support unit |
||||
APGS = 2 # advanced parking guidance system |
||||
|
||||
|
||||
# addr, [ecu, bus, 1/freq*100, vl] |
||||
STATIC_MSGS = {0x141: (ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 1, 2, '\x00\x00\x00\x46'), |
||||
0x128: (ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 1, 3, '\xf4\x01\x90\x83\x00\x37'), |
||||
|
||||
0x292: (ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 3, '\x00\x00\x00\x00\x00\x00\x00\x9e'), |
||||
0x283: (ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 3, '\x00\x00\x00\x00\x00\x00\x8c'), |
||||
0x2E6: (ECU.DSU, (CAR.PRIUS, CAR.RAV4H,), 0, 3, '\xff\xf8\x00\x08\x7f\xe0\x00\x4e'), |
||||
0x2E7: (ECU.DSU, (CAR.PRIUS, CAR.RAV4H,), 0, 3, '\xa8\x9c\x31\x9c\x00\x00\x00\x02'), |
||||
|
||||
0x240: (ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 1, 5, '\x00\x10\x01\x00\x10\x01\x00'), |
||||
0x241: (ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 1, 5, '\x00\x10\x01\x00\x10\x01\x00'), |
||||
0x244: (ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 1, 5, '\x00\x10\x01\x00\x10\x01\x00'), |
||||
0x245: (ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 1, 5, '\x00\x10\x01\x00\x10\x01\x00'), |
||||
0x248: (ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 1, 5, '\x00\x00\x00\x00\x00\x00\x01'), |
||||
0x344: (ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 5, '\x00\x00\x01\x00\x00\x00\x00\x50'), |
||||
|
||||
0x160: (ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 1, 7, '\x00\x00\x08\x12\x01\x31\x9c\x51'), |
||||
0x161: (ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 1, 7, '\x00\x1e\x00\x00\x00\x80\x07'), |
||||
|
||||
0x32E: (ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 20, '\x00\x00\x00\x00\x00\x00\x00\x00'), |
||||
0x33E: (ECU.DSU, (CAR.PRIUS, CAR.RAV4H,), 0, 20, '\x0f\xff\x26\x40\x00\x1f\x00'), |
||||
0x365: (ECU.DSU, (CAR.PRIUS, CAR.RAV4H,), 0, 20, '\x00\x00\x00\x80\x03\x00\x08'), |
||||
0x365: (ECU.DSU, (CAR.RAV4,), 0, 20, '\x00\x00\x00\x80\xfc\x00\x08'), |
||||
0x366: (ECU.DSU, (CAR.PRIUS, CAR.RAV4H,), 0, 20, '\x00\x00\x4d\x82\x40\x02\x00'), |
||||
0x366: (ECU.DSU, (CAR.RAV4,), 0, 20, '\x00\x72\x07\xff\x09\xfe\x00'), |
||||
|
||||
0x367: (ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 40, '\x06\x00'), |
||||
|
||||
0x414: (ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 100, '\x00\x00\x00\x00\x00\x00\x17\x00'), |
||||
0x489: (ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 100, '\x00\x00\x00\x00\x00\x00\x00'), |
||||
0x48a: (ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 100, '\x00\x00\x00\x00\x00\x00\x00'), |
||||
0x48b: (ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 100, '\x66\x06\x08\x0a\x02\x00\x00\x00'), |
||||
0x4d3: (ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 100, '\x1C\x00\x00\x01\x00\x00\x00\x00'), |
||||
0x130: (ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 1, 100, '\x00\x00\x00\x00\x00\x00\x38'), |
||||
0x466: (ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 1, 100, '\x20\x20\xAD'), |
||||
0x396: (ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 100, '\xBD\x00\x00\x00\x60\x0F\x02\x00'), |
||||
0x43A: (ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 100, '\x84\x00\x00\x00\x00\x00\x00\x00'), |
||||
0x43B: (ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 100, '\x00\x00\x00\x00\x00\x00\x00\x00'), |
||||
0x497: (ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 100, '\x00\x00\x00\x00\x00\x00\x00\x00'), |
||||
0x4CC: (ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 100, '\x0D\x00\x00\x00\x00\x00\x00\x00'), |
||||
0x4CB: (ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 0, 100, '\x0c\x00\x00\x00\x00\x00\x00\x00'), |
||||
0x470: (ECU.DSU, (CAR.PRIUS, CAR.RAV4H,), 1, 100, '\x00\x00\x02\x7a'), |
||||
} |
||||
|
||||
|
||||
def check_ecu_msgs(fingerprint, candidate, ecu): |
||||
# return True if fingerprint contains messages normally sent by a given ecu |
||||
ecu_msgs = [x for x in STATIC_MSGS if (ecu == STATIC_MSGS[x][0] and |
||||
candidate in STATIC_MSGS[x][1] and |
||||
STATIC_MSGS[x][2] == 0)] |
||||
|
||||
return any(msg for msg in fingerprint if msg in ecu_msgs) |
||||
|
@ -1 +1 @@ |
||||
#define COMMA_VERSION "0.3.9-openpilot" |
||||
#define COMMA_VERSION "0.4.0.1-openpilot" |
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
@ -0,0 +1,24 @@ |
||||
#!/usr/bin/env python |
||||
from cereal import car |
||||
import time |
||||
|
||||
|
||||
class RadarInterface(object): |
||||
def __init__(self): |
||||
# radar |
||||
self.pts = {} |
||||
self.delay = 0.1 |
||||
|
||||
def update(self): |
||||
|
||||
ret = car.RadarState.new_message() |
||||
time.sleep(0.05) # radard runs on RI updates |
||||
|
||||
return ret |
||||
|
||||
if __name__ == "__main__": |
||||
RI = RadarInterface() |
||||
while 1: |
||||
ret = RI.update() |
||||
print(chr(27) + "[2J") |
||||
print ret |
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in new issue