Skip to content

Commit

Permalink
Small Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SippieCup committed Apr 18, 2020
1 parent 82ea5ae commit f374e9b
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 96 deletions.
98 changes: 50 additions & 48 deletions README.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion common/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ def remaining(self):
return self._remaining

# Maintain loop rate by calling this at the end of each loop
def keep_time(self):
def keep_time(self, offset=0.):
lagged = self.monitor_time()
if self._remaining > 0:
time.sleep(self._remaining)
elif not offset == 0.:
self._next_frame_time += offset
return lagged

# this only monitor the cumulative lag, but does not enforce a rate
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/boardd/boardd_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ARCH_DIR = 'x64'
else:
libraries = [':libcan_list_to_can_capnp.a', 'capnp', 'kj']
if os.path.isdir("/system"):
if os.path.isdir("/system") or os.path.isdir('/data/oprun'):
ARCH_DIR = 'aarch64'
else:
ARCH_DIR = 'larch64'
Expand Down
7 changes: 5 additions & 2 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def __init__(self, CP, CarController, CarState):
self.VM = VehicleModel(CP)

self.frame = 0
self.gas_pressed_prev = False
self.brake_pressed_prev = False
self.cruise_enabled_prev = False
self.low_speed_alert = False

self.CS = CarState(CP)
Expand Down Expand Up @@ -105,8 +108,8 @@ def create_common_events(self, cs_out, extra_gears=[], gas_resume_speed=-1, pcm_
# Disable on rising edge of gas or brake. Also disable on brake when speed > 0.
# Optionally allow to press gas at zero speed to resume.
# e.g. Chrysler does not spam the resume button yet, so resuming with gas is handy. FIXME!
if (cs_out.gasPressed and (not self.CS.out.gasPressed) and cs_out.vEgo > gas_resume_speed) or \
(cs_out.brakePressed and (not self.CS.out.brakePressed or not cs_out.standstill)):
if (cs_out.gasPressed and (not self.gas_pressed_prev) and cs_out.vEgo > gas_resume_speed) or \
(cs_out.brakePressed and (not self.brake_pressed_prev or not cs_out.standstill)):
events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE]))

# we engage when pcm is active (rising edge)
Expand Down
5 changes: 5 additions & 0 deletions selfdrive/car/tesla/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ def __init__(self, CP):
self.ahbOffDuration = 5
self.roadCameraID = ""
self.driverCameraID = ""
self.roadCameraFx = 0.73
self.driverCameraFx = 0.75
self.roadCameraFlip = 0
self.driverCameraFlip = 0
self.monitorForcedRes = ""
#read config file
read_config_file(self)
### END OF MAIN CONFIG OPTIONS ###
Expand Down
11 changes: 4 additions & 7 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@


LANE_DEPARTURE_THRESHOLD = 0.1
STEER_ANGLE_SATURATION_TIMEOUT = 1.0 / DT_CTRL
STEER_ANGLE_SATURATION_THRESHOLD = 2.5 # Degrees
EER_ANGLE_SATURATION_TIMEOUT = 1.0 / DT_CTRL
STEER_ANGLE_SATURATION_THRESHOLD = 250 # Degrees

ThermalStatus = log.ThermalData.ThermalStatus
State = log.ControlsState.OpenpilotState
Expand Down Expand Up @@ -119,7 +119,7 @@ def data_sample(CI, CC, sm, can_sock, state, mismatch_counter, can_error_counter
else:
events.append(create_event('calibrationInvalid', [ET.NO_ENTRY, ET.SOFT_DISABLE]))

if CS.vEgo > 92 * CV.MPH_TO_MS:
if CS.vEgo > 150 * CV.MPH_TO_MS:
events.append(create_event('speedTooHigh', [ET.NO_ENTRY, ET.SOFT_DISABLE]))

# When the panda and controlsd do not agree on controls_allowed
Expand Down Expand Up @@ -470,10 +470,6 @@ def controlsd_thread(sm=None, pm=None, can_sock=None):

passive = passive or not openpilot_enabled_toggle

# Passive if internet needed
internet_needed = params.get("Offroad_ConnectivityNeeded", encoding='utf8') is not None
passive = passive or internet_needed

# Pub/Sub Sockets
if pm is None:
pm = messaging.PubMaster(['sendcan', 'controlsState', 'carState', 'carControl', 'carEvents', 'carParams'])
Expand Down Expand Up @@ -548,6 +544,7 @@ def controlsd_thread(sm=None, pm=None, can_sock=None):
# controlsd is driven by can recv, expected at 100Hz
rk = Ratekeeper(100, print_delay_threshold=None)

internet_needed = params.get("Offroad_ConnectivityNeeded", encoding='utf8') is not None

prof = Profiler(False) # off by default

Expand Down
20 changes: 3 additions & 17 deletions selfdrive/controls/lib/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __gt__(self, alert2):

Alert(
"preDriverDistracted",
"KEEP EYES ON ROAD: Driver Distracted",
"KEEP EYES ON ROAD: Driver Appears Distracted",
"",
AlertStatus.normal, AlertSize.small,
Priority.LOW, VisualAlert.steerRequired, AudibleAlert.none, .0, .1, .1, alert_rate=0.75),
Expand Down Expand Up @@ -272,7 +272,7 @@ def __gt__(self, alert2):
Alert(
"dataNeededNoEntry",
"openpilot Unavailable",
"Calibration Needs Data. Upload Drive, Try Again",
"Data Needed for Calibration. Upload Drive, Try Again",
AlertStatus.normal, AlertSize.mid,
Priority.LOW, VisualAlert.none, AudibleAlert.chimeError, .4, 0., 3.),

Expand Down Expand Up @@ -526,13 +526,6 @@ def __gt__(self, alert2):
AlertStatus.normal, AlertSize.mid,
Priority.HIGH, VisualAlert.none, AudibleAlert.chimeDisengage, .4, 2., 3.),

Alert(
"speedTooHigh",
"Speed Too High",
"Slow down to resume operation",
AlertStatus.normal, AlertSize.mid,
Priority.HIGH, VisualAlert.none, AudibleAlert.chimeDisengage, .4, 2., 3.),

# Cancellation alerts causing non-entry
Alert(
"overheatNoEntry",
Expand All @@ -551,7 +544,7 @@ def __gt__(self, alert2):
Alert(
"calibrationInvalidNoEntry",
"openpilot Unavailable",
"Calibration Invalid: Reposition Device & Recalibrate",
"Calibration Invalid: Reposition Device and Recalibrate",
AlertStatus.normal, AlertSize.mid,
Priority.LOW, VisualAlert.none, AudibleAlert.chimeError, .4, 2., 3.),

Expand Down Expand Up @@ -752,13 +745,6 @@ def __gt__(self, alert2):
AlertStatus.normal, AlertSize.mid,
Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., .2),

Alert(
"invalidLkasSettingPermanent",
"Stock LKAS is turned on",
"Turn off stock LKAS to engage",
AlertStatus.normal, AlertSize.mid,
Priority.LOWER, VisualAlert.none, AudibleAlert.none, 0., 0., .2),

Alert(
"internetConnectivityNeededPermanent",
"Please connect to Internet",
Expand Down
4 changes: 2 additions & 2 deletions tools/webcam/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ git clone https://github.com/commaai/openpilot.git
```
- Follow [this readme](https://github.com/commaai/openpilot/tree/master/tools) to install the requirements
- Add line "export PYTHONPATH=$HOME/openpilot" to your ~/.bashrc
- You also need to install tensorflow-gpu 2.1.0 (if not working, try 2.0.0) and nvidia drivers: nvidia-xxx/cuda10.0/cudnn7.6.5
- You also need to install tensorflow-gpu 2.1.0 and nvidia drivers: nvidia-xxx/cuda10.0/cudnn7.6.5
- Install [OpenCL Driver](http://registrationcenter-download.intel.com/akdlm/irc_nas/12556/opencl_runtime_16.1.2_x64_rh_6.4.0.37.tgz)
- (Note: the code assumes cl platforms order to be 0.GPU/1.CPU when running clinfo; if reverse, change the -1 to -2 in selfdrive/modeld/modeld.cc#L130; helping us refactor this mess is encouraged)
- Install [OpenCV4](https://www.pyimagesearch.com/2018/08/15/how-to-install-opencv-4-on-ubuntu/) (ignore the Python part)
- Install [OpenCV4](https://www.pyimagesearch.com/2018/08/15/how-to-install-opencv-4-on-ubuntu/)

## Build openpilot for webcam
```
Expand Down
6 changes: 3 additions & 3 deletions tools/webcam/front_mount_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3.6
import numpy as np

# copied from common.transformations/camera.py
Expand All @@ -15,7 +15,7 @@
[ 0., webcam_focal_length, 720/2.],
[ 0., 0., 1.]])

cam_id = 2
cam_id = 1

if __name__ == "__main__":
import cv2
Expand All @@ -32,4 +32,4 @@
img = cv2.warpPerspective(img, trans_webcam_to_eon_front, (1152,864), borderMode=cv2.BORDER_CONSTANT, borderValue=0)
img = img[:,-864//2:,:]
cv2.imshow('preview', img)
cv2.waitKey(10)
cv2.waitKey(10)
17 changes: 11 additions & 6 deletions tools/webcam/jetson_test_cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
" nvvidconv ! video/x-raw(memory:NVMM),format=I420 !"
" nvvidconv ! video/x-raw,format=BGRx !"
" videoconvert ! video/x-raw,format=BGR !"
" videoscale ! video/x-raw,width=%d,height=%d !"
" videoscale ! video/x-raw,width=%d,height=%d ! %s"
" videobox autocrop=true ! video/x-raw,width=%d,height=%d !"
" appsink ")
cs = CarSettings()
if len(sys.argv) != 2:
Expand All @@ -21,11 +22,15 @@
if cam == "road" or cam == "driver":
print ("Processing camera [%s]\n" % cam)
if cam == "road":
strm = strm_template % (cs.roadCameraID, 800, 600, 20, 1164,874)
dx = round(1164/4)
dy = round(874/4)
flip_command = ""
if cs.roadCameraFlip == 1:
flip_command = "videoflip method=rotate-180 ! "
strm = strm_template % (cs.roadCameraID, 800, 600, 20, round(1164*cs.roadCameraFx*1.5),round(874*cs.roadCameraFx*1.5),flip_command,1164,874)
else:
strm = strm_template % (cs.driverCameraID, 640, 480, 10, 1152,864)
flip_command = ""
if cs.driverCameraFlip == 1:
flip_command = "videoflip method=180 ! "
strm = strm_template % (cs.driverCameraID, 640, 480, 10, round(1152*cs.driverCameraFx),round(864*cs.driverCameraFx),flip_command,1152,864)
dx = round(1152/4)
dy = round(864/4)
print("Capturing with stream [%s}\n" % strm)
Expand All @@ -35,7 +40,7 @@
while True:
ret, frame = cap.read()
if cam == "road":
img = frame[ dy:3*dy, dx:3*dx]
img = frame
else:
img = frame[:,-864//2:,:]
if ret:
Expand Down
19 changes: 10 additions & 9 deletions tools/webcam/warp_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
eon_focal_length = 910.0 # pixels
eon_dcam_focal_length = 860.0 # pixels

webcam_focal_length = -908.0/1.5 # pixels
webcam_focal_length = 1408.0/1.5 # pixels

eon_intrinsics = np.array([
[eon_focal_length, 0., 1164/2.],
Expand All @@ -18,8 +18,8 @@
[ 0, 0, 1]])

webcam_intrinsics = np.array([
[webcam_focal_length, 0., 1280/2/1.5],
[ 0., webcam_focal_length, 720/2/1.5],
[webcam_focal_length, 0., 960/2/1.5],
[ 0., webcam_focal_length, 544/2/1.5],
[ 0., 0., 1.]])

if __name__ == "__main__":
Expand All @@ -29,17 +29,18 @@
print("trans_webcam_to_eon_rear:\n", trans_webcam_to_eon_rear)
print("trans_webcam_to_eon_front:\n", trans_webcam_to_eon_front)

cap = cv2.VideoCapture(1)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 853)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
cap = cv2.VideoCapture(2)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 960)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 544)

while (True):
ret, img = cap.read()
ret, img = cap.read(1)
if ret:
# img = cv2.warpPerspective(img, trans_webcam_to_eon_rear, (1164,874), borderMode=cv2.BORDER_CONSTANT, borderValue=0)
img = cv2.warpPerspective(img, trans_webcam_to_eon_front, (1164,874), borderMode=cv2.BORDER_CONSTANT, borderValue=0)
#img = cv2.warpPerspective(img, trans_webcam_to_eon_rear, (1164,874), borderMode=cv2.BORDER_CONSTANT, borderValue=0)
img = cv2.warpPerspective(img, trans_webcam_to_eon_front, (1164,874), borderMode=cv2.BORDER_CONSTANT, borderValue=100)
print(img.shape, end='\r')
cv2.imshow('preview', img)
cv2.waitKey(10)



0 comments on commit f374e9b

Please sign in to comment.