Skip to content

Commit

Permalink
new outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyhaibin committed Nov 27, 2024
1 parent 14e976a commit 0ae9a19
Showing 1 changed file with 79 additions and 74 deletions.
153 changes: 79 additions & 74 deletions tools/car_porting/examples/hkg_can_gear_message.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,36 @@
"cells": [
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 17,
"id": "228a6736-de31-4255-9d72-a6ff391b968d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found 1 qualifying vehicles:\n",
" HYUNDAI_IONIQ_PHEV\n"
"Found 21 qualifying vehicles:\n",
" HYUNDAI_IONIQ_EV_LTD\n",
" KIA_NIRO_EV\n",
" HYUNDAI_IONIQ_HEV_2022\n",
" HYUNDAI_IONIQ_PHEV\n",
" HYUNDAI_KONA_HEV\n",
" KIA_NIRO_PHEV\n",
" HYUNDAI_IONIQ\n",
" KIA_K5_HEV_2020\n",
" HYUNDAI_KONA_EV_2022\n",
" HYUNDAI_IONIQ_PHEV_2019\n",
" HYUNDAI_SANTA_FE_PHEV_2022\n",
" HYUNDAI_SONATA_HYBRID\n",
" HYUNDAI_AZERA_HEV_6TH_GEN\n",
" HYUNDAI_IONIQ_EV_2020\n",
" KIA_NIRO_PHEV_2022\n",
" KIA_OPTIMA_H_G4_FL\n",
" HYUNDAI_SANTA_FE_HEV_2022\n",
" HYUNDAI_ELANTRA_HEV_2021\n",
" HYUNDAI_KONA_EV\n",
" KIA_OPTIMA_H\n",
" KIA_NIRO_HEV_2021\n"
]
}
],
Expand All @@ -20,8 +40,8 @@
"from opendbc.car.hyundai.values import CAR, HyundaiFlags\n",
"from opendbc.car.hyundai.fingerprints import FW_VERSIONS\n",
"\n",
"#TEST_PLATFORMS = set(CAR.with_flags(HyundaiFlags.EV | HyundaiFlags.HYBRID)) - set(CAR.with_flags(HyundaiFlags.CANFD)) # CAN hybrid and electric vehicles only\n",
"TEST_PLATFORMS = [CAR.HYUNDAI_IONIQ_PHEV, ]\n",
"TEST_PLATFORMS = set(CAR.with_flags(HyundaiFlags.EV | HyundaiFlags.HYBRID)) - set(CAR.with_flags(HyundaiFlags.CANFD)) # CAN hybrid and electric vehicles only\n",
"#TEST_PLATFORMS = [CAR.HYUNDAI_IONIQ_PHEV, ]\n",
"\n",
"print(f\"Found {len(TEST_PLATFORMS)} qualifying vehicles:\")\n",
"for platform in TEST_PLATFORMS:\n",
Expand All @@ -30,7 +50,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 20,
"id": "ed1c8aec-c274-4c61-b83d-711ea194bf86",
"metadata": {},
"outputs": [
Expand All @@ -39,22 +59,40 @@
"output_type": "stream",
"text": [
"Collecting segments from commaCarSegments dataset:\n",
"Got 1115 segments for platform HYUNDAI_IONIQ_PHEV, sampling 40 segments\n",
"Collected 40 segments for analysis\n"
"Got 9 segments for platform HYUNDAI_IONIQ_EV_LTD, sampling 9 segments\n",
"Got 1201 segments for platform KIA_NIRO_EV, sampling 1201 segments\n",
"Got 4 segments for platform HYUNDAI_IONIQ_HEV_2022, sampling 4 segments\n",
"Got 1115 segments for platform HYUNDAI_IONIQ_PHEV, sampling 1115 segments\n",
"Got 3 segments for platform HYUNDAI_KONA_HEV, sampling 3 segments\n",
"Got 86 segments for platform KIA_NIRO_PHEV, sampling 86 segments\n",
"Got 348 segments for platform HYUNDAI_IONIQ, sampling 348 segments\n",
"Got 3 segments for platform KIA_K5_HEV_2020, sampling 3 segments\n",
"Got 440 segments for platform HYUNDAI_KONA_EV_2022, sampling 440 segments\n",
"Got 3 segments for platform HYUNDAI_IONIQ_PHEV_2019, sampling 3 segments\n",
"Got 1050 segments for platform HYUNDAI_SANTA_FE_PHEV_2022, sampling 1050 segments\n",
"Got 1062 segments for platform HYUNDAI_SONATA_HYBRID, sampling 1062 segments\n",
"Got 4 segments for platform HYUNDAI_AZERA_HEV_6TH_GEN, sampling 4 segments\n",
"Got 274 segments for platform HYUNDAI_IONIQ_EV_2020, sampling 274 segments\n",
"Got 3 segments for platform KIA_NIRO_PHEV_2022, sampling 3 segments\n",
"Got 3 segments for platform KIA_OPTIMA_H_G4_FL, sampling 3 segments\n",
"Got 892 segments for platform HYUNDAI_SANTA_FE_HEV_2022, sampling 892 segments\n",
"Got 1043 segments for platform HYUNDAI_ELANTRA_HEV_2021, sampling 1043 segments\n",
"Got 1015 segments for platform HYUNDAI_KONA_EV, sampling 1015 segments\n",
"Got 3 segments for platform KIA_OPTIMA_H, sampling 3 segments\n",
"Got 546 segments for platform KIA_NIRO_HEV_2021, sampling 546 segments\n",
"Collected 9107 segments for analysis\n"
]
}
],
"source": [
"import random\n",
"\n",
"from openpilot.tools.lib.logreader import LogReader\n",
"from openpilot.tools.lib.comma_car_segments import get_comma_car_segments_database\n",
"from opendbc.car.hyundai.values import CAR\n",
"\n",
"database = get_comma_car_segments_database()\n",
"TEST_SEGMENTS = []\n",
"\n",
"MAX_SEGS_PER_PLATFORM = 40 # TODO: Increase this to search more segments\n",
"MAX_SEGS_PER_PLATFORM = 1115 # TODO: Increase this to search more segments\n",
"\n",
"print(\"Collecting segments from commaCarSegments dataset:\")\n",
"for platform in TEST_PLATFORMS:\n",
Expand All @@ -65,72 +103,40 @@
" \n",
" all_segments = database[platform]\n",
"\n",
" NUM_SEGMENTS = min(len(all_segments), MAX_SEGS_PER_PLATFORM)\n",
" #NUM_SEGMENTS = min(len(all_segments), MAX_SEGS_PER_PLATFORM)\n",
" NUM_SEGMENTS = len(all_segments)\n",
"\n",
" print(f\"Got {len(all_segments)} segments for platform {platform}, sampling {NUM_SEGMENTS} segments\")\n",
"\n",
" TEST_SEGMENTS.extend(random.sample(all_segments, NUM_SEGMENTS))\n",
" TEST_SEGMENTS.extend(all_segments)\n",
"\n",
"print(f\"Collected {len(TEST_SEGMENTS)} segments for analysis\")\n"
]
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 22,
"id": "0c75e8f2-4f5f-4f89-b8db-5223a6534a9f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Analyzing segment 8fd9d7b55c053355/2023-11-22--14-15-12/22/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment f78ea8bac6cf6c9d/2023-12-07--07-31-30/18/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 37f27727e9056e1c/2023-12-12--16-27-58/4/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 37f27727e9056e1c/2023-12-14--15-16-25/64/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment c447f3983314c453/2024-01-15--16-09-23/19/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 8fd9d7b55c053355/2023-12-06--13-29-24/20/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 74f6ab69c669f8c5/2023-11-06--14-32-39/3/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 74f6ab69c669f8c5/2023-12-05--12-30-06/10/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 8fd9d7b55c053355/2023-11-22--18-28-57/11/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 78fdfacf4a805561/2023-12-12--17-31-17/76/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 37f27727e9056e1c/2024-01-25--14-37-27/83/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 2833de0636d26d55/2024-01-17--18-16-59/10/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment f78ea8bac6cf6c9d/2023-12-18--07-03-43/4/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 8fd9d7b55c053355/2023-11-18--15-05-42/37/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 8fd9d7b55c053355/2023-12-20--12-44-07/7/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 8fd9d7b55c053355/2023-12-10--15-31-28/90/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 37f27727e9056e1c/2023-11-25--11-02-38/7/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 8fd9d7b55c053355/2023-10-31--11-18-27/12/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 37f27727e9056e1c/2023-12-08--21-11-37/29/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 8fd9d7b55c053355/2023-12-10--15-31-28/96/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 2833de0636d26d55/2024-01-10--08-48-13/13/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 4ce786edc1839031/2023-11-28--16-54-10/11/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 37f27727e9056e1c/2023-12-26--13-02-45/37/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment f78ea8bac6cf6c9d/2024-01-23--16-33-11/3/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment c447f3983314c453/2024-01-22--17-23-35/18/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 74f6ab69c669f8c5/2023-12-13--12-31-14/1/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 78fdfacf4a805561/2023-11-19--18-13-39/10/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 74f6ab69c669f8c5/2023-12-05--12-30-06/75/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 74f6ab69c669f8c5/2023-12-12--15-05-24/13/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment f78ea8bac6cf6c9d/2023-10-31--17-23-16/23/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 37f27727e9056e1c/2023-12-14--15-16-25/46/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 74f6ab69c669f8c5/2023-11-08--16-14-41/2/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 37f27727e9056e1c/2023-12-05--16-12-13/8/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 2833de0636d26d55/2024-01-17--18-16-59/18/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 8fd9d7b55c053355/2023-10-28--11-46-45/34/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 37f27727e9056e1c/2023-12-22--14-41-06/23/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 37f27727e9056e1c/2023-12-08--21-11-37/12/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 201c5aaced09a24a/2023-05-20--12-39-01/15/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 1220/9107 \n",
"Non-Drive gear found in segment 201c5aaced09a24a/2023-05-20--12-39-01/15/s for HYUNDAI IONIQ PHEV 2020\n",
" ELECT_GEAR gear=4.0\n",
"Analyzing segment 1224/9107 \n",
"Non-Drive gear found in segment b28e9dbe4004e915/2023-06-11--19-55-28/2/s for HYUNDAI IONIQ PHEV 2020\n",
" ELECT_GEAR gear=4.0\n",
"Analyzing segment 74f6ab69c669f8c5/2023-11-29--15-40-46/12/s for HYUNDAI IONIQ PHEV 2020\n",
"Analyzing segment 2833de0636d26d55/2024-01-17--18-16-59/14/s for HYUNDAI IONIQ PHEV 2020\n",
"Analysis finished\n"
"Analyzing segment 9107/9107 ...Analysis finished. Total segments analyzed: 9107\n"
]
}
],
"source": [
"import copy\n",
"import sys\n",
"import time\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
Expand All @@ -141,41 +147,40 @@
"from openpilot.selfdrive.pandad import can_capnp_to_list\n",
"from openpilot.tools.lib.logreader import LogReader\n",
"\n",
"message_names = [\"ELECT_GEAR\"]\n",
"analyzed_segments_count = 0\n",
"dot_counter = 0\n",
"\n",
"print(\"Analyzing segments\", end=\"\", flush=True)\n",
"for segment in TEST_SEGMENTS:\n",
" lr = LogReader(segment)\n",
" CP = lr.first(\"carParams\")\n",
" if CP is None:\n",
" continue\n",
"\n",
" can_msgs = [msg for msg in lr if msg.which() == \"can\"]\n",
" parser_messages = []\n",
" for name in message_names:\n",
" parser_messages.append((name, 0))\n",
" parser_messages = [(\"ELECT_GEAR\", 0)]\n",
" cp = CANParser(DBC[platform][Bus.pt], parser_messages, 0)\n",
"\n",
" parsed_message_history = []\n",
" examples = []\n",
"\n",
" for msg in can_msgs:\n",
" cp.update_strings(can_capnp_to_list([msg.as_builder().to_bytes()]))\n",
" parsed_message_history.append(copy.copy(cp.vl))\n",
"\n",
" print(f\"Analyzing segment {segment:<44} for {CP.carFingerprint}\")\n",
" for name in message_names:\n",
" if parsed_message_history[0][name][\"Elect_Gear_Shifter\"] != 0: # Message is present for this segment\n",
" gear_prev = parsed_message_history[0][name][\"Elect_Gear_Shifter\"]\n",
" if gear_prev == 4.0:\n",
" print(f\" {name:<15} gear={gear_prev}\")\n",
" for i, parsed_messages in enumerate(parsed_message_history):\n",
" gear = parsed_messages[name][\"Elect_Gear_Shifter\"]\n",
" if gear != gear_prev:\n",
" print(f\" *** Signal transition found! ***\")\n",
" examples.append(i)\n",
" gear_prev = gear\n",
"\n",
"print(f\"Analysis finished\")\n"
" for message in parsed_message_history:\n",
" if message[\"ELECT_GEAR\"][\"Elect_Gear_Shifter\"] in (4, 4.0): # Sport gear\n",
" gear = message[\"ELECT_GEAR\"][\"Elect_Gear_Shifter\"]\n",
" print(f\"\\nNon-Drive gear found in segment {segment:<44} for {CP.carFingerprint}\")\n",
" print(f\" {\"ELECT_GEAR\":<15} gear={gear}\")\n",
" break\n",
"\n",
" analyzed_segments_count += 1\n",
"\n",
" dot_counter = (dot_counter + 1) % 4\n",
" sys.stdout.write(f\"\\rAnalyzing segment {analyzed_segments_count}/{len(TEST_SEGMENTS)} {'.' * dot_counter}{' ' * (3 - dot_counter)}\")\n",
" sys.stdout.flush()\n",
"\n",
"print(f\"Analysis finished. Total segments analyzed: {analyzed_segments_count}\")\n"
]
},
{
Expand Down

0 comments on commit 0ae9a19

Please sign in to comment.