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

Auto hold #30

Merged
merged 8 commits into from
Mar 16, 2024
Merged
Changes from 4 commits
Commits
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
18 changes: 17 additions & 1 deletion board/safety/safety_toyota.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const CanMsg TOYOTA_INTERCEPTOR_TX_MSGS[] = {
{.msg = {{ 0xaa, 0, 8, .check_checksum = false, .frequency = 83U}, { 0 }, { 0 }}}, \
{.msg = {{0x260, 0, 8, .check_checksum = true, .quality_flag = (lta), .frequency = 50U}, { 0 }, { 0 }}}, \
{.msg = {{0x1D2, 0, 8, .check_checksum = true, .frequency = 33U}, { 0 }, { 0 }}}, \
{.msg = {{0x1D3, 0, 8, .check_checksum = true, .frequency = 33U}, { 0 }, { 0 }}}, \
{.msg = {{0x224, 0, 8, .check_checksum = false, .frequency = 40U}, \
{0x226, 0, 8, .check_checksum = false, .frequency = 40U}, { 0 }}}, \

Expand Down Expand Up @@ -190,6 +191,13 @@ static void toyota_rx_hook(const CANPacket_t *to_push) {
}
}

// wrap lateral controls on main
if (addr == 0x1D3) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To check the status of mainon. We only want to allow Break hold when mainon is active

// ACC main switch on is a prerequisite to enter controls, exit controls immediately on main switch off
// Signal: PCM_CRUISE_2/MAIN_ON at 15th bit
acc_main_on = GET_BIT(to_push, 15U);
}

// sample speed
if (addr == 0xaa) {
int speed = 0;
Expand Down Expand Up @@ -339,6 +347,12 @@ static bool toyota_tx_hook(const CANPacket_t *to_send) {
}
}
}
// DP: auto break hold https://github.com/AlexandreSato
if ((addr == 0x344) && (alternative_experience & ALT_EXP_ALLOW_AEB)) {
if (vehicle_moving || gas_pressed || !acc_main_on) {
tx = false;
}
}
}

// UDS: Only tester present ("\x0F\x02\x3E\x00\x00\x00\x00\x00") allowed on diagnostics address
Expand Down Expand Up @@ -403,7 +417,9 @@ static int toyota_fwd_hook(int bus_num, int addr) {
int is_lkas_msg = ((addr == 0x2E4) || (addr == 0x412) || (addr == 0x191));
// in TSS2 the camera does ACC as well, so filter 0x343
int is_acc_msg = (addr == 0x343);
int block_msg = is_lkas_msg || (is_acc_msg && !toyota_stock_longitudinal);
// DP: Block AEB when stoped to use as a automatic brakehold
int is_aeb_msg = ((addr == 0x344) && (alternative_experience & ALT_EXP_ALLOW_AEB));
int block_msg = is_lkas_msg || (is_acc_msg && !toyota_stock_longitudinal) || (is_aeb_msg && !vehicle_moving && acc_main_on && !gas_pressed);
if (!block_msg) {
bus_fwd = 0;
}
Expand Down
Loading