diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ff4024930..2ff884418 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,11 +7,11 @@ repos: - id: check-executables-have-shebangs - id: check-shebang-scripts-are-executable - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.6.1 + rev: v1.8.0 hooks: - id: mypy - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.3 + rev: v0.1.9 hooks: - id: ruff - repo: local diff --git a/car.capnp b/car.capnp index 7c2c727a8..d31266293 100644 --- a/car.capnp +++ b/car.capnp @@ -51,7 +51,6 @@ struct CarEvent @0x9b1657f34caf3ad3 { parkBrake @29; manualRestart @30; lowSpeedLockout @31; - plannerError @32; joystickDebug @34; steerTempUnavailableSilent @35; resumeRequired @36; @@ -162,6 +161,7 @@ struct CarEvent @0x9b1657f34caf3ad3 { startupFuzzyFingerprintDEPRECATED @97; noTargetDEPRECATED @25; brakeUnavailableDEPRECATED @2; + plannerErrorDEPRECATED @32; } } @@ -479,9 +479,9 @@ struct CarParams { enableBsm @56 :Bool; # blind spot monitoring flags @64 :UInt32; # flags for car specific quirks experimentalLongitudinalAvailable @71 :Bool; - pcmCruiseSpeed @73 :Bool; # is openpilot's state tied to the PCM's cruise speed? - customStockLongAvailable @74 :Bool; - spFlags @75 :UInt32; # flags for car specific quirks in sunnypilot + pcmCruiseSpeed @74 :Bool; # is openpilot's state tied to the PCM's cruise speed? + customStockLongAvailable @75 :Bool; + spFlags @76 :UInt32; # flags for car specific quirks in sunnypilot minEnableSpeed @7 :Float32; minSteerSpeed @8 :Float32; @@ -533,6 +533,7 @@ struct CarParams { openpilotLongitudinalControl @37 :Bool; # is openpilot doing the longitudinal control? carVin @38 :Text; # VIN number queried during fingerprinting dashcamOnly @41: Bool; + passive @73: Bool; # is openpilot in control? transmissionType @43 :TransmissionType; carFw @44 :List(CarFw); diff --git a/log.capnp b/log.capnp index 27b4420cb..7ffb2698e 100644 --- a/log.capnp +++ b/log.capnp @@ -130,8 +130,9 @@ struct InitData { struct FrameData { frameId @0 :UInt32; - encodeId @1 :UInt32; # DEPRECATED frameIdSensor @25 :UInt32; + requestId @28 :UInt32; + encodeId @1 :UInt32; frameType @7 :FrameType; @@ -166,6 +167,7 @@ struct FrameData { unknown @0; ar0231 @1; ox03c10 @2; + os04c10 @3; } frameLengthDEPRECATED @3 :Int32; @@ -297,6 +299,29 @@ struct GpsLocationData { } } +enum Desire { + none @0; + turnLeft @1; + turnRight @2; + laneChangeLeft @3; + laneChangeRight @4; + keepLeft @5; + keepRight @6; +} + +enum LaneChangeState { + off @0; + preLaneChange @1; + laneChangeStarting @2; + laneChangeFinishing @3; +} + +enum LaneChangeDirection { + none @0; + left @1; + right @2; +} + struct CanData { address @0 :UInt32; busTime @1 :UInt16; @@ -408,7 +433,6 @@ struct DeviceState @0xa4d8b5af2aa492eb { struct PandaState @0xa7649e2575e4591e { ignitionLine @2 :Bool; - gasInterceptorDetected @4 :Bool; rxBufferOverflow @7 :UInt32; txBufferOverflow @8 :UInt32; gmlanSendErrs @9 :UInt32; @@ -494,6 +518,7 @@ struct PandaState @0xa7649e2575e4591e { redPanda @7; redPandaV2 @8; tres @9; + cuatro @10; } enum HarnessStatus { @@ -541,6 +566,7 @@ struct PandaState @0xa7649e2575e4591e { } } + gasInterceptorDetectedDEPRECATED @4 :Bool; startedSignalDetectedDEPRECATED @5 :Bool; hasGpsDEPRECATED @6 :Bool; fanSpeedRpmDEPRECATED @11 :UInt16; @@ -666,7 +692,6 @@ struct ControlsState @0x97ff69c53601abf1 { aTarget @35 :Float32; curvature @37 :Float32; # path curvature from vehicle model desiredCurvature @61 :Float32; # lag adjusted curvatures used by lateral controllers - desiredCurvatureRate @62 :Float32; forceDecel @51 :Bool; # UI alerts @@ -824,6 +849,7 @@ struct ControlsState @0x97ff69c53601abf1 { steerOverrideDEPRECATED @20 :Bool; steeringAngleDesiredDegDEPRECATED @29 :Float32; canMonoTimesDEPRECATED @21 :List(UInt64); + desiredCurvatureRateDEPRECATED @62 :Float32; } # All SI units and in device frame @@ -875,7 +901,8 @@ struct ModelDataV2 { locationMonoTime @24 :UInt64; # e2e lateral planner - lateralPlannerSolution @25: LateralPlannerSolution; + lateralPlannerSolutionDEPRECATED @25: LateralPlannerSolution; + action @26: Action; struct LeadDataV2 { prob @0 :Float32; # probability that car is your lead at time t @@ -913,6 +940,9 @@ struct ModelDataV2 { desireState @5 :List(Float32); disengagePredictions @6 :DisengagePredictions; hardBrakePredicted @7 :Bool; + laneChangeState @8 :LaneChangeState; + laneChangeDirection @9 :LaneChangeDirection; + # deprecated brakeDisengageProbDEPRECATED @2 :Float32; @@ -954,6 +984,9 @@ struct ModelDataV2 { yawRateStd @7 :List(Float32); } + struct Action { + desiredCurvature @0 :Float32; + } } struct EncodeIndex { @@ -2167,6 +2200,8 @@ struct EncodeData { data @1 :Data; header @2 :Data; unixTimestampNanos @3 :UInt64; + width @4 :UInt32; + height @5 :UInt32; } struct UserFlag { @@ -2214,7 +2249,6 @@ struct Event { carState @22 :Car.CarState; carControl @23 :Car.CarControl; longitudinalPlan @24 :LongitudinalPlan; - lateralPlan @64 :LateralPlan; uiPlan @106 :UiPlan; ubloxGnss @34 :UbloxGnss; ubloxRaw @39 :Data; @@ -2226,7 +2260,7 @@ struct Event { liveTorqueParameters @94 :LiveTorqueParametersData; cameraOdometry @63 :CameraOdometry; thumbnail @66: Thumbnail; - carEvents @68: List(Car.CarEvent); + onroadEvents @68: List(Car.CarEvent); carParams @69: Car.CarParams; driverMonitoringState @71: DriverMonitoringState; liveLocationKalman @72 :LiveLocationKalman; @@ -2335,5 +2369,6 @@ struct Event { pandaStateDEPRECATED @12 :PandaState; driverStateDEPRECATED @59 :DriverStateDEPRECATED; sensorEventsDEPRECATED @11 :List(SensorEventData); + lateralPlanDEPRECATED @64 :LateralPlan; } } diff --git a/messaging/__init__.py b/messaging/__init__.py index 57675212f..6a4740366 100644 --- a/messaging/__init__.py +++ b/messaging/__init__.py @@ -41,10 +41,13 @@ def log_from_bytes(dat: bytes) -> capnp.lib.capnp._DynamicStructReader: return msg -def new_message(service: Optional[str] = None, size: Optional[int] = None) -> capnp.lib.capnp._DynamicStructBuilder: - dat = log.Event.new_message() - dat.logMonoTime = int(time.monotonic() * 1e9) - dat.valid = True +def new_message(service: Optional[str], size: Optional[int] = None, **kwargs) -> capnp.lib.capnp._DynamicStructBuilder: + args = { + 'valid': False, + 'logMonoTime': int(time.monotonic() * 1e9), + **kwargs + } + dat = log.Event.new_message(**args) if service is not None: if size is None: dat.init(service) @@ -154,7 +157,7 @@ def recv_one_retry(sock: SubSocket) -> capnp.lib.capnp._DynamicStructReader: class SubMaster: def __init__(self, services: List[str], poll: Optional[List[str]] = None, ignore_alive: Optional[List[str]] = None, ignore_avg_freq: Optional[List[str]] = None, - addr: str = "127.0.0.1"): + ignore_valid: Optional[List[str]] = None, addr: str = "127.0.0.1"): self.frame = -1 self.updated = {s: False for s in services} self.rcv_time = {s: 0. for s in services} @@ -174,6 +177,7 @@ def __init__(self, services: List[str], poll: Optional[List[str]] = None, self.ignore_average_freq = [] if ignore_avg_freq is None else ignore_avg_freq self.ignore_alive = [] if ignore_alive is None else ignore_alive + self.ignore_valid = [] if ignore_valid is None else ignore_valid self.simulation = bool(int(os.getenv("SIMULATION", "0"))) for s in services: @@ -187,9 +191,10 @@ def __init__(self, services: List[str], poll: Optional[List[str]] = None, except capnp.lib.capnp.KjException: # pylint: disable=c-extension-no-member data = new_message(s, 0) # lists - self.data[s] = getattr(data, s) + self.data[s] = getattr(data.as_reader(), s) self.logMonoTime[s] = 0 - self.valid[s] = data.valid + # TODO: this should default to False + self.valid[s] = True def __getitem__(self, s: str) -> capnp.lib.capnp._DynamicStructReader: return self.data[s] @@ -266,7 +271,7 @@ def all_freq_ok(self, service_list=None) -> bool: def all_valid(self, service_list=None) -> bool: if service_list is None: # check all service_list = self.valid.keys() - return all(self.valid[s] for s in service_list) + return all(self.valid[s] for s in service_list if s not in self.ignore_valid) def all_checks(self, service_list=None) -> bool: if service_list is None: # check all diff --git a/messaging/tests/test_messaging.py b/messaging/tests/test_messaging.py index f9c85e0dc..ee1344de7 100755 --- a/messaging/tests/test_messaging.py +++ b/messaging/tests/test_messaging.py @@ -123,7 +123,7 @@ def test_new_message(self, evt): except capnp.lib.capnp.KjException: msg = messaging.new_message(evt, random.randrange(200)) self.assertLess(time.monotonic() - msg.logMonoTime, 0.1) - self.assertTrue(msg.valid) + self.assertFalse(msg.valid) self.assertEqual(evt, msg.which()) @parameterized.expand(events) diff --git a/services.py b/services.py index fc195d305..657f2e95f 100755 --- a/services.py +++ b/services.py @@ -58,9 +58,8 @@ def __init__(self, port: int, should_log: bool, frequency: float, decimation: Op "liveLocationKalman": (True, 20., 5), "liveParameters": (True, 20., 5), "cameraOdometry": (True, 20., 5), - "lateralPlan": (True, 20., 5), "thumbnail": (True, 0.2, 1), - "carEvents": (True, 1., 1), + "onroadEvents": (True, 1., 1), "carParams": (True, 0.02, 1), "roadCameraState": (True, 20., 20), "driverCameraState": (True, 20., 20), diff --git a/visionipc/visionipc_client.cc b/visionipc/visionipc_client.cc index 169afbb36..e3c6d0d1c 100644 --- a/visionipc/visionipc_client.cc +++ b/visionipc/visionipc_client.cc @@ -3,24 +3,19 @@ #include #include +#include #include "cereal/visionipc/ipc.h" #include "cereal/visionipc/visionipc_client.h" #include "cereal/visionipc/visionipc_server.h" #include "cereal/logger/logger.h" static int connect_to_vipc_server(const std::string &name, bool blocking) { - char* prefix = std::getenv("OPENPILOT_PREFIX"); - std::string path = "/tmp/"; - if (prefix) { - path = path + std::string(prefix) + "_"; - } - path = path + "visionipc_" + name; - - int socket_fd = ipc_connect(path.c_str()); + const std::string ipc_path = get_ipc_path(name); + int socket_fd = ipc_connect(ipc_path.c_str()); while (socket_fd < 0 && blocking) { std::cout << "VisionIpcClient connecting" << std::endl; std::this_thread::sleep_for(std::chrono::milliseconds(100)); - socket_fd = ipc_connect(path.c_str()); + socket_fd = ipc_connect(ipc_path.c_str()); } return socket_fd; } diff --git a/visionipc/visionipc_client.h b/visionipc/visionipc_client.h index d67734d32..970bac3a7 100644 --- a/visionipc/visionipc_client.h +++ b/visionipc/visionipc_client.h @@ -2,11 +2,8 @@ #include #include -#include -#include #include "cereal/messaging/messaging.h" -#include "cereal/visionipc/visionipc.h" #include "cereal/visionipc/visionbuf.h" class VisionIpcClient { diff --git a/visionipc/visionipc_server.cc b/visionipc/visionipc_server.cc index c51e13ea1..da9d11f91 100644 --- a/visionipc/visionipc_server.cc +++ b/visionipc/visionipc_server.cc @@ -22,6 +22,14 @@ std::string get_endpoint_name(std::string name, VisionStreamType type){ } } +std::string get_ipc_path(const std::string& name) { + std::string path = "/tmp/"; + if (char* prefix = std::getenv("OPENPILOT_PREFIX")) { + path += std::string(prefix) + "_"; + } + return path + "visionipc_" + name; +} + VisionIpcServer::VisionIpcServer(std::string name, cl_device_id device_id, cl_context ctx) : name(name), device_id(device_id), ctx(ctx) { msg_ctx = Context::create(); @@ -83,14 +91,8 @@ void VisionIpcServer::start_listener(){ void VisionIpcServer::listener(){ std::cout << "Starting listener for: " << name << std::endl; - char* prefix = std::getenv("OPENPILOT_PREFIX"); - std::string path = "/tmp/"; - if (prefix) { - path = path + std::string(prefix) + "_"; - } - path = path + "visionipc_" + name; - - int sock = ipc_bind(path.c_str()); + const std::string ipc_path = get_ipc_path(name); + int sock = ipc_bind(ipc_path.c_str()); assert(sock >= 0); while (!should_exit){ @@ -160,7 +162,7 @@ void VisionIpcServer::listener(){ std::cout << "Stopping listener for: " << name << std::endl; close(sock); - unlink(path.c_str()); + unlink(ipc_path.c_str()); } diff --git a/visionipc/visionipc_server.h b/visionipc/visionipc_server.h index 6ad86f146..c494b1fcf 100644 --- a/visionipc/visionipc_server.h +++ b/visionipc/visionipc_server.h @@ -6,10 +6,10 @@ #include #include "cereal/messaging/messaging.h" -#include "cereal/visionipc/visionipc.h" #include "cereal/visionipc/visionbuf.h" std::string get_endpoint_name(std::string name, VisionStreamType type); +std::string get_ipc_path(const std::string &name); class VisionIpcServer { private: