Skip to content

Commit

Permalink
Promote panda fixes from alpha to devel (#98)
Browse files Browse the repository at this point in the history
* Fix for mock car crash

* fix ALCA module

* do not use

* radar_interface logic improvements

* remove radar logging

* radar_interface refactoring

* Log radar_interface CAN error, Process Comm Errors (#95)

* Log radar_interface CAN error

* Add support for process comm error logging

* Improve Process Comm error logging

* Can and CommError throttling

* Update radar_interface.py

* fixing push per Raf's comments

* ALCA and radar_interface work (#96) (#97)

* do not use

* radar_interface logic improvements

* remove radar logging

* radar_interface refactoring

* Update radar_interface.py

* fixing push per Raf's comments

* fix process comm issue

* switch radard from lane_parser to model

* radar/ALCA changes

* fix lane width

* switched back to not deleting CarParams to avoid radar failure when rebooting EON while driving

* cleanup some debug info to be able to restart ALCA research

* tweaks on safety_tesla.h for can bus isolation

* few more cleanups to safety_tesla.h

* fix start signal logic
  • Loading branch information
BogGyver authored Sep 4, 2019
1 parent b044c65 commit 75d986f
Show file tree
Hide file tree
Showing 17 changed files with 290 additions and 181 deletions.
1 change: 1 addition & 0 deletions cereal/tesla.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct TeslaRadarPoint {
movingState @3 :UInt8; # 0-indeterminate 1-moving 2-stopped 3-standing
length @4 :Float32; # length in meters
obstacleProb @5 :Float32; # probability to be an obstacle
timeStamp @6 :UInt64; #timestamp when the pair was received
}

struct ICCarsLR {
Expand Down
2 changes: 1 addition & 1 deletion common/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class UnknownKeyName(Exception):
"AccessToken": [TxType.PERSISTENT],
"AthenadPid": [TxType.PERSISTENT],
"CalibrationParams": [TxType.PERSISTENT],
"CarParams": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT], #[TxType.CLEAR_ON_CAR_START],
"CarParams": [TxType.CLEAR_ON_CAR_START], #[TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT], #[TxType.CLEAR_ON_CAR_START],
"CarVin": [TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT], #[TxType.PERSISTENT], #[TxType.CLEAR_ON_MANAGER_START, TxType.CLEAR_ON_PANDA_DISCONNECT],
"CompletedTrainingVersion": [TxType.PERSISTENT],
"ControlsParams": [TxType.PERSISTENT],
Expand Down
34 changes: 16 additions & 18 deletions panda/board/safety/safety_tesla.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ int high_beam_lever_state = 0;

int tesla_radar_status = 0; //0-not present, 1-initializing, 2-active
uint32_t tesla_last_radar_signal = 0;
const uint32_t TESLA_RADAR_TIMEOUT = 1000000; // 1 second between real time checks
const uint32_t TESLA_RADAR_TIMEOUT = 10000000; // 10s second between real time checks
char radar_VIN[] = " "; //leave empty if your radar VIN matches the car VIN
int tesla_radar_vin_complete = 0;
int tesla_radar_can = 1;
int tesla_epas_can = 2;
int tesla_radar_trigger_message_id = 0; //not used by tesla, to showcase for other cars
int radarPosition = 0; //0 nosecone, 1 facelift
int radarEpasType = 0; //0/1 bosch, 2-4 mando
Expand Down Expand Up @@ -945,15 +946,15 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push)
}

//let's see if the pedal was pressed
if ((addr == 0x552) && (bus_number == 2)) {
if ((addr == 0x552) && (bus_number == tesla_epas_can)) {
//m1 = 0.050796813
//m2 = 0.101593626
//d = -22.85856576
DAS_pedalPressed = (int)((((to_push->RDLR & 0xFF00) >> 8) + ((to_push->RDLR & 0xFF) << 8)) * 0.050796813 -22.85856576);
}

//we use 0x108 at 100Hz to detect timing of messages sent by our fake DAS and EPB
if (addr == 0x108) {
if ((addr == 0x108) && (bus_number == 0)) {
if (fake_DAS_counter % 10 == 5) {
do_EPB_epasControl(to_push->RIR,to_push->RDTR);
}
Expand All @@ -962,16 +963,15 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push)
}

// Record the current car time in current_car_time (for use with double-pulling cruise stalk)
if (addr == 0x318)
{
if ((addr == 0x318) && (bus_number == 0)) {
int hour = (to_push->RDLR & 0x1F000000) >> 24;
int minute = (to_push->RDHR & 0x3F00) >> 8;
int second = (to_push->RDLR & 0x3F0000) >> 16;
current_car_time = (hour * 3600) + (minute * 60) + second;
}

//we use EPAS_sysStatus 0x370 to determine if the car is off or on
if (addr == 0x370) {
if ((addr == 0x370) && (bus_number != 1)) {
time_last_EPAS_data = current_car_time;
}

Expand All @@ -986,7 +986,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push)
}

//see if cruise is enabled [Enabled, standstill or Override] and cancel if using pedal
if (addr == 0x368) {
if ((addr == 0x368) && (bus_number == 0)) {
//first save values for spamming
DAS_diStateL = to_push->RDLR;
DAS_diStateH = to_push->RDHR;
Expand All @@ -999,7 +999,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push)
}

//looking for radar messages;
if ((addr == 0x300) && (bus_number ==1))
if ((addr == 0x300) && (bus_number == tesla_radar_can))
{
uint32_t ts = TIM2->CNT;
uint32_t ts_elapsed = get_ts_elapsed(ts, tesla_last_radar_signal);
Expand All @@ -1018,7 +1018,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push)
}

//0x631 is sent by radar to initiate the sync
if ((addr == 0x631) && (bus_number == 1))
if ((addr == 0x631) && (bus_number == tesla_radar_can))
{
uint32_t ts = TIM2->CNT;
uint32_t ts_elapsed = get_ts_elapsed(ts, tesla_last_radar_signal);
Expand All @@ -1036,8 +1036,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push)
}
}

if (addr == 0x45)
{
if ((addr == 0x45) && (bus_number == 0)) {
//first save for future use
DAS_lastStalkL = to_push->RDLR;
DAS_lastStalkH = to_push->RDHR;
Expand Down Expand Up @@ -1240,7 +1239,8 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push)

// exit controls on EPAS error
// EPAS_sysStatus::EPAS_eacStatus 0x370
if ((addr == 0x370) && (bus_number == 1))
//BB this was on bus_number 1 which is wrong, but not tested on 2 yet
if ((addr == 0x370) && (bus_number == tesla_epas_can))
{
// if EPAS_eacStatus is not 1 or 2, disable control
eac_status = (GET_BYTE(to_push, 6) >> 5) & 0x7;
Expand Down Expand Up @@ -1293,8 +1293,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push)

/* <-- revB giraffe GPIO */
//BO_ 1001 DAS_bodyControls: 8 XXX
if (addr == 0x3e9)
{
if ((addr == 0x3e9) && (bus_number == 0)) {
int high_beam_decision = (to_push->RDLR >> 10) & 0x3; //DAS_highLowBeamDecision : 10|2@1+
// highLowBeamDecision:
//0: Undecided (Car off)
Expand All @@ -1320,8 +1319,7 @@ static void tesla_rx_hook(CAN_FIFOMailBox_TypeDef *to_push)
} //DAS_bodyControls

//BO_ 872 DI_state: 8 DI
if (addr == 0x368)
{
if ((addr == 0x368) && (bus_number == 0)) {
int regen_brake_light = (to_push->RDLR >> 8) & 0x1; //DI_regenLight : 8|1@1+
//if the car's brake lights are on, set pin 2 to high
if (regen_brake_light == 1)
Expand Down Expand Up @@ -1863,7 +1861,7 @@ static int tesla_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd)
return -1;
}

if (bus_num == 2)
if (bus_num == tesla_epas_can)
{

// remove GTW_epasControl in forwards
Expand Down Expand Up @@ -1893,4 +1891,4 @@ const safety_hooks tesla_hooks = {
.tx_lin = nooutput_tx_lin_hook,
.ignition = tesla_ign_hook,
.fwd = tesla_fwd_hook,
};
};
6 changes: 0 additions & 6 deletions selfdrive/can/plant_can_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from selfdrive.car.honda.hondacan import fix
from common.realtime import sec_since_boot
from common.dbc import dbc
from selfdrive.tinklad.tinkla_interface import TinklaClient

class CANParser(object):
def __init__(self, dbc_f, signals, checks=None):
Expand Down Expand Up @@ -57,8 +56,6 @@ def __init__(self, dbc_f, signals, checks=None):
for i, x in enumerate(self._msgs):
self._message_indices[x].append(i)

self.tinklaClient = TinklaClient()

def update_can(self, can_recv):
msgs_upd = []
cn_vl_max = 5 # no more than 5 wrong counter checks
Expand All @@ -82,7 +79,6 @@ def update_can(self, can_recv):
# compare recalculated vs received checksum
if msg_vl != cdat:
print("CHECKSUM FAIL: {0}".format(hex(msg)))
self.tinklaClient.logCANErrorEvent(canMessage=msg, additionalInformation="Checksum failure")
self.ck[msg] = False
self.ok[msg] = False
# counter check
Expand All @@ -98,7 +94,6 @@ def update_can(self, can_recv):
# message status is invalid if we received too many wrong counter values
if self.cn_vl[msg] >= cn_vl_max:
print("COUNTER WRONG: {0}".format(hex(msg)))
self.tinklaClient.logCANErrorEvent(canMessage=msg, additionalInformation="Too many wrong counter values")
self.ok[msg] = False

# update msg time stamps and counter value
Expand Down Expand Up @@ -134,5 +129,4 @@ def _check_dead_msgs(self):
for msg in set(self._msgs):
if msg in self.msgs_ck and self.sec_since_boot_cached - self.ct[msg] > 10./self.frqs[msg]:
self.ok[msg] = False
self.tinklaClient.logCANErrorEvent(canMessage=msg, additionalInformation="Dead message")

Loading

0 comments on commit 75d986f

Please sign in to comment.