diff --git a/README.md b/README.md index 24596f4b3..7af20f07b 100644 --- a/README.md +++ b/README.md @@ -52,11 +52,18 @@ Supported Cars - By default it uses stock Toyota ACC for longitudinal control - openpilot longitudinal control available after unplugging the [Driving Support ECU](https://community.comma.ai/wiki/index.php/Toyota#Corolla_.28for_openpilot.29) and can be enabled above 20 mph +- Lexus RX 2017 hybrid (alpha!) + - By default it uses stock Lexus ACC for longitudinal control + - openpilot longitudinal control available after unplugging the [Driving Support ECU](https://community.comma.ai/wiki/index.php/Toyota#Lexus_RX_hybrid) + In Progress Cars ------ -- Probably all TSS-P Toyota with Steering Assist. +- All TSS-P Toyota with Steering Assist. - 'Full Speed Range Dynamic Radar Cruise Control' is required to enable stop-and-go. Only the Prius, Camry and C-HR have this option. - Even though the Tundra, Sequoia and the Land Cruiser have TSS-P, they don't have Steering Assist and are not supported. +- All LSS-P Lexus with Steering Assist or Lane Keep Assist. + - 'All-Speed Range Dynamic Radar Cruise Control' is required to enable stop-and-go. Only the GS, GSH, GS, F, RX, RXH, LX, NX, NXH, LC, LCH, LS, LSH have this option. + - Even though the LX have TSS-P, it does not have Steering Assist and is not supported. Community WIP Cars ------ diff --git a/RELEASES.md b/RELEASES.md index 4e0c81fe8..1acd4fc8f 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,8 +1,17 @@ +Version 0.4.2 (2018-02-05) +========================== + * Add alpha support for 2017 Lexus RX Hybrid + * Add alpha support for 2018 ACURA RDX + * Updated fingerprint to include Toyota Rav4 SE and Prius Prime + * Bugfixes for Acura ILX and Honda Odyssey + Version 0.4.1 (2018-01-30) ========================== * Add alpha support for 2017 Toyota Corolla + * Add alpha support for 2018 Honda Odyssey with Honda Sensing * Add alpha support for Grey Panda * Refactored car abstraction layer to make car ports easier + * Increased steering torque limit on Honda CR-V by 30% Version 0.4.0.2 (2018-01-18) ========================== diff --git a/SAFETY.md b/SAFETY.md index 125705ad0..0c8ae7e51 100644 --- a/SAFETY.md +++ b/SAFETY.md @@ -42,7 +42,7 @@ Honda/Acura - Honda CAN uses both a counter and a checksum to ensure integrity and prevent replay of the same message. -Toyota +Toyota/Lexus ------ - While the system is engaged, gas, brake and steer limits are subject to the same limits used by @@ -59,7 +59,7 @@ Toyota software to a value of -1500 and 1500. In addition, the vehicle EPS unit will not respond to commands outside these limits. A steering torque rate limit is enforced by the board and in software so that the commanded steering torque must rise from 0 to max value no faster than - 1.5s. Commanded steering torque is limited by the board and in software to be no more than 500 + 1.5s. Commanded steering torque is limited by the board and in software to be no more than 350 units above the actual EPS generated motor torque to ensure limited differences between commanded and actual torques. diff --git a/common/dbc.py b/common/dbc.py index 8be1eed13..cc914f9d6 100755 --- a/common/dbc.py +++ b/common/dbc.py @@ -214,8 +214,6 @@ class dbc(object): return [sgs.name for sgs in self.msgs[msg][1]] if __name__ == "__main__": - import sys - import os from opendbc import DBC_PATH dbc_test = dbc(os.path.join(DBC_PATH, sys.argv[1])) diff --git a/common/fingerprints.py b/common/fingerprints.py index 3a4fdfa95..1e0c71da4 100644 --- a/common/fingerprints.py +++ b/common/fingerprints.py @@ -11,6 +11,7 @@ class TOYOTA: RAV4H = "TOYOTA RAV4 2017 HYBRID" RAV4 = "TOYOTA RAV4 2017" COROLLA = "TOYOTA COROLLA 2017" + LEXUS_RXH = "LEXUS RX HYBRID 2017" _FINGERPRINTS = { @@ -36,10 +37,10 @@ _FINGERPRINTS = { 57L: 3, 148L: 8, 228L: 5, 229L: 4, 316L: 8, 342L: 6, 344L: 8, 380L: 8, 399L: 7, 411L: 5, 419L: 8, 420L: 8, 427L: 3, 432L: 7, 450L: 8, 463L: 8, 464L: 8, 476L: 4, 490L: 8, 506L: 8, 542L: 7, 545L: 6, 597L: 8, 662L: 4, 773L: 7, 777L: 8, 780L: 8, 795L: 8, 800L: 8, 804L: 8, 806L: 8, 808L: 8, 817L: 4, 819L: 7, 821L: 5, 825L: 4, 829L: 5, 837L: 5, 856L: 7, 862L: 8, 871L: 8, 881L: 8, 882L: 4, 884L: 8, 891L: 8, 892L: 8, 905L: 8, 923L: 2, 927L: 8, 929L: 8, 963L: 8, 965L: 8, 966L: 8, 967L: 8, 983L: 8, 985L: 3, 1029L: 8, 1036L: 8, 1052L: 8, 1064L: 7, 1088L: 8, 1089L: 8, 1092L: 1, 1108L: 8, 1110L: 8, 1125L: 8, 1296L: 8, 1302L: 8, 1600L: 5, 1601L: 8, 1612L: 5, 1613L: 5, 1614L: 5, 1615L: 8, 1616L: 5, 1619L: 5, 1623L: 5, 1668L: 5 }, TOYOTA.RAV4: { - 36L: 8, 37L: 8, 170L: 8, 180L: 8, 186L: 4, 426L: 6, 452L: 8, 464L: 8, 466L: 8, 467L: 8, 547L: 8, 548L: 8, 552L: 4, 562L: 4, 608L: 8, 610L: 5, 643L: 7, 705L: 8, 725L: 2, 740L: 5, 800L: 8, 835L: 8, 836L: 8, 849L: 4, 869L: 7, 870L: 7, 871L: 2, 896L: 8, 897L: 8, 900L: 6, 902L: 6, 905L: 8, 911L: 8, 916L: 3, 918L: 7, 921L: 8, 933L: 8, 944L: 8, 945L: 8, 951L: 8, 955L: 4, 956L: 8, 979L: 2, 998L: 5, 999L: 7, 1000L: 8, 1001L: 8, 1008L: 2, 1014L: 8, 1017L: 8, 1041L: 8, 1042L: 8, 1043L: 8, 1044L: 8, 1056L: 8, 1059L: 1, 1114L: 8, 1161L: 8, 1162L: 8, 1163L: 8, 1176L: 8, 1177L: 8, 1178L: 8, 1179L: 8, 1180L: 8, 1181L: 8, 1190L: 8, 1191L: 8, 1192L: 8, 1196L: 8, 1227L: 8, 1228L: 8, 1235L: 8, 1237L: 8, 1263L: 8, 1279L: 8, 1408L: 8, 1409L: 8, 1410L: 8, 1552L: 8, 1553L: 8, 1554L: 8, 1555L: 8, 1556L: 8, 1557L: 8, 1561L: 8, 1562L: 8, 1568L: 8, 1569L: 8, 1570L: 8, 1571L: 8, 1572L: 8, 1584L: 8, 1589L: 8, 1592L: 8, 1593L: 8, 1595L: 8, 1596L: 8, 1597L: 8, 1600L: 8, 1656L: 8, 1664L: 8, 1728L: 8, 1745L: 8, 1779L: 8, 1904L: 8, 1912L: 8, 1990L: 8, 1998L: 8 + 36L: 8, 37L: 8, 170L: 8, 180L: 8, 186L: 4, 426L: 6, 452L: 8, 464L: 8, 466L: 8, 467L: 8, 547L: 8, 548L: 8, 552L: 4, 562L: 4, 608L: 8, 610L: 5, 643L: 7, 705L: 8, 725L: 2, 740L: 5, 800L: 8, 835L: 8, 836L: 8, 849L: 4, 869L: 7, 870L: 7, 871L: 2, 896L: 8, 897L: 8, 900L: 6, 902L: 6, 905L: 8, 911L: 8, 916L: 3, 918L: 7, 921L: 8, 933L: 8, 944L: 8, 945L: 8, 951L: 8, 955L: 4, 956L: 8, 979L: 2, 998L: 5, 999L: 7, 1000L: 8, 1001L: 8, 1005L: 2, 1008L: 2, 1014L: 8, 1017L: 8, 1041L: 8, 1042L: 8, 1043L: 8, 1044L: 8, 1056L: 8, 1059L: 1, 1114L: 8, 1161L: 8, 1162L: 8, 1163L: 8, 1176L: 8, 1177L: 8, 1178L: 8, 1179L: 8, 1180L: 8, 1181L: 8, 1190L: 8, 1191L: 8, 1192L: 8, 1196L: 8, 1227L: 8, 1228L: 8, 1235L: 8, 1237L: 8, 1263L: 8, 1264L: 8, 1279L: 8, 1408L: 8, 1409L: 8, 1410L: 8, 1552L: 8, 1553L: 8, 1554L: 8, 1555L: 8, 1556L: 8, 1557L: 8, 1561L: 8, 1562L: 8, 1568L: 8, 1569L: 8, 1570L: 8, 1571L: 8, 1572L: 8, 1584L: 8, 1589L: 8, 1592L: 8, 1593L: 8, 1595L: 8, 1596L: 8, 1597L: 8, 1600L: 8, 1656L: 8, 1664L: 8, 1728L: 8, 1745L: 8, 1779L: 8, 1904L: 8, 1912L: 8, 1990L: 8, 1998L: 8 }, TOYOTA.RAV4H: { - 36L: 8, 37L: 8, 170L: 8, 180L: 8, 186L: 4, 426L: 6, 452L: 8, 464L: 8, 466L: 8, 467L: 8, 547L: 8, 548L: 8, 552L: 4, 562L: 4, 608L: 8, 610L: 5, 643L: 7, 705L: 8, 725L: 2, 740L: 5, 800L: 8, 835L: 8, 836L: 8, 849L: 4, 869L: 7, 870L: 7, 871L: 2, 896L: 8, 897L: 8, 900L: 6, 902L: 6, 905L: 8, 911L: 8, 916L: 3, 918L: 7, 921L: 8, 933L: 8, 944L: 8, 945L: 8, 951L: 8, 955L: 8, 956L: 8, 979L: 2, 998L: 5, 999L: 7, 1000L: 8, 1001L: 8, 1008L: 2, 1014L: 8, 1017L: 8, 1041L: 8, 1042L: 8, 1043L: 8, 1044L: 8, 1056L: 8, 1059L: 1, 1114L: 8, 1161L: 8, 1162L: 8, 1163L: 8, 1176L: 8, 1177L: 8, 1178L: 8, 1179L: 8, 1180L: 8, 1181L: 8, 1190L: 8, 1191L: 8, 1192L: 8, 1196L: 8, 1227L: 8, 1228L: 8, 1235L: 8, 1237L: 8, 1263L: 8, 1279L: 8, 1408L: 8, 1409L: 8, 1410L: 8, 1552L: 8, 1553L: 8, 1554L: 8, 1555L: 8, 1556L: 8, 1557L: 8, 1561L: 8, 1562L: 8, 1568L: 8, 1569L: 8, 1570L: 8, 1571L: 8, 1572L: 8, 1584L: 8, 1589L: 8, 1592L: 8, 1593L: 8, 1595L: 8, 1596L: 8, 1597L: 8, 1600L: 8, 1656L: 8, 1664L: 8, 1728L: 8, 1745L: 8, 1779L: 8, 1904L: 8, 1912L: 8, 1990L: 8, 1998L: 8, 581L: 5, 296: 8, 552L: 8, 560L: 7, 552L: 4, 713L: 8, 550L: 8, 608L: 8, 37L: 8, 36L: 8, 950L: 8, 1198L: 8, 1197L: 8, 1199L: 8, 1212L: 8, 953L: 3, 1264L: 8, 1184L: 8, 1005L: 2, 1185L: 8, 1232L: 8, 1186L: 8 + 36L: 8, 37L: 8, 170L: 8, 180L: 8, 186L: 4, 426L: 6, 452L: 8, 464L: 8, 466L: 8, 467L: 8, 547L: 8, 548L: 8, 552L: 4, 562L: 4, 608L: 8, 610L: 5, 643L: 7, 705L: 8, 725L: 2, 740L: 5, 800L: 8, 835L: 8, 836L: 8, 849L: 4, 869L: 7, 870L: 7, 871L: 2, 896L: 8, 897L: 8, 900L: 6, 902L: 6, 905L: 8, 911L: 8, 916L: 3, 918L: 7, 921L: 8, 933L: 8, 944L: 8, 945L: 8, 951L: 8, 955L: 8, 956L: 8, 979L: 2, 998L: 5, 999L: 7, 1000L: 8, 1001L: 8, 1008L: 2, 1014L: 8, 1017L: 8, 1041L: 8, 1042L: 8, 1043L: 8, 1044L: 8, 1056L: 8, 1059L: 1, 1114L: 8, 1161L: 8, 1162L: 8, 1163L: 8, 1176L: 8, 1177L: 8, 1178L: 8, 1179L: 8, 1180L: 8, 1181L: 8, 1190L: 8, 1191L: 8, 1192L: 8, 1196L: 8, 1227L: 8, 1228L: 8, 1235L: 8, 1237L: 8, 1263L: 8, 1279L: 8, 1408L: 8, 1409L: 8, 1410L: 8, 1552L: 8, 1553L: 8, 1554L: 8, 1555L: 8, 1556L: 8, 1557L: 8, 1561L: 8, 1562L: 8, 1568L: 8, 1569L: 8, 1570L: 8, 1571L: 8, 1572L: 8, 1584L: 8, 1589L: 8, 1592L: 8, 1593L: 8, 1595L: 8, 1596L: 8, 1597L: 8, 1600L: 8, 1656L: 8, 1664L: 8, 1728L: 8, 1745L: 8, 1779L: 8, 1904L: 8, 1912L: 8, 1990L: 8, 1998L: 8, 581L: 5, 296: 8, 560L: 7, 713L: 8, 550L: 8, 608L: 8, 37L: 8, 36L: 8, 950L: 8, 1198L: 8, 1197L: 8, 1199L: 8, 1212L: 8, 953L: 3, 1264L: 8, 1184L: 8, 1005L: 2, 1185L: 8, 1232L: 8, 1186L: 8 }, TOYOTA.PRIUS: [{ 36L: 8, 37L: 8, 166L: 8, 170L: 8, 180L: 8, 295L: 8, 296L: 8, 426L: 6, 452L: 8, 466L: 8, 467L: 8, 550L: 8, 552L: 4, 560L: 7, 562L: 6, 581L: 5, 608L: 8, 610L: 8, 614L: 8, 643L: 7, 658L: 8, 713L: 8, 740L: 5, 742L: 8, 743L: 8, 800L: 8, 810L: 2, 814L: 8, 829L: 2, 830L: 7, 835L: 8, 836L: 8, 863L: 8, 869L: 7, 870L: 7, 871L: 2, 898L: 8, 900L: 6, 902L: 6, 905L: 8, 918L: 8, 921L: 8, 933L: 8, 944L: 8, 945L: 8, 950L: 8, 951L: 8, 953L: 8, 955L: 8, 956L: 8, 971L: 7, 975L: 5, 993L: 8, 998L: 5, 999L: 7, 1000L: 8, 1001L: 8, 1014L: 8, 1017L: 8, 1020L: 8, 1041L: 8, 1042L: 8, 1044L: 8, 1056L: 8, 1057L: 8, 1059L: 1, 1071L: 8, 1077L: 8, 1082L: 8, 1083L: 8, 1084L: 8, 1085L: 8, 1086L: 8, 1114L: 8, 1132L: 8, 1161L: 8, 1162L: 8, 1163L: 8, 1175L: 8, 1227L: 8, 1228L: 8, 1235L: 8, 1237L: 8, 1279L: 8, 1552L: 8, 1553L: 8, 1556L: 8, 1557L: 8, 1568L: 8, 1570L: 8, 1571L: 8, 1572L: 8, 1595L: 8, 1777L: 8, 1779L: 8, 1904L: 8, 1912L: 8, 1990L: 8, 1998L: 8 @@ -56,6 +57,9 @@ _FINGERPRINTS = { TOYOTA.COROLLA: { 36: 8, 37: 8, 170: 8, 180: 8, 186: 4, 426: 6, 452: 8, 464: 8, 466: 8, 467: 8, 547: 8, 548: 8, 552: 4, 608: 8, 610: 5, 643: 7, 705: 8, 740: 5, 800: 8, 835: 8, 836: 8, 849: 4, 869: 7, 870: 7, 871: 2, 896: 8, 897: 8, 900: 6, 902: 6, 905: 8, 911: 8, 916: 2, 921: 8, 933: 8, 944: 8, 945: 8, 951: 8, 955: 4, 956: 8, 979: 2, 992: 8, 998: 5, 999: 7, 1000: 8, 1001: 8, 1017: 8, 1041: 8, 1042: 8, 1043: 8, 1044: 8, 1056: 8, 1059: 1, 1114: 8, 1161: 8, 1162: 8, 1163: 8, 1196: 8, 1227: 8, 1235: 8, 1279: 8, 1552: 8, 1553: 8, 1556: 8, 1557: 8, 1561: 8, 1562: 8, 1568: 8, 1569: 8, 1570: 8, 1571: 8, 1572: 8, 1584: 8, 1589: 8, 1592: 8, 1596: 8, 1597: 8, 1600: 8, 1664: 8, 1728: 8, 1779: 8, 1904: 8, 1912: 8, 1990: 8, 1998: 8 }, + TOYOTA.LEXUS_RXH: { + 36: 8, 37: 8, 166: 8, 170: 8, 180: 8, 295: 8, 296: 8, 426: 6, 452: 8, 466: 8, 467: 8, 550: 8, 552: 4, 560: 7, 562: 6, 581: 5, 608: 8, 610: 5, 643: 7, 658: 8, 713: 8, 740: 5, 742: 8, 743: 8, 800: 8, 810: 2, 812: 3, 814: 8, 830: 7, 835: 8, 836: 8, 845: 5, 863: 8, 869: 7, 870: 7, 871: 2, 898: 8, 900: 6, 902: 6, 905: 8, 913: 8, 918: 8, 921: 8, 933: 8, 944: 8, 945: 8, 950: 8, 951: 8, 953: 8, 955: 8, 956: 8, 971: 7, 975: 6, 993: 8, 998: 5, 999: 7, 1000: 8, 1001: 8, 1005: 2, 1014: 8, 1017: 8, 1020: 8, 1041: 8, 1042: 8, 1044: 8, 1056: 8, 1059: 1, 1063: 8, 1071: 8, 1077: 8, 1082: 8, 1114: 8, 1161: 8, 1162: 8, 1163: 8, 1164: 8, 1165: 8, 1166: 8, 1167: 8, 1227: 8, 1228: 8, 1235: 8, 1237: 8, 1264: 8, 1279: 8, 1552: 8, 1553: 8, 1556: 8, 1557: 8, 1568: 8, 1570: 8, 1571: 8, 1572: 8, 1575: 8, 1595: 8, 1777: 8, 1779: 8, 1808: 8, 1810: 8, 1816: 8, 1818: 8, 1840: 8, 1848: 8, 1904: 8, 1912: 8, 1940: 8, 1941: 8, 1948: 8, 1949: 8, 1952: 8, 1956: 8, 1960: 8, 1964: 8, 1986: 8, 1990: 8, 1994: 8, 1998: 8, 2004: 8, 2012: 8 + }, } # support additional internal only fingerprints diff --git a/common/kalman/ekf.py b/common/kalman/ekf.py index feebe0883..c70431991 100644 --- a/common/kalman/ekf.py +++ b/common/kalman/ekf.py @@ -1,6 +1,5 @@ import abc import numpy as np -import numpy.matlib # The EKF class contains the framework for an Extended Kalman Filter, but must be subclassed to use. # A subclass must implement: # 1) calc_transfer_fun(); see bottom of file for more info. diff --git a/common/params.py b/common/params.py index d6503291e..b843c9b98 100755 --- a/common/params.py +++ b/common/params.py @@ -227,7 +227,7 @@ class DBWriter(DBAccessor): data_path = self._data_path() try: old_data_path = os.path.join(self._path, os.readlink(data_path)) - except (OSError, IOError) as e: + except (OSError, IOError): # NOTE(mgraczyk): If other DB implementations have bugs, this could cause # copies to be left behind, but we still want to overwrite. pass diff --git a/common/realtime.py b/common/realtime.py index e84e6eb49..b8d75db09 100644 --- a/common/realtime.py +++ b/common/realtime.py @@ -1,7 +1,6 @@ """Utilities for reading real time clocks and keeping soft real time constraints.""" import os import time -import ctypes import platform import threading import subprocess diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index 29ae70f4b..b47285730 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -451,6 +451,7 @@ void _pigeon_send(const char *dat, int len) { memcpy(&a[1], &dat[i], ll); pthread_mutex_lock(&usb_lock); err = libusb_bulk_transfer(dev_handle, 2, a, ll+1, &sent, TIMEOUT); + if (err < 0) { handle_usb_issue(err, __func__); } assert(err == 0); assert(sent == ll+1); //hexdump(a, ll+1); @@ -460,20 +461,24 @@ void _pigeon_send(const char *dat, int len) { void pigeon_set_power(int power) { pthread_mutex_lock(&usb_lock); - libusb_control_transfer(dev_handle, 0xc0, 0xd9, power, 0, NULL, 0, TIMEOUT); + int err = libusb_control_transfer(dev_handle, 0xc0, 0xd9, power, 0, NULL, 0, TIMEOUT); + if (err < 0) { handle_usb_issue(err, __func__); } pthread_mutex_unlock(&usb_lock); } void pigeon_set_baud(int baud) { + int err; pthread_mutex_lock(&usb_lock); - libusb_control_transfer(dev_handle, 0xc0, 0xe2, 1, 0, NULL, 0, TIMEOUT); - libusb_control_transfer(dev_handle, 0xc0, 0xe4, 1, baud/300, NULL, 0, TIMEOUT); + err = libusb_control_transfer(dev_handle, 0xc0, 0xe2, 1, 0, NULL, 0, TIMEOUT); + if (err < 0) { handle_usb_issue(err, __func__); } + err = libusb_control_transfer(dev_handle, 0xc0, 0xe4, 1, baud/300, NULL, 0, TIMEOUT); + if (err < 0) { handle_usb_issue(err, __func__); } pthread_mutex_unlock(&usb_lock); } void pigeon_init() { usleep(1000*1000); - LOGW("pigeon start"); + LOGW("grey panda start"); // power off pigeon pigeon_set_power(0); @@ -513,7 +518,7 @@ void pigeon_init() { pigeon_send("\xB5\x62\x06\x01\x03\x00\x01\x07\x01\x13\x51"); pigeon_send("\xB5\x62\x06\x01\x03\x00\x02\x15\x01\x22\x70"); - LOGW("pigeon is ready to fly"); + LOGW("grey panda is ready to fly"); } @@ -551,6 +556,7 @@ void *pigeon_thread(void *crap) { while (alen < 0xfc0) { pthread_mutex_lock(&usb_lock); int len = libusb_control_transfer(dev_handle, 0xc0, 0xe0, 1, 0, dat+alen, 0x40, TIMEOUT); + if (len < 0) { handle_usb_issue(len, __func__); } pthread_mutex_unlock(&usb_lock); if (len <= 0) break; diff --git a/selfdrive/can/common.h b/selfdrive/can/common.h index 6c4db6049..2741e3971 100644 --- a/selfdrive/can/common.h +++ b/selfdrive/can/common.h @@ -8,6 +8,8 @@ #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) +unsigned int honda_checksum(unsigned int address, uint64_t d, int l); +unsigned int toyota_checksum(unsigned int address, uint64_t d, int l); struct SignalPackValue { const char* name; diff --git a/selfdrive/can/libdbc_py.py b/selfdrive/can/libdbc_py.py index 4914dca6b..7495c88ad 100644 --- a/selfdrive/can/libdbc_py.py +++ b/selfdrive/can/libdbc_py.py @@ -67,7 +67,7 @@ typedef struct { void* can_init(int bus, const char* dbc_name, size_t num_message_options, const MessageParseOptions* message_options, - size_t num_signal_options, const SignalParseOptions* signal_options); + size_t num_signal_options, const SignalParseOptions* signal_options, bool sendcan); void can_update(void* can, uint64_t sec, bool wait); @@ -77,8 +77,7 @@ const DBC* dbc_lookup(const char* dbc_name); void* canpack_init(const char* dbc_name); -uint64_t canpack_pack(void* inst, uint32_t address, size_t num_vals, const SignalPackValue *vals); - +uint64_t canpack_pack(void* inst, uint32_t address, size_t num_vals, const SignalPackValue *vals, int counter); """) libdbc = ffi.dlopen(libdbc_fn) diff --git a/selfdrive/can/packer.cc b/selfdrive/can/packer.cc index 3eddc6aee..2443f10f7 100644 --- a/selfdrive/can/packer.cc +++ b/selfdrive/can/packer.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include "common.h" @@ -12,70 +13,104 @@ namespace { -class CANPacker { -public: - CANPacker(const std::string& dbc_name) { - dbc = dbc_lookup(dbc_name); - assert(dbc); - - for (int i=0; inum_msgs; i++) { - const Msg* msg = &dbc->msgs[i]; - for (int j=0; jnum_sigs; j++) { - const Signal* sig = &msg->sigs[j]; - signal_lookup[std::make_pair(msg->address, std::string(sig->name))] = *sig; + uint64_t set_value(uint64_t ret, Signal sig, int64_t ival){ + uint64_t mask = ((1ULL << sig.b2)-1) << sig.bo; + uint64_t dat = (ival & ((1ULL << sig.b2)-1)) << sig.bo; + ret &= ~mask; + ret |= dat; + return ret; + } + + class CANPacker { + public: + CANPacker(const std::string& dbc_name) { + dbc = dbc_lookup(dbc_name); + assert(dbc); + + for (int i=0; inum_msgs; i++) { + const Msg* msg = &dbc->msgs[i]; + message_lookup[msg->address] = *msg; + for (int j=0; jnum_sigs; j++) { + const Signal* sig = &msg->sigs[j]; + signal_lookup[std::make_pair(msg->address, std::string(sig->name))] = *sig; + } } } - } - uint64_t pack(uint32_t address, const std::vector &signals) { - uint64_t ret = 0; - for (const auto& sigval : signals) { - std::string name = std::string(sigval.name); - double value = sigval.value; + uint64_t pack(uint32_t address, const std::vector &signals, int counter) { + uint64_t ret = 0; + for (const auto& sigval : signals) { + std::string name = std::string(sigval.name); + double value = sigval.value; + + auto sig_it = signal_lookup.find(std::make_pair(address, name)); + if (sig_it == signal_lookup.end()) { + WARN("undefined signal %s - %d\n", name.c_str(), address); + continue; + } + auto sig = sig_it->second; + + int64_t ival = (int64_t)(round((value - sig.offset) / sig.factor)); + if (ival < 0) { + ival = (1ULL << sig.b2) + ival; + } + + ret = set_value(ret, sig, ival); + } + + if (counter >= 0){ + auto sig_it = signal_lookup.find(std::make_pair(address, "COUNTER")); + if (sig_it == signal_lookup.end()) { + WARN("COUNTER not defined\n"); + return ret; + } + auto sig = sig_it->second; - auto sig_it = signal_lookup.find(make_pair(address, name)); - if (sig_it == signal_lookup.end()) { - WARN("undefined signal %s", name.c_str()); - continue; + if (sig.type != SignalType::HONDA_COUNTER){ + WARN("COUNTER signal type not valid\n"); + } + + ret = set_value(ret, sig, counter); } - auto sig = sig_it->second; - int64_t ival = (int64_t)((value - sig.offset) / sig.factor); - if (ival < 0) { - WARN("signed pack unsupported right now"); - continue; + auto sig_it = signal_lookup.find(std::make_pair(address, "CHECKSUM")); + if (sig_it != signal_lookup.end()) { + auto sig = sig_it->second; + if (sig.type == SignalType::HONDA_CHECKSUM){ + unsigned int chksm = honda_checksum(address, ret, message_lookup[address].size); + ret = set_value(ret, sig, chksm); + } + else if (sig.type == SignalType::TOYOTA_CHECKSUM){ + unsigned int chksm = toyota_checksum(address, ret, message_lookup[address].size); + ret = set_value(ret, sig, chksm); + } else { + WARN("CHECKSUM signal type not valid\n"); + } } - uint64_t mask = ((1ULL << sig.b2)-1) << sig.bo; - uint64_t dat = (ival & ((1ULL << sig.b2)-1)) << sig.bo; - ret &= ~mask; - ret |= dat; + return ret; } - return ret; - } - -private: - const DBC *dbc = NULL; - std::map, Signal> signal_lookup; -}; + private: + const DBC *dbc = NULL; + std::map, Signal> signal_lookup; + std::map message_lookup; + }; } extern "C" { + void* canpack_init(const char* dbc_name) { + CANPacker *ret = new CANPacker(std::string(dbc_name)); + return (void*)ret; + } -void* canpack_init(const char* dbc_name) { - CANPacker *ret = new CANPacker(std::string(dbc_name)); - return (void*)ret; -} - -uint64_t canpack_pack(void* inst, uint32_t address, size_t num_vals, const SignalPackValue *vals) { - CANPacker *cp = (CANPacker*)inst; + uint64_t canpack_pack(void* inst, uint32_t address, size_t num_vals, const SignalPackValue *vals, int counter, bool checksum) { + CANPacker *cp = (CANPacker*)inst; - return cp->pack(address, std::vector(vals, vals+num_vals)); -} + return cp->pack(address, std::vector(vals, vals+num_vals), counter); + } } - diff --git a/selfdrive/can/packer.py b/selfdrive/can/packer.py index 81458f59a..5ea6e3449 100644 --- a/selfdrive/can/packer.py +++ b/selfdrive/can/packer.py @@ -1,13 +1,26 @@ import struct +import numbers from selfdrive.can.libdbc_py import libdbc, ffi class CANPacker(object): def __init__(self, dbc_name): self.packer = libdbc.canpack_init(dbc_name) + self.dbc = libdbc.dbc_lookup(dbc_name) self.sig_names = {} + self.name_to_address_and_size = {} + self.address_to_size = {} - def pack(self, addr, values): + num_msgs = self.dbc[0].num_msgs + for i in range(num_msgs): + msg = self.dbc[0].msgs[i] + + name = ffi.string(msg.name) + address = msg.address + self.name_to_address_and_size[name] = (address, msg.size) + self.address_to_size[address] = msg.size + + def pack(self, addr, values, counter): # values: [(signal_name, signal_value)] values_thing = [] @@ -22,10 +35,19 @@ class CANPacker(object): values_c = ffi.new("SignalPackValue[]", values_thing) - return libdbc.canpack_pack(self.packer, addr, len(values_thing), values_c) + return libdbc.canpack_pack(self.packer, addr, len(values_thing), values_c, counter) + + def pack_bytes(self, addr, values, counter=-1): + if isinstance(addr, numbers.Number): + size = self.address_to_size[addr] + else: + addr, size = self.name_to_address_and_size[addr] + r = struct.pack(">Q", self.pack(addr, values, counter)) + return addr, r[:size] - def pack_bytes(self, addr, values): - return struct.pack(">Q", self.pack(addr, values)) + def make_can_msg(self, addr, bus, values, counter=-1): + addr, msg = self.pack_bytes(addr, values, counter) + return [addr, 0, msg, bus] if __name__ == "__main__": diff --git a/selfdrive/can/parser.cc b/selfdrive/can/parser.cc index 828f95a93..a32844fea 100644 --- a/selfdrive/can/parser.cc +++ b/selfdrive/can/parser.cc @@ -27,19 +27,6 @@ #define MAX_BAD_COUNTER 5 -namespace { - -uint64_t read_u64_be(const uint8_t* v) { - return (((uint64_t)v[0] << 56) - | ((uint64_t)v[1] << 48) - | ((uint64_t)v[2] << 40) - | ((uint64_t)v[3] << 32) - | ((uint64_t)v[4] << 24) - | ((uint64_t)v[5] << 16) - | ((uint64_t)v[6] << 8) - | (uint64_t)v[7]); -} - unsigned int honda_checksum(unsigned int address, uint64_t d, int l) { d >>= ((8-l)*8); // remove padding d >>= 4; // remove checksum @@ -60,10 +47,24 @@ unsigned int toyota_checksum(unsigned int address, uint64_t d, int l) { unsigned int s = l; while (address) { s += address & 0xff; address >>= 8; } while (d) { s += d & 0xff; d >>= 8; } - + return s & 0xFF; } +namespace { + +uint64_t read_u64_be(const uint8_t* v) { + return (((uint64_t)v[0] << 56) + | ((uint64_t)v[1] << 48) + | ((uint64_t)v[2] << 40) + | ((uint64_t)v[3] << 32) + | ((uint64_t)v[4] << 24) + | ((uint64_t)v[5] << 16) + | ((uint64_t)v[6] << 8) + | (uint64_t)v[7]); +} + + struct MessageState { uint32_t address; unsigned int size; @@ -99,7 +100,7 @@ struct MessageState { return false; } } else if (sig.type == SignalType::TOYOTA_CHECKSUM) { - // DEBUG("CHECKSUM %d %d %018llX - %lld vs %d\n", address, size, dat, tmp, toyota_checksum(address, dat, size)); + // INFO("CHECKSUM %d %d %018llX - %lld vs %d\n", address, size, dat, tmp, toyota_checksum(address, dat, size)); if (toyota_checksum(address, dat, size) != tmp) { INFO("%X CHECKSUM FAIL\n", address); @@ -140,13 +141,19 @@ class CANParser { public: CANParser(int abus, const std::string& dbc_name, const std::vector &options, - const std::vector &sigoptions) + const std::vector &sigoptions, + bool sendcan) : bus(abus) { // connect to can on 8006 context = zmq_ctx_new(); subscriber = zmq_socket(context, ZMQ_SUB); zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, "", 0); - zmq_connect(subscriber, "tcp://127.0.0.1:8006"); + + if (sendcan) { + zmq_connect(subscriber, "tcp://127.0.0.1:8017"); + } else { + zmq_connect(subscriber, "tcp://127.0.0.1:8006"); + } dbc = dbc_lookup(dbc_name); assert(dbc); @@ -274,7 +281,7 @@ class CANParser { // extract the messages capnp::FlatArrayMessageReader cmsg(amsg); cereal::Event::Reader event = cmsg.getRoot(); - + auto cans = event.getCan(); UpdateCans(sec, cans); @@ -290,7 +297,7 @@ class CANParser { for (const auto& kv : message_states) { const auto& state = kv.second; if (sec != 0 && state.seen != sec) continue; - + for (int i=0; i(message_options, message_options+num_message_options) - : std::vector{}), - (signal_options ? std::vector(signal_options, signal_options+num_signal_options) - : std::vector{})); + (message_options ? std::vector(message_options, message_options+num_message_options) + : std::vector{}), + (signal_options ? std::vector(signal_options, signal_options+num_signal_options) + : std::vector{}), sendcan); return (void*)ret; } @@ -376,7 +384,7 @@ int main(int argc, char** argv) { {0x30c, 0}, }, std::vector{ - // sig_name, sig_address, default + // sig_name, sig_address, default {0x158, "XMISSION_SPEED", 0}, {0x1d0, "WHEEL_SPEED_FL", 0}, {0x1d0, "WHEEL_SPEED_FR", 0}, diff --git a/selfdrive/can/parser.py b/selfdrive/can/parser.py index c15fe59e4..13603b788 100644 --- a/selfdrive/can/parser.py +++ b/selfdrive/can/parser.py @@ -1,4 +1,3 @@ -import os import time from collections import defaultdict import numbers @@ -6,7 +5,7 @@ import numbers from selfdrive.can.libdbc_py import libdbc, ffi class CANParser(object): - def __init__(self, dbc_name, signals, checks=[], bus=0): + def __init__(self, dbc_name, signals, checks=[], bus=0, sendcan=False): self.can_valid = True self.vl = defaultdict(dict) self.ts = defaultdict(dict) @@ -56,12 +55,12 @@ class CANParser(object): message_options_c = ffi.new("MessageParseOptions[]", [ { - 'address': address, + 'address': msg_address, 'check_frequency': freq, - } for address, freq in message_options.iteritems()]) + } for msg_address, freq in message_options.iteritems()]) self.can = libdbc.can_init(bus, dbc_name, len(message_options_c), message_options_c, - len(signal_options_c), signal_options_c) + len(signal_options_c), signal_options_c, sendcan) self.p_can_valid = ffi.new("bool*") diff --git a/selfdrive/can/process_dbc.py b/selfdrive/can/process_dbc.py index 9acf125ab..c3cb48099 100755 --- a/selfdrive/can/process_dbc.py +++ b/selfdrive/can/process_dbc.py @@ -26,11 +26,28 @@ msgs = [(address, msg_name, msg_size, sorted(msg_sigs, key=lambda s: s.name not if can_dbc.name.startswith("honda") or can_dbc.name.startswith("acura"): checksum_type = "honda" + checksum_size = 4 elif can_dbc.name.startswith("toyota"): checksum_type = "toyota" + checksum_size = 8 else: checksum_type = None +for address, msg_name, msg_size, sigs in msgs: + for sig in sigs: + if checksum_type is not None and sig.name == "CHECKSUM": + if sig.size != checksum_size: + sys.exit("CHECKSUM is not %d bits longs %s" % (checksum_size, msg_name)) + if checksum_type == "honda" and sig.start_bit % 8 != 3: + sys.exit("CHECKSUM starts at wrong bit %s" % msg_name) + if checksum_type == "toyota" and sig.start_bit % 8 != 7: + sys.exit("CHECKSUM starts at wrong bit %s" % msg_name) + if checksum_type == "honda" and sig.name == "COUNTER": + if sig.size != 2: + sys.exit("COUNTER is not 2 bits longs %s" % msg_name) + if sig.start_bit % 8 != 5: + sys.exit("COUNTER starts at wrong bit %s" % msg_name) + # Fail on duplicate messgae names c = Counter([msg_name for address, msg_name, msg_size, sigs in msgs]) diff --git a/selfdrive/car/__init__.py b/selfdrive/car/__init__.py index 03d54cbe8..8b85dbd4a 100644 --- a/selfdrive/car/__init__.py +++ b/selfdrive/car/__init__.py @@ -1,5 +1,4 @@ import os -from cereal import car from common.realtime import sec_since_boot from common.fingerprints import eliminate_incompatible_cars, all_known_cars @@ -33,6 +32,7 @@ interfaces = { TOYOTA.RAV4: ToyotaInterface, TOYOTA.RAV4H: ToyotaInterface, TOYOTA.COROLLA: ToyotaInterface, + TOYOTA.LEXUS_RXH: ToyotaInterface, "simulator2": Sim2Interface, "mock": MockInterface @@ -63,7 +63,8 @@ def fingerprint(logcan, timeout): # message has elapsed, exit. Toyota needs higher time_fingerprint, since DSU does not # broadcast immediately if len(candidate_cars) == 1 and st is not None: - time_fingerprint = 1.0 if "TOYOTA" in candidate_cars[0] else 0.1 + # TODO: better way to decide to wait more if Toyota + time_fingerprint = 1.0 if ("TOYOTA" in candidate_cars[0] or "LEXUS" in candidate_cars[0]) else 0.1 if (ts-st) > time_fingerprint: break diff --git a/selfdrive/car/honda/carcontroller.py b/selfdrive/car/honda/carcontroller.py index f964c1eb7..c1b8d7b3d 100644 --- a/selfdrive/car/honda/carcontroller.py +++ b/selfdrive/car/honda/carcontroller.py @@ -2,7 +2,6 @@ from collections import namedtuple import os from selfdrive.boardd.boardd import can_list_to_can_capnp from selfdrive.controls.lib.drive_helpers import rate_limit -from common.realtime import sec_since_boot from common.numpy_fast import clip from . import hondacan from .values import AH @@ -115,11 +114,10 @@ class CarController(object): # **** process the car messages **** # *** compute control surfaces *** - tt = sec_since_boot() GAS_MAX = 1004 BRAKE_MAX = 1024/4 if CS.CP.carFingerprint in (CAR.CIVIC, CAR.ODYSSEY): - is_fw_modified = os.getenv("DONGLE_ID") in ['b0f5a01cf604185c'] + is_fw_modified = os.getenv("DONGLE_ID") in ['99c94dc769b5d96e'] STEER_MAX = 0x1FFF if is_fw_modified else 0x1000 elif CS.CP.carFingerprint in (CAR.CRV, CAR.ACURA_RDX): STEER_MAX = 0x3e8 # CR-V only uses 12-bits and requires a lower value (max value from energee) diff --git a/selfdrive/car/honda/carstate.py b/selfdrive/car/honda/carstate.py index 4d9892a73..374dfa343 100644 --- a/selfdrive/car/honda/carstate.py +++ b/selfdrive/car/honda/carstate.py @@ -1,7 +1,5 @@ import os -from cereal import car from common.numpy_fast import interp -import selfdrive.messaging as messaging from selfdrive.can.parser import CANParser from selfdrive.config import Conversions as CV from common.kalman.simple_kalman import KF1D @@ -120,8 +118,7 @@ def get_can_signals(CP): signals += [("MAIN_ON", "SCM_BUTTONS", 0)] elif CP.carFingerprint == CAR.ODYSSEY: dbc_f = 'honda_odyssey_exl_2018_generated.dbc' - signals += [("CAR_GAS", "GAS_PEDAL_2", 0), - ("MAIN_ON", "SCM_FEEDBACK", 0), + signals += [("MAIN_ON", "SCM_FEEDBACK", 0), ("EPB_STATE", "EPB_STATUS", 0), ("BRAKE_HOLD_ACTIVE", "VSA_STATUS", 0)] checks += [("EPB_STATUS", 50)] @@ -238,7 +235,7 @@ class CarState(object): else: self.park_brake = 0 # TODO self.brake_hold = 0 # TODO - + self.main_on = cp.vl["SCM_BUTTONS"]['MAIN_ON'] self.cruise_speed_offset = calc_cruise_offset(cp.vl["CRUISE_PARAMS"]['CRUISE_SPEED_OFFSET'], self.v_ego) @@ -246,12 +243,12 @@ class CarState(object): self.pedal_gas = cp.vl["POWERTRAIN_DATA"]['PEDAL_GAS'] # crv doesn't include cruise control - if self.CP.carFingerprint in (CAR.CRV, CAR.ACURA_RDX): - self.car_gas = self.pedal_gas + if self.CP.carFingerprint in (CAR.CRV, CAR.ODYSSEY, CAR.ACURA_RDX): + self.car_gas = self.pedal_gas else: - self.car_gas = cp.vl["GAS_PEDAL_2"]['CAR_GAS'] - - #rdx has different steer override threshold + self.car_gas = cp.vl["GAS_PEDAL_2"]['CAR_GAS'] + + #rdx has different steer override threshold if self.CP.carFingerprint in (CAR.ACURA_RDX): self.steer_override = abs(cp.vl["STEER_STATUS"]['STEER_TORQUE_SENSOR']) > 400 else: @@ -278,7 +275,6 @@ class CarState(object): if __name__ == '__main__': import zmq import time - from selfdrive.services import service_list context = zmq.Context() class CarParams(object): diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 23d68fcce..a573b3f23 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -158,7 +158,7 @@ class CarInterface(object): ret.centerToFront = centerToFront_civic ret.steerRatio = 13.0 # Civic at comma has modified steering FW, so different tuning for the Neo in that car - is_fw_modified = os.getenv("DONGLE_ID") in ['b0f5a01cf604185c'] + is_fw_modified = os.getenv("DONGLE_ID") in ['99c94dc769b5d96e'] ret.steerKp, ret.steerKi = [0.4, 0.12] if is_fw_modified else [0.8, 0.24] ret.longitudinalKpBP = [0., 5., 35.] @@ -172,7 +172,7 @@ class CarInterface(object): ret.centerToFront = ret.wheelbase * 0.37 ret.steerRatio = 15.3 # Acura at comma has modified steering FW, so different tuning for the Neo in that car - is_fw_modified = os.getenv("DONGLE_ID") in ['cb38263377b873ee'] + is_fw_modified = os.getenv("DONGLE_ID") in ['85a6c74d4ad9c310'] ret.steerKp, ret.steerKi = [0.4, 0.12] if is_fw_modified else [0.8, 0.24] ret.longitudinalKpBP = [0., 5., 35.] diff --git a/selfdrive/car/honda/radar_interface.py b/selfdrive/car/honda/radar_interface.py index fb2a68693..7cf4c7d61 100755 --- a/selfdrive/car/honda/radar_interface.py +++ b/selfdrive/car/honda/radar_interface.py @@ -1,6 +1,5 @@ #!/usr/bin/env python import os -import numpy as np from selfdrive.can.parser import CANParser diff --git a/selfdrive/car/mock/interface.py b/selfdrive/car/mock/interface.py index 4f55800c3..3db6eb65e 100755 --- a/selfdrive/car/mock/interface.py +++ b/selfdrive/car/mock/interface.py @@ -1,14 +1,9 @@ #!/usr/bin/env python -import os -import time import zmq -from common.realtime import sec_since_boot -import common.numpy_fast as np from cereal import car from selfdrive.config import Conversions as CV from selfdrive.services import service_list import selfdrive.messaging as messaging -from selfdrive.controls.lib.drive_helpers import EventTypes as ET, create_event # mocked car interface to work with chffrplus TS = 0.01 # 100Hz @@ -110,7 +105,6 @@ class CarInterface(object): ret.steeringAngle = curvature * self.CP.steerRatio * self.CP.wheelbase * CV.RAD_TO_DEG events = [] - #events.append(create_event('passive', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE])) ret.events = events return ret.as_reader() diff --git a/selfdrive/car/toyota/carcontroller.py b/selfdrive/car/toyota/carcontroller.py index f762d0fd6..3fd19f946 100644 --- a/selfdrive/car/toyota/carcontroller.py +++ b/selfdrive/car/toyota/carcontroller.py @@ -1,14 +1,10 @@ -from common.numpy_fast import clip, interp -from common.realtime import sec_since_boot +from common.numpy_fast import clip from selfdrive.boardd.boardd import can_list_to_can_capnp -from selfdrive.controls.lib.drive_helpers import rate_limit from selfdrive.car.toyota.toyotacan import make_can_msg, create_video_target,\ create_steer_command, create_ui_command, \ create_ipas_steer_command, create_accel_command, \ create_fcw_command from selfdrive.car.toyota.values import ECU, STATIC_MSGS -from common.fingerprints import TOYOTA as CAR - ACCEL_HYST_GAP = 0.02 # don't change accel command for small oscilalitons within this value ACCEL_MAX = 1500 # 1.5 m/s2 @@ -82,7 +78,6 @@ class CarController(object): pcm_cancel_cmd, hud_alert, audible_alert): # *** compute control surfaces *** - ts = sec_since_boot() # steer torque is converted back to CAN reference (positive when steering right) apply_accel = actuators.gas - actuators.brake diff --git a/selfdrive/car/toyota/carstate.py b/selfdrive/car/toyota/carstate.py index 4444ead5f..24fc85239 100644 --- a/selfdrive/car/toyota/carstate.py +++ b/selfdrive/car/toyota/carstate.py @@ -1,5 +1,4 @@ import os -import selfdrive.messaging as messaging from common.fingerprints import TOYOTA as CAR from selfdrive.can.parser import CANParser from selfdrive.config import Conversions as CV @@ -20,7 +19,8 @@ def parse_gear_shifter(can_gear, car_fingerprint): return "drive" elif can_gear == 0x4: return "brake" - elif car_fingerprint in [CAR.RAV4, CAR.RAV4H, CAR.COROLLA]: + elif car_fingerprint in [CAR.RAV4, CAR.RAV4H, + CAR.LEXUS_RXH, CAR.COROLLA]: if can_gear == 0x20: return "park" elif can_gear == 0x10: @@ -45,6 +45,8 @@ def get_can_parser(CP): dbc_f = 'toyota_rav4_2017_pt_generated.dbc' elif CP.carFingerprint == CAR.COROLLA: dbc_f = 'toyota_corolla_2017_pt_generated.dbc' + elif CP.carFingerprint == CAR.LEXUS_RXH: + dbc_f = 'lexus_rx_hybrid_2017_pt_generated.dbc' signals = [ # sig_name, sig_address, default diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 20cf8e8db..53cfbb180 100755 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -1,11 +1,7 @@ #!/usr/bin/env python -import os from common.realtime import sec_since_boot -import common.numpy_fast as np from cereal import car from selfdrive.config import Conversions as CV -from selfdrive.services import service_list -import selfdrive.messaging as messaging from selfdrive.controls.lib.drive_helpers import EventTypes as ET, create_event from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.toyota.carstate import CarState, get_can_parser @@ -79,34 +75,44 @@ class CarInterface(object): if candidate == CAR.PRIUS: ret.safetyParam = 66 # see conversion factor for STEER_TORQUE_EPS in dbc file ret.wheelbase = 2.70 - ret.steerRatio = 14.5 #TODO: find exact value for Prius + ret.steerRatio = 14.5 # TODO: find exact value for Prius ret.mass = 3045./2.205 + std_cargo + ret.steerKp, ret.steerKi = 0.6, 0.05 + ret.steerKf = 0.00006 # full torque for 10 deg at 80mph means 0.00007818594 + ret.steerRateCost = 2. elif candidate in [CAR.RAV4, CAR.RAV4H]: ret.safetyParam = 73 # see conversion factor for STEER_TORQUE_EPS in dbc file ret.wheelbase = 2.65 ret.steerRatio = 14.5 # Rav4 2017 ret.mass = 3650./2.205 + std_cargo # mean between normal and hybrid + ret.steerKp, ret.steerKi = 0.6, 0.05 + ret.steerKf = 0.00006 # full torque for 10 deg at 80mph means 0.00007818594 + ret.steerRateCost = 1. elif candidate == CAR.COROLLA: ret.safetyParam = 100 # see conversion factor for STEER_TORQUE_EPS in dbc file ret.wheelbase = 2.70 ret.steerRatio = 17.8 ret.mass = 2860./2.205 + std_cargo # mean between normal and hybrid - - ret.centerToFront = ret.wheelbase * 0.44 - - if candidate == CAR.COROLLA: ret.steerKp, ret.steerKi = 0.2, 0.05 ret.steerKf = 0.00003 # full torque for 20 deg at 80mph means 0.00007818594 - else: - ret.steerKp, ret.steerKi = 0.6, 0.05 + ret.steerRateCost = 1. + elif candidate == CAR.LEXUS_RXH: + ret.safetyParam = 100 # see conversion factor for STEER_TORQUE_EPS in dbc file + ret.wheelbase = 2.79 + ret.steerRatio = 16. # official specs say 14.8, but it does not seem right + ret.mass = 4481./2.205 + std_cargo # mean between min and max + ret.steerKp, ret.steerKi = 0.6, 0.1 ret.steerKf = 0.00006 # full torque for 10 deg at 80mph means 0.00007818594 + ret.steerRateCost = .8 + + ret.centerToFront = ret.wheelbase * 0.44 ret.longPidDeadzoneBP = [0., 9.] ret.longPidDeadzoneV = [0., .15] # min speed to enable ACC. if car can do stop and go, then set enabling speed # to a negative value, so it won't matter. - if candidate in [CAR.PRIUS, CAR.RAV4H]: # rav4 hybrid can do stop and go + if candidate in [CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH]: # rav4 hybrid can do stop and go ret.minEnableSpeed = -1. elif candidate in [CAR.RAV4, CAR.COROLLA]: # TODO: hack ICE to do stop and go ret.minEnableSpeed = 19. * CV.MPH_TO_MS @@ -154,17 +160,11 @@ class CarInterface(object): ret.longitudinalKiBP = [0., 35.] ret.longitudinalKiV = [0.54, 0.36] - if candidate in [CAR.PRIUS]: - ret.steerRateCost = 2. - elif candidate in [CAR.RAV4, CAR.RAV4H, CAR.COROLLA]: - ret.steerRateCost = 1. - return ret # returns a car.CarState def update(self, c): # ******************* do can recv ******************* - can_pub_main = [] canMonoTimes = [] self.cp.update(int(sec_since_boot() * 1e9), False) @@ -189,7 +189,7 @@ class CarInterface(object): ret.gearShifter = self.CS.gear_shifter # gas pedal - ret.gas = self.CS.car_gas / 256.0 + ret.gas = self.CS.car_gas ret.gasPressed = self.CS.pedal_gas > 0 # brake pedal diff --git a/selfdrive/car/toyota/radar_interface.py b/selfdrive/car/toyota/radar_interface.py index cd60925d0..c06f8b809 100755 --- a/selfdrive/car/toyota/radar_interface.py +++ b/selfdrive/car/toyota/radar_interface.py @@ -1,6 +1,5 @@ #!/usr/bin/env python import os -import numpy as np from selfdrive.can.parser import CANParser from cereal import car from common.realtime import sec_since_boot @@ -14,7 +13,6 @@ RADAR_MSGS = range(0x210, 0x220) def _create_radard_can_parser(): dbc_f = 'toyota_prius_2017_adas.dbc' msg_n = len(RADAR_MSGS) - msg_last = RADAR_MSGS[-1] signals = zip(['LONG_DIST'] * msg_n + ['NEW_TRACK'] * msg_n + ['LAT_DIST'] * msg_n + ['REL_SPEED'] * msg_n + ['VALID'] * msg_n, RADAR_MSGS * 5, @@ -45,7 +43,7 @@ class RadarInterface(object): while 1: tm = int(sec_since_boot() * 1e9) updated_messages.update(self.rcp.update(tm, True)) - # TODO: use msg_last + # TODO: do not hardcode last msg if 0x21f in updated_messages: break diff --git a/selfdrive/car/toyota/toyotacan.py b/selfdrive/car/toyota/toyotacan.py index 812032f8d..c4c64e45c 100644 --- a/selfdrive/car/toyota/toyotacan.py +++ b/selfdrive/car/toyota/toyotacan.py @@ -1,6 +1,4 @@ import struct -import common.numpy_fast as np -from selfdrive.config import Conversions as CV # *** Toyota specific *** @@ -9,21 +7,21 @@ def fix(msg, addr): checksum = 0 idh = (addr & 0xff00) >> 8 idl = (addr & 0xff) - + checksum = idh + idl + len(msg) + 1 for d_byte in msg: checksum += ord(d_byte) - + #return msg + chr(checksum & 0xFF) return msg + struct.pack("B", checksum & 0xFF) - - + + def make_can_msg(addr, dat, alt, cks=False): if cks: dat = fix(dat, addr) return [addr, 0, dat, alt] - - + + def create_video_target(frame, addr): counter = frame & 0xff msg = struct.pack("!BBBBBBB", counter, 0x03, 0xff, 0x00, 0x00, 0x00, 0x00) @@ -42,7 +40,7 @@ def create_ipas_steer_command(steer): move = 0x40 mode = 0x30 if steer else 0x10 - + steer_h = (steer & 0xF00) >> 8 steer_l = steer & 0xff @@ -56,11 +54,11 @@ def create_steer_command(steer, raw_cnt): counter = ((raw_cnt & 0x3f) << 1) | 0x80 if steer != 0: counter |= 1 - + # hud # 00 => Regular # 40 => Actively Steering (with beep) - # 80 => Actively Steering (without beep) + # 80 => Actively Steering (without beep) hud = 0x00 msg = struct.pack("!BhB", counter, steer, hud) @@ -86,6 +84,6 @@ def create_fcw_command(fcw): def create_ui_command(steer, sound1, sound2): - msg = struct.pack("!BBBBBBBB", 0x54, 0x04 + steer + (sound2<<4), 0x0C, 0x00, + msg = struct.pack("!BBBBBBBB", 0x54, 0x04 + steer + (sound2<<4), 0x0C, 0x00, sound1, 0x2C, 0x38, 0x02) return make_can_msg(0x412, msg, 0, False) diff --git a/selfdrive/car/toyota/values.py b/selfdrive/car/toyota/values.py index 212b45b7a..937e32209 100644 --- a/selfdrive/car/toyota/values.py +++ b/selfdrive/car/toyota/values.py @@ -7,48 +7,48 @@ class ECU: # addr: (ecu, cars, bus, 1/freq*100, vl) -STATIC_MSGS = [(0x141, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 1, 2, '\x00\x00\x00\x46'), - (0x128, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 1, 3, '\xf4\x01\x90\x83\x00\x37'), - - (0x292, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 3, '\x00\x00\x00\x00\x00\x00\x00\x9e'), - (0x283, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 3, '\x00\x00\x00\x00\x00\x00\x8c'), - (0x2E6, ECU.DSU, (CAR.PRIUS, CAR.RAV4H), 0, 3, '\xff\xf8\x00\x08\x7f\xe0\x00\x4e'), - (0x2E7, ECU.DSU, (CAR.PRIUS, CAR.RAV4H), 0, 3, '\xa8\x9c\x31\x9c\x00\x00\x00\x02'), - - (0x240, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 1, 5, '\x00\x10\x01\x00\x10\x01\x00'), - (0x241, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 1, 5, '\x00\x10\x01\x00\x10\x01\x00'), - (0x244, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 1, 5, '\x00\x10\x01\x00\x10\x01\x00'), - (0x245, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 1, 5, '\x00\x10\x01\x00\x10\x01\x00'), - (0x248, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 1, 5, '\x00\x00\x00\x00\x00\x00\x01'), - (0x344, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 5, '\x00\x00\x01\x00\x00\x00\x00\x50'), - - (0x160, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 1, 7, '\x00\x00\x08\x12\x01\x31\x9c\x51'), - (0x161, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 1, 7, '\x00\x1e\x00\x00\x00\x80\x07'), - - (0x32E, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 20, '\x00\x00\x00\x00\x00\x00\x00\x00'), - (0x33E, ECU.DSU, (CAR.PRIUS, CAR.RAV4H), 0, 20, '\x0f\xff\x26\x40\x00\x1f\x00'), - (0x365, ECU.DSU, (CAR.PRIUS, CAR.RAV4H), 0, 20, '\x00\x00\x00\x80\x03\x00\x08'), +STATIC_MSGS = [(0x141, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 1, 2, '\x00\x00\x00\x46'), + (0x128, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 1, 3, '\xf4\x01\x90\x83\x00\x37'), + + (0x292, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 3, '\x00\x00\x00\x00\x00\x00\x00\x9e'), + (0x283, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 3, '\x00\x00\x00\x00\x00\x00\x8c'), + (0x2E6, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH), 0, 3, '\xff\xf8\x00\x08\x7f\xe0\x00\x4e'), + (0x2E7, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH), 0, 3, '\xa8\x9c\x31\x9c\x00\x00\x00\x02'), + + (0x240, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 1, 5, '\x00\x10\x01\x00\x10\x01\x00'), + (0x241, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 1, 5, '\x00\x10\x01\x00\x10\x01\x00'), + (0x244, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 1, 5, '\x00\x10\x01\x00\x10\x01\x00'), + (0x245, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 1, 5, '\x00\x10\x01\x00\x10\x01\x00'), + (0x248, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 1, 5, '\x00\x00\x00\x00\x00\x00\x01'), + (0x344, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 5, '\x00\x00\x01\x00\x00\x00\x00\x50'), + + (0x160, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 1, 7, '\x00\x00\x08\x12\x01\x31\x9c\x51'), + (0x161, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 1, 7, '\x00\x1e\x00\x00\x00\x80\x07'), + + (0x32E, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 20, '\x00\x00\x00\x00\x00\x00\x00\x00'), + (0x33E, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH), 0, 20, '\x0f\xff\x26\x40\x00\x1f\x00'), + (0x365, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH), 0, 20, '\x00\x00\x00\x80\x03\x00\x08'), (0x365, ECU.DSU, (CAR.RAV4, CAR.COROLLA), 0, 20, '\x00\x00\x00\x80\xfc\x00\x08'), - (0x366, ECU.DSU, (CAR.PRIUS, CAR.RAV4H), 0, 20, '\x00\x00\x4d\x82\x40\x02\x00'), + (0x366, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH), 0, 20, '\x00\x00\x4d\x82\x40\x02\x00'), (0x366, ECU.DSU, (CAR.RAV4, CAR.COROLLA), 0, 20, '\x00\x72\x07\xff\x09\xfe\x00'), - (0x367, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 40, '\x06\x00'), + (0x367, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 40, '\x06\x00'), - (0x414, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 100, '\x00\x00\x00\x00\x00\x00\x17\x00'), - (0x489, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 100, '\x00\x00\x00\x00\x00\x00\x00'), - (0x48a, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 100, '\x00\x00\x00\x00\x00\x00\x00'), - (0x48b, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 100, '\x66\x06\x08\x0a\x02\x00\x00\x00'), - (0x4d3, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 100, '\x1C\x00\x00\x01\x00\x00\x00\x00'), - (0x130, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 1, 100, '\x00\x00\x00\x00\x00\x00\x38'), - (0x466, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4), 1, 100, '\x20\x20\xAD'), + (0x414, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 100, '\x00\x00\x00\x00\x00\x00\x17\x00'), + (0x489, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 100, '\x00\x00\x00\x00\x00\x00\x00'), + (0x48a, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 100, '\x00\x00\x00\x00\x00\x00\x00'), + (0x48b, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 100, '\x66\x06\x08\x0a\x02\x00\x00\x00'), + (0x4d3, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 100, '\x1C\x00\x00\x01\x00\x00\x00\x00'), + (0x130, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 1, 100, '\x00\x00\x00\x00\x00\x00\x38'), + (0x466, ECU.CAM, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4), 1, 100, '\x20\x20\xAD'), (0x466, ECU.CAM, (CAR.COROLLA), 1, 100, '\x24\x20\xB1'), - (0x396, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 100, '\xBD\x00\x00\x00\x60\x0F\x02\x00'), - (0x43A, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 100, '\x84\x00\x00\x00\x00\x00\x00\x00'), - (0x43B, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 100, '\x00\x00\x00\x00\x00\x00\x00\x00'), - (0x497, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 100, '\x00\x00\x00\x00\x00\x00\x00\x00'), - (0x4CC, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 100, '\x0D\x00\x00\x00\x00\x00\x00\x00'), - (0x4CB, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.RAV4, CAR.COROLLA), 0, 100, '\x0c\x00\x00\x00\x00\x00\x00\x00'), - (0x470, ECU.DSU, (CAR.PRIUS, CAR.RAV4H), 1, 100, '\x00\x00\x02\x7a'), + (0x396, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 100, '\xBD\x00\x00\x00\x60\x0F\x02\x00'), + (0x43A, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 100, '\x84\x00\x00\x00\x00\x00\x00\x00'), + (0x43B, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 100, '\x00\x00\x00\x00\x00\x00\x00\x00'), + (0x497, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 100, '\x00\x00\x00\x00\x00\x00\x00\x00'), + (0x4CC, ECU.APGS, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 100, '\x0D\x00\x00\x00\x00\x00\x00\x00'), + (0x4CB, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.RAV4, CAR.COROLLA), 0, 100, '\x0c\x00\x00\x00\x00\x00\x00\x00'), + (0x470, ECU.DSU, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH), 1, 100, '\x00\x00\x02\x7a'), ] diff --git a/selfdrive/common/version.h b/selfdrive/common/version.h index b5ca9cccd..348ff4591 100644 --- a/selfdrive/common/version.h +++ b/selfdrive/common/version.h @@ -1 +1 @@ -#define COMMA_VERSION "0.4.1-openpilot" +#define COMMA_VERSION "0.4.2-openpilot" diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 729eabf8b..483868aa3 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -73,7 +73,7 @@ def data_sample(CI, CC, thermal, calibration, health, poller, cal_status, overte overtemp_proc = any(t > 950 for t in (td.thermal.cpu0, td.thermal.cpu1, td.thermal.cpu2, td.thermal.cpu3, td.thermal.mem, td.thermal.gpu)) - overtemp_bat = td.thermal.bat > 50000 # 50c + overtemp_bat = td.thermal.bat > 60000 # 60c overtemp = overtemp_proc or overtemp_bat # under 15% of space free no enable allowed diff --git a/selfdrive/controls/lib/latcontrol.py b/selfdrive/controls/lib/latcontrol.py index 1feec0f56..74020a592 100644 --- a/selfdrive/controls/lib/latcontrol.py +++ b/selfdrive/controls/lib/latcontrol.py @@ -94,9 +94,9 @@ class LatControl(object): output_steer = 0.0 self.pid.reset() else: - dt = min(cur_time - self.angle_steers_des_time, _DT_MPC + _DT) + _DT # no greater than dt mpc + dt, to prevent too high extraps # TODO: ideally we should interp, but for tuning reasons we keep the mpc solution # constant for 0.05s. + #dt = min(cur_time - self.angle_steers_des_time, _DT_MPC + _DT) + _DT # no greater than dt mpc + dt, to prevent too high extraps #self.angle_steers_des = self.angle_steers_des_prev + (dt / _DT_MPC) * (self.angle_steers_des_mpc - self.angle_steers_des_prev) self.angle_steers_des = self.angle_steers_des_mpc steers_max = get_steer_max(VM.CP, v_ego) diff --git a/selfdrive/controls/lib/longcontrol.py b/selfdrive/controls/lib/longcontrol.py index 0257898f6..d6a7cc769 100644 --- a/selfdrive/controls/lib/longcontrol.py +++ b/selfdrive/controls/lib/longcontrol.py @@ -1,6 +1,4 @@ -import numpy as np from common.numpy_fast import clip, interp -from selfdrive.config import Conversions as CV from selfdrive.controls.lib.pid import PIController STOPPING_EGO_SPEED = 0.5 diff --git a/selfdrive/controls/lib/planner.py b/selfdrive/controls/lib/planner.py index 1772325a5..219ba42ee 100755 --- a/selfdrive/controls/lib/planner.py +++ b/selfdrive/controls/lib/planner.py @@ -7,7 +7,6 @@ import math from collections import defaultdict from common.realtime import sec_since_boot -from common.params import Params from common.numpy_fast import interp import selfdrive.messaging as messaging from selfdrive.swaglog import cloudlog diff --git a/selfdrive/controls/lib/radar_helpers.py b/selfdrive/controls/lib/radar_helpers.py index 6dbb72c5c..0fa226bc9 100644 --- a/selfdrive/controls/lib/radar_helpers.py +++ b/selfdrive/controls/lib/radar_helpers.py @@ -1,6 +1,5 @@ import os import sys -import math import platform import numpy as np diff --git a/selfdrive/controls/radard.py b/selfdrive/controls/radard.py index f02fb79e1..4ffe15cb0 100755 --- a/selfdrive/controls/radard.py +++ b/selfdrive/controls/radard.py @@ -1,8 +1,6 @@ #!/usr/bin/env python -import os import zmq import numpy as np -import numpy.matlib import importlib from collections import defaultdict from fastcluster import linkage_vector @@ -16,7 +14,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.swaglog import cloudlog from cereal import car from common.params import Params -from common.realtime import sec_since_boot, set_realtime_priority, Ratekeeper +from common.realtime import set_realtime_priority, Ratekeeper from common.kalman.ekf import EKF, SimpleSensor DEBUG = False diff --git a/selfdrive/debug/can_printer.py b/selfdrive/debug/can_printer.py index 115b54ea6..75a5ea698 100755 --- a/selfdrive/debug/can_printer.py +++ b/selfdrive/debug/can_printer.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import os import sys -import struct from collections import defaultdict from common.realtime import sec_since_boot import zmq diff --git a/selfdrive/debug/get_fingerprint.py b/selfdrive/debug/get_fingerprint.py index c4b1e9835..97476cc61 100755 --- a/selfdrive/debug/get_fingerprint.py +++ b/selfdrive/debug/get_fingerprint.py @@ -19,7 +19,8 @@ msgs = {} while True: lc = messaging.recv_sock(logcan, True) for c in lc.can: - if c.src == 0: + # read also msgs sent by EON on CAN bus 0x80 + if c.src%0x80 == 0: msgs[c.address] = len(c.dat) fingerprint = ', '.join("%d: %d" % v for v in sorted(msgs.items())) diff --git a/selfdrive/debug/getframes/getframes.py b/selfdrive/debug/getframes/getframes.py index 498716faf..8ab2811d5 100755 --- a/selfdrive/debug/getframes/getframes.py +++ b/selfdrive/debug/getframes/getframes.py @@ -1,9 +1,7 @@ #!/usr/bin/env python import os -import time import subprocess from cffi import FFI -import ctypes import numpy as np diff --git a/selfdrive/debug/test_carcontroller.py b/selfdrive/debug/test_carcontroller.py deleted file mode 100755 index d672cfb3d..000000000 --- a/selfdrive/debug/test_carcontroller.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env python -import time -import numpy as np -import zmq -from evdev import InputDevice -from select import select - -from cereal import car -from common.realtime import Ratekeeper - -import selfdrive.messaging as messaging -from selfdrive.services import service_list -from selfdrive.car import get_car - - -if __name__ == "__main__": - # ***** connect to joystick ***** - # we use a Mad Catz V.1 - dev = InputDevice("/dev/input/event8") - print dev - - button_values = [0]*7 - axis_values = [0.0, 0.0, 0.0] - - # ***** connect to car ***** - context = zmq.Context() - logcan = messaging.sub_sock(context, service_list['can'].port) - sendcan = messaging.pub_sock(context, service_list['sendcan'].port) - - CI, CP = get_car(logcan, sendcan) - CC = car.CarControl.new_message() - - rk = Ratekeeper(100) - - while 1: - # **** handle joystick **** - r, w, x = select([dev], [], [], 0.0) - if dev in r: - for event in dev.read(): - # button event - if event.type == 1: - btn = event.code - 288 - if btn >= 0 and btn < 7: - button_values[btn] = int(event.value) - - # axis move event - if event.type == 3: - if event.code < 3: - if event.code == 2: - axis_values[event.code] = np.clip((255-int(event.value))/250.0, 0.0, 1.0) - else: - DEADZONE = 5 - if event.value-DEADZONE < 128 and event.value+DEADZONE > 128: - event.value = 128 - axis_values[event.code] = np.clip((int(event.value)-128)/120.0, -1.0, 1.0) - - print axis_values, button_values - # **** handle car **** - - CS = CI.update(CC) - #print CS - CC = car.CarControl.new_message() - - - CC.enabled = True - - CC.gas = float(np.clip(-axis_values[1], 0, 1.0)) - CC.brake = float(np.clip(axis_values[1], 0, 1.0)) - CC.steeringTorque = float(-axis_values[0]) - - CC.hudControl.speedVisible = bool(button_values[1]) - CC.hudControl.lanesVisible = bool(button_values[2]) - CC.hudControl.leadVisible = bool(button_values[3]) - - CC.cruiseControl.override = bool(button_values[0]) - CC.cruiseControl.cancel = bool(button_values[-1]) - - CC.hudControl.setSpeed = float(axis_values[2] * 100.0) - - # TODO: test alerts - CC.hudControl.visualAlert = "none" - CC.hudControl.audibleAlert = "none" - - #print CC - - if not CI.apply(CC): - print "CONTROLS FAILED" - - rk.keep_time() - - - diff --git a/selfdrive/debug/test_carstate.py b/selfdrive/debug/test_carstate.py deleted file mode 100755 index 98d2f7fc1..000000000 --- a/selfdrive/debug/test_carstate.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python -import os -import zmq -from cereal import car - -import selfdrive.messaging as messaging -from selfdrive.services import service_list - -from selfdrive.car import get_car - -def bpressed(CS, btype): - for b in CS.buttonEvents: - if b.type == btype: - return True - return False - -def test_loop(): - context = zmq.Context() - logcan = messaging.sub_sock(context, service_list['can'].port) - - CI, CP = get_car(logcan) - - state = 0 - - states = [ - "'seatbeltNotLatched' in CS.errors", - "CS.gasPressed", - "CS.brakePressed", - "CS.steeringPressed", - "bpressed(CS, 'leftBlinker')", - "bpressed(CS, 'rightBlinker')", - "bpressed(CS, 'cancel')", - "bpressed(CS, 'accelCruise')", - "bpressed(CS, 'decelCruise')", - "bpressed(CS, 'altButton1')", - "'doorOpen' in CS.errors", - "False"] - - while 1: - CC = car.CarControl.new_message() - # read CAN - CS = CI.update(CC) - - while eval(states[state]) == True: - state += 1 - - print "IN STATE %d: waiting for %s" % (state, states[state]) - #print CS - -if __name__ == "__main__": - test_loop() - diff --git a/selfdrive/loggerd/loggerd b/selfdrive/loggerd/loggerd index 45e458937..198ae7c77 100755 --- a/selfdrive/loggerd/loggerd +++ b/selfdrive/loggerd/loggerd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2a4054a85749c1fca49b6f13490bb370781012d20577a190b3f2e795dc00aee5 +oid sha256:1aef5754792c54dff148331a9dfe287c6e45ca2d83cac045767c99f187bcb951 size 1412368 diff --git a/selfdrive/manager.py b/selfdrive/manager.py index 1d90cca83..c374f2ef9 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -1,8 +1,6 @@ #!/usr/bin/env python2.7 - import os import sys -import time import fcntl import errno import signal @@ -53,7 +51,6 @@ from common.basedir import BASEDIR sys.path.append(os.path.join(BASEDIR, "pyextra")) os.environ['BASEDIR'] = BASEDIR -import usb1 import zmq from setproctitle import setproctitle from smbus2 import SMBus @@ -250,15 +247,19 @@ def manager_init(): if "-private" in subprocess.check_output(["git", "config", "--get", "remote.origin.url"]): upstream = "origin/master" else: - upstream = "origin/release" + if 'chffrplus' in version: + upstream = "origin/release" + else: + upstream = "origin/release2" + dirty = subprocess.call(["git", "diff-index", "--quiet", upstream, "--"]) != 0 cloudlog.info("dirty is %d" % dirty) if not dirty: os.environ['CLEAN'] = '1' - cloudlog.bind_global(dongle_id=dongle_id, version=version, dirty=dirty) + cloudlog.bind_global(dongle_id=dongle_id, version=version, dirty=dirty, is_eon=EON) crash.bind_user(id=dongle_id) - crash.bind_extra(version=version, dirty=dirty) + crash.bind_extra(version=version, dirty=dirty, is_eon=EON) os.umask(0) try: @@ -463,7 +464,7 @@ def manager_thread(): if passive and not ignition_seen: should_start = should_start or passive_starter.update(started_ts, location) - # with 2% left, we killall, otherwise the phone is bricked + # with 2% left, we killall, otherwise the phone will take a long time to boot should_start = should_start and avail > 0.02 # require usb power @@ -471,9 +472,10 @@ def manager_thread(): should_start = should_start and accepted_terms and (not do_uninstall) - # if any CPU gets above 107 or the battery gets above 53, kill all processes - # controls will warn with CPU above 95 or battery above 50 - if max_temp > 107.0 or msg.thermal.bat >= 53000: + # if any CPU gets above 107 or the battery gets above 63, kill all processes + # controls will warn with CPU above 95 or battery above 60 + if max_temp > 107.0 or msg.thermal.bat >= 63000: + # TODO: Add a better warning when this is happening should_start = False if should_start: @@ -554,7 +556,7 @@ def update_apks(): cloudlog.info("installed apks %s" % (str(installed), )) for app in installed.iterkeys(): - + apk_path = os.path.join(BASEDIR, "apk/"+app+".apk") if not os.path.exists(apk_path): apk_path = os.path.join(BASEDIR, "apk/external/out/"+app+".apk") diff --git a/selfdrive/registration.py b/selfdrive/registration.py index ff522a12e..d444ded20 100644 --- a/selfdrive/registration.py +++ b/selfdrive/registration.py @@ -1,4 +1,3 @@ -import os import json import subprocess diff --git a/selfdrive/sensord/gpsd b/selfdrive/sensord/gpsd index 3654edd38..bcd8dfda8 100755 --- a/selfdrive/sensord/gpsd +++ b/selfdrive/sensord/gpsd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:270b694abedbfa8e865b5bf769b29114e34c1664910bfc1f699c83f02a1ba319 +oid sha256:5061b6fb43d5a6caf54b615c00146bac96d807ffc0fde9509ab9295e4725d132 size 981400 diff --git a/selfdrive/sensord/sensord b/selfdrive/sensord/sensord index 89f9f0959..67dadf2be 100755 --- a/selfdrive/sensord/sensord +++ b/selfdrive/sensord/sensord @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1ed7402c2cdffdcf7b74f381c8f37cce397fd757ac74f66bd7558bbeebb04ac4 +oid sha256:00afc9dbd055acd5ade3891a690c05a0220fae7f65533decf7a82bf731034570 size 972296 diff --git a/selfdrive/test/plant/maneuver.py b/selfdrive/test/plant/maneuver.py index af370ea7b..1564aac51 100644 --- a/selfdrive/test/plant/maneuver.py +++ b/selfdrive/test/plant/maneuver.py @@ -1,5 +1,3 @@ -import os -from enum import Enum from maneuverplots import ManeuverPlot from plant import Plant import numpy as np @@ -31,7 +29,6 @@ class Maneuver(object): ) last_live100 = None - event_queue = sorted(self.cruise_button_presses, key=lambda a: a[1])[::-1] plot = ManeuverPlot(self.title) buttons_sorted = sorted(self.cruise_button_presses, key=lambda a: a[1]) diff --git a/selfdrive/test/plant/maneuverplots.py b/selfdrive/test/plant/maneuverplots.py index c0bbf6ef9..36b3e5bf8 100644 --- a/selfdrive/test/plant/maneuverplots.py +++ b/selfdrive/test/plant/maneuverplots.py @@ -63,7 +63,7 @@ class ManeuverPlot(object): def write_plot(self, path, maneuver_name): - title = self.title or maneuver_name + # title = self.title or maneuver_name # TODO: Missing plots from the old one: # long_control_state # proportional_gb, intergral_gb diff --git a/selfdrive/test/plant/plant.py b/selfdrive/test/plant/plant.py index 28eceeb16..1c97cea4b 100755 --- a/selfdrive/test/plant/plant.py +++ b/selfdrive/test/plant/plant.py @@ -11,7 +11,6 @@ from common.realtime import Ratekeeper from selfdrive.config import Conversions as CV import selfdrive.messaging as messaging from selfdrive.services import service_list -from selfdrive.config import CruiseButtons from selfdrive.car.honda.hondacan import fix from common.fingerprints import HONDA as CAR from selfdrive.car.honda.carstate import get_can_signals @@ -20,7 +19,6 @@ from selfdrive.boardd.boardd import can_capnp_to_can_list, can_list_to_can_capnp from selfdrive.car.honda.old_can_parser import CANParser from selfdrive.car.honda.interface import CarInterface -from cereal import car from common.dbc import dbc honda = dbc(os.path.join(DBC_PATH, "honda_civic_touring_2016_can_generated.dbc")) @@ -38,8 +36,7 @@ def car_plant(pos, speed, grade, gas, brake): speed_base = power_peak/force_peak rolling_res = 0.01 g = 9.81 - wheel_r = 0.31 - frontal_area = 2.2 + #frontal_area = 2.2 TODO: use it! air_density = 1.225 gas_to_peak_linear_slope = 3.33 brake_to_peak_linear_slope = 0.3 @@ -191,7 +188,6 @@ class Plant(object): # ******** run the car ******** speed, acceleration = car_plant(self.distance_prev, self.speed_prev, grade, gas, brake) - standstill = (speed == 0) distance = self.distance_prev + speed * self.ts speed = self.speed_prev + self.ts * acceleration if speed <= 0: @@ -208,7 +204,6 @@ class Plant(object): else: d_rel = 200. v_rel = 0. - a_rel = 0 lateral_pos_rel = 0. # print at 5hz @@ -312,10 +307,6 @@ class Plant(object): def plant_thread(rate=100): plant = Plant(rate) while 1: - if plant.rk.frame%100 >= 20 and plant.rk.frame%100 <= 25: - cruise_buttons = CruiseButtons.RES_ACCEL - else: - cruise_buttons = 0 plant.step() if __name__ == "__main__": diff --git a/selfdrive/test/test_openpilot.py b/selfdrive/test/test_openpilot.py index 81fd2042a..0a825e3a3 100644 --- a/selfdrive/test/test_openpilot.py +++ b/selfdrive/test/test_openpilot.py @@ -4,7 +4,6 @@ os.environ['FAKEUPLOAD'] = "1" from common.testing import phone_only from selfdrive.manager import manager_init, manager_prepare from selfdrive.manager import start_managed_process, kill_managed_process, get_running -from selfdrive.config import CruiseButtons from functools import wraps import time diff --git a/selfdrive/visiond/visiond b/selfdrive/visiond/visiond index dc093ea1d..e9d0c0bbb 100755 --- a/selfdrive/visiond/visiond +++ b/selfdrive/visiond/visiond @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bb6cd32436a8c4c5d6170222105997ab66d395974dca6e15758e9d9d49ce991e +oid sha256:1625ce5b2a59f2a67882f9ae909096a752c4964700e38bf01aa46bf176d6c0b5 size 13345424