Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hongqi HS5 #882

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
317b2da
FAW: Barebones vehicle port
jyoung8607 Mar 21, 2022
415a3d8
GC old comment
jyoung8607 Mar 21, 2022
9b831f4
GC old comment
jyoung8607 Mar 21, 2022
2c795f3
MISRA letting me off easy today
jyoung8607 Mar 21, 2022
e57d1bc
blind test
jyoung8607 Mar 23, 2022
8916693
Merge branch 'master' into faw-hongqi-hs5
jyoung8607 Aug 6, 2022
e171095
follow refactoring
jyoung8607 Aug 6, 2022
4b79257
clean up commonized tests
jyoung8607 Aug 6, 2022
20cf44b
more commonized tests, GET_BIT usage
jyoung8607 Aug 6, 2022
0484fce
MISRA
jyoung8607 Aug 6, 2022
349a20d
bump opendbc ref
jyoung8607 Aug 6, 2022
188be5a
living my best submodule life
jyoung8607 Aug 6, 2022
0d78410
detail oriented
jyoung8607 Aug 6, 2022
7b66219
different MISRA
jyoung8607 Aug 6, 2022
cd67ef2
allow magic torque value for steering disabled
jyoung8607 Aug 8, 2022
db3d9a6
signal and counter refactor
jyoung8607 Aug 8, 2022
2b8ccf4
check all engaged states
jyoung8607 Aug 9, 2022
5f9fb77
adjust ramp-rates and driver torque allowance
jyoung8607 Aug 9, 2022
ce659c3
Merge branch 'master' into faw-hongqi-hs5
jyoung8607 Aug 23, 2022
f6a02bb
faw -> hongqi
jyoung8607 Aug 24, 2022
7c633b0
more renaming
jyoung8607 Aug 24, 2022
7ff1f31
follow torque rate control refactor
jyoung8607 Aug 26, 2022
c9592d8
Merge branch 'master' into faw-hongqi-hs5
jyoung8607 Oct 16, 2022
3b535a3
Merge branch 'master' of https://github.com/commaai/panda into faw-ho…
jyoung8607 Oct 22, 2022
aaa6806
follow pcm_cruise_check refactor
jyoung8607 Oct 22, 2022
de5559a
temp hack out other safeties to build on H7
jyoung8607 Oct 22, 2022
804cae5
more temp hack outs
jyoung8607 Oct 22, 2022
6aa9c78
Revert "more temp hack outs"
jyoung8607 Oct 31, 2022
b626af2
Revert "temp hack out other safeties to build on H7"
jyoung8607 Oct 31, 2022
13aedb9
Merge branch 'master' of https://github.com/commaai/panda into faw-ho…
jyoung8607 Oct 31, 2022
3625167
bump Docker refs
jyoung8607 Oct 31, 2022
6e7edcf
Merge branch 'master' into faw-hongqi-hs5
jyoung8607 Jan 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more renaming
  • Loading branch information
jyoung8607 committed Aug 24, 2022
commit 7c633b066024c7d8573fd6b22c4884d89a80fb48
2 changes: 1 addition & 1 deletion board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ const safety_hook_config safety_hook_registry[] = {
{SAFETY_TESLA, &tesla_hooks},
{SAFETY_SUBARU_LEGACY, &subaru_legacy_hooks},
{SAFETY_VOLKSWAGEN_PQ, &volkswagen_pq_hooks},
{SAFETY_HONGQI, &faw_hooks},
{SAFETY_HONGQI, &hongqi_hooks},
{SAFETY_ALLOUTPUT, &alloutput_hooks},
{SAFETY_FORD, &ford_hooks},
#endif
Expand Down
66 changes: 33 additions & 33 deletions board/safety/safety_hongqi.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const int FAW_MAX_STEER = 300; // As-yet unknown fault boundary, guessing 300 / 3.0Nm for now
const int FAW_MAX_RT_DELTA = 113; // 6 max rate up * 50Hz send rate * 250000 RT interval / 1000000 = 75 ; 50 * 1.5 for safety pad = 113
const uint32_t FAW_RT_INTERVAL = 250000; // 250ms between real time checks
const int FAW_MAX_RATE_UP = 6; // 10 unit/sec observed from factory LKAS, fault boundary unknown
const int FAW_MAX_RATE_DOWN = 10; // 10 unit/sec observed from factory LKAS, fault boundary unknown
const int FAW_DRIVER_TORQUE_ALLOWANCE = 50;
const int FAW_DRIVER_TORQUE_FACTOR = 3;
const int HONGQI_MAX_STEER = 300; // As-yet unknown fault boundary, guessing 300 / 3.0Nm for now
const int HONGQI_MAX_RT_DELTA = 113; // 6 max rate up * 50Hz send rate * 250000 RT interval / 1000000 = 75 ; 50 * 1.5 for safety pad = 113
const uint32_t HONGQI_RT_INTERVAL = 250000; // 250ms between real time checks
const int HONGQI_MAX_RATE_UP = 6; // 10 unit/sec observed from factory LKAS, fault boundary unknown
const int HONGQI_MAX_RATE_DOWN = 10; // 10 unit/sec observed from factory LKAS, fault boundary unknown
const int HONGQI_DRIVER_TORQUE_ALLOWANCE = 50;
const int HONGQI_DRIVER_TORQUE_FACTOR = 3;

#define MSG_ECM_1 0x92 // RX from ABS, for brake pressures
#define MSG_ABS_1 0xC0 // RX from ABS, for wheel speeds
Expand All @@ -13,29 +13,29 @@ const int FAW_DRIVER_TORQUE_FACTOR = 3;
#define MSG_LKAS 0x112 // TX from openpilot, for LKAS torque
#define MSG_EPS_2 0x150 // RX from EPS, torque inputs and outputs

const CanMsg FAW_TX_MSGS[] = {{MSG_LKAS, 0, 8}};
#define FAW_TX_MSGS_LEN (sizeof(FAW_TX_MSGS) / sizeof(FAW_TX_MSGS[0]))
const CanMsg HONGQI_TX_MSGS[] = {{MSG_LKAS, 0, 8}};
#define HONGQI_TX_MSGS_LEN (sizeof(HONGQI_TX_MSGS) / sizeof(HONGQI_TX_MSGS[0]))

AddrCheckStruct faw_addr_checks[] = {
AddrCheckStruct hongqi_addr_checks[] = {
{.msg = {{MSG_ECM_1, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}},
{.msg = {{MSG_ABS_1, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}},
{.msg = {{MSG_MAYBE_ABS, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}},
{.msg = {{MSG_ACC, 2, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}},
{.msg = {{MSG_EPS_2, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}},
};
#define FAW_ADDR_CHECKS_LEN (sizeof(faw_addr_checks) / sizeof(faw_addr_checks[0]))
addr_checks faw_rx_checks = {faw_addr_checks, FAW_ADDR_CHECKS_LEN};
#define HONGQI_ADDR_CHECKS_LEN (sizeof(hongqi_addr_checks) / sizeof(hongqi_addr_checks[0]))
addr_checks hongqi_rx_checks = {hongqi_addr_checks, HONGQI_ADDR_CHECKS_LEN};


static uint32_t faw_get_checksum(CANPacket_t *to_push) {
static uint32_t hongqi_get_checksum(CANPacket_t *to_push) {
return (uint8_t)GET_BYTE(to_push, 0);
}

static uint8_t faw_get_counter(CANPacket_t *to_push) {
static uint8_t hongqi_get_counter(CANPacket_t *to_push) {
return ((uint8_t)GET_BYTE(to_push, 7) >> 4) & 0xFU;
}

static uint32_t faw_compute_checksum(CANPacket_t *to_push) {
static uint32_t hongqi_compute_checksum(CANPacket_t *to_push) {
int len = GET_LEN(to_push);
int checksum = 0;

Expand All @@ -46,15 +46,15 @@ static uint32_t faw_compute_checksum(CANPacket_t *to_push) {
return checksum;
}

static const addr_checks* faw_init(uint16_t param) {
static const addr_checks* hongqi_init(uint16_t param) {
UNUSED(param);

return &faw_rx_checks;
return &hongqi_rx_checks;
}

static int faw_rx_hook(CANPacket_t *to_push) {
static int hongqi_rx_hook(CANPacket_t *to_push) {

bool valid = addr_safety_check(to_push, &faw_rx_checks, faw_get_checksum, faw_compute_checksum, faw_get_counter);
bool valid = addr_safety_check(to_push, &hongqi_rx_checks, hongqi_get_checksum, hongqi_compute_checksum, hongqi_get_counter);
int bus = GET_BUS(to_push);
int addr = GET_ADDR(to_push);

Expand Down Expand Up @@ -114,13 +114,13 @@ static int faw_rx_hook(CANPacket_t *to_push) {
return valid;
}

static int faw_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
static int hongqi_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
UNUSED(longitudinal_allowed);

int addr = GET_ADDR(to_send);
int tx = 1;

if (!msg_allowed(to_send, FAW_TX_MSGS, FAW_TX_MSGS_LEN)) {
if (!msg_allowed(to_send, HONGQI_TX_MSGS, HONGQI_TX_MSGS_LEN)) {
tx = 0;
}

Expand All @@ -130,7 +130,7 @@ static int faw_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
if (addr == MSG_LKAS) {
int desired_torque = GET_BYTE(to_send, 1) | ((GET_BYTE(to_send, 2) & 0x3U) << 8);
int sign = (GET_BYTE(to_send, 2) & 0x4U) >> 2;
// FAW sends 1022 when steering is inactive
// Hongqi sends 1022 when steering is inactive
if (desired_torque == 1022) {
desired_torque = 0;
}
Expand All @@ -143,20 +143,20 @@ static int faw_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {

if (controls_allowed) {
// *** global torque limit check ***
violation |= max_limit_check(desired_torque, FAW_MAX_STEER, -FAW_MAX_STEER);
violation |= max_limit_check(desired_torque, HONGQI_MAX_STEER, -HONGQI_MAX_STEER);

// *** torque rate limit check ***
violation |= driver_limit_check(desired_torque, desired_torque_last, &torque_driver,
FAW_MAX_STEER, FAW_MAX_RATE_UP, FAW_MAX_RATE_DOWN,
FAW_DRIVER_TORQUE_ALLOWANCE, FAW_DRIVER_TORQUE_FACTOR);
HONGQI_MAX_STEER, HONGQI_MAX_RATE_UP, HONGQI_MAX_RATE_DOWN,
HONGQI_DRIVER_TORQUE_ALLOWANCE, HONGQI_DRIVER_TORQUE_FACTOR);
desired_torque_last = desired_torque;

// *** torque real time rate limit check ***
violation |= rt_rate_limit_check(desired_torque, rt_torque_last, FAW_MAX_RT_DELTA);
violation |= rt_rate_limit_check(desired_torque, rt_torque_last, HONGQI_MAX_RT_DELTA);

// every RT_INTERVAL set the new limits
uint32_t ts_elapsed = get_ts_elapsed(ts, ts_last);
if (ts_elapsed > FAW_RT_INTERVAL) {
if (ts_elapsed > HONGQI_RT_INTERVAL) {
rt_torque_last = desired_torque;
ts_last = ts;
}
Expand Down Expand Up @@ -193,7 +193,7 @@ static int faw_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
return tx;
}

static int faw_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
static int hongqi_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
int addr = GET_ADDR(to_fwd);
int bus_fwd = -1;

Expand All @@ -218,10 +218,10 @@ static int faw_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
return bus_fwd;
}

const safety_hooks faw_hooks = {
.init = faw_init,
.rx = faw_rx_hook,
.tx = faw_tx_hook,
const safety_hooks hongqi_hooks = {
.init = hongqi_init,
.rx = hongqi_rx_hook,
.tx = hongqi_tx_hook,
.tx_lin = nooutput_tx_lin_hook,
.fwd = faw_fwd_hook,
.fwd = hongqi_fwd_hook,
};
2 changes: 1 addition & 1 deletion python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Panda:
SAFETY_HYUNDAI_LEGACY = 23
SAFETY_HYUNDAI_COMMUNITY = 24
SAFETY_STELLANTIS = 25
SAFETY_FAW = 26
SAFETY_HONGQI = 26
SAFETY_BODY = 27
SAFETY_HYUNDAI_CANFD = 28

Expand Down
10 changes: 5 additions & 5 deletions tests/safety/test_hongqi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
MSG_EPS_2 = 0x150 # RX from EPS, torque inputs and outputs


class TestFawSafety(common.PandaSafetyTest, common.DriverTorqueSteeringSafetyTest):
class TestHongqiSafety(common.PandaSafetyTest, common.DriverTorqueSteeringSafetyTest):
STANDSTILL_THRESHOLD = 1
RELAY_MALFUNCTION_ADDR = MSG_LKAS
RELAY_MALFUNCTION_BUS = 0
Expand All @@ -29,7 +29,7 @@ class TestFawSafety(common.PandaSafetyTest, common.DriverTorqueSteeringSafetyTes

@classmethod
def setUpClass(cls):
if cls.__name__ == "TestFawSafety":
if cls.__name__ == "TestHongqiSafety":
cls.packer = None
cls.safety = None
raise unittest.SkipTest
Expand Down Expand Up @@ -92,15 +92,15 @@ def test_torque_measurements(self):
self.assertEqual(0, self.safety.get_torque_driver_min())


class TestFawStockSafety(TestFawSafety):
class TestHongqiStockSafety(TestHongqiSafety):
TX_MSGS = [[MSG_LKAS, 0]]
FWD_BLACKLISTED_ADDRS = {2: [MSG_LKAS]}
FWD_BUS_LOOKUP = {0: 2, 2: 0}

def setUp(self):
self.packer = CANPackerPanda("faw")
self.packer = CANPackerPanda("hongqi_hs5")
self.safety = libpandasafety_py.libpandasafety
self.safety.set_safety_hooks(Panda.SAFETY_FAW, 0)
self.safety.set_safety_hooks(Panda.SAFETY_HONGQI, 0)
self.safety.init_tests()

# TODO: implement
Expand Down