Skip to content

Commit

Permalink
Merge remote-tracking branch 'commaai/cereal/master' into sync-20240201
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyhaibin committed Feb 2, 2024
2 parents d3d5b06 + c54369f commit b8dd36f
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions car.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ struct CarEvent @0x9b1657f34caf3ad3 {
parkBrake @29;
manualRestart @30;
lowSpeedLockout @31;
plannerError @32;
joystickDebug @34;
steerTempUnavailableSilent @35;
resumeRequired @36;
Expand Down Expand Up @@ -162,6 +161,7 @@ struct CarEvent @0x9b1657f34caf3ad3 {
startupFuzzyFingerprintDEPRECATED @97;
noTargetDEPRECATED @25;
brakeUnavailableDEPRECATED @2;
plannerErrorDEPRECATED @32;
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
47 changes: 41 additions & 6 deletions log.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -166,6 +167,7 @@ struct FrameData {
unknown @0;
ar0231 @1;
ox03c10 @2;
os04c10 @3;
}

frameLengthDEPRECATED @3 :Int32;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -494,6 +518,7 @@ struct PandaState @0xa7649e2575e4591e {
redPanda @7;
redPandaV2 @8;
tres @9;
cuatro @10;
}

enum HarnessStatus {
Expand Down Expand Up @@ -541,6 +566,7 @@ struct PandaState @0xa7649e2575e4591e {
}
}

gasInterceptorDetectedDEPRECATED @4 :Bool;
startedSignalDetectedDEPRECATED @5 :Bool;
hasGpsDEPRECATED @6 :Bool;
fanSpeedRpmDEPRECATED @11 :UInt16;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -954,6 +984,9 @@ struct ModelDataV2 {
yawRateStd @7 :List(Float32);
}

struct Action {
desiredCurvature @0 :Float32;
}
}

struct EncodeIndex {
Expand Down Expand Up @@ -2167,6 +2200,8 @@ struct EncodeData {
data @1 :Data;
header @2 :Data;
unixTimestampNanos @3 :UInt64;
width @4 :UInt32;
height @5 :UInt32;
}

struct UserFlag {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -2335,5 +2369,6 @@ struct Event {
pandaStateDEPRECATED @12 :PandaState;
driverStateDEPRECATED @59 :DriverStateDEPRECATED;
sensorEventsDEPRECATED @11 :List(SensorEventData);
lateralPlanDEPRECATED @64 :LateralPlan;
}
}
21 changes: 13 additions & 8 deletions messaging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}
Expand All @@ -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:
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion messaging/tests/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
13 changes: 4 additions & 9 deletions visionipc/visionipc_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@
#include <iostream>
#include <thread>

#include <unistd.h>
#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;
}
Expand Down
3 changes: 0 additions & 3 deletions visionipc/visionipc_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

#include <set>
#include <string>
#include <vector>
#include <unistd.h>

#include "cereal/messaging/messaging.h"
#include "cereal/visionipc/visionipc.h"
#include "cereal/visionipc/visionbuf.h"

class VisionIpcClient {
Expand Down
20 changes: 11 additions & 9 deletions visionipc/visionipc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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());
}


Expand Down
2 changes: 1 addition & 1 deletion visionipc/visionipc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include <map>

#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:
Expand Down

0 comments on commit b8dd36f

Please sign in to comment.