Skip to content

Commit

Permalink
Merge pull request commaai#66 from BogGyver/tesla_alpha_0.5.12
Browse files Browse the repository at this point in the history
Tesla alpha 0.5.12
  • Loading branch information
BogGyver authored Jun 12, 2019
2 parents 678a6af + d5abe28 commit 0f3be9f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
16 changes: 12 additions & 4 deletions panda/board/pedal_tesla/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,31 @@ CERT = ../../certs/debug
CFLAGS += "-DALLOW_DEBUG"

canflash: obj/$(PROJ_NAME).bin
../../tests/pedal/enter_canloader.py $<
../../tests/pedal/enter_canloader_tesla.py $<

usbflash: obj/$(PROJ_NAME).bin
../../tests/pedal/enter_canloader.py; sleep 0.5
../../tests/pedal/enter_canloader_tesla.py; sleep 0.5
PYTHONPATH=../../ python -c "from python import Panda; p = [x for x in [Panda(x) for x in Panda.list()] if x.bootstub]; assert(len(p)==1); p[0].flash('obj/$(PROJ_NAME).bin', reconnect=False)"

recover: obj/bootstub.bin obj/$(PROJ_NAME).bin
../../tests/pedal/enter_canloader.py --recover; sleep 0.5
../../tests/pedal/enter_canloader_tesla.py --recover; sleep 0.5
$(DFU_UTIL) -d 0483:df11 -a 0 -s 0x08004000 -D obj/$(PROJ_NAME).bin
$(DFU_UTIL) -d 0483:df11 -a 0 -s 0x08000000:leave -D obj/bootstub.bin

include ../../common/version.mk

obj/cert.h: ../../crypto/getcertheader.py
../../crypto/getcertheader.py ../../certs/debug.pub ../../certs/release.pub > $@

obj/main.o: main.c ../*.h
mkdir -p obj
$(CC) $(CFLAGS) -o $@ -c $<

obj/bootstub.o: ../bootstub.c ../*.h
obj/bootstub.o: ../bootstub.c ../*.h obj/gitversion.h obj/cert.h
mkdir -p obj
mkdir -p ../obj
cp obj/gitversion.h ../obj/gitversion.h
cp obj/cert.h ../obj/cert.h
$(CC) $(CFLAGS) -o $@ -c $<

obj/$(STARTUP_FILE).o: ../$(STARTUP_FILE).s
Expand Down
5 changes: 3 additions & 2 deletions panda/board/pedal_tesla/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@

#define CAN CAN1

//#define PEDAL

//#define PEDAL_USB

#ifdef PEDAL_USB
#include "drivers/usb.h"
#endif

#define ENTER_BOOTLOADER_MAGIC 0xdeadbeef
uint32_t enter_bootloader_mode;

void __initialize_hardware_early() {
Expand Down Expand Up @@ -87,6 +86,8 @@ int can_cksum(uint8_t *dat, int len, int addr) {
// addresses to be used on CAN
#define CAN_GAS_INPUT 0x551
#define CAN_GAS_OUTPUT 0x552
#define CAN_GAS_SIZE 6
#define COUNTER_CYCLE 0xF

void CAN1_TX_IRQHandler() {
// clear interrupt
Expand Down
1 change: 1 addition & 0 deletions panda/tests/pedal/enter_canloader_tesla.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def bulkRead(self, endpoint, length, timeout=0):
exit(0)
else:
p.can_send(0x551, "\xce\xfa\xad\xde\x1e\x0b\xb0\x0a", 2)

if args.fn:
time.sleep(0.1)
print "flashing", args.fn
Expand Down
12 changes: 9 additions & 3 deletions selfdrive/car/tesla/PCC_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def __init__(self,carcontroller):
self.a_acc_sol = 0.0
self.v_cruise = 0.0
self.a_cruise = 0.0
self.had_lead = False
#Long Control
self.LoC = None
#when was radar data last updated?
Expand Down Expand Up @@ -497,7 +498,10 @@ def calc_follow_speed_ms(self, CS):
else:
lead_dist_m = _visual_radar_adjusted_dist_m(self.lead_1.dRel, CS)
# Grab the relative speed.
rel_speed_kph = self.lead_1.vRel * CV.MS_TO_KPH
rel_speed_kph = 0.
if self.had_lead:
#avoid inital break when lead just detected
rel_speed_kph = self.lead_1.vRel * CV.MS_TO_KPH
# v_ego is in m/s, so safe_distance is in meters.
safe_dist_m = _safe_distance_m(CS.v_ego)
# Current speed in kph
Expand All @@ -509,7 +513,9 @@ def calc_follow_speed_ms(self, CS):
# If no lead is present, accel up to max speed
if lead_dist_m == 0:
new_speed_kph = self.pedal_speed_kph
self.had_lead = False
elif lead_dist_m > 0:
self.had_lead = True
lead_absolute_speed_kph = actual_speed_kph + rel_speed_kph
if lead_dist_m < MIN_SAFE_DIST_M:
new_speed_kph = MIN_PCC_V_KPH
Expand Down Expand Up @@ -543,7 +549,7 @@ def calc_follow_speed_ms(self, CS):
# still an acceptable speed, accept it. This could happen if the
# driver manually accelerates, or if we roll down a hill. In either
# case, don't fight the extra velocity unless necessary.
if actual_speed_kph > new_speed_kph and min_kph < actual_speed_kph < max_kph:
if (actual_speed_kph > new_speed_kph) and (min_kph < actual_speed_kph < max_kph):
new_speed_kph = actual_speed_kph

new_speed_kph = clip(new_speed_kph, min_kph, max_kph)
Expand Down Expand Up @@ -594,7 +600,7 @@ def _min_safe_vrel_kph(m):
# (meters, safe relative velocity in kph)
# Remember, a negative relative velocity means we are closing the distance.
(MIN_SAFE_DIST_M, 1), # If lead is close, it better be pulling away.
(200, -15)]) # if lead is far, it's ok if we're closing.
(100, -15)]) # if lead is far, it's ok if we're closing.
return _interp_map(m, min_vrel_by_distance)

def _is_present(lead):
Expand Down

0 comments on commit 0f3be9f

Please sign in to comment.